Write operand to file in matmul kernel

This commit is contained in:
Hansung Kim
2023-11-29 11:30:54 -08:00
parent 5825680303
commit 158624bc1b

View File

@@ -56,6 +56,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 compare_equal(float a, float b, int ulp = 21) {
union fi_t { int i; float f; };
fi_t fa, fb;
@@ -204,6 +225,12 @@ int main (int argc, char **argv) {
h_c[i] = 0xdeadbeef;
}
// NOTE(hansung): Dump operand buffer to a file
if (write_operand_file("matmul.input.a.bin", h_a.data(), nbytes) != 0)
return EXIT_FAILURE;
if (write_operand_file("matmul.input.b.bin", h_b.data(), nbytes) != 0)
return EXIT_FAILURE;
// Creating command queue
commandQueue = CL_CHECK2(clCreateCommandQueue(context, device_id, 0, &_err));