How can a create a vector directly on GPU, just like we can create a vector on CPU?

1 view (last 30 days)
lut = [0;0;1;1;0;0;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1];
How can I create the above vector directly on GPU.
i want to avoid gpuArray(lut). Because it takes extra time for transferring data.

Accepted Answer

Joss Knight
Joss Knight on 4 Jul 2018
It's a little bit far-fetched to expect to be able to create an arbitrary array directly on the GPU - after all, the only way to read in the numbers you type is via main memory.
However, there are many standard build functions that create default arrays directly on the GPU: https://uk.mathworks.com/help/distcomp/establish-arrays-on-a-gpu.html#bspvmhe-1
For instance, in your case you might go:
lut = ones(40, 1, 'gpuArray');
lut([1 2 5 6]) = 0;

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!