I'm working in Julia and I need call some customize C functions that use ArraFire library, when I use a code like:
void copy(const af::array &A, af::array &B,size_t length) {
// 2.Obtain the device, context, and queue used by ArrayFire
// 3.Obtain cl_mem references to af::array objects
cl_mem * d_A = A.device<cl_mem>();
cl_mem * d_B = B.device<cl_mem>();
// 4. Load, build, and use your kernels.
// Set arguments and launch your kernels
//kernel is the function build in step 4
clSetKernelArg(kernel, 0, sizeof(cl_mem), d_A);
clSetKernelArg(kernel, 1, sizeof(cl_mem), d_B);
clEnqueueNDRangeKernel(af_queue, kernel, 1, NULL, &length, NULL, 0, NULL, NULL);
// 5. Return control of af::array memory to ArrayFire
A.unlock();
B.unlock();
}
I used as reference the example provided in:Interoperability with OpenCL
I call this function in Julia as follows:
ccall((:copy,"path/to/dll"),Cvoid(Ref{af_array},Ref{af_array}),Af.arr,Bf.arr)
Af
and Bf
are ArrayFire arrays, the call works as expected, the problem is when I use directly B=A
only to test i.e.
void copy(const af::array &A, af::array &B,size_t length) {
B=A;//only to test
}
the call stop works in Julia, this made me doubt if I'm using the correct way to write and call this functions.
Some of the Arrayfire functions incorporated in Julia that I saw, call functions that have af_array
as arguments that are different from the arguments af :: array
. Well I want to change the arguments, then I do this:
void copy(const af_array &dA, af_array &dB,size_t length) {
//this to be able to use A.device and B.device
array A=array(dA);
array B=array(dB);
//steps 2 to 5 in the original code
}
It doesn't work in C or in Julia, the question is if I want to use af_array as arguments how I get the device pointer? or what is the corret way to handle this functions to avoid problems when I call them in Julia?
thanks in advance.
UPD
I changed B=A;
inside the function:
void copy(const af::array &A, af::array &B,size_t length) {
size_t len = A.dims(0);
seq idx(0, len - 1, 1);
af::copy(B, A, idx);
}
And works! However, I still doubt that this is the correct way, since this code is very simple. I will work with a more complex code that may stop working in a similar way.