public class KernelLauncher extends Object
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
KernelLauncher#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(...);
| Modifier and Type | Field and Description |
|---|---|
static String |
FUNCTION_NAME |
| Modifier and Type | Method and Description |
|---|---|
void |
call(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.
The given arguments must all be either of the type Pointer, or of a primitive type except boolean. |
static KernelLauncher |
compile(String sourceCode,
String functionName,
String... nvccArguments)
Create a new KernelLauncher for the function with the given
name, that is defined in the given source code.
|
CUcontext |
context() |
static KernelLauncher |
create(String cuFileName,
String functionName,
boolean forceRebuild,
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(String cuFileName,
String functionName,
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(String functionName)
Create a new KernelLauncher which uses the same module as
this KernelLauncher, but may be used to execute a different
function.
|
CUfunction |
getFunction() |
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(InputStream moduleInputStream,
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(String functionName,
String type,
CUmodule module)
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.
|
static KernelLauncher |
load(String moduleFileName,
String functionName,
String type)
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.
This corresponds to the second parameter in the runtime call:
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
The default block size is (1,1,1) |
static void |
setCompilerPath(String path)
Set the path to the NVCC compiler.
|
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.
This corresponds to the first parameter in the runtime call:
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
The default grid size is (1,1,1) |
KernelLauncher |
setGridSize(int x,
int y,
int z)
Set the grid size (number of blocks per grid) for the function
call.
This corresponds to the first parameter in the runtime call:
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
The default grid size is (1,1,1) |
void |
setModule(CUmodule module) |
KernelLauncher |
setSharedMemSize(int sharedMemSize)
Set the size of the shared memory for the function
call.
This corresponds to the third parameter in the runtime call:
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
The default shared memory size is 0. |
KernelLauncher |
setStream(CUstream stream)
Set the stream for the function call.
This corresponds to the fourth parameter in the runtime call:
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
The default stream is null (0). |
KernelLauncher |
setup(dim3 gridSize,
dim3 blockSize)
Set the given grid size and block size for this KernelLauncher.
|
KernelLauncher |
setup(dim3 gridSize,
dim3 blockSize,
int sharedMemSize)
Set the given grid size and block size and shared memory size
for this KernelLauncher.
|
KernelLauncher |
setup(dim3 gridSize,
dim3 blockSize,
int sharedMemSize,
CUstream stream)
Set the given grid size and block size, shared memory size
and stream for this KernelLauncher.
|
String |
toString() |
public static final String FUNCTION_NAME
public static void setCompilerPath(String path)
setCompilerPath("C:/CUDA/bin");
path - The path to the NVCC compiler.public void setDeviceNumber(int number)
number - The number of the device to useCudaException - If number < 0 or number >= deviceCountpublic static KernelLauncher compile(String sourceCode, String functionName, 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 NVCCCudaException - 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...)public void setModule(CUmodule module)
public static KernelLauncher create(String cuFileName, String functionName, 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 NVCCCudaException - 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(InputStream, String)public static KernelLauncher create(String cuFileName, String functionName, boolean forceRebuild, 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 NVCCCudaException - 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(InputStream, String)public static KernelLauncher load(String functionName, String type, CUmodule module)
functionName - The name of the functionCudaException - 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(InputStream, String)public static KernelLauncher load(String moduleFileName, String functionName, String type)
moduleFileName - The name of the PTX- or CUBIN filefunctionName - The name of the functionCudaException - 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(InputStream, String)public static KernelLauncher load(InputStream moduleInputStream, String functionName)
moduleInputStream - The stream for the PTX- or CUBIN datafunctionName - The name of the functionCudaException - 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(InputStream, String)public KernelLauncher forFunction(String functionName)
functionName - The name of the functionCudaException - If the specified function can not
be obtained from the module of this KernelLauncher.public 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-directioncall(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-directioncall(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-directioncall(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 bytescall(Object...),
setup(dim3, dim3),
setup(dim3, dim3, int),
setup(dim3, dim3, int, CUstream)public KernelLauncher setStream(CUstream stream)
kernel<<<gridSize, blockSize,
sharedMemSize, stream>>>(...);
stream - The stream for the function callcall(Object...),
setup(dim3, dim3),
setup(dim3, dim3, int),
setup(dim3, dim3, int, CUstream)public KernelLauncher setup(dim3 gridSize, 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(dim3 gridSize, 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 memorycall(Object...),
setup(dim3, dim3),
setup(dim3, dim3, int, CUstream)public CUcontext context()
public KernelLauncher setup(dim3 gridSize, dim3 blockSize, int sharedMemSize, 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 invocationcall(Object...),
setup(dim3, dim3),
setup(dim3, dim3, int)public void call(Object... args)
Pointer, or of a primitive type except boolean.
Otherwise, a CudaException will be thrown.args - The arguments for the function callCudaException - if an argument with an invalid type
was given, or one of the internal functions for setting
up and executing the kernel failed.public CUfunction getFunction()
Copyright © 2015. All Rights Reserved.