<< gpuNorm sciGPGPU gpuSize >>

sciGPGPU >> sciGPGPU > gpuSetData

gpuSetData

Upload a Scilab matrix to the GPU memory

Call sequence

gA=gpuSetData(A)

Parameters

A

Real/Complex matrix

gA

Pointer to a matrix stored in GPU memory.

Description

gA=gpuSetData(A)

gA=gpuSetData(A) is used when the user wants to launch a computation using its GPU. GPU needs to have its data in GPU memory. The value returned is equivalent to a double* in C for gpu.

gAis equivalent to a double* in C for gpu. It can be passed to gpuApplyFunction, gpuMult, gpuSum ... and later to gpuFromGpu to retrieve computation results.

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)
C=0*ones(16,16);gC=gpuSetData(C)

bin=gpuBuild(gpuPATH+"/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);
gpuExit();

See Also

<< gpuNorm sciGPGPU gpuSize >>