matlab struct to gpuArray

조회 수: 10 (최근 30일)
EssGee
EssGee 2013년 4월 12일
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