Fine-grained control/'pinned' attribute in C++?

Hello,

It seems that in CUDA Fortran, the “pinned” attribute can be used for selected arrays, and provide some level of fine-grained control. I wonder whether we can do the same in C++? i.e. only use pinned memory for certain arrays that have to go through frequent transfers. If not, is there a plan of enabling this feature in the future?

If we truly want to have this fine-grained control, would it be feasible to compile the codes separately and only partial codes see the “pinned” compiler flag?

Thanks,
Shine

Hi Shine,

If we truly want to have this fine-grained control, would it be feasible to compile the codes separately and only partial codes see the “pinned” compiler flag?

Basically all pinned does is replace malloc/new calls with calls to cudaMallocManaged (and free/delete with cudaFree). So, yes, you can apply “-ta=tesla:pinned” to the particular files and only those variables allocated in that file will get pinned.

Alternatively, you can replace malloc/new calls with “cudaMallocManaged” directly on the individual arrays (as well as replace free/delete with cudaFree) to get more fine grain control.

-Mat

Thanks, Mat! cudaMallocManaged is exactly what I am looking for.

Cheers,
Shine