From f586ab28df4dc47033ea0d07c64289aa83dac7ca Mon Sep 17 00:00:00 2001 From: Hansung Kim Date: Mon, 12 Feb 2024 20:47:36 -0800 Subject: [PATCH] vecadd: save operand to file --- tests/opencl/vecadd/main.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/opencl/vecadd/main.cc b/tests/opencl/vecadd/main.cc index 23aa49b4..9e03ac42 100644 --- a/tests/opencl/vecadd/main.cc +++ b/tests/opencl/vecadd/main.cc @@ -52,6 +52,27 @@ static int read_kernel_file(const char* filename, uint8_t** data, size_t* size) return 0; } +static int write_operand_file(const char* filename, void* data, size_t size) { + if (nullptr == filename || nullptr == data || 0 == size) + return -1; + + FILE* fp = fopen(filename, "wb"); + if (NULL == fp) { + fprintf(stderr, "Failed to write operand data.\n"); + return -1; + } + + size_t wsize = fwrite(data, size, 1, fp); + if (wsize != 1) { + fprintf(stderr, "Failed to write operand data.\n"); + return -1; + } + + fclose(fp); + + return 0; +} + static bool almost_equal(float a, float b, int ulp = 4) { union fi_t { int i; float f; }; fi_t fa, fb; @@ -174,6 +195,12 @@ int main (int argc, char **argv) { //printf("*** [%d]: h_a=%f, h_b=%f\n", i, h_a[i], h_b[i]); } + // NOTE(hansung): Dump operand buffer to a file + if (write_operand_file("vecadd.input.a.size64.bin", h_a, nbytes) != 0) + return EXIT_FAILURE; + if (write_operand_file("vecadd.input.b.size64.bin", h_b, nbytes) != 0) + return EXIT_FAILURE; + // Creating command queue commandQueue = CL_CHECK2(clCreateCommandQueue(context, device_id, 0, &_err)); @@ -183,8 +210,9 @@ int main (int argc, char **argv) { printf("Execute the kernel\n"); size_t global_work_size[1] = {size}; + size_t local_work_size[1] = {1}; auto time_start = std::chrono::high_resolution_clock::now(); - CL_CHECK(clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL)); + CL_CHECK(clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL)); CL_CHECK(clFinish(commandQueue)); auto time_end = std::chrono::high_resolution_clock::now(); double elapsed = std::chrono::duration_cast(time_end - time_start).count();