[tests] vecadd|sgemm|saxpy: save input buffers to file

This commit is contained in:
Hansung Kim
2023-09-25 13:29:00 -07:00
parent 576e7aab78
commit b97e94b8ed
3 changed files with 74 additions and 0 deletions

View File

@@ -78,6 +78,25 @@ 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;
}
return 0;
}
uint8_t *kernel_bin = NULL;
///
@@ -209,6 +228,11 @@ int main(int argc, char **argv) {
for (int i = 0; i < size; i++) {
h_src[i] = ((float)rand() / (float)(RAND_MAX)) * 100.0;
}
// NOTE(hansung): Dump operand buffer to a file
if (write_operand_file("saxpy.input.src.bin", h_src, nbytes) != 0)
return EXIT_FAILURE;
CL_CHECK(clEnqueueWriteBuffer(queue, input_buffer, CL_TRUE, 0, nbytes, h_src, 0, NULL, NULL));
free(h_src);

View File

@@ -52,6 +52,25 @@ 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;
}
return 0;
}
static void matmul(float *C, const float* A, const float *B, int M, int N, int K) {
for (int m = 0; m < M; ++m) {
for (int n = 0; n < N; ++n) {
@@ -194,6 +213,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("sgemm.input.a.bin", h_a, nbytes) != 0)
return EXIT_FAILURE;
if (write_operand_file("sgemm.input.b.bin", h_b, nbytes) != 0)
return EXIT_FAILURE;
// Creating command queue
commandQueue = CL_CHECK2(clCreateCommandQueue(context, device_id, 0, &_err));

View File

@@ -52,6 +52,25 @@ 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;
}
return 0;
}
static bool almost_equal(float a, float b, int ulp = 4) {
union fi_t { int i; float f; };
fi_t fa, fb;
@@ -175,6 +194,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.bin", h_a, nbytes) != 0)
return EXIT_FAILURE;
if (write_operand_file("vecadd.input.b.bin", h_b, nbytes) != 0)
return EXIT_FAILURE;
// Creating command queue
// NOTE(hansung): The 3rd properties arg is a bit-field, where fields like
// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE can be set. With value of 0,