Calling cudaMallocHost within a matlab mex file

I have been working with CUDA and matlab mex files, and I’ve never been able to allocate pinned memory within a mex file using cudaMallocHost. It seems that this call is inherently incompatible with matlab’s memory management. For me, attempts to do this just cause matlab to crash. Has anyone been able to use pinned memory with a mex file? How was it done?

If pinned memory within matlab is not now possible, this would be a nice feature to have at some point.

I have brought this issue up with the Mathworks. Did not hear anything yet (it’s been more than a year since I asked as far as I remember). I think it will require cooperation from both NVIDIA and the Mathworks to make something like this happen.

You cannot use pinned memory from inside a mex file, since you need to use mxMalloc.
Mathworks needs to expose it, there is nothing we can do.

What’s the advantage with pinned memory?

Thanks for the replies - it is nice to confirm that cudaMallocHost does indeed fail in a mex file (for now).

(Pinned memory allows a direct copy between PC memory and GPU memory, by-passing the PC kernel overhead; it allows considerably faster data transfer, apparently)