diff options
author | Pan Xiuli <xiuli.pan@intel.com> | 2016-08-08 11:31:22 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2016-08-12 18:16:37 +0800 |
commit | adc46f6704bb652b14ddff20f5cd200ca7629df6 (patch) | |
tree | 53289574dc9015debc5b1d39ab08f48098f25c46 /utests | |
parent | 4a427b69612e0aac100ad68c634594752d250260 (diff) | |
download | beignet-adc46f6704bb652b14ddff20f5cd200ca7629df6.tar.gz |
Utest: Add test case for half type vload\store
V2: Half program is different with normal program, reorder the test case
order.
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'utests')
-rw-r--r-- | utests/compiler_vector_load_store.cpp | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/utests/compiler_vector_load_store.cpp b/utests/compiler_vector_load_store.cpp index 5a1a8d12..80e72a98 100644 --- a/utests/compiler_vector_load_store.cpp +++ b/utests/compiler_vector_load_store.cpp @@ -1,15 +1,27 @@ #include "utest_helper.hpp" #include <string.h> +#include <math.h> template<typename T> static void compiler_vector_load_store(int elemNum, const char *kernelName) { const size_t n = elemNum * 256; + if (strstr(kernelName, "half") != NULL) + if (!cl_check_half()) + return; // Setup kernel and buffers - OCL_CREATE_KERNEL_FROM_FILE("compiler_vector_load_store", kernelName); + if (strstr(kernelName, "half") != NULL) + OCL_CALL(cl_kernel_init, "compiler_vector_load_store.cl", kernelName, + SOURCE, "-DHALF"); + else + OCL_CREATE_KERNEL_FROM_FILE("compiler_vector_load_store", kernelName); buf_data[0] = (T*) malloc(sizeof(T) * n); - for (uint32_t i = 0; i < n; ++i) - ((T*)buf_data[0])[i] = i; + for (uint32_t i = 0; i < n; ++i) { + if (strstr(kernelName, "half") != NULL) + ((T*)buf_data[0])[i] = __float_to_half(as_uint((float)i/(float)n)); + else + ((T*)buf_data[0])[i] = i; + } OCL_CREATE_BUFFER(buf[0], CL_MEM_COPY_HOST_PTR, n * sizeof(T), buf_data[0]); OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(T), NULL); free(buf_data[0]); @@ -28,10 +40,17 @@ static void compiler_vector_load_store(int elemNum, const char *kernelName) for (uint32_t i = 0; i < n; ++i) { int shift = ((i % elemNum) + 1); - if (strstr(kernelName, "double") == NULL) - OCL_ASSERT(((T*)buf_data[1])[i] == (T)(((T*)buf_data[0])[i] + shift)); - else + if (strstr(kernelName, "double") != NULL) OCL_ASSERT((((T*)buf_data[1])[i] - ((T)((T*)buf_data[0])[i] + shift)) < 1e-5); + else if (strstr(kernelName, "half") != NULL) { + float fdst = as_float(__half_to_float(((T*)buf_data[1])[i])); + float fsrc = as_float(__half_to_float((T)(((T*)buf_data[0])[i]))); + fsrc += shift; + //printf("%d (%f, %f)\n",i, fdst, fsrc); + OCL_ASSERT((fabs(fsrc - fdst) <= 0.03 * fabs(fdst))); + } + else + OCL_ASSERT(((T*)buf_data[1])[i] == (T)(((T*)buf_data[0])[i] + shift)); } OCL_UNMAP_BUFFER(0); OCL_UNMAP_BUFFER(1); @@ -61,3 +80,4 @@ test_all_vector(float, float, true) //test_all_vector(double, double, true) test_all_vector(int64_t, long, true) test_all_vector(uint64_t, ulong, false) +test_all_vector(uint16_t, half, false) |