代写代考 OpenCL Events

OpenCL Events

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License
Computer Graphics

Copyright By PowCoder代写 加微信 powcoder

opencl.events.pptx
mjb – , March 27, 2021

OpenCL Events
An event is an object that communicates the status of OpenCL commands
Whopp-a, whopp-a
Read Buffer dC
Execute Kernel
Write Buffer dB
Write Buffer dA
Computer Graphics
mjb – , March 27, 2021

From the OpenCL Notes:
11. Enqueue the Kernel Object for Execution
size_t globalWorkSize[ 3 ] = { NUM_ELEMENT, 1, 1 }; size_t localWorkSize[ 3 ] = { LOCAL_SIZE, 1, 1 } ;
status = clEnqueueNDRangeKernel( cmdQueue, kernel, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, NULL );
event that will be thrown when this kernel is finished executing
status = clEnqueueNDRangeKernel( cmdQueue, kernel, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, NULL );
# events to wait for before this kernel is allowed to execute
event wait list
Computer Graphics
mjb – , March 27, 2021

Creating an Event
event that will be thrown when this kernel is finished executing
cl_event waitKernelA, waitKernel B, waitKernelC;
status = clEnqueueNDRangeKernel( cmdQueue, kernel, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, &waitKernelC );
event(s) to wait for before this kernel is allowed to execute
Computer Graphics
mjb – , March 27, 2021

Waiting for Events from Previously-Executed Kernels
cl_event waitKernelA, waitKernel B, waitKernelC; …
cl_event dependenciesAB[ 2 ]; dependenciesAB[ 0 ] = waitKernelA;
event that will be thrown when this kernel is finished executing
dependenciesAB[ 1 ] = waitKernelB;
status = clEnqueueNDRangeKernel( cmdQueue, kernelC, 1, NULL, globalWorkSize, localWorkSize, 2, dependenciesAB, NULL );
event(s) to wait for before this kernel is allowed to execute
Computer Graphics
mjb – , March 27, 2021

Creating an Execution Graph Structure
cl_event waitKernelA, waitKernel B, waitKernelC;
event that will be thrown when this
cl_event dependenciesAB[ 2 ]; kernel is finished executing
dependenciesAB[ 0 ] = waitKernelA; dependenciesAB[ 1 ] = waitKernelB;
status = clEnqueueNDRangeKernel( cmdQueue, kernelC, 1, NULL, globalWorkSize, localWorkSize, 2, dependenciesAB, &waitKernelC );
event(s) to wait for before this kernel is allowed to execute
Computer Graphics
mjb – , March 27, 2021

Creating the Full Execution Graph Structure
cl_event waitKernelA, waitKernel B, waitKernelC, waitKernelD;
cl_event dependenciesAB[ 2 ]; dependenciesAB[ 0 ] = waitKernelA; dependenciesAB[ 1 ] = waitKernelB;
cl_event dependenciesCD[ 2 ]; dependenciesCD[ 0 ] = waitKernelC; dependenciesCD[ 1 ] = waitKernelD;
status = clEnqueueNDRangeKernel( cmdQueue, kernelA, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, &waitKernelA );
status = clEnqueueNDRangeKernel( cmdQueue, kernelB, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, &waitKernelB );
status = clEnqueueNDRangeKernel( cmdQueue, kernelC, 1, NULL, globalWorkSize, localWorkSize, 2, dependenciesAB, &waitKernelC ); status = clEnqueueNDRangeKernel( cmdQueue, kernelD, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, &waitKernelD );
status = clEnqueueNDRangeKernel( cmdQueue, kernelE, 1, NULL, globalWorkSize, localWorkSize, 2, dependenciesCD, NULL );
Computer Graphics
mjb – , March 27, 2021

Computer Graphics
Waiting for One Event
cl_event waitKernelA, waitKernel B.
status = clEnqueueNDRangeKernel( cmdQueue, kernelC, 1, NULL, globalWorkSize, localWorkSize, 1, &waitKernelA, NULL );
event(s) to wait for
mjb – , March 27, 2021

Placing a Barrier in the Command Queue
status = clEnqueueBarrier( cmdQueue );
Note: this cannot throw its own event
This does not complete until all commands enqueued before it have completed.
Computer Graphics
mjb – , March 27, 2021

Placing an Event Marker in the Command Queue
cl_event waitMarker;
status = clEnqueueMarker( cmdQueue, &waitMarker );
Note: this can throw its own event
This does not complete until all commands enqueued before it have completed.
This is just like a barrier, but it can throw an event to be waited for.
Computer Graphics
mjb – , March 27, 2021

Waiting for Events Without Enqueuing Another Command
status = clWaitForEvents( 2, dependencies );
event(s) to wait for
This blocks until the specified events are thrown, so use it carefully!
Computer Graphics
mjb – , March 27, 2021

I Like Synchronizing Things This Way
// wait until all queued tasks have taken place:
Wait( cl_command_queue queue ) {
cl_event wait; cl_int status;
status = clEnqueueMarker( queue, &wait ); if( status != CL_SUCCESS )
fprintf( stderr, “Wait: clEnqueueMarker failed\n” );
status = clWaitForEvents( 1, &wait ); // blocks until everything is done! if( status != CL_SUCCESS )
fprintf( stderr, “Wait: clWaitForEvents failed\n” );
Call this before starting the timer, before ending the timer, and before retrieving data from an array computed in an OpenCL program.
Computer Graphics
mjb – , March 27, 2021

CL_EVENT_COMMAND_EXECUTION_STATUS returns one of these
CL_QUEUED CL_SUBMITTED CL_RUNNING CL_COMPLETE
Computer Graphics
cl_int is what type CL_EVENT_COMMAND_EXECUTION_STATUS returns
Getting Event Statuses Without Blocking
CL_EVENT_COMMAND_QUEUE CL_EVENT_CONTEXT CL_EVENT_COMMAND_TYPE CL_EVENT_COMMAND_EXECUTION_STATUS
Specify one of these
cl_int eventStatus;
status = clGetEventInfo( waitKernelC, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &eventStatus, NULL );
Note that this a nice way to check on event statuses without blocking. Thus, you could put this in a loop and go get some other work done in between calls.
mjb – , March 27, 2021

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com