1

Is there any way to do an arrayfun with a shared matrix in a gpuArray type?

In my case I wanted to make the sum of two or more columns of a gpuArray matrix, but i dont know how to implement in a gpuFunction, arrayfun is the best option?

I wanted to make this easy operation in a CUDA because I need to make a million of this kind of operations with the different combinations.

Thank you very much.

Im going to explain the problem better.If you see my problem is like that

functionarrayfun = @(row)functionMex(data1,data2,row );

i = 1:length(tablaCombinaciones(:,1));%from 1 to end of rows

ratio = arrayfun(functionarrayfun,i);

Error using gpuArray/arrayfun Indexing is not supported. error at line: 6

2
  • As an alternative to arrayfun, gpuArray and gpuFunction, you could try to write your function directly in CUDA, compiling it with nvcc and then linking it under Matlab as a mex-file. Commented Jul 20, 2013 at 6:46
  • yes i knew it, but im asking because i wanted to know if there were any other way to do it, i wanted to avoid c , but i think i will have to do it Commented Aug 13, 2013 at 7:52

1 Answer 1

1

Arrayfun and bsxfun work with a gpuArray:

See the example:

A = gpuArray.rand(100,2);
B = A(:,1);
C = A(:,2);
bsxfun(@plus,A(:,1),A(:,2))
arrayfun(@(x,y)x+y,A(:,1),A(:,2))
Sign up to request clarification or add additional context in comments.

1 Comment

the problem is that in gpu arrayfun you cant use a @ function, it needs to have a written function.In my case i want to have the arrayfun for a function like that [ ratio(i) ] = functionMex(array1,array2,i ) I think right now its not possible only in matlab you need to use mex, with cuda kernels. or use arrayfire jacket for matlab that is not avaible to buy. thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.