libgpuverify

Signature verification on GPUs (WiP)
Log | Files | Refs | README | LICENSE

commit 19b783ad7b7689c8237490319f2ee686d5d131ee
parent 9674275f1102fb2c0ec1bd12dd6ef226065af7ab
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 18 Nov 2023 20:21:42 +0100

fix non-0-terminated buffers by passing length

Diffstat:
Msource/opencl-test.c | 48++++++++++++++++++++++++------------------------
Msource/rsa-test.c | 2+-
2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/source/opencl-test.c b/source/opencl-test.c @@ -10,9 +10,9 @@ #define DATA_SIZE (1024) int opencl_tests(void) { - + int err; // error code returned from api calls - + float data[DATA_SIZE]; // original data set given to device float results[DATA_SIZE]; // results returned from device unsigned int correct; // number of correct results returned @@ -25,15 +25,15 @@ int opencl_tests(void) { cl_command_queue commands; // compute command queue cl_program program; // compute program cl_kernel kernel; // compute kernel - + cl_mem input; // device memory used for the input array cl_mem output; // device memory used for the output array - - + + int i = 0; unsigned int count = DATA_SIZE; - - + + // Connect to a compute device // int gpu = 1; @@ -43,23 +43,23 @@ int opencl_tests(void) { printf("Error: Failed to create a device group!\n"); return EXIT_FAILURE; } - + size_t retSize_1 = 0; clGetDeviceInfo(device_id, CL_DRIVER_VERSION, 0, NULL, &retSize_1); char driver_version[retSize_1]; clGetDeviceInfo(device_id, CL_DRIVER_VERSION, retSize_1, &driver_version, &retSize_1); - + printf("driver version: %s\n", driver_version); - - + + size_t retSize_2 = sizeof(cl_uint); cl_uint address_bits = 0; clGetDeviceInfo(device_id, CL_DEVICE_ADDRESS_BITS, 0, NULL, &retSize_2); clGetDeviceInfo(device_id, CL_DEVICE_ADDRESS_BITS, retSize_2, &address_bits, &retSize_2); - + printf("device address bits: %i\n", address_bits); - - + + // Create a compute context // context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); @@ -77,15 +77,15 @@ int opencl_tests(void) { printf("Error: Failed to create a command commands!\n"); return EXIT_FAILURE; } - + // get the kernel from a file instead of a constant - + FILE *fp = fopen("./verify.cl", "r"); fseek(fp, 0L, SEEK_END); size_t sz = ftell(fp); rewind(fp); - + char *kernelBuf = malloc(sz); fread(kernelBuf, sizeof(char), sz, fp); fclose(fp); @@ -93,7 +93,7 @@ int opencl_tests(void) { // Create the compute program from the source buffer // //program = clCreateProgramWithSource(context, 1, (const char **) & KernelSource, NULL, &err); - program = clCreateProgramWithSource(context, 1, (const char **) & kernelBuf, NULL, &err); + program = clCreateProgramWithSource(context, 1, (const char **) & kernelBuf, &sz, &err); if (!program) { printf("Error: Failed to create compute program!\n"); @@ -132,7 +132,7 @@ int opencl_tests(void) { printf("Error: Failed to allocate device memory!\n"); exit(1); } - + // Write our data set into the input array in device memory // err = clEnqueueWriteBuffer(commands, input, CL_TRUE, 0, sizeof(float) * count, data, 0, NULL, NULL); @@ -186,13 +186,13 @@ int opencl_tests(void) { printf("Error: Failed to read output array! %d\n", err); exit(1); } - - - + + + // Print a brief summary detailing the results // printf("Computed '%d/%d' correct values!\n", correct, count); - + // Shutdown and cleanup // clReleaseMemObject(input); @@ -201,5 +201,5 @@ int opencl_tests(void) { clReleaseKernel(kernel); clReleaseCommandQueue(commands); clReleaseContext(context); - + } diff --git a/source/rsa-test.c b/source/rsa-test.c @@ -273,7 +273,7 @@ int verify_with_opencl(DIGIT_T *bases, size_t *b_len, // Create the compute program from the source buffer // //program = clCreateProgramWithSource(context, 1, (const char **) & KernelSource, NULL, &err); - program = clCreateProgramWithSource(context, 1, (const char **) & kernelBuf, NULL, &err); + program = clCreateProgramWithSource(context, 1, (const char **) & kernelBuf, &sz, &err); if (!program) { printf("Error: Failed to create compute program!\n");