views:

65

answers:

1

I have a .NET program that is utilizing CUDA.

The CUDA is accessed through a C DLL.

What I am doing is initializing my CUDA application by allocating buffers (cudaMalloc) on the device at program startup. Pointers to these buffers are then maintained in static variables declared in the DLL. Data is copied to and from the buffers throughout the program. Upon program termination the previously allocated buffers are freed.

Is it ok to maintain pointers to the allocated device memory or should I be reallocating every time I execute the kernel (which would seem to be very inefficient)?

I haven't noticed any side effects at present, but just wanted to confirm that this usage pattern is preferred and acceptable.

+2  A: 

As far as I know the only strong recomendation for using device memory - reduce copy operations. cudaMalloc works much faster than cudaMemcpy. So, it's not a big deal to reuse buffers. It will work right, if you're using device mem correctly

KoppeKTop