// // 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 #if defined(__APPLE__) #include #include #else #include #include #endif #include "testBase.h" #include "harness/typeWrappers.h" #include "harness/testHarness.h" #include "procs.h" enum { SUCCESS, FAILURE }; typedef enum { NON_NULL_PATH, ADDROF_NULL_PATH, NULL_PATH } test_type; #define NITEMS 4096 /* places the comparison result of value of the src ptr against 0 into each element of the output * array, to allow testing that the kernel actually _gets_ the NULL value */ const char *kernel_string_long = "kernel void test_kernel(global float *src, global long *dst)\n" "{\n" " uint tid = get_global_id(0);\n" " dst[tid] = (long)(src != 0);\n" "}\n"; // For gIsEmbedded const char *kernel_string = "kernel void test_kernel(global float *src, global int *dst)\n" "{\n" " uint tid = get_global_id(0);\n" " dst[tid] = (int)(src != 0);\n" "}\n"; /* * The guts of the test: * call setKernelArgs with a regular buffer, &NULL, or NULL depending on * the value of 'test_type' */ static int test_setargs_and_execution(cl_command_queue queue, cl_kernel kernel, cl_mem test_buf, cl_mem result_buf, test_type type) { unsigned int test_success = 0; unsigned int i; cl_int status; const char *typestr; if (type == NON_NULL_PATH) { status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &test_buf); typestr = "non-NULL"; } else if (type == ADDROF_NULL_PATH) { test_buf = NULL; status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &test_buf); typestr = "&NULL"; } else if (type == NULL_PATH) { status = clSetKernelArg(kernel, 0, sizeof(cl_mem), NULL); typestr = "NULL"; } log_info("Testing setKernelArgs with %s buffer.\n", typestr); if (status != CL_SUCCESS) { log_error("clSetKernelArg failed with status: %d\n", status); return FAILURE; // no point in continuing *this* test } size_t global = NITEMS; status = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, NULL, 0, NULL, NULL); test_error(status, "NDRangeKernel failed."); if (gIsEmbedded) { cl_int* host_result = (cl_int*)malloc(NITEMS*sizeof(cl_int)); status = clEnqueueReadBuffer(queue, result_buf, CL_TRUE, 0, sizeof(cl_int)*NITEMS, host_result, 0, NULL, NULL); test_error(status, "ReadBuffer failed."); // in the non-null case, we expect NONZERO values: if (type == NON_NULL_PATH) { for (i=0; i