How to reshape a gpuArray in a mex file?

I have a variable x, a gpuArray. I call a mex function func(x). In the mex function, I want to reshape this variable.
The only mex function relevant seems to be "mxSetDimensions". I tried it in a way like this
mxSetDimensions((mxArray *) in[0], new_size, (size_t) 4 );
where "in" is the input argument of mexFunction(...)
It didn't work and corrupted my variable. After I call this mex file, I cannot even get the size of this variable.
>> size(x)
Error using gpuArray/size
Invalid number of objects.
Ideally, I don't want to duplicate the array, since this array maybe very large and this function is required to be as fast as possible. Why does one have to duplicate an array to reshape it? After reshaping it will be used later in the mex file.
Could someone help me? Thanks!

댓글 수: 1

Jack Lee
Jack Lee 2016년 1월 16일
편집: Jack Lee 2016년 1월 16일
Some discussion says that we shouldn't modify the input (passed by reference). http://www.mathworks.com/matlabcentral/newsreader/view_thread/296362
But my data is really large. It'd be ideal if I can reshape it in-place.

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 1월 16일

0 개 추천

What you have been passed is not the data for the gpuarray but rather data for a MATLAB object that refers to the GPU array; the actual data is on the GPU, no longer in user space.
I do not know enough about gpuarray to know if the GPU explicitly knows the size and so would have to be told about the reshape.
Edric Ellis
Edric Ellis 2016년 1월 18일

0 개 추천

Walter is correct that the data in the mxArray is on the GPU. You cannot use mxSetDimensions on an mxArray that refers to an mxGPUArray, and unfortunately there is no other way to modify the dimensions of an mxGPUArray. Of course, inside your MEX function, you can treat the underlying pointer as being of any (compatible) dimensions you please.

카테고리

도움말 센터File Exchange에서 GPU CUDA and MEX Programming에 대해 자세히 알아보기

질문:

2016년 1월 15일

답변:

2016년 1월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by