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 comentario

Jack Lee
Jack Lee el 16 de En. de 2016
Editada: Jack Lee el 16 de En. de 2016
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.

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 16 de En. de 2016

0 votos

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 el 18 de En. de 2016

0 votos

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.

Categorías

Preguntada:

el 15 de En. de 2016

Respondida:

el 18 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by