6

Given that OpenCL is meant to be an API for heterogeneous programming, it by almost definition has a huge latency penalty associated with it. Therefore there MUST be an asynchronous API for it.

I am however finding it difficult to find the asynchronous API in OpenCL.net. I have found the OpenCl.Net.Event struct, which seems to be an out parameter in most API calls. However I can't find anyway to associate a callback on the event, as it seems clSetEventCallback is missing from opencl.net.

Does anyone know how to await an asynchronous operation in opencl.net?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Aron
  • 15,464
  • 3
  • 31
  • 64
  • What do you mean by latency? Is it about the time the function calls block while waiting for results? – Eric Nov 04 '14 at 07:19
  • For example in OpenCL you will need to load your data into memory of the target `device`. This is done by enqueuing a load memory operation. The sample code shows how to do this synchronously (by setting async false, and ignoring the `out` `Event` `object`). From an implementation point of view, loading data onto the GPU is "slow" in that latency is high (even if we are just taking into account GDDR5 latencies). When we have hundreds of round trips to the GPU via the PCI-E bus, we lose all performance gains. Thus I want to be able to enqueue operations and be notified of completion. – Aron Nov 04 '14 at 07:26
  • I'm not very familiar with openCl but isn't the batch processing of openCl we are talkingn about? What you want is to spend as much time as possible queuing data and as little time as possible waiting for results (or anything else) right? – Eric Nov 04 '14 at 07:50
  • @Eric Batch processing is certainly something worth doing. But given that there are several operations (loading the data/loading the kernal (compuation)/flushing the operation/waiting for completion/exporting the data back to RAM) that need to be done to get computation to happen async is still important. – Aron Nov 04 '14 at 07:52
  • @Eric Just so that you know. I want to extend [GpuLinq](https://github.com/nessos/GpuLinq/blob/gpu/tests/GpuLinq.Tests.CSharp/packages.config) to both support batch processing and asynchronous processing. At the moment async seems easier. – Aron Nov 04 '14 at 09:45
  • Could this be because OpenCl.Net is a wrapper for OpenCl 1.0? The method `clSetEventCallback` only appeared in OpenCl 1.1 I believe. – Lukazoid Dec 12 '14 at 17:10

1 Answers1

1

I don't know much about OpenCL.net, but isn't the CommandQueue what you are looking for? You can enqueue all your aynch tasks a fait with the Finish command until all tasks are finished?

For example here: GPGPU image processing basics using OpenCL.NET under The image processing part

For clSetEventCallback i only found clFinish or clWaitForEvents.

Refering to your statement:

as it seems clSetEventCallback is missing from opencl.net

I could not find any way to do what you want, sorry.

EDIT: This seems to be very intestring: Google-Code / GPUTracer. You should take a look at OpenCL.cs and Event.cs. I think they solved your problem.

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • Unfortunately this is not what I am looking for. I am looking for how to use those command with `Blocking` set to `false` which is the opposite of every tutorial I found so far. This tutorial is for doing blocking/synchronous API. – Aron Nov 06 '14 at 15:46
  • What is with this: https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFinish.html (clFinish)? Sorry if i'm completly wrong, just trying to help :) – BendEg Nov 06 '14 at 15:52
  • "Blocks until all previously queued OpenCL commands in a command-queue are issued to the associated device and have completed." Which by definition is the OPPOSITE of asynchronous. – Aron Nov 06 '14 at 15:53
  • Ok, but then i do not understand this part of your question: `Does anyone know how to await an asynchronous operation in opencl.net?` – BendEg Nov 06 '14 at 15:56
  • Ah you are correct. I should have clarified, but I was using the C#5 definition of the `await` keyword, which is a non-blocking call. I was hoping to convert the API to work with C#5 async/await. – Aron Nov 06 '14 at 15:57
  • 1
    @Aron ok, now i understand and updated my post, but could not found any solution with the curren OPenCL.Net version, sorry. – BendEg Nov 06 '14 at 16:04
  • @Aron i found something else, hope it helps. – BendEg Nov 06 '14 at 16:17