vecadd: save operand to file
This commit is contained in:
@@ -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<std::chrono::milliseconds>(time_end - time_start).count();
|
||||
|
||||
Reference in New Issue
Block a user