// // 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" #ifndef uchar typedef unsigned char uchar; #endif #define USE_LOCAL_WORK_GROUP 1 const char *mem_read_write_kernel_code = "__kernel void test_mem_read_write(__global int *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = dst[tid]+1;\n" "}\n"; const char *mem_read_kernel_code = "__kernel void test_mem_read(__global int *src, __global int *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = src[tid]+1;\n" "}\n"; const char *mem_write_kernel_code = "__kernel void test_mem_write(__global int *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = dst[tid]+1;\n" "}\n"; static int verify_mem( int *outptr, int n ) { int i; for ( i = 0; i < n; i++ ){ if ( outptr[i] != ( i + 1 ) ) return -1; } return 0; } int test_mem_read_write_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ) { cl_mem buffers[1]; cl_int *inptr, *outptr; cl_program program[1]; cl_kernel kernel[1]; size_t global_work_size[3]; #ifdef USE_LOCAL_WORK_GROUP size_t local_work_size[3]; #endif cl_int err; int i; size_t min_alignment = get_min_alignment(context); global_work_size[0] = (cl_uint)num_elements; inptr = (cl_int*)align_malloc(sizeof(cl_int) * num_elements, min_alignment); outptr = (cl_int*)align_malloc(sizeof(cl_int) * num_elements, min_alignment); buffers[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_int) * num_elements, NULL, &err); if (err != CL_SUCCESS) { print_error( err, "clCreateBuffer failed"); align_free( (void *)outptr ); align_free( (void *)inptr ); return -1; } for (i=0; i