Manipulate mxGPUArrays in conjunction with shared C libraries

조회 수: 1 (최근 30일)
Matt J
Matt J 2015년 7월 7일
댓글: Matt J 2015년 7월 21일
I'm asking this question on behalf of someone else more technically proficient in the issue than me. If I understand him, though, the goal is to know how to pass (set and get) data between an mxGPUArray object (corresponding to a gpuArray object in the MATLAB workspace) and a loaded C shared library (MEX-compiled). Also, to know how to create a new mxGPUArray object or resize/repopulate an existing one from said library. Finally, it is desirable to do this entirely on the GPU, so that data doesn't have to go through the host.
Is there a way to do all of the above? If so, what is the best way?

채택된 답변

Edric Ellis
Edric Ellis 2015년 7월 8일
Yes, all of this should be possible. You can extract the underlying pointer to the data of a gpuArray. I suggest starting with this section in the documentation, and examining the referenced example code which shows how to first get hold of an mxGPUArray object from the mxArray, and from there how to get hold of the underlying data (e.g. double *) from the mxGPUArray. Once you've got a pointer to the underlying data, you can call external CUDA code with that pointer. You can use mxGPUCreateGPUArray to create a new gpuArray, and then once you've filled out the contents, use mxGPUCreateMxArrayOnGPU to create an mxArray to return back to MATLAB.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU CUDA and MEX Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by