Load a kernel created with Cuda/OpenCL and compiled with gpuBuild function.
fonc=gpuLoadFunction(bin,"kernelname");
Matrix of string which contain the path of the file containing the kernel and the language of kernels writing (Cuda or OpenCL).
Name of the kernel
Pointer to the kernel.
fonc=gpuLoadFunction(bin,kernelname)
loads
a kernel from a compiling file.Then the returned value can be passed to
gpuApplyFunction.
bin
is an absolute path to a compiling file. The
user must ckeck that its hardware meets kernel requirement (that is, a ptx
build for 1.3 compute capable gpu card will return false results when
launched on a 1.1 compute capable gpu card.)
kernelname
is the name of the kernel inside the
PTX file. It is the name given to the corresponding function in C for gpu
source code, but can be mangled. To avoid name mangling, please add the
extern "C" attribute before declaring the 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) 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(); | ![]() | ![]() |