// // 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. // #if defined(__APPLE__) #include #include #else #include #include #endif #include #include #include #include "harness/kernelHelpers.h" /////////////////////////////////////////////////////////////////////////////// // CL error checking. #if defined(_MSC_VER) #define CL_EXIT_ERROR(cmd,...) \ { \ if ((cmd) != CL_SUCCESS) { \ log_error("CL ERROR: %s %u: ", __FILE__,__LINE__);\ log_error(## __VA_ARGS__ );\ log_error("\n");\ return -1;\ }\ } #else #define CL_EXIT_ERROR(cmd,format,...) \ { \ if ((cmd) != CL_SUCCESS) { \ log_error("CL ERROR: %s %u: ", __FILE__,__LINE__);\ log_error(format,## __VA_ARGS__ );\ log_error("\n");\ return -1;\ }\ } #endif #define CL_EXIT_BUILD_ERROR(cmd,program,format,...) \ { \ if ((cmd) != CL_SUCCESS) { \ cl_uint num_devices_;\ clGetProgramInfo(program,CL_PROGRAM_NUM_DEVICES,sizeof(num_devices_),&num_devices_,NULL);\ cl_device_id *device_list;\ device_list=(cl_device_id *)malloc(num_devices_*sizeof(cl_device_id));\ clGetProgramInfo(program,CL_PROGRAM_DEVICES,num_devices_*sizeof(cl_device_id),device_list,NULL);\ for (unsigned i=0;i= CL_SUBMITTED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status before user event",i); } log_info("Setting user event status to complete\n"); CL_EXIT_ERROR(clSetUserEventStatus(u1,CL_COMPLETE),"clSetUserEventStatus failed"); log_info("Waiting for tasks to finish executing\n"); CL_EXIT_ERROR(clWaitForEvents( 1, &e[N-1] ),"clWaitForEvent failed"); log_info("Checking task status after setting user event status\n"); for (cl_uint i = 0; i != N; ++i) { CL_EXIT_ERROR(clGetEventInfo(e[i],CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof s,&s,0),"clGetEventInfo failed"); CL_EXIT_ERROR((s != CL_QUEUED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status %04x after successful user event",i,s); } CL_EXIT_ERROR(clReleaseEvent(u1),"clReleaseEvent failed"); for (cl_uint i = 0; i != N; ++i) CL_EXIT_ERROR(clReleaseEvent(e[i]),"clReleaseEvent failed"); log_info("Successful user event case passed.\n"); } // Test unsuccessful user event case. /////////////////////////////////////////////////////////////////// { cl_event u2 = clCreateUserEvent( context, &err ); CL_EXIT_ERROR(err,"clCreateUserEvent failed"); cl_event e[4]; cl_uint N = sizeof e / sizeof(cl_event); log_info("Enqueuing tasks\n"); for (cl_uint i = 0; i != N; ++i) CL_EXIT_ERROR(clEnqueueTask(queue,k0,1,&u2,&e[i]),"clEnqueueTaskFailed"); log_info("Checking task status before setting user event status\n"); for (cl_uint i = 0; i != N; ++i) { CL_EXIT_ERROR(clGetEventInfo(e[i],CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof s,&s,0),"clGetEventInfo failed"); CL_EXIT_ERROR((s == CL_QUEUED || s == CL_SUBMITTED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status %d before user event",i, (int) s); } log_info("Setting user event status to unsuccessful result\n"); CL_EXIT_ERROR(clSetUserEventStatus(u2,-1),"clSetUserEventStatus failed"); log_info("Waiting for tasks to finish executing\n"); CL_EXIT_ERROR((clWaitForEvents( N, &e[0] )!=CL_SUCCESS) ? CL_SUCCESS : -1,"clWaitForEvent succeeded when it should have failed"); log_info("Checking task status after setting user event status\n"); for (cl_uint i = 0; i != N; ++i) { CL_EXIT_ERROR(clGetEventInfo(e[i],CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof s,&s,0),"clGetEventInfo failed"); CL_EXIT_ERROR((s != CL_QUEUED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status %04x after unsuccessful user event",i,s); } CL_EXIT_ERROR(clReleaseEvent(u2),"clReleaseEvent failed"); for (cl_uint i = 0; i != N; ++i) CL_EXIT_ERROR(clReleaseEvent(e[i]),"clReleaseEvent failed"); log_info("Unsuccessful user event case passed.\n"); } clReleaseKernel(k0); clReleaseProgram(program); clReleaseMemObject(output); return 0; }