// // 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" #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 #endif #define CLAMP_KERNEL( type ) \ const char *clamp_##type##_kernel_code = \ EMIT_PRAGMA_DIRECTIVE \ "__kernel void test_clamp(__global " #type " *x, __global " #type " *minval, __global " #type " *maxval, __global " #type " *dst)\n" \ "{\n" \ " int tid = get_global_id(0);\n" \ "\n" \ " dst[tid] = clamp(x[tid], minval[tid], maxval[tid]);\n" \ "}\n"; #define CLAMP_KERNEL_V( type, size) \ const char *clamp_##type##size##_kernel_code = \ EMIT_PRAGMA_DIRECTIVE \ "__kernel void test_clamp(__global " #type #size " *x, __global " #type #size " *minval, __global " #type #size " *maxval, __global " #type #size " *dst)\n" \ "{\n" \ " int tid = get_global_id(0);\n" \ "\n" \ " dst[tid] = clamp(x[tid], minval[tid], maxval[tid]);\n" \ "}\n"; #define CLAMP_KERNEL_V3( type, size) \ const char *clamp_##type##size##_kernel_code = \ EMIT_PRAGMA_DIRECTIVE \ "__kernel void test_clamp(__global " #type " *x, __global " #type " *minval, __global " #type " *maxval, __global " #type " *dst)\n" \ "{\n" \ " int tid = get_global_id(0);\n" \ "\n" \ " vstore3(clamp(vload3(tid, x), vload3(tid,minval), vload3(tid,maxval)), tid, dst);\n" \ "}\n"; #define EMIT_PRAGMA_DIRECTIVE " " CLAMP_KERNEL( float ) CLAMP_KERNEL_V( float, 2 ) CLAMP_KERNEL_V( float, 4 ) CLAMP_KERNEL_V( float, 8 ) CLAMP_KERNEL_V( float, 16 ) CLAMP_KERNEL_V3( float, 3) #undef EMIT_PRAGMA_DIRECTIVE #define EMIT_PRAGMA_DIRECTIVE "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" CLAMP_KERNEL( double ) CLAMP_KERNEL_V( double, 2 ) CLAMP_KERNEL_V( double, 4 ) CLAMP_KERNEL_V( double, 8 ) CLAMP_KERNEL_V( double, 16 ) CLAMP_KERNEL_V3( double, 3 ) #undef EMIT_PRAGMA_DIRECTIVE const char *clamp_float_codes[] = { clamp_float_kernel_code, clamp_float2_kernel_code, clamp_float4_kernel_code, clamp_float8_kernel_code, clamp_float16_kernel_code, clamp_float3_kernel_code }; const char *clamp_double_codes[] = { clamp_double_kernel_code, clamp_double2_kernel_code, clamp_double4_kernel_code, clamp_double8_kernel_code, clamp_double16_kernel_code, clamp_double3_kernel_code }; static int verify_clamp(float *x, float *minval, float *maxval, float *outptr, int n) { float t; int i; for (i=0; i