// // Copyright (c) 2017 The Khronos Group Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include "harness/compat.h" #include #include #include #include #include "procs.h" static int test_sign_double(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems); const char *sign_kernel_code = "__kernel void test_sign(__global float *src, __global float *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = sign(src[tid]);\n" "}\n"; const char *sign2_kernel_code = "__kernel void test_sign2(__global float2 *src, __global float2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = sign(src[tid]);\n" "}\n"; const char *sign4_kernel_code = "__kernel void test_sign4(__global float4 *src, __global float4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = sign(src[tid]);\n" "}\n"; const char *sign8_kernel_code = "__kernel void test_sign8(__global float8 *src, __global float8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = sign(src[tid]);\n" "}\n"; const char *sign16_kernel_code = "__kernel void test_sign16(__global float16 *src, __global float16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = sign(src[tid]);\n" "}\n"; const char *sign3_kernel_code = "__kernel void test_sign3(__global float *src, __global float *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " vstore3(sign(vload3(tid,src)), tid, dst);\n" "}\n"; static int verify_sign(float *inptr, float *outptr, int n) { float r; int i; for (i=0; i 0.0f) r = 1.0f; else if (inptr[i] < 0.0f) r = -1.0f; else r = 0.0f; if (r != outptr[i]) return -1; } return 0; } static const char *fn_names[] = { "SIGN float", "SIGN float2", "SIGN float4", "SIGN float8", "SIGN float16", "SIGN float3" }; int test_sign(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems) { cl_mem streams[2]; cl_float *input_ptr[1], *output_ptr, *p; cl_program program[kTotalVecCount]; cl_kernel kernel[kTotalVecCount]; void *values[2]; size_t threads[1]; int num_elements; int err; int i; MTdata d; num_elements = n_elems * 16; input_ptr[0] = (cl_float*)malloc(sizeof(cl_float) * num_elements); output_ptr = (cl_float*)malloc(sizeof(cl_float) * num_elements); streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * num_elements, NULL, NULL); if (!streams[0]) { log_error("clCreateBuffer failed\n"); return -1; } streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * num_elements, NULL, NULL); if (!streams[1]) { log_error("clCreateBuffer failed\n"); return -1; } d = init_genrand( gRandomSeed ); p = input_ptr[0]; for (i=0; i 0.0) r = 1.0; else if (inptr[i] < 0.0) r = -1.0; else r = 0.0f; if (r != outptr[i]) return -1; } return 0; } static const char *fn_names_double[] = { "SIGN double", "SIGN double2", "SIGN double4", "SIGN double8", "SIGN double16", "SIGN double3" }; int test_sign_double(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems) { cl_mem streams[2]; cl_double *input_ptr[1], *output_ptr, *p; cl_program program[kTotalVecCount]; cl_kernel kernel[kTotalVecCount]; void *values[2]; size_t threads[1]; int num_elements; int err; int i; MTdata d; num_elements = n_elems * 16; input_ptr[0] = (cl_double*)malloc(sizeof(cl_double) * num_elements); output_ptr = (cl_double*)malloc(sizeof(cl_double) * num_elements); streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_double) * num_elements, NULL, NULL); if (!streams[0]) { log_error("clCreateBuffer failed\n"); return -1; } streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_double) * num_elements, NULL, NULL); if (!streams[1]) { log_error("clCreateBuffer failed\n"); return -1; } d = init_genrand( gRandomSeed ); p = input_ptr[0]; for (i=0; i