diff options
author | Homer Hsing <homer.xing@intel.com> | 2013-09-13 09:41:02 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@linux.intel.com> | 2013-09-17 13:12:46 +0800 |
commit | 3ae20b67ab88bd595a6dca9814dd642c5d056d9f (patch) | |
tree | 9acb48e9075aa4bd0feb2690e25d6892c33777b7 /utests/compiler_long_convert.cpp | |
parent | 041867b623ee068b3a3b00f407f9fd01318e3736 (diff) |
support converting 64-bit integer to 32-bit float
version 2:
improve algorithm to convert signed integer
fix source operand type in llvm_gen_backend
enable predicate in addWithCarry
change test case to test signed integer
Signed-off-by: Homer Hsing <homer.xing@intel.com>
Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
Diffstat (limited to 'utests/compiler_long_convert.cpp')
-rw-r--r-- | utests/compiler_long_convert.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/utests/compiler_long_convert.cpp b/utests/compiler_long_convert.cpp index fe976be5..827a45bd 100644 --- a/utests/compiler_long_convert.cpp +++ b/utests/compiler_long_convert.cpp @@ -116,3 +116,43 @@ void compiler_long_convert_2(void) } MAKE_UTEST_FROM_FUNCTION(compiler_long_convert_2); + +// convert 64-bit integer to 32-bit float +void compiler_long_convert_to_float(void) +{ + const size_t n = 16; + int64_t src[n]; + + // Setup kernel and buffers + OCL_CREATE_KERNEL_FROM_FILE("compiler_long_convert", "compiler_long_convert_to_float"); + OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL); + OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(int64_t), 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; + + // Run random tests + for (int32_t i = 0; i < (int32_t) n; ++i) { + src[i] = -(int64_t)i; + } + OCL_MAP_BUFFER(1); + memcpy(buf_data[1], src, sizeof(src)); + OCL_UNMAP_BUFFER(1); + + // Run the kernel on GPU + OCL_NDRANGE(1); + + // Compare + OCL_MAP_BUFFER(0); + OCL_MAP_BUFFER(1); + float *dst = ((float *)buf_data[0]); + for (int32_t i = 0; i < (int32_t) n; ++i) { + //printf("%f\n", dst[i]); + OCL_ASSERT(dst[i] == src[i]); + } + OCL_UNMAP_BUFFER(0); + OCL_UNMAP_BUFFER(1); +} + +MAKE_UTEST_FROM_FUNCTION(compiler_long_convert_to_float); |