[tests] vecadd|sgemm|saxpy: save input buffers to file
This commit is contained in:
@@ -78,6 +78,25 @@ static int read_kernel_file(const char* filename, uint8_t** data, size_t* size)
|
|||||||
return 0;
|
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;
|
uint8_t *kernel_bin = NULL;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -209,6 +228,11 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
h_src[i] = ((float)rand() / (float)(RAND_MAX)) * 100.0;
|
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));
|
CL_CHECK(clEnqueueWriteBuffer(queue, input_buffer, CL_TRUE, 0, nbytes, h_src, 0, NULL, NULL));
|
||||||
free(h_src);
|
free(h_src);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,25 @@ static int read_kernel_file(const char* filename, uint8_t** data, size_t* size)
|
|||||||
return 0;
|
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) {
|
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 m = 0; m < M; ++m) {
|
||||||
for (int n = 0; n < N; ++n) {
|
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]);
|
//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
|
// Creating command queue
|
||||||
commandQueue = CL_CHECK2(clCreateCommandQueue(context, device_id, 0, &_err));
|
commandQueue = CL_CHECK2(clCreateCommandQueue(context, device_id, 0, &_err));
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,25 @@ static int read_kernel_file(const char* filename, uint8_t** data, size_t* size)
|
|||||||
return 0;
|
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) {
|
static bool almost_equal(float a, float b, int ulp = 4) {
|
||||||
union fi_t { int i; float f; };
|
union fi_t { int i; float f; };
|
||||||
fi_t fa, fb;
|
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]);
|
//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
|
// Creating command queue
|
||||||
// NOTE(hansung): The 3rd properties arg is a bit-field, where fields like
|
// 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,
|
// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE can be set. With value of 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user