I am new to use Fortran, and for a c function like below:
cudaError_t cudaMalloc (void** devPtr, size_t size)
Allocates size bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared. cudaMalloc() returns cudaErrorMemoryAllocation in case of failure.
Parameters:
devPtr - Pointer to allocated device memory
size - Requested allocation size in bytes
Returns:
cudaSuccess, cudaErrorMemoryAllocation
I want to create an Fortran interface to use this c function but how to fix void** ptr? Can anyone help me? Thanks in advance!
I have no idea whether it will work OK with the device pointers (i.e., if
cudaMalloc
is callable from non-CUDA C), but generally in Fortran-C interoperability you representvoid*
astype(c_ptr)
from theiso_c_binding
module. C interoperable procedures pass their arguments by reference by default, so this should work:The pointer is passed by reference, so that the C side sees a pointer to pointer and can change it to store the value of the device pointer.
With some more work you can also define the enumeration with the return codes.