Sparse gpuArray indexing limitations
Mostra commenti meno recenti
When trying to extract a sub-matrix of a sparse gpuArray, I get,
>> S=gpuArray(sprand(100,100,0.1));
>> S(1:5,1:5)
Sparse gpuArray matrices only support referencing whole rows or whole columns.
OK, but here, I am indexing a block of complete rows and get the same error,
>> S(1:5,:)
Sparse gpuArray matrices only support referencing whole rows or whole columns.
Aside from this, what is the internal hurdle that makes subsrefing a sparse matrix so hard on the GPU? This has been a limitation for quite a while now.
3 Commenti
Walter Roberson
circa 2 ore fa
I do not have easy access to a gpu system at this time.
I wonder if
S(1,:)
S(:,1)
would work? That is, perhaps the limit is on indexing more than one complete row or column ?
Matt J
circa 4 ore fa
Theoretically, yes it could be done but creates the complexity issue noted before so the ability isn't directly supported. Reading the gpuArray doc on <Working With Sparse GPU Arrays> again and parsing the addressing discussion more carefully, it appears to be a restriction documented by example and the implication that index is a single value, not by an explicit statement. "Sparse GPU arrays only support referencing whole rows or columns by index. For example ..." uses 5 in that example but doesn't directly state that "index" cannot be a colon expression. Like you apparently, @Matt J, I initially presumed the index could be generalized as with addressing in-memory arrays, sparse or not.
If this operation is needed, it would have to be implemented by extracting each row/column individually and catenating them in local memory as assigning values to sparse GPU arrays by index is not supported. The result would then have to be moved to a GPU array from memory. It's not clear from the documentation whether the writing restrictions precludes something like
B=gpuArray(sparse([])); % empty sparse GPU array????
for i=1:5
B=[B;S(i,:)];
end
but I suspect they do/will.
Syntax issues aside, even if it were to work, constructing a new sparse matrix dynamically would require the GPU to rebuild the entire CSR/CSC data structure for every iteration. If it were toy-sized arrays this might be feasible, but presuming real cases would be large enought to actually need sparse instead of dense arrays, the reconstruction sequentially would undoubtedly turn out to be prohibitively slow.
It's hard to wrap one's head around, but the GPU CSC/CSR storage scheme is efficient for the given array it is constructed for, but it has to be recomputed from scratch to build a new array.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!