GPU에서 희소 형식 배열 사용하기
희소 GPU 배열 만들기
sparse
를 gpuArray
입력값과 함께 호출하거나 gpuArray
를 희소 형식 입력값과 함께 호출하여 희소 형식 gpuArray
를 만들 수 있습니다. 예를 들면 다음과 같습니다.
X = [0 1 0 0 0; 0 0 0 0 1]
0 1 0 0 0 0 0 0 0 1
S = sparse(X)
(1,2) 1 (2,5) 1
G = gpuArray(G); % G is a sparse gpuArray Gt = transpose(G); % Gt is a sparse gpuArray F = full(Gt) % F is a full gpuArray
0 0 1 0 0 0 0 0 0 1
GPU 배열 인덱싱
희소 GPU 배열은 전체 행 또는 전체 열을 인덱스로 참조하는 것만 지원합니다. 예를 들어 희소 행렬 A
의 5번째 행에 액세스하려면 A(5,:)
또는 A(5,1:end)
를 호출합니다.
A = gpuArray.speye(10); A(5,:)
(1,5) 1
full(A(5,:))
0 0 0 0 1 0 0 0 0 0
희소 GPU 배열의 0이 아닌 요소를 찾으려면 find
함수를 사용합니다. 그런 다음 원하는 값을 바꾸고 희소 gpuArray
를 새로 생성할 수 있습니다.
A = gpuArray.speye(10); [row,col] = find(A); [row,col]
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
인덱스로 희소 GPU 배열에 값을 할당하는 것은 지원되지 않습니다.
희소 GPU 배열을 지원하는 함수
다음 표에는 희소 형식 gpuArray
객체를 지원하는 함수가 나와 있습니다.
abs acos acosd acosh acot acotd acoth acsc acscd acsch angle asec asecd asech asin asind asinh atan atand atanh bicg bicgstab ceil cgs classUnderlying conj cos cosd cosh cospi cot cotd coth csc cscd csch ctranspose deg2rad diag end | eps exp expint expm1 find fix floor full gmres gpuArray.speye imag isaUnderlying isdiag isempty isequal isequaln isfinite isfloat isinteger islogical isnumeric isreal issparse istril istriu isUnderlyingType length log log2 log10 log1p lsqr minus mtimes mpower mustBeUnderlyingType ndims nextpow2 nnz nonzeros | norm numel nzmax pcg plus power qmr rad2deg real reallog realsqrt round sec secd sech sign sin sind sinh sinpi size sparse spfun spones sprandsym sqrt subsref sum tan tand tanh tfqmr times (.*) trace transpose tril triu uminus underlyingType uplus |