|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcuda.utils.KernelLauncher
public class KernelLauncher
This is a utility class that simplifies the setup and launching
of CUDA kernels using the JCuda Driver API.
Instances of this class may be created using one of the following
methods:
compile(String, String, String...)
will
compile a kernel from a String containing the CUDA source code
create(String, String, String...)
will
create a kernel for a function that is contained in a CUDA
source file
load(String, String)
will load a kernel from
a PTX or CUBIN (CUDA binary) file.
load(InputStream, String)
will load a kernel
from PTX- or CUBIN data which is provided via an InputStream
(useful for packaging PTX- or CUBIN files into JAR archives)call(Object...)
method. The actual
kernel function arguments which are passed to this method
will be set up automatically, and aligned appropriately for
their respective size.
kernel<<<gridDim, blockDim,
sharedMemorySize, stream>>>(...);
setup(dim3, dim3, int, CUstream)
method:
kernelLauncher.setup(gridDim,
blockDim, sharedMemorySize, stream).call(...);
kernelLauncher.setup(gridDim,
blockDim).call(kernel);
kernelLauncher.setGridSize(gridSize);
kernelLauncher.setBlockSize(blockSize);
kernelLauncher.call(...);
Method Summary | |
---|---|
void |
call(java.lang.Object... args)
Call the function of this KernelLauncher with the current grid size, block size, shared memory size and stream, and with the given arguments. |
static KernelLauncher |
compile(java.lang.String sourceCode,
java.lang.String functionName,
java.lang.String... nvccArguments)
Create a new KernelLauncher for the function with the given name, that is defined in the given source code. |
static KernelLauncher |
create(java.lang.String cuFileName,
java.lang.String functionName,
boolean forceRebuild,
java.lang.String... nvccArguments)
Create a new KernelLauncher for the function with the given name, that is contained in the .CU CUDA source file with the given name. |
static KernelLauncher |
create(java.lang.String cuFileName,
java.lang.String functionName,
java.lang.String... nvccArguments)
Create a new KernelLauncher for the function with the given name, that is contained in the .CU CUDA source file with the given name. |
KernelLauncher |
forFunction(java.lang.String functionName)
Create a new KernelLauncher which uses the same module as this KernelLauncher, but may be used to execute a different function. |
jcuda.driver.CUmodule |
getModule()
Returns the module that was created from the PTX- or CUBIN file, and which contains the function that should be executed. |
static KernelLauncher |
load(java.io.InputStream moduleInputStream,
java.lang.String functionName)
Create a new KernelLauncher which may be used to execute the specified function which is loaded from the PTX- or CUBIN data that is read from the given input stream. |
static KernelLauncher |
load(java.lang.String moduleFileName,
java.lang.String functionName)
Create a new KernelLauncher which may be used to execute the specified function which is loaded from the PTX- or CUBIN (CUDA binary) file with the given name. |
KernelLauncher |
setBlockSize(int x,
int y,
int z)
Set the block size (number of threads per block) for the function call. |
static void |
setCompilerPath(java.lang.String path)
Set the path to the NVCC compiler. |
static void |
setDeviceNumber(int number)
Set the number (index) of the device which should be used by the KernelLauncher |
KernelLauncher |
setGridSize(int x,
int y)
Set the grid size (number of blocks per grid) for the function call. |
KernelLauncher |
setGridSize(int x,
int y,
int z)
Set the grid size (number of blocks per grid) for the function call. |
KernelLauncher |
setSharedMemSize(int sharedMemSize)
Set the size of the shared memory for the function call. |
KernelLauncher |
setStream(jcuda.driver.CUstream stream)
Set the stream for the function call. |
KernelLauncher |
setup(jcuda.runtime.dim3 gridSize,
jcuda.runtime.dim3 blockSize)
Set the given grid size and block size for this KernelLauncher. |
KernelLauncher |
setup(jcuda.runtime.dim3 gridSize,
jcuda.runtime.dim3 blockSize,
int sharedMemSize)
Set the given grid size and block size and shared memory size for this KernelLauncher. |
KernelLauncher |
setup(jcuda.runtime.dim3 gridSize,
jcuda.runtime.dim3 blockSize,
int sharedMemSize,
jcuda.driver.CUstream stream)
Set the given grid size and block size, shared memory size and stream for this KernelLauncher. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void setCompilerPath(java.lang.String path)
setCompilerPath("C:/CUDA/bin");
path
- The path to the NVCC compiler.public static void setDeviceNumber(int number)
number
- The number of the device to use
jcuda.CudaException
- If number<0 or number>=deviceCountpublic static KernelLauncher compile(java.lang.String sourceCode, java.lang.String functionName, java.lang.String... nvccArguments)
setCompilerPath(String)
with the respective path. extern "C"
function:
extern "C"
__global__ void functionName(...)
{
...
}
sourceCode
- The source code containing the functionfunctionName
- The name of the function.nvccArguments
- Optional arguments for the NVCC
jcuda.CudaException
- If the creation of the CU- or PTX file
fails, or the PTX may not be loaded, or the specified
function can not be obtained.create(String, String, String...)
,
create(String, String, boolean, String...)
,
load(String, String)
public static KernelLauncher create(java.lang.String cuFileName, java.lang.String functionName, java.lang.String... nvccArguments)
extern "C"
function:
extern "C"
__global__ void functionName(...)
{
...
}
setCompilerPath(String)
with the respective path.
cuFileName
- The name of the source file.functionName
- The name of the function.nvccArguments
- Optional arguments for the NVCC
jcuda.CudaException
- If the creation of the PTX file fails,
or the PTX may not be loaded, or the specified function can
not be obtained.compile(String, String, String...)
,
create(String, String, boolean, String...)
,
load(String, String)
,
load(InputStream, String)
public static KernelLauncher create(java.lang.String cuFileName, java.lang.String functionName, boolean forceRebuild, java.lang.String... nvccArguments)
extern "C"
function:
extern "C"
__global__ void functionName(...)
{
...
}
forceRebuild
flag is 'true', then the
PTX file will be recompiled from the given source file,
even if it already existed or was newer than the source
file, and the already existing PTX file will be
overwritten.setCompilerPath(String)
with the respective path.
cuFileName
- The name of the source file.functionName
- The name of the function.forceRebuild
- Whether the PTX file should be recompiled
and overwritten if it already exists.nvccArguments
- Optional arguments for the NVCC
jcuda.CudaException
- If the creation of the PTX file fails,
or the PTX may not be loaded, or the specified function can
not be obtained.compile(String, String, String...)
,
create(String, String, String...)
,
load(String, String)
,
load(InputStream, String)
public static KernelLauncher load(java.lang.String moduleFileName, java.lang.String functionName)
moduleFileName
- The name of the PTX- or CUBIN filefunctionName
- The name of the function
jcuda.CudaException
- If the PTX- or CUBIN may not be loaded,
or the specified function can not be obtained.compile(String, String, String...)
,
create(String, String, boolean, String...)
,
load(String, String)
,
load(InputStream, String)
public static KernelLauncher load(java.io.InputStream moduleInputStream, java.lang.String functionName)
moduleInputStream
- The stream for the PTX- or CUBIN datafunctionName
- The name of the function
jcuda.CudaException
- If the PTX- or CUBIN may not be loaded,
or the specified function can not be obtained.compile(String, String, String...)
,
create(String, String, boolean, String...)
,
load(String, String)
,
load(InputStream, String)
public KernelLauncher forFunction(java.lang.String functionName)
functionName
- The name of the function
jcuda.CudaException
- If the specified function can not
be obtained from the module of this KernelLauncher.public jcuda.driver.CUmodule getModule()
public KernelLauncher setGridSize(int x, int y)
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
x
- The number of blocks per grid in x-directiony
- The number of blocks per grid in y-direction
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setGridSize(int x, int y, int z)
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
x
- The number of blocks per grid in x-directiony
- The number of blocks per grid in y-directionz
- The number of blocks per grid in z-direction
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setBlockSize(int x, int y, int z)
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
x
- The number of threads per block in x-directiony
- The number of threads per block in y-directionz
- The number of threads per block in z-direction
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setSharedMemSize(int sharedMemSize)
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
sharedMemSize
- The size of the shared memory, in bytes
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setStream(jcuda.driver.CUstream stream)
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
stream
- The stream for the function call
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setup(jcuda.runtime.dim3 gridSize, jcuda.runtime.dim3 blockSize)
gridSize
- The grid size (number of blocks per grid)blockSize
- The block size (number of threads per block)
call(Object...)
,
setup(dim3, dim3, int)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setup(jcuda.runtime.dim3 gridSize, jcuda.runtime.dim3 blockSize, int sharedMemSize)
gridSize
- The grid size (number of blocks per grid)blockSize
- The block size (number of threads per block)sharedMemSize
- The size of the shared memory
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int, CUstream)
public KernelLauncher setup(jcuda.runtime.dim3 gridSize, jcuda.runtime.dim3 blockSize, int sharedMemSize, jcuda.driver.CUstream stream)
gridSize
- The grid size (number of blocks per grid)blockSize
- The block size (number of threads per block)sharedMemSize
- The size of the shared memorystream
- The stream for the kernel invocation
call(Object...)
,
setup(dim3, dim3)
,
setup(dim3, dim3, int)
public void call(java.lang.Object... args)
Pointer
, or of a primitive type except boolean.
Otherwise, a CudaException will be thrown.
args
- The arguments for the function call
jcuda.CudaException
- if an argument with an invalid type
was given, or one of the internal functions for setting
up and executing the kernel failed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |