cuda - Global device variable OpenCL -


how can declare device variable global threads in opencl? i'm porting code cuda opencl. in cuda implementation have like

... ...  __device__ int d_var;  ... ... void foo() {    int h_var = 0    cudamemcpytosymbol(d_var, h_var, sizeof(int));    do{       //launch kernel, inside kernel d_var modified       cudamemcpyfromsymbol(h_var, d_var, sizeof(int));    }while(h_var != 0); } 

i've been reading through opencl example codes cannot figure out how this. advise great !

unfortunately not straight-forward port. whereas i'm not sure if can @ least define , use (read/write) such global variable in opencl program (but don't think so), there no way access (read/write) variable host.

what have put kernel additional kernel argument. if writen host , read kernel ordinary int variable suffice (thus copy each kernel). in case written in kernel , read host, has __global pointer, appropriate buffer bound:

__kernel void func(..., __global int *d_var) { ... } 

which can read , write on host using usual buffer functionality (and in kernel through classic pointer dereference *d_var, of course, keep in mind concurrent writes variable have unspecified results if not atomic).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -