summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utests/CMakeLists.txt13
-rw-r--r--utests/load_program_from_bin.cpp77
-rw-r--r--utests/utest_helper.cpp8
-rw-r--r--utests/utest_helper.hpp3
4 files changed, 96 insertions, 5 deletions
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index ffabc39f..37261168 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -141,11 +141,22 @@ set (utests_sources
compiler_long_mult.cpp
compiler_long_cmp.cpp
compiler_bool_cross_basic_block.cpp
+ load_program_from_bin.cpp
utest_assert.cpp
utest.cpp
utest_file_map.cpp
utest_helper.cpp)
+SET (kernel_bin ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/compiler_ceil)
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${kernel_bin}.bin
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../backend/src/gbe_bin_generater ${kernel_bin}.cl -o${kernel_bin}.bin
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/../backend/src/gbe_bin_generater ${kernel_bin}.cl
+ )
+
+ADD_CUSTOM_TARGET(kernel_bin.bin
+ DEPENDS ${kernel_bin}.bin)
+
if (EGL_FOUND AND MESA_SOURCE_FOUND)
SET(utests_sources ${utests_sources} compiler_fill_gl_image.cpp)
SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}")
@@ -158,7 +169,7 @@ TARGET_LINK_LIBRARIES(utests cl m ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
ADD_EXECUTABLE(utest_run utest_run.cpp)
TARGET_LINK_LIBRARIES(utest_run utests)
+ADD_DEPENDENCIES (utest_run kernel_bin.bin)
ADD_EXECUTABLE(flat_address_space runtime_flat_address_space.cpp)
TARGET_LINK_LIBRARIES(flat_address_space utests)
-
diff --git a/utests/load_program_from_bin.cpp b/utests/load_program_from_bin.cpp
new file mode 100644
index 00000000..d45c2bda
--- /dev/null
+++ b/utests/load_program_from_bin.cpp
@@ -0,0 +1,77 @@
+#include "utest_helper.hpp"
+#include "utest_file_map.hpp"
+#include <cmath>
+#include <algorithm>
+
+using namespace std;
+
+static void cpu(int global_id, float *src, float *dst) {
+ dst[global_id] = ceilf(src[global_id]);
+}
+
+static void test_load_program_from_bin(void)
+{
+ const size_t n = 16;
+ float cpu_dst[16], cpu_src[16];
+ cl_int status;
+ cl_int binary_status;
+ char *ker_path = NULL;
+
+ cl_file_map_t *fm = cl_file_map_new();
+ ker_path = cl_do_kiss_path("compiler_ceil.bin", device);
+ OCL_ASSERT (cl_file_map_open(fm, ker_path) == CL_FILE_MAP_SUCCESS);
+
+ const unsigned char *src = (const unsigned char *)cl_file_map_begin(fm);
+ const size_t sz = cl_file_map_size(fm);
+
+ program = clCreateProgramWithBinary(ctx, 1,
+ &device, &sz, &src, &binary_status, &status);
+
+ OCL_ASSERT(program && status == CL_SUCCESS);
+
+ /* OCL requires to build the program even if it is created from a binary */
+ OCL_ASSERT(clBuildProgram(program, 1, &device, NULL, NULL, NULL) == CL_SUCCESS);
+
+ kernel = clCreateKernel(program, "compiler_ceil", &status);
+ OCL_ASSERT(status == CL_SUCCESS);
+
+ OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL);
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ globals[0] = 16;
+ locals[0] = 16;
+
+ // Run random tests
+ for (uint32_t pass = 0; pass < 8; ++pass) {
+ OCL_MAP_BUFFER(0);
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ cpu_src[i] = ((float*)buf_data[0])[i] = .1f * (rand() & 15) - .75f;
+ OCL_UNMAP_BUFFER(0);
+
+ // Run the kernel on GPU
+ OCL_NDRANGE(1);
+
+ // Run on CPU
+ for (int32_t i = 0; i < (int32_t) n; ++i) cpu(i, cpu_src, cpu_dst);
+
+ // Compare
+ OCL_MAP_BUFFER(1);
+
+#if 0
+ printf("#### GPU:\n");
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ printf(" %f", ((float *)buf_data[1])[i]);
+ printf("\n#### CPU:\n");
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ printf(" %f", cpu_dst[i]);
+ printf("\n");
+#endif
+
+ for (int32_t i = 0; i < (int32_t) n; ++i)
+ OCL_ASSERT(((float *)buf_data[1])[i] == cpu_dst[i]);
+ OCL_UNMAP_BUFFER(1);
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(test_load_program_from_bin);
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index b4f61df4..80897991 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -205,8 +205,8 @@ clpanic(const char *msg, int rval)
exit(-1);
}
-static char*
-do_kiss_path(const char *file, cl_device_id device)
+char*
+cl_do_kiss_path(const char *file, cl_device_id device)
{
cl_int ver;
const char *sub_path = NULL;
@@ -239,7 +239,7 @@ cl_kernel_init(const char *file_name, const char *kernel_name, int format, const
cl_int status = CL_SUCCESS;
/* Load the program and build it */
- ker_path = do_kiss_path(file_name, device);
+ ker_path = cl_do_kiss_path(file_name, device);
if (format == LLVM)
program = clCreateProgramWithLLVMIntel(ctx, 1, &device, ker_path, &status);
else if (format == SOURCE) {
@@ -513,7 +513,7 @@ struct bmphdr {
int *cl_read_bmp(const char *filename, int *width, int *height)
{
struct bmphdr hdr;
- char *bmppath = do_kiss_path(filename, device);
+ char *bmppath = cl_do_kiss_path(filename, device);
FILE *fp = fopen(bmppath, "rb");
assert(fp);
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index 4a6071de..29a21d54 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -186,6 +186,9 @@ extern int cl_ocl_init(void);
extern int cl_kernel_init(const char *file_name,
const char *kernel_name, int format, const char * build_opt);
+/* Get the file path */
+extern char* cl_do_kiss_path(const char *file, cl_device_id device);
+
/* init the bunch of global varaibles here */
extern int cl_test_init(const char *file_name, const char *kernel_name, int format);