SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
committed by
GitHub
parent
5840940caa
commit
f7338717ae
@@ -33,15 +33,13 @@ const unsigned int MAX_READ_MODES = 1;
|
||||
|
||||
static const unsigned int NumReads[NUM_READ_MODES] = {1};
|
||||
// 256KB, 1 MB, 4MB, 16 MB and 64 MB
|
||||
static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304,
|
||||
16777216};
|
||||
static const unsigned int Sizes[NUM_SIZES] = {262144, 1048576, 4194304, 16777216};
|
||||
static const unsigned int MaxTypes = 2;
|
||||
static unsigned int NumTypes = MaxTypes;
|
||||
static const char *types[MaxTypes] = {"float", "double"};
|
||||
static const unsigned int TypeSize[MaxTypes] = {sizeof(cl_float),
|
||||
sizeof(cl_double)};
|
||||
static const char* types[MaxTypes] = {"float", "double"};
|
||||
static const unsigned int TypeSize[MaxTypes] = {sizeof(cl_float), sizeof(cl_double)};
|
||||
static const unsigned int NumVecWidths = 5;
|
||||
static const char *vecWidths[NumVecWidths] = {"", "2", "4", "8", "16"};
|
||||
static const char* vecWidths[NumVecWidths] = {"", "2", "4", "8", "16"};
|
||||
#define CHAR_BUF_SIZE 512
|
||||
|
||||
// Quiet pesky warnings
|
||||
@@ -50,8 +48,7 @@ static const char *vecWidths[NumVecWidths] = {"", "2", "4", "8", "16"};
|
||||
#else
|
||||
#define SNPRINTF snprintf
|
||||
#endif
|
||||
void OCLPerfUAVReadSpeedHostMem::genShader(unsigned int type,
|
||||
unsigned int vecWidth,
|
||||
void OCLPerfUAVReadSpeedHostMem::genShader(unsigned int type, unsigned int vecWidth,
|
||||
unsigned int numReads) {
|
||||
char buf[CHAR_BUF_SIZE];
|
||||
|
||||
@@ -72,8 +69,7 @@ void OCLPerfUAVReadSpeedHostMem::genShader(unsigned int type,
|
||||
shader_ +=
|
||||
"{\n"
|
||||
" int i = (int) get_global_id(0);\n";
|
||||
SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp = 0;\n", types[type],
|
||||
vecWidths[vecWidth]);
|
||||
SNPRINTF(buf, CHAR_BUF_SIZE, " %s%s temp = 0;\n", types[type], vecWidths[vecWidth]);
|
||||
shader_.append(buf);
|
||||
shader_ += " temp = *(inBuf + i);\n";
|
||||
if (vecWidth == 0) {
|
||||
@@ -90,34 +86,32 @@ void OCLPerfUAVReadSpeedHostMem::genShader(unsigned int type,
|
||||
// printf("shader:\n%s\n", shader_.c_str());
|
||||
}
|
||||
|
||||
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) {}
|
||||
|
||||
OCLPerfUAVReadSpeedHostMem::OCLPerfUAVReadSpeedHostMem() {
|
||||
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;
|
||||
context_ = 0;
|
||||
|
||||
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");
|
||||
// Get last for default
|
||||
platform = platforms[numPlatforms - 1];
|
||||
for (unsigned i = 0; i < numPlatforms; ++i) {
|
||||
char pbuf[100];
|
||||
error_ = _wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR,
|
||||
sizeof(pbuf), pbuf, NULL);
|
||||
error_ =
|
||||
_wrapper->clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL);
|
||||
num_devices = 0;
|
||||
/* Get the number of requested devices */
|
||||
error_ =
|
||||
_wrapper->clGetDeviceIDs(platforms[i], type_, 0, NULL, &num_devices);
|
||||
error_ = _wrapper->clGetDeviceIDs(platforms[i], 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");
|
||||
@@ -136,29 +130,26 @@ OCLPerfUAVReadSpeedHostMem::OCLPerfUAVReadSpeedHostMem() {
|
||||
*/
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
char *p = strstr(charbuf, "cl_khr_fp64");
|
||||
char *p2 = strstr(charbuf, "cl_amd_fp64");
|
||||
char* p = strstr(charbuf, "cl_khr_fp64");
|
||||
char* p2 = strstr(charbuf, "cl_amd_fp64");
|
||||
|
||||
NumTypes = MaxTypes;
|
||||
|
||||
@@ -176,40 +167,34 @@ OCLPerfUAVReadSpeedHostMem::OCLPerfUAVReadSpeedHostMem() {
|
||||
OCLPerfUAVReadSpeedHostMem::~OCLPerfUAVReadSpeedHostMem() {}
|
||||
|
||||
void OCLPerfUAVReadSpeedHostMem::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);
|
||||
}
|
||||
|
||||
void OCLPerfUAVReadSpeedHostMem::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);
|
||||
}
|
||||
|
||||
void OCLPerfUAVReadSpeedHostMem::open(unsigned int test, char *units,
|
||||
double &conversion,
|
||||
void OCLPerfUAVReadSpeedHostMem::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;
|
||||
@@ -227,7 +212,7 @@ void OCLPerfUAVReadSpeedHostMem::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
|
||||
@@ -237,13 +222,11 @@ void OCLPerfUAVReadSpeedHostMem::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");
|
||||
@@ -275,26 +258,23 @@ void OCLPerfUAVReadSpeedHostMem::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");
|
||||
|
||||
device = devices[0];
|
||||
|
||||
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);
|
||||
CHECK_RESULT(cmd_queue_ == 0, "clCreateCommandQueue failed");
|
||||
|
||||
inBuffer_ = _wrapper->clCreateBuffer(context_,
|
||||
CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
|
||||
bufSize_, NULL, &error_);
|
||||
inBuffer_ = _wrapper->clCreateBuffer(context_, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, bufSize_,
|
||||
NULL, &error_);
|
||||
CHECK_RESULT(inBuffer_ == 0, "clCreateBuffer(inBuffer) failed");
|
||||
|
||||
outBuffer_ = _wrapper->clCreateBuffer(context_, 0, bufSize_, NULL, &error_);
|
||||
@@ -304,9 +284,8 @@ void OCLPerfUAVReadSpeedHostMem::open(unsigned int test, char *units,
|
||||
CHECK_RESULT(constBuffer_ == 0, "clCreateBuffer(constBuffer) failed");
|
||||
|
||||
genShader(typeIdx_, vecSizeIdx_, numReads_);
|
||||
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");
|
||||
|
||||
std::string args;
|
||||
@@ -321,15 +300,13 @@ void OCLPerfUAVReadSpeedHostMem::open(unsigned int test, char *units,
|
||||
args += "-D USE_KHR_DOUBLES ";
|
||||
}
|
||||
}
|
||||
error_ =
|
||||
_wrapper->clBuildProgram(program_, 1, &device, args.c_str(), NULL, NULL);
|
||||
error_ = _wrapper->clBuildProgram(program_, 1, &device, args.c_str(), 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");
|
||||
@@ -337,26 +314,21 @@ void OCLPerfUAVReadSpeedHostMem::open(unsigned int test, char *units,
|
||||
kernel_ = _wrapper->clCreateKernel(program_, "_uavReadSpeedHostMem", &error_);
|
||||
CHECK_RESULT(kernel_ == 0, "clCreateKernel failed");
|
||||
|
||||
error_ =
|
||||
_wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void *)&inBuffer_);
|
||||
error_ =
|
||||
_wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void *)&outBuffer_);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem),
|
||||
(void *)&constBuffer_);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 0, sizeof(cl_mem), (void*)&inBuffer_);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 1, sizeof(cl_mem), (void*)&outBuffer_);
|
||||
error_ = _wrapper->clSetKernelArg(kernel_, 2, sizeof(cl_mem), (void*)&constBuffer_);
|
||||
|
||||
setData(inBuffer_, 0.0f);
|
||||
setData(outBuffer_, 1.2345678f);
|
||||
unsigned int *cBuf = (unsigned int *)_wrapper->clEnqueueMapBuffer(
|
||||
cmd_queue_, constBuffer_, true, CL_MAP_WRITE, 0, 16 * 2, 0, NULL, NULL,
|
||||
&error_);
|
||||
unsigned int* cBuf = (unsigned int*)_wrapper->clEnqueueMapBuffer(
|
||||
cmd_queue_, constBuffer_, true, CL_MAP_WRITE, 0, 16 * 2, 0, NULL, NULL, &error_);
|
||||
cBuf[0] = bufSize_ / (TypeSize[typeIdx_] * (1 << vecSizeIdx_));
|
||||
cBuf[1] = 0;
|
||||
cBuf[2] = 1024;
|
||||
cBuf[3] = 2048;
|
||||
cBuf[4] = 3072;
|
||||
cBuf[5] = 0;
|
||||
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, constBuffer_, cBuf, 0,
|
||||
NULL, NULL);
|
||||
error_ = _wrapper->clEnqueueUnmapMemObject(cmd_queue_, constBuffer_, cBuf, 0, NULL, NULL);
|
||||
_wrapper->clFinish(cmd_queue_);
|
||||
}
|
||||
|
||||
@@ -372,9 +344,9 @@ void OCLPerfUAVReadSpeedHostMem::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");
|
||||
}
|
||||
@@ -384,8 +356,7 @@ void OCLPerfUAVReadSpeedHostMem::run(void) {
|
||||
double sec = timer.GetElapsedTime();
|
||||
|
||||
// Constant bandwidth in GB/s
|
||||
double perf =
|
||||
((double)bufSize_ * numReads_ * NUM_ITER * (double)(1e-09)) / sec;
|
||||
double perf = ((double)bufSize_ * numReads_ * NUM_ITER * (double)(1e-09)) / sec;
|
||||
|
||||
_perfInfo = (float)perf;
|
||||
char buf[256];
|
||||
@@ -402,18 +373,15 @@ unsigned int OCLPerfUAVReadSpeedHostMem::close(void) {
|
||||
|
||||
if (inBuffer_) {
|
||||
error_ = _wrapper->clReleaseMemObject(inBuffer_);
|
||||
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS,
|
||||
"clReleaseMemObject(inBuffer_) failed");
|
||||
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject(inBuffer_) failed");
|
||||
}
|
||||
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 (constBuffer_) {
|
||||
error_ = _wrapper->clReleaseMemObject(constBuffer_);
|
||||
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS,
|
||||
"clReleaseMemObject(constBuffer_) failed");
|
||||
CHECK_RESULT_NO_RETURN(error_ != CL_SUCCESS, "clReleaseMemObject(constBuffer_) failed");
|
||||
}
|
||||
if (kernel_) {
|
||||
error_ = _wrapper->clReleaseKernel(kernel_);
|
||||
@@ -425,8 +393,7 @@ unsigned int OCLPerfUAVReadSpeedHostMem::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