mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-24 22:07:41 -04:00
Migrating all tests to new kernel launch API
This commit is contained in:
parent
8b63305201
commit
250a5741f7
77 changed files with 961 additions and 1108 deletions
|
@ -25,8 +25,8 @@
|
|||
exit(1); \
|
||||
}
|
||||
|
||||
static int read_data(float *A0, int nx,int ny,int nz,FILE *fp)
|
||||
{
|
||||
static int read_data(float *A0, int nx,int ny,int nz,FILE *fp)
|
||||
{
|
||||
int s=0;
|
||||
int i,j,k;
|
||||
for(i=0;i<nz;i++)
|
||||
|
@ -47,7 +47,7 @@ static char* replaceFilenameExtension(const char* filename, const char* ext) {
|
|||
const char* dot = strrchr(filename, '.');
|
||||
int baseLen = dot ? (dot - filename) : strlen(filename);
|
||||
char* sz_out = (char*)malloc(baseLen + strlen(ext) + 1);
|
||||
if (!sz_out)
|
||||
if (!sz_out)
|
||||
return NULL;
|
||||
strncpy(sz_out, filename, baseLen);
|
||||
strcpy(sz_out + baseLen, ext);
|
||||
|
@ -93,8 +93,8 @@ static float* read_output_file(const char* filename, int* out_size) {
|
|||
static int compare_floats(const float* src, const float* gold, int count) {
|
||||
int num_errors = 0;
|
||||
float abstol = 0.0f;
|
||||
float max_value = 0.0f;
|
||||
// Find the maximum magnitude in the gold array for absolute tolerance calculation
|
||||
float max_value = 0.0f;
|
||||
// Find the maximum magnitude in the gold array for absolute tolerance calculation
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (fabs(gold[i]) > max_value)
|
||||
max_value = fabs(gold[i]);
|
||||
|
@ -128,16 +128,16 @@ static int read_kernel_file(const char* filename, uint8_t** data, size_t* size)
|
|||
|
||||
*data = (uint8_t*)malloc(fsize);
|
||||
*size = fread(*data, 1, fsize, fp);
|
||||
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
struct pb_TimerSet timers;
|
||||
struct pb_Parameters *parameters;
|
||||
|
||||
|
||||
printf("OpenCL accelerated 7 points stencil codes****\n");
|
||||
printf("Author: Li-Wen Chang <lchang20@illinois.edu>\n");
|
||||
|
||||
|
@ -150,7 +150,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
pb_InitializeTimerSet(&timers);
|
||||
pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE);
|
||||
|
||||
|
||||
//declaration
|
||||
int nx,ny,nz;
|
||||
int size;
|
||||
|
@ -158,7 +158,7 @@ int main(int argc, char** argv) {
|
|||
float c0=1.0f/6.0f;
|
||||
float c1=1.0f/6.0f/6.0f;
|
||||
|
||||
if (argc<5)
|
||||
if (argc<5)
|
||||
{
|
||||
printf("Usage: probe nx ny nz t\n"
|
||||
"nx: the grid size x\n"
|
||||
|
@ -180,7 +180,7 @@ int main(int argc, char** argv) {
|
|||
iteration = atoi(argv[4]);
|
||||
if(iteration<1)
|
||||
return -1;
|
||||
|
||||
|
||||
cl_int clStatus;
|
||||
cl_context clContext;
|
||||
cl_device_id clDevice;
|
||||
|
@ -190,7 +190,7 @@ int main(int argc, char** argv) {
|
|||
pb_Context* pb_context;
|
||||
pb_context = pb_InitOpenCLContext(parameters);
|
||||
if (pb_context == NULL) {
|
||||
fprintf (stderr, "Error: No OpenCL platform/device can be found.");
|
||||
fprintf (stderr, "Error: No OpenCL platform/device can be found.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -208,22 +208,14 @@ int main(int argc, char** argv) {
|
|||
//cl_program clProgram = clCreateProgramWithSource(clContext,1,clSource,NULL,&clStatus);
|
||||
uint8_t *kernel_bin = NULL;
|
||||
size_t kernel_size;
|
||||
cl_int binary_status = 0;
|
||||
cl_int binary_status = 0;
|
||||
cl_program clProgram;
|
||||
|
||||
#ifdef HOSTGPU
|
||||
clStatus = read_kernel_file("kernel.cl", &kernel_bin, &kernel_size);
|
||||
CHECK_ERROR("read_kernel_file")
|
||||
CHECK_ERROR("read_kernel_file")
|
||||
clProgram = clCreateProgramWithSource(
|
||||
clContext, 1, (const char**)&kernel_bin, &kernel_size, &clStatus);
|
||||
CHECK_ERROR("clCreateProgramWithSource")
|
||||
#else
|
||||
clStatus = read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size);
|
||||
CHECK_ERROR("read_kernel_file")
|
||||
clProgram = clCreateProgramWithBinary(
|
||||
clContext, 1, &clDevice, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &clStatus);
|
||||
CHECK_ERROR("clCreateProgramWithBinary")
|
||||
#endif
|
||||
|
||||
char clOptions[50];
|
||||
sprintf(clOptions,"-I src/opencl_base");
|
||||
|
@ -236,15 +228,15 @@ int main(int argc, char** argv) {
|
|||
//host data
|
||||
float *h_A0;
|
||||
float *h_Anext;
|
||||
|
||||
|
||||
//device
|
||||
cl_mem d_A0;
|
||||
cl_mem d_Anext;
|
||||
|
||||
//load data from files
|
||||
|
||||
|
||||
size=nx*ny*nz;
|
||||
|
||||
|
||||
h_A0=(float*)malloc(sizeof(float)*size);
|
||||
h_Anext=(float*)malloc(sizeof(float)*size);
|
||||
pb_SwitchToTimer(&timers, pb_TimerID_IO);
|
||||
|
@ -254,13 +246,13 @@ int main(int argc, char** argv) {
|
|||
memcpy (h_Anext,h_A0,sizeof(float)*size);
|
||||
|
||||
pb_SwitchToTimer(&timers, pb_TimerID_COPY);
|
||||
|
||||
|
||||
//memory allocation
|
||||
d_A0 = clCreateBuffer(clContext,CL_MEM_READ_WRITE,size*sizeof(float),NULL,&clStatus);
|
||||
CHECK_ERROR("clCreateBuffer")
|
||||
d_Anext = clCreateBuffer(clContext,CL_MEM_READ_WRITE,size*sizeof(float),NULL,&clStatus);
|
||||
CHECK_ERROR("clCreateBuffer")
|
||||
|
||||
CHECK_ERROR("clCreateBuffer")
|
||||
|
||||
//memory copy
|
||||
clStatus = clEnqueueWriteBuffer(clCommandQueue,d_A0,CL_FALSE,0,size*sizeof(float),h_A0,0,NULL,NULL);
|
||||
CHECK_ERROR("clEnqueueWriteBuffer")
|
||||
|
@ -277,7 +269,7 @@ int main(int argc, char** argv) {
|
|||
size_t offset[3] = {1,1,1};
|
||||
printf("grid size in x/y/z = %ld %ld %ld\n",grid[0],grid[1],grid[2]);
|
||||
printf("block size in x/y/z = %ld %ld %ld\n",block[0],block[1],block[2]);
|
||||
|
||||
|
||||
printf ("blocks = %ld\n", (grid[0]/block[0])*(grid[1]/block[1])*(grid[2]*block[2]));
|
||||
|
||||
clStatus = clSetKernelArg(clKernel,0,sizeof(float),(void*)&c0);
|
||||
|
@ -298,10 +290,10 @@ int main(int argc, char** argv) {
|
|||
clStatus = clEnqueueNDRangeKernel(clCommandQueue,clKernel,3,NULL,grid,block,0,NULL,NULL);
|
||||
//printf("iteration %d\n",t)
|
||||
CHECK_ERROR("clEnqueueNDRangeKernel")
|
||||
|
||||
|
||||
cl_mem d_temp = d_A0;
|
||||
d_A0 = d_Anext;
|
||||
d_Anext = d_temp;
|
||||
d_Anext = d_temp;
|
||||
clStatus = clSetKernelArg(clKernel,2,sizeof(cl_mem),(void*)&d_A0);
|
||||
clStatus = clSetKernelArg(clKernel,3,sizeof(cl_mem),(void*)&d_Anext);
|
||||
}
|
||||
|
@ -322,11 +314,11 @@ int main(int argc, char** argv) {
|
|||
CHECK_ERROR("clReleaseContext")
|
||||
clStatus = clReleaseDevice(clDevice);
|
||||
|
||||
int output_size = nx*ny*nz;
|
||||
|
||||
int output_size = nx*ny*nz;
|
||||
|
||||
if (parameters->outFile) {
|
||||
pb_SwitchToTimer(&timers, pb_TimerID_IO);
|
||||
outputData(parameters->outFile,h_Anext,output_size);
|
||||
outputData(parameters->outFile,h_Anext,output_size);
|
||||
}
|
||||
|
||||
// verify output
|
||||
|
@ -349,7 +341,7 @@ int main(int argc, char** argv) {
|
|||
free(gold_file);
|
||||
|
||||
pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE);
|
||||
|
||||
|
||||
//free((void*)clSource[0]);
|
||||
if (kernel_bin) free(kernel_bin);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue