// // 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 #include "procs.h" const char *barrier_kernel_code = "__kernel void compute_sum(__global int *a, int n, __global int *tmp_sum, __global int *sum)\n" "{\n" " int tid = get_local_id(0);\n" " int lsize = get_local_size(0);\n" " int i;\n" "\n" " tmp_sum[tid] = 0;\n" " for (i=tid; i1; i = hadd(i,1))\n" " {\n" " barrier(CLK_GLOBAL_MEM_FENCE);\n" " if (tid + i < lsize)\n" " tmp_sum[tid] += tmp_sum[tid + i];\n" " lsize = i; \n" " }\n" "\n" " //no barrier is required here because last person to write to tmp_sum[0] was tid 0 \n" " if (tid == 0)\n" " *sum = tmp_sum[0];\n" "}\n"; static int verify_sum(int *inptr, int *outptr, int n) { int r = 0; int i; for (i=0; i max_local_workgroup_size[0]) max_threadgroup_size = max_local_workgroup_size[0]; // work group size must divide evenly into the global size while( num_elements % max_threadgroup_size ) max_threadgroup_size--; input_ptr = (int*)malloc(sizeof(int) * num_elements); output_ptr = (int*)malloc(sizeof(int)); streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_int) * num_elements, NULL, &err); test_error(err, "clCreateBuffer failed."); streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_int), NULL, &err); test_error(err, "clCreateBuffer failed."); streams[2] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_int) * max_threadgroup_size, NULL, &err); test_error(err, "clCreateBuffer failed."); d = init_genrand( gRandomSeed ); for (i=0; i