INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../include)
-ADD_LIBRARY(utest SHARED
- utest_error.c
- utest_helper.cpp
- utest_file_map.cpp
- utest_assert.cpp
- utest.cpp)
-ADD_EXECUTABLE(compiler_write_only compiler_write_only.cpp)
-TARGET_LINK_LIBRARIES(compiler_write_only cl m utest)
+ADD_EXECUTABLE(run
+ utest_error.c
+ utest_helper.cpp
+ utest_file_map.cpp
+ utest_assert.cpp
+ utest.cpp
+ utest_run.cpp
+ compiler_write_only.cpp
+ compiler_copy_buffer.cpp
+ compiler_copy_buffer_row.cpp)
+TARGET_LINK_LIBRARIES(run cl m)
* 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)
+
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#include "cl_test.h"
+#include "utest_helper.hpp"
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-main (int argc, char *argv[])
+static void compiler_copy_buffer_row(void)
{
- cl_mem dst, src, data;
- IF_DEBUG(uint32_t *dst_buffer = NULL);
uint32_t *src_buffer = NULL;
int *data_buffer = NULL;
const int row = 8192;
const int row_n = 2;
const int n = row * row_n;
- const size_t global_work_size = row;
- const size_t local_work_size = 256;
- int status = 0, i;
+ int status = 0;
- if ((status = cl_test_init("test_copy_buffer_row.cl", "test_copy_buffer_row", SOURCE)) != 0)
- goto error;
+ CALL (cl_test_init, "test_copy_buffer_row.cl", "test_copy_buffer_row", SOURCE);
- /* Fill the buffer with some values */
+ // Create the input data
src_buffer = (uint32_t *) malloc(sizeof(uint32_t) * n);
- for (i = 0; i < n; ++i) src_buffer[i] = i;
-
- /* Just put copy info in a buffer */
+ for (int32_t i = 0; i < n; ++i) src_buffer[i] = i;
data_buffer = (int *) malloc(sizeof(int) * 2);
data_buffer[0] = row;
data_buffer[1] = n;
- /* 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;
- data = clCreateBuffer(ctx, CL_MEM_COPY_HOST_PTR, 2 * sizeof(int), data_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);
- CALL (clSetKernelArg, kernel, 2, sizeof(cl_mem), &data);
-
- /* 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 */
-
+ // Allocate all buffers
+ OCL_CREATE_BUFFER(buf[0], CL_MEM_COPY_HOST_PTR, n * sizeof(uint32_t), src_buffer);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(uint32_t), NULL);
+ OCL_CREATE_BUFFER(buf[2], CL_MEM_COPY_HOST_PTR, 2 * sizeof(uint32_t), data_buffer);
free(src_buffer);
free(data_buffer);
- CALL (clReleaseMemObject, dst);
- CALL (clReleaseMemObject, src);
- CALL (clReleaseMemObject, data);
- cl_test_destroy();
- printf("%i memory leaks\n", clIntelReportUnfreed());
- assert(clIntelReportUnfreed() == 0);
+ // Run the code
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ OCL_SET_ARG(2, sizeof(cl_mem), &buf[2]);
+ globals[0] = n;
+ locals[0] = 16;
+ OCL_NDRANGE(1);
+
+ // Check results
+ OCL_MAP_BUFFER(0);
+ OCL_MAP_BUFFER(1);
+ for (int32_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_row)
+
#include "utest_helper.hpp"
-int
-main (int argc, char *argv[])
+void compiler_write_only(void)
{
const size_t n = 2048;
- int status = 0, i;
+ int status = 0;
CALL (cl_test_init, "test_write_only.cl", "test_write_only", SOURCE);
OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL);
locals[0] = 16;
OCL_NDRANGE(1);
OCL_MAP_BUFFER(0);
- for (i = 0; i < n; ++i) assert(((int*)buf_data[0])[i] == i);
+ for (uint32_t i = 0; i < n; ++i) assert(((uint32_t*)buf_data[0])[i] == i);
OCL_UNMAP_BUFFER(0);
error:
cl_release_buffers();
cl_report_error(status);
cl_test_destroy();
- return status;
}
+UTEST_REGISTER(compiler_write_only);
+
#include "CL/cl.h"
#include "CL/cl_intel.h"
+#include "utest.hpp"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
CALL (clSetKernelArg, kernel, ID, SIZE, ARG); \
} while (0)
-#ifdef __cplusplus
-extern "C" {
-#endif
-
+enum { MAX_BUFFER_N = 16 };
extern cl_platform_id platform;
extern cl_device_id device;
extern cl_context ctx;
extern cl_program program;
extern cl_kernel kernel;
extern cl_command_queue queue;
-enum { MAX_BUFFER_N = 16 };
extern cl_mem buf[MAX_BUFFER_N]; // initialized at NULL
extern void* buf_data[MAX_BUFFER_N]; // initialized at NULL
extern size_t globals[3]; // initialized at zero
/* Nicely output the performance counters */
extern void cl_report_perf_counters(cl_mem perf);
-#ifdef __cplusplus
-}
-#endif
-
#endif /* __UTEST_HELPER_HPP__ */
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file utest_run.cpp
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ *
+ * Just run the unit tests. The user can possibly provides the subset of it
+ */
+#include "utest.hpp"
+
+int main(int argc, char *argv[])
+{
+ if (argc >= 2)
+ for (int i = 1; i < argc; ++i)
+ UTest::run(argv[i]);
+ else
+ UTest::runAll();
+}
+