// // 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 "procs.h" #include static const char *linear_ids_source[1] = { "__kernel void test_linear_ids(__global int2 *out)\n" "{\n" " size_t lid, gid;\n" " uint d = get_work_dim();\n" " if (d == 1U) {\n" " gid = get_global_id(0) - get_global_offset(0);\n" " lid = get_local_id(0);\n" " } else if (d == 2U) {\n" " gid = (get_global_id(1) - get_global_offset(1)) * get_global_size(0) +\n" " (get_global_id(0) - get_global_offset(0));\n" " lid = get_local_id(1) * get_local_size(0) + get_local_id(0);\n" " } else {\n" " gid = ((get_global_id(2) - get_global_offset(2)) * get_global_size(1) +\n" " (get_global_id(1) - get_global_offset(1))) * get_global_size(0) +\n" " (get_global_id(0) - get_global_offset(0));\n" " lid = (get_local_id(2) * get_local_size(1) +\n" " get_local_id(1)) * get_local_size(0) + get_local_id(0);\n" " }\n" " out[gid].x = gid == get_global_linear_id();\n" " out[gid].y = lid == get_local_linear_id();\n" "}\n" }; #define NUM_ITER 12 #define MAX_1D 4096 #define MAX_2D 64 #define MAX_3D 16 #define MAX_OFFSET 100000 int test_get_linear_ids(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements) { clProgramWrapper program; clKernelWrapper kernel; clMemWrapper outbuf; int error, iter, i, j, k; size_t lws[3], gws[3], gwo[3]; cl_uint dims; cl_int outmem[2*MAX_1D], *om; // Create the kernel error = create_single_kernel_helper(context, &program, &kernel, 1, linear_ids_source, "test_linear_ids"); if (error) return error; // Create the out buffer outbuf = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(outmem), NULL, &error); test_error(error, "failed to create result buffer\n"); // This will leak if there is an error, but this is what is done everywhere else MTdata seed = init_genrand(gRandomSeed); // Run some tests for (iter=0; iter