minor update

This commit is contained in:
Blaise Tine 2023-11-15 00:28:26 -08:00
parent 61e3442ef8
commit ede5e1c311
8 changed files with 100 additions and 106 deletions

View file

@ -36,9 +36,9 @@ run-simx:
$(MAKE) -C lbm run-simx
$(MAKE) -C oclprintf run-simx
$(MAKE) -C blackscholes run-simx
$(MAKE) -C matmul run-simx
$(MAKE) -C transpose run-simx
$(MAKE) -C convolution run-simx
# $(MAKE) -C matmul run-simx
# $(MAKE) -C vectorhypot run-simx
# $(MAKE) -C mri-q run-simx
@ -59,8 +59,8 @@ run-rtlsim:
$(MAKE) -C lbm run-rtlsim
$(MAKE) -C oclprintf run-rtlsim
$(MAKE) -C blackscholes run-rtlsim
$(MAKE) -C matmul run-rtlsim
$(MAKE) -C convolution run-rtlsim
# $(MAKE) -C matmul run-rtlsim
# $(MAKE) -C vectorhypot run-rtlsim
# $(MAKE) -C mri-q run-rtlsim
@ -81,8 +81,8 @@ run-opae:
$(MAKE) -C lbm run-opae
$(MAKE) -C oclprintf run-opae
$(MAKE) -C blackscholes run-opae
$(MAKE) -C matmul run-opae
$(MAKE) -C convolution run-opae
# $(MAKE) -C matmul run-opae
# $(MAKE) -C vectorhypot run-opae
# $(MAKE) -C mri-q run-opae

View file

@ -41,13 +41,12 @@ CXXFLAGS += -std=c++11 -Wall -Wextra -Wfatal-errors
CXXFLAGS += -Wno-deprecated-declarations -Wno-unused-parameter -Wno-narrowing
CXXFLAGS += -pthread
CXXFLAGS += -I$(POCL_RT_PATH)/include
LDFLAGS += -L$(POCL_RT_PATH)/lib -L$(VORTEX_RT_PATH)/stub -lvortex
ifdef HOSTGPU
CXXFLAGS += -DHOSTGPU
LDFLAGS += -lOpenCL
else
LDFLAGS += $(POCL_RT_PATH)/lib/libOpenCL.so
LDFLAGS += -L$(VORTEX_RT_PATH)/stub -lvortex $(POCL_RT_PATH)/lib/libOpenCL.so
endif
# Debugigng

View file

@ -106,11 +106,6 @@ int main (int argc, char **argv) {
cl_platform_id platform_id;
size_t kernel_size;
cl_int binary_status;
// read kernel binary from file
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
// Getting platform and device information
CL_CHECK(clGetPlatformIDs(1, &platform_id, NULL));
@ -124,12 +119,17 @@ int main (int argc, char **argv) {
a_memobj = CL_CHECK2(clCreateBuffer(context, CL_MEM_READ_ONLY, nbytes, NULL, &_err));
printf("Create program from kernel source\n");
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &_err));
if (program == NULL) {
cleanup();
#ifdef HOSTGPU
if (0 != read_kernel_file("kernel.cl", &kernel_bin, &kernel_size))
return -1;
}
program = CL_CHECK2(clCreateProgramWithSource(
context, 1, (const char**)&kernel_bin, &kernel_size, &_err));
#else
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, NULL, &_err));
#endif
// Build program
CL_CHECK(clBuildProgram(program, 1, &device_id, NULL, NULL, NULL));

View file

