diff options
author | Zhigang Gong <zhigang.gong@linux.intel.com> | 2013-05-24 17:42:18 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@linux.intel.com> | 2013-05-29 13:58:27 +0800 |
commit | f289075a6928e8b2f5243dbca2c0df2e5628f582 (patch) | |
tree | bda1105bf0f742ea514c1b36e2cdcb5bc1e95f1b /utests/compiler_vector_load_store.cpp | |
parent | f017fe759939edd75ba09288327b81120d6805a3 (diff) | |
download | beignet-f289075a6928e8b2f5243dbca2c0df2e5628f582.tar.gz |
utests: test vector load and store.
Add float4/short4/char4 test case.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Tested-by: Lv, Meng <meng.lv@intel.com>
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'utests/compiler_vector_load_store.cpp')
-rw-r--r-- | utests/compiler_vector_load_store.cpp | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/utests/compiler_vector_load_store.cpp b/utests/compiler_vector_load_store.cpp index 96fcfa97..76c12a11 100644 --- a/utests/compiler_vector_load_store.cpp +++ b/utests/compiler_vector_load_store.cpp @@ -1,10 +1,59 @@ #include "utest_helper.hpp" - -void compiler_vector_load_store(void) +template<typename T> +static void compiler_vector_load_store(int elemNum, const char *kernelName) { - OCL_CREATE_KERNEL("compiler_vector_load_store"); + const size_t n = elemNum * 256; + + // Setup kernel and buffers + 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; + OCL_CREATE_BUFFER(buf[0], CL_MEM_COPY_HOST_PTR, n * sizeof(float), buf_data[0]); + OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL); + free(buf_data[0]); + buf_data[0] = NULL; + + // Run the kernel + OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); + OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]); + globals[0] = n / elemNum; + locals[0] = 16; + OCL_NDRANGE(1); + + // Check result + OCL_MAP_BUFFER(0); + OCL_MAP_BUFFER(1); + for (uint32_t i = 0; i < n; ++i) + { + int shift = ((i % elemNum) + 1); + OCL_ASSERT(((T*)buf_data[1])[i] == (T)(((T*)buf_data[0])[i] + shift)); + } + OCL_UNMAP_BUFFER(0); + OCL_UNMAP_BUFFER(1); } -MAKE_UTEST_FROM_FUNCTION(compiler_vector_load_store); +#define compiler_vector_load_store(type, n, kernel_type) \ +static void compiler_vector_ ##kernel_type ##n ##_load_store(void)\ +{\ + compiler_vector_load_store<type>(n, "test_" #kernel_type #n);\ +}\ +MAKE_UTEST_FROM_FUNCTION(compiler_vector_ ## kernel_type ##n ##_load_store); +#define test_all_vector(type, kernel_type) \ + compiler_vector_load_store(type, 2, kernel_type) \ + /*compiler_vector_load_store(type, 3, kernel_type)*/ \ + compiler_vector_load_store(type, 4, kernel_type) \ + compiler_vector_load_store(type, 8, kernel_type) \ + compiler_vector_load_store(type, 16, kernel_type) +test_all_vector(int8_t, char) +test_all_vector(uint8_t, uchar) +test_all_vector(int16_t, short) +test_all_vector(uint16_t, ushort) +test_all_vector(int32_t, int) +test_all_vector(uint32_t, uint) +test_all_vector(float, float) +//test_all_vector(double, double) +//test_all_vector(int64_t, long) +//test_all_vector(uint64_t, ulong) |