diff options
author | Benjamin Segovia <segovia.benjamin@gmail.com> | 2012-05-03 16:24:24 +0000 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-08-10 16:16:58 -0700 |
commit | ccd746d3af1a4778e5c145fb752ea5a739f70840 (patch) | |
tree | 0c2be48dec1047e9629210ecda488a5fa5e087f8 /utests/compiler_copy_buffer.cpp | |
parent | 1a9bcd8ff623a0b96cb034df711e4b02bfab8c6e (diff) | |
download | beignet-ccd746d3af1a4778e5c145fb752ea5a739f70840.tar.gz |
Revamped tests to make them smaller and simpler (and more automatic to use)
Diffstat (limited to 'utests/compiler_copy_buffer.cpp')
-rw-r--r-- | utests/compiler_copy_buffer.cpp | 90 |
1 files changed, 29 insertions, 61 deletions
diff --git a/utests/compiler_copy_buffer.cpp b/utests/compiler_copy_buffer.cpp index 57e2dab2..9380ace0 100644 --- a/utests/compiler_copy_buffer.cpp +++ b/utests/compiler_copy_buffer.cpp @@ -17,72 +17,40 @@ * Author: Benjamin Segovia <benjamin.segovia@intel.com> */ -#include "cl_test.h" +#include "utest_helper.hpp" -int -main (int argc, char *argv[]) +static void compiler_copy_buffer(void) { - cl_mem dst, src; - IF_DEBUG(uint32_t *dst_buffer = NULL); - uint32_t *src_buffer = NULL; const size_t n = 8192 * 4; - const size_t global_work_size = n; - const size_t local_work_size = 32; - int status = 0, i; - - if ((status = cl_test_init("test_copy_buffer.cl", "test_copy_buffer", SOURCE)) != 0) - goto error; - - /* Fill the buffer with random values */ - if ((src_buffer = malloc(sizeof(uint32_t) * n)) == NULL) { - fprintf(stderr, "Allocation failed\n"); - status = CL_OUT_OF_HOST_MEMORY; - goto error; - } - for (i = 0; i < n; ++i) - src_buffer[i] = i; - - /* Allocate the two buffers */ - dst = clCreateBuffer(ctx, 0, n * sizeof(uint32_t), NULL, &status); - if (status != CL_SUCCESS) - goto error; - src = clCreateBuffer(ctx, CL_MEM_COPY_HOST_PTR, n * sizeof(uint32_t), src_buffer, &status); - if (status != CL_SUCCESS) - goto error; - - /* Set source and destination */ - CALL (clSetKernelArg, kernel, 0, sizeof(cl_mem), &src); - CALL (clSetKernelArg, kernel, 1, sizeof(cl_mem), &dst); - - /* Run the kernel */ - CALL (clEnqueueNDRangeKernel, queue, - kernel, - 1, - NULL, - &global_work_size, - &local_work_size, - 0, - NULL, - NULL); - -#ifndef NDEBUG - /* Be sure that everything run fine */ - dst_buffer = (uint32_t *) clIntelMapBuffer(dst, &status); - if (status != CL_SUCCESS) - goto error; - for (i = 0; i < n; ++i) - assert(src_buffer[i] == dst_buffer[i]); - CALL (clIntelUnmapBuffer, dst); -#endif /* NDEBUG */ - free(src_buffer); - CALL (clReleaseMemObject, dst); - CALL (clReleaseMemObject, src); - cl_test_destroy(); - printf("%i memory leaks\n", clIntelReportUnfreed()); - assert(clIntelReportUnfreed() == 0); + int status = 0; + + CALL (cl_test_init, "test_copy_buffer.cl", "test_copy_buffer", SOURCE); + buf_data[0] = (uint32_t*) malloc(sizeof(uint32_t) * n); + for (uint32_t i = 0; i < n; ++i) ((uint32_t*)buf_data[0])[i] = i; + OCL_CREATE_BUFFER(buf[0], CL_MEM_COPY_HOST_PTR, n * sizeof(uint32_t), buf_data[0]); + OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(uint32_t), NULL); + free(buf_data[0]); + buf_data[0] = NULL; + + OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); + OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]); + + globals[0] = n; + locals[0] = 16; + OCL_NDRANGE(1); + + OCL_MAP_BUFFER(0); + OCL_MAP_BUFFER(1); + for (uint32_t i = 0; i < n; ++i) + assert(((uint32_t*)buf_data[0])[i] == ((uint32_t*)buf_data[1])[i]); + OCL_UNMAP_BUFFER(0); + OCL_UNMAP_BUFFER(1); error: + cl_release_buffers(); cl_report_error(status); - return status; + cl_test_destroy(); } +UTEST_REGISTER(compiler_copy_buffer) + |