AnsweredAssumed Answered

OpenCL Questions (mostly 2.0)

Question asked by zypo on Apr 4, 2015
Latest reply on Apr 10, 2015 by dipak

Hi, being self-tought in openCL, I have a lot of questions that I cannot find in documents or via a google search (maybe I'm just typeing the wrong stuff).  Can someone help me with any of these questions?



1) When creating SVM memory with clSVMAlloc(...), it returns a CPU pointer that points to GPU memory. Am I correct?



typedef struct { Node *node } Node;

2) I want to use my Node structure in my kernel using SVM (1000 values). I don't know how to initialize the node values.  I want each kernel instance to access the 0th element (myLinkedList pointer) and traverse from there.  The code below shows how I am thinking.  Please help me change this code to be useful:



  Node *myLinkedList = clSVMAlloc(myContext, CL_MEM_READ_WRITE, 1000, 0);


  Node *current = myLinkedList;

  for (int index = 0; index < 1000; index++)


  //current->node does not point to anything yet.... we must point to something!

  current->node = new Node(); //I'm doing something wrong here!!! Doesn't this allocate on the CPU?

  current = current->node;





3) What does clEnqueSVMMap(...) ACTUALLY do.. is it a mutex lock? Does it copy memory?  Is it fast (can I use it a lot)?



4) OpenCL 2.0 introduces Pipes and everyone seems to think they are a great thing.  My understanding is that they are used for 2 kernels to talk to each other Without having to go to the host(CPU).  Do these kernels have to be run on the same device? Also, How do I get a pointer(to the kernel) to the other end of the pipe? Can I pass a value into a pipe, and after my kernel finishes, run another kernel and retrieve the piped value (same gid) from the pipe (or are buffers easier)?



5) Can device enque call another kernel in another *.cl file?  In other words, If I create the cl_kernel to kernel#2 on the host, can I pass that cl_kernel to kernel#1 as an argument and have the kernel#1 then call kernel#2, or would the cpu queue be used for that stuff?  If I used the cpu queue, doesn't that cause more overhead?



5) OpenCl General question: (I don't know how I even got this far without knowing this) When I enqueue a kernel, I assume that it performs in the background while my cpu keeps going.  If I enqueue another one immediately after, it is put into a queue where that kernel is executed next.  How do I have opencl use a callback function when kernel#1 is complete, and a different function when kernel#2 is complete? Can the callbacks be member functions(void myClass::MyFunction()) w/o using boost libraries (c++11 is okay)? 



Note) A HUGE thanks to the OpenCL guys for making nonuniform workgroup sizes! I had to use "if (gid < numThreads)" in every kernel... now I don't have to!!! I know there are better reasons to use 2.0 out there, but this is the #1 reason that I will moving to OpenCL 2.0 (and therefore use AMD graphics cards in the future when I like cutting-edge computing)