Hello there!
I’m trying to figure out how should I describe thrust function called
“min_element” in interface section:
cmin.cu:
#include <thrust>
#include <thrust>
#include <thrust>
extern "C" {
//Min for float arrays
void min_float_wrapper( float *data, int N)
{
thrust::device_ptr <float> dev_ptr(data);
thrust::min_element(dev_ptr, dev_ptr+N);
}
}
kernel.cuf:
interface thrustmin
subroutine min_float(input,N) bind(C,name="min_float_wrapper")
use iso_c_binding
real(c_float),device:: input(*)
integer(c_int),value:: N
end subroutine
end interface
But of course this is incorrect, because thrust::min_element should return a pointer to the element, like this:
#include <thrust>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::min_element(data, data + 6);
// result is data + 1
// *result is 0
I’m using http://cudamusing.blogspot.com/2011/06/calling-thrust-from-cuda-fortran.html as a reference, but there is no example on how I should convert C++ pointer to Fortran pointer. I’ve read PGI Fortran Reference manual, page 371: Interoperability with C.
It says:
c_f_pointer: A subroutine that assigns the C pointer target to the Fortran pointer, and specifies its shape.
Syntax
c_f_pointer (cptr, fptr [,shape] )
But I’m still confused on syntax in interface section. Could you demonstrate simple example on how I can make it work?
My current sources are here:
http://paste.pocoo.org/show/579214/ (cmin.cu)
http://pastebin.com/PwWAYDWs (kernel.cuf)
I’ve tried to make some calculations on pointers (in wrap function) to return only index of minimum element (not C pointer), but I can’t find good explanation of class hierarchy (or just how can I convert dev_ptr to integer) in thrust library.
It should compile ok on Windows with:
nvcc -m32 -c -arch sm_13 cmin.cu --cl-version 2008 -o a.obj (Microsoft Visual Studio 2010 Command Prompt)
and then:
pgf90 -V -m32 kernel.cuf a.obj (PGI WorkStation 12.3)
But when I launch it, then error shows: http://i.imgur.com/NZoGF.png
It seems error shows after this line (in cmin.cu):
thrust::min_element(dev_ptr, dev_ptr+5);
Thank you for your hard work!