Signed-off-by: rander <rander.w...@intel.com> --- kernels/builtin_convert_double2int16.cl | 73 ++++++++++++++ utests/CMakeLists.txt | 3 +- utests/builtin_convert_double2int16.cpp | 167 ++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 kernels/builtin_convert_double2int16.cl create mode 100644 utests/builtin_convert_double2int16.cpp
diff --git a/kernels/builtin_convert_double2int16.cl b/kernels/builtin_convert_double2int16.cl new file mode 100644 index 0000000..fb3baea --- /dev/null +++ b/kernels/builtin_convert_double2int16.cl @@ -0,0 +1,73 @@ +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +__kernel void builtin_convert_double2int16(__global double *X, + __global short *Z, + __global ushort *uZ, + int max_input) +{ + int i = get_global_id(0); + int j; + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_sat(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_rtz(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_rtn(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_rte(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_rtp(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_sat_rtz(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_sat_rtn(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_sat_rte(X[j]); + + for(j = 0; j < max_input; j++) + Z[i++] = convert_short_sat_rtp(X[j]); + + i = 0; + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_sat(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_rtz(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_rtn(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_rte(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_rtp(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_sat_rtz(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_sat_rtn(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_sat_rte(X[j]); + + for(j = 0; j < max_input; j++) + uZ[i++] = convert_ushort_sat_rtp(X[j]); + +} + diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index f12643f..c18f79d 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -300,7 +300,8 @@ set (utests_sources compiler_device_enqueue.cpp builtin_relation_fp64.cpp builtin_commonFunc_fp64.cpp - builtin_convert_double2int8.cpp) + builtin_convert_double2int8.cpp + builtin_convert_double2int16.cpp) if (LLVM_VERSION_NODOT VERSION_GREATER 34) SET(utests_sources diff --git a/utests/builtin_convert_double2int16.cpp b/utests/builtin_convert_double2int16.cpp new file mode 100644 index 0000000..c38d49b --- /dev/null +++ b/utests/builtin_convert_double2int16.cpp @@ -0,0 +1,167 @@ +#include "utest_helper.hpp" +#include <cmath> +#include <algorithm> + +namespace{ +double doubleX[] = { + 0x1.0000000001p0, + -0x1.0000000001p2, + 0x1.1ffp8, + -0x1.1fffp8, + 0x1.0p7, + -0x1.0p7, + 0x1.fffp6, + -0x1.ffffp6, + 0x1.ffffp7, + 0x1.1p-64, + -0x1.ffffp7, + 0x1.00001p8, + -0x1.00001p8, + 0x1.00000001p5, + -0x1.00000001p5, + 0x1.0p-32, + -0x1.0p-32, + 0x1.000000001p16, + -0x1.000000001p16, + 0x1.ffffffffffp15, + -0x1.1p-64 + -0x1.ffffffffffp15, + 0x1.fffffffffp8, + -0x1.fffffffffp8, + 0x1fffffp128, + -0x1ffffffp128, + 0x1.1000001p12, + -0x1.1000001p12, + 0x1.cp13, + -0x1.cp13, + 0x1.100001p11, + -0x1.100001p11, +}; + +const char* testFunc[] = +{ + " short convert_short(double x)", + " short convert_short_sat(double x)", + " short convert_short_rtz(double x)", + " short convert_short_rtn(double x)", + " short convert_short_rte(double x)", + " short convert_short_rtp(double x)", + " short convert_short_sat_rtz(double x)", + " short convert_short_sat_rtn(double x)", + " short convert_short_sat_rte(double x)", + " short convert_short_sat_rtp(double x)", + + " ushort convert_ushort(double x)", + " ushort convert_ushort_sat(double x)", + " ushort convert_ushort_rtz(double x)", + " ushort convert_ushort_rtn(double x)", + " ushort convert_ushort_rte(double x)", + " ushort convert_ushort_rtp(double x)", + " ushort convert_ushort_sat_rtz(double x)", + " ushort convert_ushort_sat_rtn(double x)", + " ushort convert_ushort_sat_rte(double x)", + " ushort convert_ushort_sat_rtp(double x)" +}; + +short expectResultshort[] = { + 1, -4, 287, -287, 128, -128, 127, -127, 255, 0, -255, 256, -256, 32, -32, 0, + 0, 32767, -32768, 32767, -32768, 511, -511, 32767, -32768, 4352, -4352, 14336, -14336, 2176, -2176, 0, + 1, -4, 287, -287, 128, -128, 127, -127, 255, 0, -255, 256, -256, 32, -32, 0, + 0, 32767, -32768, 32767, -32768, 511, -511, 32767, -32768, 4352, -4352, 14336, -14336, 2176, -2176, 0, + 1, -4, 287, -287, 128, -128, 127, -127, 255, 0, -255, 256, -256, 32, -32, 0, + 0, 0, 0, -1, 1, 511, -511, -1, 1, 4352, -4352, 14336, -14336, 2176, -2176, 0, + 1, -5, 287, -288, 128, -128, 127, -128, 255, 0, -256, 256, -257, 32, -33, 0, + -1, 0, -1, -1, 0, 511, -512, -1, 1, 4352, -4353, 14336, -14336, 2176, -2177, 0, + 1, -4, 288, -288, 128, -128, 128, -128, 256, 0, -256, 256, -256, 32, -32, 0, + 0, 0, 0, 0, 0, 512, -512, 0, 0, 4352, -4352, 14336, -14336, 2176, -2176, 0, + 2, -4, 288, -287, 128, -128, 128, -127, 256, 1, -255, 257, -256, 33, -32, 1, + 0, 1, 0, 0, 1, 512, -511, 0, 0, 4353, -4352, 14336, -14336, 2177, -2176, 0, + 1, -4, 287, -287, 128, -128, 127, -127, 255, 0, -255, 256, -256, 32, -32, 0, + 0, 32767, -32768, 32767, -32768, 511, -511, 32767, -32768, 4352, -4352, 14336, -14336, 2176, -2176, 0, + 1, -5, 287, -288, 128, -128, 127, -128, 255, 0, -256, 256, -257, 32, -33, 0, + -1, 32767, -32768, 32767, -32768, 511, -512, 32767, -32768, 4352, -4353, 14336, -14336, 2176, -2177, 0, + 1, -4, 288, -288, 128, -128, 128, -128, 256, 0, -256, 256, -256, 32, -32, 0, + 0, 32767, -32768, 32767, -32768, 512, -512, 32767, -32768, 4352, -4352, 14336, -14336, 2176, -2176, 0, + 2, -4, 288, -287, 128, -128, 128, -127, 256, 1, -255, 257, -256, 33, -32, 1, + 0, 32767, -32768, 32767, -32768, 512, -511, 32767, -32768, 4353, -4352, 14336, -14336, 2177, -2176, 0 +}; + +unsigned short expectResultUshort[] = { + 1, 0, 287, 0, 128, 0, 127, 0, 255, 0, 0, 256, 0, 32, 0, 0, + 0, 65535, 0, 65535, 0, 511, 0, 65535, 0, 4352, 0, 14336, 0, 2176, 0, 0, + 1, 0, 287, 0, 128, 0, 127, 0, 255, 0, 0, 256, 0, 32, 0, 0, + 0, 65535, 0, 65535, 0, 511, 0, 65535, 0, 4352, 0, 14336, 0, 2176, 0, 0, + 1, 0, 287, 0, 128, 0, 127, 0, 255, 0, 0, 256, 0, 32, 0, 0, + 0, 0, 0, 65535, 0, 511, 0, 65535, 0, 4352, 0, 14336, 0, 2176, 0, 0, + 1, 4, 287, 287, 128, 128, 127, 127, 255, 0, 255, 256, 256, 32, 32, 0, + 0, 0, 0, 65535, 65535, 511, 511, 65535, 65535, 4352, 4352, 14336, 14336, 2176, 2176, 0, + 1, 65532, 288, 65248, 128, 65408, 128, 65408, 256, 0, 65280, 256, 65280, 32, 65504, 0, + 0, 0, 0, 0, 0, 512, 65024, 0, 0, 4352, 61184, 14336, 51200, 2176, 63360, 0, + 2, 0, 288, 0, 128, 0, 128, 0, 256, 1, 0, 257, 0, 33, 0, 1, + 0, 1, 0, 0, 0, 512, 0, 0, 0, 4353, 0, 14336, 0, 2177, 0, 0, + 1, 0, 287, 0, 128, 0, 127, 0, 255, 0, 0, 256, 0, 32, 0, 0, + 0, 65535, 0, 65535, 0, 511, 0, 65535, 0, 4352, 0, 14336, 0, 2176, 0, 0, + 1, 0, 287, 0, 128, 0, 127, 0, 255, 0, 0, 256, 0, 32, 0, 0, + 0, 65535, 0, 65535, 0, 511, 0, 65535, 0, 4352, 0, 14336, 0, 2176, 0, 0, + 1, 0, 288, 0, 128, 0, 128, 0, 256, 0, 0, 256, 0, 32, 0, 0, + 0, 65535, 0, 65535, 0, 512, 0, 65535, 0, 4352, 0, 14336, 0, 2176, 0, 0, + 2, 0, 288, 0, 128, 0, 128, 0, 256, 1, 0, 257, 0, 33, 0, 1, + 0, 65535, 0, 65535, 0, 512, 0, 65535, 0, 4353, 0, 14336, 0, 2177, 0, 0 +}; + +double *input_data; +const int count_input = 32; +const int max_function = 20; + +static void builtin_convert_double2int16(void) +{ + // Setup kernel and buffers + int k, i, index_cur; + short gpu_data[max_function * count_input] = {0}; + float diff; + short log[256] = {0}; + + OCL_CREATE_KERNEL("builtin_convert_double2int16"); + + OCL_CREATE_BUFFER(buf[0], CL_MEM_READ_WRITE, count_input * max_function * sizeof(double), NULL); + OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, count_input * max_function * sizeof(short), NULL); + OCL_CREATE_BUFFER(buf[2], CL_MEM_READ_WRITE, count_input * max_function * sizeof(short), NULL); + + 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]); + OCL_SET_ARG(3, sizeof(int), &count_input); + + globals[0] = 1; + locals[0] = 1; + + input_data = (double *)doubleX; + clEnqueueWriteBuffer( queue, buf[0], CL_TRUE, 0, count_input * max_function * sizeof(double), input_data, 0, NULL, NULL); + + // Run the kernel + OCL_NDRANGE( 1 ); + + clEnqueueReadBuffer( queue, buf[1], CL_TRUE, 0, sizeof(short) * max_function/2 * count_input, gpu_data, 0, NULL, NULL); + for (k = 0; (uint)k < count_input*max_function/2; k++) + { + OCL_ASSERT(gpu_data[k] == expectResultshort[k]); + if(gpu_data[k] != expectResultshort[k]) + { + printf("failed at function:%s, expect value: %d, but get :%d \n", testFunc[k/count_input], expectResultshort[k], gpu_data[k]); + } + } + + clEnqueueReadBuffer( queue, buf[2], CL_TRUE, 0, sizeof(short) * max_function/2 * count_input, gpu_data, 0, NULL, NULL); + unsigned short *ugpu_data = (unsigned short *)gpu_data; + for (k = 0; (uint)k < count_input*max_function/2; k++) + { + OCL_ASSERT(ugpu_data[k] == expectResultUshort[k]); + if(ugpu_data[k] != expectResultUshort[k]) + { + printf("failed at function:%s, expect value: %d, but get :%d \n", testFunc[k/count_input + max_function/2 ], expectResultUshort[k], ugpu_data[k]); + } + } +} + +MAKE_UTEST_FROM_FUNCTION(builtin_convert_double2int16) +} -- 2.7.4 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/beignet