cuda.bindings._v2.driver.launch_kernel#
- cuda.bindings._v2.driver.launch_kernel(
- intptr_t f,
- unsigned int grid_dim_x,
- unsigned int grid_dim_y,
- unsigned int grid_dim_z,
- unsigned int block_dim_x,
- unsigned int block_dim_y,
- unsigned int block_dim_z,
- unsigned int shared_mem_bytes,
- intptr_t h_stream,
- kernel_params,
- intptr_t extra,
Launches a CUDA function
CUfunctionor a CUDA kernelCUkernel.Invokes the function
CUfunctionor the kernelCUkernelfon agrid_dim_xxgrid_dim_yxgrid_dim_zgrid of blocks. Each block containsblock_dim_xxblock_dim_yxblock_dim_zthreads.shared_mem_bytessets the amount of dynamic shared memory that will be available to each thread block. Kernel parameters tofcan be specified in one of two ways:. 1) Kernel parameters can be specified viakernel_params. Iffhas N parameters, thenkernel_paramsneeds to be an array of N pointers. Each ofkernel_params[0] throughkernel_params[N-1] must point to a region of memory from which the actual kernel parameter will be copied. The number of kernel parameters and their offsets and sizes do not need to be specified as that information is retrieved directly from the kernel’s image. 2) Kernel parameters can also be packaged by the application into a single buffer that is passed in via theextraparameter. This places the burden on the application of knowing each kernel parameter’s size and alignment/padding within the buffer. Here is an example of using theextraparameter in this manner:. **View CUDA Toolkit Documentation for a C++ code example**. Theextraparameter exists to allowcuLaunchKernelto take additional less commonly used arguments.extraspecifies a list of names of extra settings and their corresponding values. Each extra setting name is immediately followed by the corresponding value. The list must be terminated with either NULL orCU_LAUNCH_PARAM_END.CU_LAUNCH_PARAM_END, which indicates the end of theextraarray;.CU_LAUNCH_PARAM_BUFFER_POINTER, which specifies that the next value inextrawill be a pointer to a buffer containing all the kernel parameters for launching kernelf;.CU_LAUNCH_PARAM_BUFFER_SIZE, which specifies that the next value inextrawill be a pointer to a size_t containing the size of the buffer specified withCU_LAUNCH_PARAM_BUFFER_POINTER;.
The error
CUDA_ERROR_INVALID_VALUEwill be returned if kernel parameters are specified with bothkernel_paramsandextra(i.e. bothkernel_paramsandextraare non-NULL). Callinglaunch_kernel()invalidates the persistent function state set through the following deprecated APIs:func_set_block_shape(),func_set_shared_size(),param_set_size(),param_seti(),param_setf(),param_setv(). Note that to uselaunch_kernel(), the kernelfmust either have been compiled with toolchain version 3.2 or later so that it will contain kernel parameter information, or have no kernel parameters. If either of these conditions is not met, thenlaunch_kernel()will returnCUDA_ERROR_INVALID_IMAGE. Note that the API can also be used to launch context-less kernelCUkernelby querying the handle usinglibrary_get_kernel()and then passing it to the API by casting toCUfunction. Here, the context to launch the kernel on will either be taken from the specified streamh_streamor the current context in case of NULL stream.- Parameters:
f (intptr_t) – Function
CUfunctionor KernelCUkernelto launch.grid_dim_x (unsigned int) – Width of grid in blocks.
grid_dim_y (unsigned int) – Height of grid in blocks.
grid_dim_z (unsigned int) – Depth of grid in blocks.
block_dim_x (unsigned int) – X dimension of each thread block.
block_dim_y (unsigned int) – Y dimension of each thread block.
block_dim_z (unsigned int) – Z dimension of each thread block.
shared_mem_bytes (unsigned int) – Dynamic shared-memory size per thread block in bytes.
h_stream (intptr_t) – Stream identifier.
kernel_params (object) – Array of pointers to kernel parameters.
extra (intptr_t) – Extra options.
See also
cuLaunchKernel