SWDEV-470698 - fix formatting, add format check workflow (#657)

This commit is contained in:
Danylo Lytovchenko authored and GitHub committed 2025-08-20 19:58:06 +05:30
1 bovenliggende 5840940caa
commit f7338717ae
1574 files changed
+162903 -199277

No files matched your search

@@ -36,16 +36,14 @@
#define NUM_TYPES 6
static const cl_image_format formats[NUM_TYPES] = {
{CL_R, CL_UNSIGNED_INT8}, {CL_RG, CL_UNSIGNED_INT8},
{CL_RGBA, CL_UNSIGNED_INT8}, {CL_R, CL_FLOAT},
{CL_RGBA, CL_HALF_FLOAT}, {CL_RGBA, CL_FLOAT}};
static const char *types[NUM_TYPES] = {
"R8", "R8G8", "R8G8B8A8", "R32F", "R16G16B16A16F", "R32G32B32A32F"};
{CL_R, CL_UNSIGNED_INT8}, {CL_RG, CL_UNSIGNED_INT8}, {CL_RGBA, CL_UNSIGNED_INT8},
{CL_R, CL_FLOAT}, {CL_RGBA, CL_HALF_FLOAT}, {CL_RGBA, CL_FLOAT}};
static const char* types[NUM_TYPES] = {"R8", "R8G8", "R8G8B8A8",
"R32F", "R16G16B16A16F", "R32G32B32A32F"};
static const unsigned int typeSizes[NUM_TYPES] = {1, 2, 4, 4, 8, 16};
#define NUM_SIZES 12
static const unsigned int sizes[NUM_SIZES] = {1, 2, 4, 8, 16, 32,
64, 128, 256, 512, 1024, 2048};
static const unsigned int sizes[NUM_SIZES] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
#define NUM_BUFS 6
#define MAX_BUFS (1 << (NUM_BUFS - 1))
@@ -97,12 +95,11 @@ void OCLPerfImageSampleRate::setData(cl_mem buffer, unsigned int val) {
size_t region[3] = {width_, width_, 1};
size_t image_row_pitch;
size_t image_slice_pitch;
unsigned int *data = (unsigned int *)_wrapper->clEnqueueMapImage(
cmd_queue_, buffer, true, CL_MAP_WRITE, origin, region, &image_row_pitch,
&image_slice_pitch, 0, NULL, NULL, &error_);
unsigned int* data = (unsigned int*)_wrapper->clEnqueueMapImage(
cmd_queue_, buffer, true, CL_MAP_WRITE, origin, region, &image_row_pitch, &image_slice_pitch,
0, NULL, NULL, &error_);
for (unsigned int i = 0; i < width_ * width_; i++) data[i] = val;
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL,
NULL);
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, NULL);
}
void OCLPerfImageSampleRate::checkData(cl_mem buffer) {
@@ -119,16 +116,15 @@ void OCLPerfImageSampleRate::checkData(cl_mem buffer) {
#endif
}
static void CL_CALLBACK notify_callback(const char *errinfo,
const void *private_info, size_t cb,
void *user_data) {}
static void CL_CALLBACK notify_callback(const char* errinfo, const void* private_info, size_t cb,
void* user_data) {}
void OCLPerfImageSampleRate::open(unsigned int test, char *units,
double &conversion, unsigned int deviceId) {
void OCLPerfImageSampleRate::open(unsigned int test, char* units, double& conversion,
unsigned int deviceId) {
cl_uint numPlatforms;
cl_platform_id platform = NULL;
cl_uint num_devices = 0;
cl_device_id *devices = NULL;
cl_device_id* devices = NULL;
cl_device_id device = NULL;
_crcword = 0;
conversion = 1.0f;
@@ -150,83 +146,74 @@ void OCLPerfImageSampleRate::open(unsigned int test, char *units,
error_ = _wrapper->clGetPlatformIDs(0, NULL, &numPlatforms);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed");
if (0 < numPlatforms) {
cl_platform_id *platforms = new cl_platform_id[numPlatforms];
cl_platform_id* platforms = new cl_platform_id[numPlatforms];
error_ = _wrapper->clGetPlatformIDs(numPlatforms, platforms, NULL);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetPlatformIDs failed");
platform = platforms[_platformIndex];
num_devices = 0;
/* Get the number of requested devices */
error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL,
&num_devices);
error_ = _wrapper->clGetDeviceIDs(platforms[_platformIndex], type_, 0, NULL, &num_devices);
delete platforms;
}
/*
* If we could find a platform, use it.
*/
CHECK_RESULT(platform == 0,
"Couldn't find platform with GPU devices, cannot proceed");
CHECK_RESULT(platform == 0, "Couldn't find platform with GPU devices, cannot proceed");
devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
devices = (cl_device_id*)malloc(num_devices * sizeof(cl_device_id));
CHECK_RESULT(devices == 0, "no devices");
/* Get the requested device */
error_ =
_wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL);
error_ = _wrapper->clGetDeviceIDs(platform, type_, num_devices, devices, NULL);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed");
CHECK_RESULT(_deviceId >= num_devices, "Requested deviceID not available");
device = devices[_deviceId];
size_t size;
cl_bool imageSupport_ = false;
error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT,
sizeof(imageSupport_), &imageSupport_, &size);
error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, sizeof(imageSupport_),
&imageSupport_, &size);
if (!imageSupport_) {
printf("\n%s\n", "Image not supported, skipping this test!");
skip_ = true;
return;
}
context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL,
&error_);
context_ = _wrapper->clCreateContext(NULL, 1, &device, notify_callback, NULL, &error_);
CHECK_RESULT(context_ == 0, "clCreateContext failed");
char charbuf[1024];
size_t retsize;
error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024,
charbuf, &retsize);
error_ = _wrapper->clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 1024, charbuf, &retsize);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed");
cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL);
CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed");
inBuffer_ = (cl_mem *)malloc(sizeof(cl_mem) * numBufs_);
inBuffer_ = (cl_mem*)malloc(sizeof(cl_mem) * numBufs_);
memset(inBuffer_, 0, sizeof(cl_mem) * numBufs_);
for (unsigned int i = 0; i < numBufs_; i++) {
inBuffer_[i] = _wrapper->clCreateImage2D(context_, CL_MEM_READ_ONLY,
&formats[typeIdx_], width_, width_,
0, NULL, &error_);
inBuffer_[i] = _wrapper->clCreateImage2D(context_, CL_MEM_READ_ONLY, &formats[typeIdx_], width_,
width_, 0, NULL, &error_);
CHECK_RESULT(inBuffer_[i] == 0, "clCreateImage2D(inBuffer) failed");
}
outBufSize_ = sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * sizeof(cl_float4);
outBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY,
outBufSize_, NULL, &error_);
outBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_WRITE_ONLY, outBufSize_, NULL, &error_);
CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed");
setKernel();
char *tmp = (char *)shader_.c_str();
program_ = _wrapper->clCreateProgramWithSource(
context_, 1, (const char **)&tmp, NULL, &error_);
char* tmp = (char*)shader_.c_str();
program_ = _wrapper->clCreateProgramWithSource(context_, 1, (const char**)&tmp, NULL, &error_);
CHECK_RESULT(program_ == 0, "clCreateProgramWithSource failed");
const char *buildOps = NULL;
const char* buildOps = NULL;
error_ = _wrapper->clBuildProgram(program_, 1, &device, buildOps, NULL, NULL);
if (error_ != CL_SUCCESS) {
cl_int intError;
char log[16384];
intError =
_wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG,
16384 * sizeof(char), log, NULL);
intError = _wrapper->clGetProgramBuildInfo(program_, device, CL_PROGRAM_BUILD_LOG,
16384 * sizeof(char), log, NULL);
printf("Build error -> %s\n", log);
CHECK_RESULT(0, "clBuildProgram failed");
@@ -234,20 +221,16 @@ void OCLPerfImageSampleRate::open(unsigned int test, char *units,
kernel_ = _wrapper->clCreateKernel(program_, "sampleRate", &error_);
CHECK_RESULT(kernel_ == 0, "clCreateKernel failed");
error_ =
_wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_);
error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&outBuffer_);
CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(outBuffer) failed");
unsigned int sizeDW = width_;
error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int),
(void *)&sizeDW);
error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(unsigned int), (void*)&sizeDW);
CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(sizeDW) failed");
unsigned int writeIt = 0;
error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int),
(void *)&writeIt);
error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(unsigned int), (void*)&writeIt);
CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(writeIt) failed");
for (unsigned int i = 0; i < numBufs_; i++) {
error_ = _wrapper->clSetKernelArg(kernel_, i + 3, sizeof(cl_mem),
(void *)&inBuffer_[i]);
error_ = _wrapper->clSetKernelArg(kernel_, i + 3, sizeof(cl_mem), (void*)&inBuffer_[i]);
CHECK_RESULT(error_ != CL_SUCCESS, "clSetKernelArg(inBuffer) failed");
// setData(inBuffer_[i], 0x3f800000);
}
@@ -270,9 +253,9 @@ void OCLPerfImageSampleRate::run(void) {
timer.Reset();
timer.Start();
for (unsigned int i = 0; i < maxIter; i++) {
error_ = _wrapper->clEnqueueNDRangeKernel(
cmd_queue_, kernel_, 1, NULL, (const size_t *)global_work_size,
(const size_t *)local_work_size, 0, NULL, NULL);
error_ = _wrapper->clEnqueueNDRangeKernel(cmd_queue_, kernel_, 1, NULL,
(const size_t*)global_work_size,
(const size_t*)local_work_size, 0, NULL, NULL);
}
CHECK_RESULT(error_, "clEnqueueNDRangeKernel failed");
@@ -283,21 +266,17 @@ void OCLPerfImageSampleRate::run(void) {
// checkData(outBuffer_);
// Compute GB/s
double perf =
((double)outBufSize_ * numBufs_ * (double)maxIter * (double)(1e-09)) /
sec;
double perf = ((double)outBufSize_ * numBufs_ * (double)maxIter * (double)(1e-09)) / sec;
char buf[256];
SNPRINTF(buf, sizeof(buf), "Domain %dx%d, %13s, %2d images,%4dx%4d (GB/s)",
sizes[NUM_SIZES - 1], sizes[NUM_SIZES - 1], types[typeIdx_],
numBufs_, width_, width_);
SNPRINTF(buf, sizeof(buf), "Domain %dx%d, %13s, %2d images,%4dx%4d (GB/s)", sizes[NUM_SIZES - 1],
sizes[NUM_SIZES - 1], types[typeIdx_], numBufs_, width_, width_);
_perfInfo = (float)perf;
testDescString = buf;
}
unsigned int OCLPerfImageSampleRate::close(void) {
if (skip_)
{
if (skip_) {
return CL_SUCCESS;
}
_wrapper->clFinish(cmd_queue_);
@@ -306,16 +285,14 @@ unsigned int OCLPerfImageSampleRate::close(void) {
for (unsigned int i = 0; i < numBufs_; i++) {
if (inBuffer_[i]) {
error_ = _wrapper->clReleaseMemObject(inBuffer_[i]);
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS,
"clReleaseMemObject(inBuffer_) failed");
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject(inBuffer_) failed");
}
}
free(inBuffer_);
}
if (outBuffer_) {
error_ = _wrapper->clReleaseMemObject(outBuffer_);
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS,
"clReleaseMemObject(outBuffer_) failed");
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject(outBuffer_) failed");
}
if (kernel_) {
error_ = _wrapper->clReleaseKernel(kernel_);
@@ -327,8 +304,7 @@ unsigned int OCLPerfImageSampleRate::close(void) {
}
if (cmd_queue_) {
error_ = _wrapper->clReleaseCommandQueue(cmd_queue_);
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS,
"clReleaseCommandQueue failed");
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseCommandQueue failed");
}
if (context_) {
error_ = _wrapper->clReleaseContext(context_);