I am trying to save memory on my GPU by saving sparse data, but matlab gives this error whenever I try to cut a sparse gpuArray in the following way.
Error using gpuArray/subsref
Sparse gpuArrays are not supported for this function.
Ex.
A=gpuArray(sparse(randi([0,1],2000,2000)));
B=A(1:50,:);
Is there any way to cut sparse gpuArrays, or am I stuck transferring data between my CPU and GPU?
NOTE: This is a piece of example code. Although this piece of code will not have memory benefits from a sparse array, my application will.

 채택된 답변

Matt J
Matt J 2016년 8월 31일

1 개 추천

Here's a workaround equivalent to B=A(1:50,:), but I do agree it seems unnecessarily awkward.
B = gpuArray.speye(50,2000) * A;

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2016년 8월 31일

0 개 추천

For the sparsity level of that matrix ~50%, the sparse array is much bigger than a regular array:
x = randi(1,100,100);
xs = sparse(x);
whos x xs
Name Size Bytes Class Attributes
x 100x100 80000 double
xs 100x100 160808 double sparse
You're better off just using a regular array. And you can generate randi directly on gpu so it doesn't need to be transferred:
gpuArray.randi(1,100,100)

댓글 수: 1

Kevin Bender
Kevin Bender 2016년 8월 31일
This is just an example, not the actual code. In my actual code, I am storing a sparse adjacency matrix that has less than 5% nonzero elements.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2016년 8월 31일

답변:

2016년 8월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by