<< gpuAdd sciGPGPU gpuApplyFunction >>

sciGPGPU >> sciGPGPU > gpuAlloc

gpuAlloc

Create a matrix in GPU memory with non-deterministic values

Call sequence

gA=gpuAlloc(m,n)

Parameters

m

Height of the generated matrix

n

Width of the generated matrix

Description

gA=gpuAlloc(m,n)

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.

Exemples

//--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);

See Also

<< gpuAdd sciGPGPU gpuApplyFunction >>