matlab struct to gpuArray

9 次查看(过去 30 天)
Is it possible to transfer a matlab struct to the GPU? So for example is something like this possible:
s.a = 1
s.b = [1; 2; 3]
s.c = []
s.d = 5
sgpu = gpuArray(s)

采纳的回答

Edric Ellis
Edric Ellis 2013-4-12
You cannot make a structure on the gpu, but you can make a structure containing gpuArrays.
s.a = gpuArray(1)
s.b = gpuArray([1; 2; 3]);
...
  2 个评论
EssGee
EssGee 2013-4-12
Thanks Eric, I was hoping not to go that route. So if the structure has many variables , they would have to individually transferred as you mention.
I assume each of these operations corresponds to a cudaMEMcpy, or is it an asynchronous memcopy with unified memory?
Edric Ellis
Edric Ellis 2013-4-15
You can use STRUCTFUN to convert a bunch of fields at a time, like this
s.a = magic(3); s.b = magic(4);
gs = structfun(@gpuArray, s, 'UniformOutput', false);
The gpuArray function is indeed currently equivalent to a cudaMemcpy call.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by