@ -115,11 +115,6 @@ int main (int argc, char **argv) {
cl_platform_id platform_id;
size_t kernel_size;
cl_int binary_status;
// read kernel binary from file
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
// Getting platform and device information
CL_CHECK(clGetPlatformIDs(1, &platform_id, NULL));
@ -134,12 +129,17 @@ int main (int argc, char **argv) {
c_memobj = CL_CHECK2(clCreateBuffer(context, CL_MEM_WRITE_ONLY, nbytes, NULL, &_err));
printf("Create program from kernel source\n");
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &_err));
if (program == NULL) {
cleanup();
#ifdef HOSTGPU
if (0 != read_kernel_file("kernel.cl", &kernel_bin, &kernel_size))
return -1;
}
program = CL_CHECK2(clCreateProgramWithSource(
context, 1, (const char**)&kernel_bin, &kernel_size, &_err));
#else
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, NULL, &_err));
#endif
// Build program
CL_CHECK(clBuildProgram(program, 1, &device_id, NULL, NULL, NULL));
@ -159,12 +159,12 @@ int main (int argc, char **argv) {
for (int i = 0; i < size; ++i) {
if (float_enable) {
float value = sinf(i)*sinf(i);
h_a[i] = *(int*)&value;
printf("*** [%d]: h_a=%f\n", i, value);
((float*)h_a)[i] = value;
printf("*** [%d]: %f\n", i, value);
} else {
int value = size*sinf(i);
h_a[i] = value;
printf("*** [%d]: h_a=%d\n", i, value);
printf("*** [%d]: %d\n", i, value);
}
}
@ -188,38 +188,44 @@ int main (int argc, char **argv) {
CL_CHECK(clEnqueueReadBuffer(commandQueue, c_memobj, CL_TRUE, 0, nbytes, h_c, 0, NULL, NULL));
printf("Verify result\n");
for (int i = 0; i < size; ++i) {
int value = h_c[i];
for (int i = 0; i < size; ++i) {
if (float_enable) {
printf("*** [%d]: h_a=%f\n", i, *(float*)&value);
float value = ((float*)h_c)[i];
printf("*** [%d]: %f\n", i, value);
} else {
printf("*** [%d]: h_a=%d\n", i, value);
int value = h_c[i];
printf("*** [%d]: %d\n", i, value);
}
}
int errors = 0;
for (int i = 0; i < size; ++i) {
int ref = h_a[i];
float ref_f = *(float*)&ref;
for (int i = 0; i < size; ++i) {
int pos = 0;
for (int j = 0; j < size; ++j) {
int cur = h_a[j];
if (float_enable) {
float cur_f = *(float*)&cur;
pos += (cur_f < ref_f) || (cur_f == ref_f && j < i);
} else {
if (float_enable) {
float ref = ((float*)h_a)[i];
for (int j = 0; j < size; ++j) {
float cur = ((float*)h_a)[j];
pos += (cur < ref) || (cur == ref && j < i);
}
float value = ((float*)h_c)[pos];
if (value != ref) {
if (errors < 100) {
printf("*** error: [%d] expected=%f, actual=%f\n", pos, ref, value);
}
++errors;
}
} else {
int ref = h_a[i];
for (int j = 0; j < size; ++j) {
int cur = h_a[j];
pos += (cur < ref) || (cur == ref && j < i);
}
}
int value = h_c[pos];
if (value != ref) {
if (errors < 100) {
if (float_enable) {
printf("*** error: [%d] expected=%f, actual=%f\n", pos, ref_f, *(float*)&value);
} else {
int value = h_c[pos];
if (value != ref) {
if (errors < 100) {
printf("*** error: [%d] expected=%d, actual=%d\n", pos, ref, value);
}
++errors;
}
++errors;
}
}
if (0 == errors) {

View file

@ -151,16 +151,12 @@ int main(int argc, char **argv) {
cl_platform_id platform_id;
cl_device_id device_id;
cl_program program;
cl_mem input_buffer;
cl_mem output_buffer;
size_t kernel_size;
cl_context context;
cl_command_queue queue;
cl_int binary_status = 0;
// read kernel binary from file
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
// Getting platform and device information
CL_CHECK(clGetPlatformIDs(1, &platform_id, NULL));
@ -172,19 +168,18 @@ int main(int argc, char **argv) {
cl_kernel kernel = 0;
cl_mem memObjects[2] = {0, 0};
// Create OpenCL program - first attempt to load cached binary.
// If that is not available, then create the program from source
// and store the binary for future use.
printf("create program from binary...\n");
cl_program program = CL_CHECK_ERR(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &_err));
if (program == NULL) {
std::cerr << "Failed to write program binary" << std::endl;
Cleanup(device_id, context, queue, program, kernel, memObjects);
return 1;
} else {
printf("Read program from binary.\n");
}
printf("Create program from kernel source\n");
#ifdef HOSTGPU
if (0 != read_kernel_file("kernel.cl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK_ERR(clCreateProgramWithSource(
context, 1, (const char**)&kernel_bin, &kernel_size, &_err));
#else
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK_ERR(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, NULL, &_err));
#endif
// Build program
CL_CHECK(clBuildProgram(program, 1, &device_id, NULL, NULL, NULL));

View file

@ -149,14 +149,10 @@ int main(int argc, char **argv) {
cl_platform_id platform_id;
cl_device_id device_id;
cl_program program;
size_t kernel_size;
cl_int binary_status = 0;
uint8_t *kernel_bin = NULL;
// read kernel binary from file
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
// Getting platform and device information
CL_CHECK(clGetPlatformIDs(1, &platform_id, NULL));
CL_CHECK(clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, NULL));
@ -170,19 +166,18 @@ int main(int argc, char **argv) {
cl_kernel kernel = 0;
cl_mem memObjects[2] = {0, 0};
// Create OpenCL program - first attempt to load cached binary.
// If that is not available, then create the program from source
// and store the binary for future use.
printf("create program from binary...\n");
cl_program program = CL_CHECK_ERR(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &_err));
if (program == NULL) {
std::cerr << "Failed to write program binary" << std::endl;
Cleanup(kernel_bin, device_id, context, queue, program, kernel, memObjects);
return 1;
} else {
printf("Read program from binary.");
}
printf("Create program from kernel source\n");
#ifdef HOSTGPU
if (0 != read_kernel_file("kernel.cl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK_ERR(clCreateProgramWithSource(
context, 1, (const char**)&kernel_bin, &kernel_size, &_err));
#else
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK_ERR(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, NULL, &_err));
#endif
// Build program
CL_CHECK(clBuildProgram(program, 1, &device_id, NULL, NULL, NULL));

View file

@ -185,13 +185,8 @@ int main (int argc, char **argv) {
cl_platform_id platform_id;
size_t kernel_size;
cl_int binary_status;
srand(50);
// read kernel binary from file
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
// Getting platform and device information
CL_CHECK(clGetPlatformIDs(1, &platform_id, NULL));
@ -207,12 +202,17 @@ int main (int argc, char **argv) {
c_memobj = CL_CHECK2(clCreateBuffer(context, CL_MEM_WRITE_ONLY, nbytes, NULL, &_err));
printf("Create program from kernel source\n");
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &_err));
if (program == NULL) {
cleanup();
#ifdef HOSTGPU
if (0 != read_kernel_file("kernel.cl", &kernel_bin, &kernel_size))
return -1;
}
program = CL_CHECK2(clCreateProgramWithSource(
context, 1, (const char**)&kernel_bin, &kernel_size, &_err));
#else
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, NULL, &_err));
#endif
// Build program
CL_CHECK(clBuildProgram(program, 1, &device_id, NULL, NULL, NULL));

View file

@ -122,11 +122,6 @@ int main (int argc, char **argv) {
cl_platform_id platform_id;
size_t kernel_size;
cl_int binary_status;
// read kernel binary from file
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
// Getting platform and device information
CL_CHECK(clGetPlatformIDs(1, &platform_id, NULL));
@ -142,13 +137,17 @@ int main (int argc, char **argv) {
c_memobj = CL_CHECK2(clCreateBuffer(context, CL_MEM_WRITE_ONLY, nbytes, NULL, &_err));
printf("Create program from kernel source\n");
cl_int _err;
program = clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, &binary_status, &_err);
if (program == NULL) {
cleanup();
#ifdef HOSTGPU
if (0 != read_kernel_file("kernel.cl", &kernel_bin, &kernel_size))
return -1;
}
program = CL_CHECK2(clCreateProgramWithSource(
context, 1, (const char**)&kernel_bin, &kernel_size, &_err));
#else
if (0 != read_kernel_file("kernel.pocl", &kernel_bin, &kernel_size))
return -1;
program = CL_CHECK2(clCreateProgramWithBinary(
context, 1, &device_id, &kernel_size, (const uint8_t**)&kernel_bin, NULL, &_err));
#endif
// Build program
CL_CHECK(clBuildProgram(program, 1, &device_id, NULL, NULL, NULL));