// // 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 "allocation_execute.h" #include "allocation_functions.h" const char *buffer_kernel_pattern = { "__kernel void sample_test(%s __global uint *result, __global %s *array_sizes, uint per_item)\n" "{\n" "\tint tid = get_global_id(0);\n" "\tuint r = 0;\n" "\t%s i;\n" "\tfor(i=(%s)tid*(%s)per_item; i<(%s)(1+tid)*(%s)per_item; i++) {\n" "%s" "\t}\n" "\tresult[tid] = r;\n" "}\n" }; const char *image_kernel_pattern = { "__kernel void sample_test(%s __global uint *result)\n" "{\n" "\tuint4 color;\n" "\tcolor = (uint4)(0);\n" "%s" "\tint x, y;\n" "%s" "\tresult[get_global_id(0)] += color.x + color.y + color.z + color.w;\n" "}\n" }; const char *read_pattern = { "\tfor(y=0; y max_size) max_size = size/sizeof(cl_uint); } if (support64) { buffer_sizes = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR, sizeof(cl_ulong)*number_of_mems_used, ulSizes, &error); } else { buffer_sizes = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR, sizeof(cl_uint)*number_of_mems_used, uiSizes, &error); } test_error_abort(error, "clCreateBuffer failed"); error = clSetKernelArg(kernel, number_of_mems_used+1, sizeof(cl_mem), &buffer_sizes); test_error(error, "clSetKernelArg failed"); per_item = (cl_uint)ceil((double)max_size/global_dims[0]); if (per_item > CL_UINT_MAX) log_error("Size is too large for a uint parameter to the kernel. Expect invalid results.\n"); per_item_uint = (cl_uint)per_item; error = clSetKernelArg(kernel, number_of_mems_used+2, sizeof(per_item_uint), &per_item_uint); test_error(error, "clSetKernelArg failed"); } if (ulSizes) { free(ulSizes); } if (uiSizes) { free(uiSizes); } size_t local_dims[3] = {1,1,1}; error = get_max_common_work_group_size(context, kernel, global_dims[0], &local_dims[0]); test_error(error, "get_max_common_work_group_size failed"); // Execute the kernel error = clEnqueueNDRangeKernel(*queue, kernel, 1, NULL, global_dims, local_dims, 0, NULL, &event); result = check_allocation_error(context, device_id, error, queue); if (result != SUCCEEDED) { if (result == FAILED_TOO_BIG) log_info("\t\tExecute kernel failed: %s (global dim: %ld, local dim: %ld)\n", IGetErrorString(error), global_dims[0], local_dims[0]); else print_error(error, "clEnqueueNDRangeKernel failed"); return result; } // Finish the test error = clFinish(*queue); result = check_allocation_error(context, device_id, error, queue); if (result != SUCCEEDED) { if (result == FAILED_TOO_BIG) log_info("\t\tclFinish failed: %s.\n", IGetErrorString(error)); else print_error(error, "clFinish failed"); return result; } // Verify that the event from the execution did not have an error error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(event_status), &event_status, NULL); test_error_abort(error, "clGetEventInfo for CL_EVENT_COMMAND_EXECUTION_STATUS failed"); if (event_status < 0) { result = check_allocation_error(context, device_id, event_status, queue); if (result != SUCCEEDED) { if (result == FAILED_TOO_BIG) log_info("\t\tEvent returned from kernel execution indicates failure: %s.\n", IGetErrorString(event_status)); else print_error(event_status, "clEnqueueNDRangeKernel failed"); return result; } } // If we are not verifying the checksum return here if (!verify_checksum) { log_info("Note: Allocations were not initialized so kernel execution can not verify correct results.\n"); return SUCCEEDED; } // Verify the checksum. // Read back the result error = clEnqueueReadBuffer(*queue, result_mem, CL_TRUE, 0, sizeof(cl_uint)*NUM_OF_WORK_ITEMS, &returned_results, 0, NULL, NULL); test_error_abort(error, "clEnqueueReadBuffer failed"); final_result = 0; if (test == BUFFER || test == IMAGE_READ || test == BUFFER_NON_BLOCKING || test == IMAGE_READ_NON_BLOCKING) { // For buffers or read images we are just looking at the sum of what each thread summed up for (i=0; i