// // 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 "testBase.h" #include "harness/os_helpers.h" const char *define_kernel_code[] = { " #define VALUE\n" "__kernel void define_test(__global int *src, __global int *dstA, __global int *dstB)\n" "{\n" " int tid = get_global_id(0);\n" "#ifdef VALUE\n" " dstA[tid] = src[tid] * 2;\n" "#else\n" " dstA[tid] = src[tid] * 4;\n" "#endif\n" "\n" "#undef VALUE\n" "#ifdef VALUE\n" " dstB[tid] = src[tid] * 2;\n" "#else\n" " dstB[tid] = src[tid] * 4;\n" "#endif\n" "\n" "}\n"}; int test_preprocessor_define_udef(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { cl_int error; clKernelWrapper kernel; clProgramWrapper program; clMemWrapper buffer[3]; cl_int *srcData, *resultData; int i; MTdata d; error = create_single_kernel_helper(context, &program, &kernel, 1, define_kernel_code, "define_test"); if (error) return -1; buffer[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, num_elements*sizeof(cl_int), NULL, &error); test_error( error, "clCreateBuffer failed"); buffer[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, num_elements*sizeof(cl_int), NULL, &error); test_error( error, "clCreateBuffer failed"); buffer[2] = clCreateBuffer(context, CL_MEM_READ_WRITE, num_elements*sizeof(cl_int), NULL, &error); test_error( error, "clCreateBuffer failed"); srcData = (cl_int*)malloc(sizeof(cl_int)*num_elements); if (srcData == NULL) { log_error("Failed to allocate storage for source data (%d cl_ints).\n", num_elements); return -1; } d = init_genrand( gRandomSeed ); for (i=0; i