cuda - In cuBLAS, how do I get or set matrix element from host? -


hi using cublas matrix operations.

occasionally, need or set individual matrix elements. per cublas documentation, matrix allocated this:

    cudamalloc((void**)&parraydev,sizeof(float)*numrows*numcols);             cublassetmatrix(numrows,numcols,sizeof(float),parray,numrows,parraydev,numrows); 

now, if need change 1 element, can use cudamemset? right way from host code? don't want copy whole array host device each time change 1 element.

cudamemset inconvenient use because operates on bytes, you'd setting every byte of float value same number. that's not want.

but cublassetmatrix has capability tiled copy. serve purpose, assuming have host copy of matrix originally. update corresponding position in host copy, cublassetmatrix call rows = 1, cols = 1, , and , b matrix pointers pointing element update in source , destination matrices:

cublassetmatrix(1,1,sizeof(float),&parray[offset],numrows,&parraydev[offset],numrows); 

if didn't have host copy of matrix sitting around, similar cudamemcpy:

float updateval = 100.0f;  // or whatever value want  cudamemcpy(&parraydev[offset], &updateval, sizeof(float), cudamemcpyhosttodevice); 

you can reverse above operations if want retrieve single element device host (e.g. use cublasgetmatrix, or cudamemcpydevicetohost, etc.)


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -