Files
TheRock/rocm-systems/projects/clr/opencl/tests/ocltst/module/runtime/OCLDynamic.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

206 lines
6.6 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include "OCLDynamic.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "CL/cl.h"
#if EMU_ENV
static const cl_uint TotalElements = 1;
#else
static const cl_uint TotalElements = 128;
#endif // EMU_ENV
static cl_uint hostArray[TotalElements];
#define KERNEL_CODE(...) #__VA_ARGS__
const static char* strKernel[] = {
KERNEL_CODE(
\n void block_fn(int tid, int mul, __global uint* res) { res[tid] = mul * 7 - 21; }
__kernel void dynamic(__global uint* res) {
int multiplier = 3;
int tid = get_global_id(0);
void (^kernelBlock)(void) = ^{
block_fn(tid, multiplier, res);
};
res[tid] = -1;
queue_t def_q = get_default_queue();
ndrange_t ndrange = ndrange_1D(1);
int enq_res;
do {
enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_NO_WAIT, ndrange, kernelBlock);
if (enq_res != 0 /*CL_SUCCESS*/) {
res[tid] = -2;
}
} while (enq_res != 0);
}
\n),
KERNEL_CODE(
\n void block_fn(int tid, int mul, __global uint* res) { res[tid] = mul * 7 - 21; }
__kernel void dynamic(__global uint* res, queue_t def_q) {
int multiplier = 3;
int tid = get_global_id(0);
void (^kernelBlock)(void) = ^{
block_fn(tid, multiplier, res);
};
res[tid] = -1;
ndrange_t ndrange = ndrange_1D(1);
// if (tid == 0) {
int enq_res = enqueue_kernel(def_q, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, kernelBlock);
if (enq_res != 0 /*CL_SUCCESS*/) {
res[tid] = -2;
return;
}
//}
}
\n)};
OCLDynamic::OCLDynamic() {
_numSubTests = 2;
deviceQueue_ = NULL;
failed_ = false;
}
OCLDynamic::~OCLDynamic() {}
void OCLDynamic::open(unsigned int test, char* units, double& conversion, unsigned int deviceId) {
// FIXME: Re-enable CPU test once bug 10143 is fixed.
if (type_ == CL_DEVICE_TYPE_CPU) {
return;
}
OCLTestImp::open(test, units, conversion, deviceId);
CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test");
testID_ = test;
size_t param_size = 0;
char* strVersion = 0;
error_ = _wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, 0, 0, &param_size);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed");
strVersion = new char[param_size];
error_ =
_wrapper->clGetDeviceInfo(devices_[_deviceId], CL_DEVICE_VERSION, param_size, strVersion, 0);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed");
if (strVersion[7] < '2') {
failed_ = true;
return;
}
delete strVersion;
char dbuffer[1024] = {0};
program_ = _wrapper->clCreateProgramWithSource(context_, 1, &strKernel[test], NULL, &error_);
CHECK_RESULT((error_ != CL_SUCCESS), "clCreateProgramWithSource() failed");
error_ = _wrapper->clBuildProgram(program_, 1, &devices_[deviceId], "-cl-std=CL2.0", NULL, NULL);
if (error_ != CL_SUCCESS) {
char programLog[1024];
_wrapper->clGetProgramBuildInfo(program_, devices_[deviceId], CL_PROGRAM_BUILD_LOG, 1024,
programLog, 0);
printf("\n%s\n", programLog);
fflush(stdout);
}
CHECK_RESULT((error_ != CL_SUCCESS), "clBuildProgram() failed");
kernel_ = _wrapper->clCreateKernel(program_, "dynamic", &error_);
CHECK_RESULT((error_ != CL_SUCCESS), "clCreateKernel() failed");
cl_mem buffer;
memset(hostArray, 0xee, sizeof(hostArray));
buffer = _wrapper->clCreateBuffer(context_, CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
sizeof(hostArray), &hostArray, &error_);
CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed");
buffers_.push_back(buffer);
#if EMU_ENV
cl_uint queueSize = 1;
#else
cl_uint queueSize = (test == 0) ? 1 : 257 * 1024;
#endif // EMU_ENV
#if defined(CL_VERSION_2_0)
const cl_queue_properties cprops[] = {
CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties>(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
CL_QUEUE_ON_DEVICE_DEFAULT | CL_QUEUE_ON_DEVICE),
CL_QUEUE_SIZE, queueSize, 0};
deviceQueue_ =
_wrapper->clCreateCommandQueueWithProperties(context_, devices_[deviceId], cprops, &error_);
CHECK_RESULT((error_ != CL_SUCCESS), "clCreateCommandQueueWithProperties() failed");
#endif
}
static void CL_CALLBACK notify_callback(const char* errinfo, const void* private_info, size_t cb,
void* user_data) {}
void OCLDynamic::run(void) {
// FIXME: Re-enable CPU test once bug 10143 is fixed.
if (type_ == CL_DEVICE_TYPE_CPU) {
return;
}
if (failed_) return;
cl_mem buffer = buffers()[0];
size_t gws[1] = {TotalElements};
size_t lws[1] = {16};
error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), &buffer);
CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed");
if (testID_ == 1) {
error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_command_queue), &deviceQueue_);
CHECK_RESULT((error_ != CL_SUCCESS), "clSetKernelArg() failed");
}
size_t offset = 0;
size_t region = TotalElements * sizeof(cl_uint);
cl_uint* host = reinterpret_cast<cl_uint*>(_wrapper->clEnqueueMapBuffer(
cmdQueues_[_deviceId], buffer, CL_TRUE, (CL_MAP_READ | CL_MAP_WRITE), offset, region, 0, NULL,
NULL, &error_));
CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueMapBuffer() failed");
error_ = _wrapper->clEnqueueNDRangeKernel(cmdQueues_[_deviceId], kernel_, 1,
#if EMU_ENV
NULL, gws, NULL, 0, NULL, NULL);
#else
NULL, gws, lws, 0, NULL, NULL);
#endif // EMU_ENV
CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueNDRangeKernel() failed");
_wrapper->clFinish(cmdQueues_[_deviceId]);
for (unsigned int i = 0; i < TotalElements; ++i) {
if (host[i] != 0) {
printf("Bad value: a[%d] = %d\n", i, host[i]);
CHECK_RESULT(true, "Incorrect result for dependency!\n");
}
}
error_ = _wrapper->clEnqueueUnmapMemObject(cmdQueues_[_deviceId], buffer, host, 0, NULL, NULL);
CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueUnmapBuffer() failed");
_wrapper->clFinish(cmdQueues_[_deviceId]);
}
unsigned int OCLDynamic::close(void) {
// FIXME: Re-enable CPU test once bug 10143 is fixed.
if (type_ == CL_DEVICE_TYPE_CPU) {
return 0;
}
if (NULL != deviceQueue_) {
_wrapper->clReleaseCommandQueue(deviceQueue_);
}
return OCLTestImp::close();
}