SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
committed by
GitHub
parent
5840940caa
commit
f7338717ae
@@ -36,8 +36,7 @@
|
||||
|
||||
#define NUM_SIZES 4
|
||||
// 256KB, 1 MB, 4MB, 16 MB
|
||||
static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304,
|
||||
16777216};
|
||||
static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, 16777216};
|
||||
|
||||
void OCLPerfLDSReadSpeed::genShader(unsigned int idx) {
|
||||
shader_.clear();
|
||||
@@ -170,45 +169,39 @@ OCLPerfLDSReadSpeed::OCLPerfLDSReadSpeed() { _numSubTests = NUM_SIZES * 3; }
|
||||
OCLPerfLDSReadSpeed::~OCLPerfLDSReadSpeed() {}
|
||||
|
||||
void OCLPerfLDSReadSpeed::setData(cl_mem buffer, float val) {
|
||||
float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true,
|
||||
CL_MAP_WRITE, 0, bufSize_,
|
||||
0, NULL, NULL, &error_);
|
||||
float* data = (float*)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_WRITE, 0,
|
||||
bufSize_, 0, NULL, NULL, &error_);
|
||||
for (unsigned int i = 0; i < (bufSize_ >> 2); i++) data[i] = val;
|
||||
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL,
|
||||
NULL);
|
||||
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, NULL);
|
||||
_wrapper->clFinish(cmd_queue_);
|
||||
}
|
||||
|
||||
void OCLPerfLDSReadSpeed::checkData(cl_mem buffer) {
|
||||
float *data = (float *)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true,
|
||||
CL_MAP_READ, 0, bufSize_,
|
||||
0, NULL, NULL, &error_);
|
||||
float* data = (float*)_wrapper->clEnqueueMapBuffer(cmd_queue_, buffer, true, CL_MAP_READ, 0,
|
||||
bufSize_, 0, NULL, NULL, &error_);
|
||||
for (unsigned int i = 0; i < (bufSize_ >> 2); i++) {
|
||||
if (data[i] != (float)numReads_) {
|
||||
printf("Data validation failed at index %d!\n", i);
|
||||
printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, numReads_,
|
||||
numReads_, numReads_, (unsigned int)data[i],
|
||||
(unsigned int)data[i + 1], (unsigned int)data[i + 2],
|
||||
printf("Expected %d %d %d %d\nGot %d %d %d %d\n", numReads_, numReads_, numReads_, numReads_,
|
||||
(unsigned int)data[i], (unsigned int)data[i + 1], (unsigned int)data[i + 2],
|
||||
(unsigned int)data[i + 3]);
|
||||
CHECK_RESULT_NO_RETURN(0, "Data validation failed!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL,
|
||||
NULL);
|
||||
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, buffer, data, 0, NULL, NULL);
|
||||
_wrapper->clFinish(cmd_queue_);
|
||||
}
|
||||
|
||||
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 OCLPerfLDSReadSpeed::open(unsigned int test, char *units,
|
||||
double &conversion, unsigned int deviceId) {
|
||||
void OCLPerfLDSReadSpeed::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;
|
||||
@@ -223,7 +216,7 @@ void OCLPerfLDSReadSpeed::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");
|
||||
#if 0
|
||||
@@ -233,13 +226,11 @@ void OCLPerfLDSReadSpeed::open(unsigned int test, char *units,
|
||||
#endif
|
||||
platform = platforms[_platformIndex];
|
||||
char pbuf[100];
|
||||
error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex],
|
||||
CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf,
|
||||
NULL);
|
||||
error_ = _wrapper->clGetPlatformInfo(platforms[_platformIndex], CL_PLATFORM_VENDOR,
|
||||
sizeof(pbuf), pbuf, NULL);
|
||||
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);
|
||||
// Runtime returns an error when no GPU devices are present instead of just
|
||||
// returning 0 devices
|
||||
// CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceIDs failed");
|
||||
@@ -267,19 +258,17 @@ void OCLPerfLDSReadSpeed::open(unsigned int test, char *units,
|
||||
*/
|
||||
CHECK_RESULT(platform == 0, "Couldn't find AMD platform, 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];
|
||||
|
||||
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");
|
||||
|
||||
cmd_queue_ = _wrapper->clCreateCommandQueue(context_, device, 0, NULL);
|
||||
@@ -289,9 +278,8 @@ void OCLPerfLDSReadSpeed::open(unsigned int test, char *units,
|
||||
CHECK_RESULT(outBuffer_ == 0, "clCreateBuffer(outBuffer) failed");
|
||||
|
||||
genShader(shaderIdx_);
|
||||
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");
|
||||
|
||||
error_ = _wrapper->clBuildProgram(program_, 1, &device, "", NULL, NULL);
|
||||
@@ -299,9 +287,8 @@ void OCLPerfLDSReadSpeed::open(unsigned int test, char *units,
|
||||
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");
|
||||
@@ -310,9 +297,8 @@ void OCLPerfLDSReadSpeed::open(unsigned int test, char *units,
|
||||
CHECK_RESULT(kernel_ == 0, "clCreateKernel failed");
|
||||
|
||||
float foo = 0;
|
||||
error_ =
|
||||
_wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&outBuffer_);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_float), (void *)&foo);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&outBuffer_);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_float), (void*)&foo);
|
||||
|
||||
setData(outBuffer_, 1.2345678f);
|
||||
}
|
||||
@@ -329,9 +315,9 @@ void OCLPerfLDSReadSpeed::run(void) {
|
||||
timer.Reset();
|
||||
timer.Start();
|
||||
for (unsigned int i = 0; i < NUM_ITER; 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");
|
||||
}
|
||||
@@ -341,7 +327,7 @@ void OCLPerfLDSReadSpeed::run(void) {
|
||||
double sec = timer.GetElapsedTime();
|
||||
|
||||
char buf[256];
|
||||
const char *buf2;
|
||||
const char* buf2;
|
||||
if (shaderIdx_ == 0) {
|
||||
buf2 = " def kernel";
|
||||
} else if (shaderIdx_ == 1) {
|
||||
@@ -353,14 +339,12 @@ void OCLPerfLDSReadSpeed::run(void) {
|
||||
}
|
||||
// LDS bandwidth in GB/s
|
||||
// We have one extra write per LDS location to initialize LDS
|
||||
double perf =
|
||||
((double)global * (numReads_ * sizeof(cl_float) + ldsSizeBytes_ / 64) *
|
||||
NUM_ITER * (double)(1e-09)) /
|
||||
double perf = ((double)global * (numReads_ * sizeof(cl_float) + ldsSizeBytes_ / 64) * NUM_ITER *
|
||||
(double)(1e-09)) /
|
||||
sec;
|
||||
|
||||
_perfInfo = (float)perf;
|
||||
SNPRINTF(buf, sizeof(buf), " %s %8d threads, %3d reads (GB/s) ", buf2, global,
|
||||
numReads_);
|
||||
SNPRINTF(buf, sizeof(buf), " %s %8d threads, %3d reads (GB/s) ", buf2, global, numReads_);
|
||||
testDescString = buf;
|
||||
// checkData(outBuffer_);
|
||||
}
|
||||
@@ -370,8 +354,7 @@ unsigned int OCLPerfLDSReadSpeed::close(void) {
|
||||
|
||||
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_);
|
||||
@@ -383,8 +366,7 @@ unsigned int OCLPerfLDSReadSpeed::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_);
|
||||
|
||||
Reference in New Issue
Block a user