cuda.bindings._v2.driver.launch_kernel_ex#
- cuda.bindings._v2.driver.launch_kernel_ex(config, intptr_t f, kernel_params, intptr_t extra)#
Launches a CUDA function
CUfunctionor a CUDA kernelCUkernelwith launch-time configuration.Invokes the function
CUfunctionor the kernelCUkernelfwith the specified launch-time configurationconfig. TheCUlaunchConfigstructure is defined as:. **View CUDA Toolkit Documentation for a C++ code example**. where:.CUlaunchConfig.gridDimXis the width of the grid in blocks.CUlaunchConfig.gridDimYis the height of the grid in blocks.CUlaunchConfig.gridDimZis the depth of the grid in blocks.CUlaunchConfig.blockDimXis the X dimension of each thread block.CUlaunchConfig.blockDimXis the Y dimension of each thread block.CUlaunchConfig.blockDimZis the Z dimension of each thread block.CUlaunchConfig.sharedMemBytesis the dynamic shared-memory size per thread block in bytes.CUlaunchConfig.hStreamis the handle to the stream to perform the launch in. The CUDA context associated with this stream must match that associated with function f.CUlaunchConfig.attrsis an array ofCUlaunchConfig.numAttrscontinguousCUlaunchAttributeelements. The value of this pointer is not considered ifCUlaunchConfig.numAttrsis zero. However, in that case, it is recommended to set the pointer to NULL.CUlaunchConfig.numAttrsis the number of attributes populating the firstCUlaunchConfig.numAttrspositions of theCUlaunchConfig.attrsarray.
Launch-time configuration is specified by adding entries to
CUlaunchConfig.attrs. Each entry is an attribute ID and a corresponding attribute value. TheCUlaunchAttributestructure is defined as:. **View CUDA Toolkit Documentation for a C++ code example**. where:.CUlaunchAttribute.idis a unique enum identifying the attribute.CUlaunchAttribute.valueis a union that hold the attribute value.
An example of using the
configparameter:. **View CUDA Toolkit Documentation for a C++ code example**. TheCUlaunchAttributeIDenum is defined as:. **View CUDA Toolkit Documentation for a C++ code example**. and the correspondingCUlaunchAttributeValueunion as :. **View CUDA Toolkit Documentation for a C++ code example**. SettingCU_LAUNCH_ATTRIBUTE_COOPERATIVEto a non-zero value causes the kernel launch to be a cooperative launch, with exactly the same usage and semantics ofcuLaunchCooperativeKernel. SettingCU_LAUNCH_ATTRIBUTE_PROGRAMMATIC_STREAM_SERIALIZATIONto a non-zero values causes the kernel to use programmatic means to resolve its stream dependency – enabling the CUDA runtime to opportunistically allow the grid’s execution to overlap with the previous kernel in the stream, if that kernel requests the overlap.CU_LAUNCH_ATTRIBUTE_PROGRAMMATIC_EVENTrecords an event along with the kernel launch. Event recorded through this launch attribute is guaranteed to only trigger after all block in the associated kernel trigger the event. A block can trigger the event through PTX launchdep.release or CUDA builtin function cudaTriggerProgrammaticLaunchCompletion(). A trigger can also be inserted at the beginning of each block’s execution if triggerAtBlockStart is set to non-0. Note that dependents (including the CPU thread callingevent_synchronize()) are not guaranteed to observe the release precisely when it is released. For example,event_synchronize()may only observe the event trigger long after the associated kernel has completed. This recording type is primarily meant for establishing programmatic dependency between device tasks. The event supplied must not be an interprocess or interop event. The event must disable timing (i.e. created withCU_EVENT_DISABLE_TIMINGflag set).CU_LAUNCH_ATTRIBUTE_LAUNCH_COMPLETION_EVENTrecords an event along with the kernel launch. Nominally, the event is triggered once all blocks of the kernel have begun execution. Currently this is a best effort. If a kernel B has a launch completion dependency on a kernel A, B may wait until A is complete. Alternatively, blocks of B may begin before all blocks of A have begun, for example:.If B can claim execution resources unavailable to A, for example if they run on different GPUs.
If B is a higher priority than A.
Exercise caution if such an ordering inversion could lead to deadlock. The event supplied must not be an interprocess or interop event. The event must disable timing (i.e. must be created with the
CU_EVENT_DISABLE_TIMINGflag set). SettingCU_LAUNCH_ATTRIBUTE_DEVICE_UPDATABLE_KERNEL_NODEto 1 on a captured launch causes the resulting kernel node to be device-updatable. This attribute is specific to graphs, and passing it to a launch in a non-capturing stream results in an error. Passing a value other than 0 or 1 is not allowed. On success, a handle will be returned viaCUlaunchAttributeValue.deviceUpdatableKernelNode.devNodewhich can be passed to the various device-side update functions to update the node’s kernel parameters from within another kernel. For more information on the types of device updates that can be made, as well as the relevant limitations thereof, seecudaGraphKernelNodeUpdatesApply. Kernel nodes which are device-updatable have additional restrictions compared to regular kernel nodes. Firstly, device-updatable nodes cannot be removed from their graph viacuGraphDestroyNode. Additionally, once opted-in to this functionality, a node cannot opt out, and any attempt to set the attribute to 0 will result in an error. Graphs containing one or more device-updatable node also do not allow multiple instantiation.CU_LAUNCH_ATTRIBUTE_PREFERRED_CLUSTER_DIMENSIONallows the kernel launch to specify a preferred substitute cluster dimension. Blocks may be grouped according to either the dimensions specified with this attribute (grouped into a “preferred substitute cluster”), or the one specified withCU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSIONattribute (grouped into a “regular cluster”). The cluster dimensions of a “preferred substitute cluster” shall be an integer multiple greater than zero of the regular cluster dimensions. The device will attempt - on a best-effort basis - to group thread blocks into preferred clusters over grouping them into regular clusters. When it deems necessary (primarily when the device temporarily runs out of physical resources to launch the larger preferred clusters), the device may switch to launch the regular clusters instead to attempt to utilize as much of the physical device resources as possible. Each type of cluster will have its enumeration / coordinate setup as if the grid consists solely of its type of cluster. For example, if the preferred substitute cluster dimensions double the regular cluster dimensions, there might be simultaneously a regular cluster indexed at (1,0,0), and a preferred cluster indexed at (1,0,0). In this example, the preferred substitute cluster (1,0,0) replaces regular clusters (2,0,0) and (3,0,0) and groups their blocks. This attribute will only take effect when a regular cluster dimension has been specified. The preferred substitute The preferred substitute cluster dimension must be an integer multiple greater than zero of the regular cluster dimension and must divide the grid. It must also be no more thanmaxBlocksPerCluster, if it is set in the kernel’s__launch_bounds__. Otherwise it must be less than the maximum value the driver can support. Otherwise, setting this attribute to a value physically unable to fit on any particular device is permitted. The effect of other attributes is consistent with their effect when set via persistent APIs. SeecuStreamSetAttributefor.CU_LAUNCH_ATTRIBUTE_ACCESS_POLICY_WINDOW.CU_LAUNCH_ATTRIBUTE_SYNCHRONIZATION_POLICY.
See
cuFuncSetAttributefor.CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION.CU_LAUNCH_ATTRIBUTE_CLUSTER_SCHEDULING_POLICY_PREFERENCE.
Kernel parameters to
fcan be specified in the same ways that they can be usingcuLaunchKernel. 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 streamCUlaunchConfig.hStreamor the current context in case of NULL stream.- Parameters:
config (intptr_t) – Config to launch.
f (intptr_t) – Function
CUfunctionor KernelCUkernelto launch.kernel_params (object) – Array of pointers to kernel parameters.
extra (intptr_t) – Extra options.
See also
cuLaunchKernelEx