From ee1ed315e2438b3ee64610533ba9905cbb5e6f14 Mon Sep 17 00:00:00 2001 From: Hansung Kim Date: Mon, 1 Jan 2024 14:26:10 -0800 Subject: [PATCH] Write out operand files in sharedmem kernel --- tests/opencl/sharedmem/main.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/opencl/sharedmem/main.cc b/tests/opencl/sharedmem/main.cc index 4ecd7489..e53b2db4 100644 --- a/tests/opencl/sharedmem/main.cc +++ b/tests/opencl/sharedmem/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; @@ -170,6 +191,10 @@ int main (int argc, char **argv) { //printf("*** [%d]: h_src=%f, h_dst=%f\n", i, h_src[i], h_dst[i]); } + // NOTE(hansung): Dump operand buffer to a file + if (write_operand_file("sharedmem.input.src.bin", h_src, nbytes) != 0) + return EXIT_FAILURE; + // Creating command queue commandQueue = CL_CHECK2(clCreateCommandQueue(context, device_id, 0, &_err));