Create a matrix in GPU memory with non-deterministic values
gA=gpuAlloc(m,n)
Height of the generated matrix
Width of the generated matrix
gA=gpuAlloc(m,n)
does allocate a matrix on GPU
with no copy. The content of this matrix is moreless random. Such matrix
are used as return value for kernel., but is a little faster because
there is no unecessary memory transfert. It is advised to pass such a
matrix as an output value to a kernel.
//--matrixAdd.cu-- extern "C" __global__ void matrixAdd(double* C, double* A, double* B, int M, int N) { int idx = blockIdx.x; int idy = blockIdx.y; int dx = blockDim.x; int dy = blockDim.y; int tx = threadIdx.x; int ty = threadIdx.y; int x=tx+dx*idx; int y=ty+dy*idy; if(x<M && y<N) C[ x + y*M ]= A[ x + y*M ] + B[ x+ y*M ]; } //--Scilab script-- A=ones(16,16);gA=gpuSetData(A) B=2*ones(16,16);gB=gpuSetData(B) gC=gpuAlloc(16,16) bin = gpuBuild(CUDAPATH+"/tests/unit_tests/"+"matrixAdd"); fonc=gpuLoadFunction(bin,"matrixAdd") lst=list(gC,gB,gA,16,16) gpuApplyFunction(fonc,lst,16,16,1,1); C=gpuGetData(gC); gpuFree(gA); gpuFree(gB); gpuFree(gC); | ![]() | ![]() |