@@ -45,9 +45,6 @@ class LaunchConfig:
4545 Group of threads (Thread Block) that will execute on the same
4646 streaming multiprocessor (SM). Threads within a thread blocks have
4747 access to shared memory and can be explicitly synchronized.
48- stream : :obj:`~_stream.Stream`
49- The stream establishing the stream ordering semantic of a
50- launch.
5148 shmem_size : int, optional
5249 Dynamic shared-memory size per thread block in bytes.
5350 (Default to size 0)
@@ -58,7 +55,6 @@ class LaunchConfig:
5855 grid : Union [tuple , int ] = None
5956 cluster : Union [tuple , int ] = None
6057 block : Union [tuple , int ] = None
61- stream : Stream = None
6258 shmem_size : Optional [int ] = None
6359
6460 def __post_init__ (self ):
@@ -72,12 +68,6 @@ def __post_init__(self):
7268 if Device ().compute_capability < (9 , 0 ):
7369 raise CUDAError ("thread block clusters are not supported on devices with compute capability < 9.0" )
7470 self .cluster = self ._cast_to_3_tuple (self .cluster )
75- # we handle "stream=None" in the launch API
76- if self .stream is not None and not isinstance (self .stream , Stream ):
77- try :
78- self .stream = Stream ._init (self .stream )
79- except Exception as e :
80- raise ValueError ("stream must either be a Stream object or support __cuda_stream__" ) from e
8171 if self .shmem_size is None :
8272 self .shmem_size = 0
8373
@@ -105,27 +95,35 @@ def _cast_to_3_tuple(self, cfg):
10595 raise ValueError
10696
10797
108- def launch (kernel , config , * kernel_args ):
98+ def launch (stream , config , kernel , * kernel_args ):
10999 """Launches a :obj:`~_module.Kernel`
110100 object with launch-time configuration.
111101
112102 Parameters
113103 ----------
114- kernel : :obj:`~_module.Kernel`
115- Kernel to launch.
104+ stream : :obj:`~_stream.Stream`
105+ The stream establishing the stream ordering semantic of a
106+ launch.
116107 config : :obj:`~_launcher.LaunchConfig`
117108 Launch configurations inline with options provided by
118109 :obj:`~_launcher.LaunchConfig` dataclass.
110+ kernel : :obj:`~_module.Kernel`
111+ Kernel to launch.
119112 *kernel_args : Any
120113 Variable length argument list that is provided to the
121114 launching kernel.
122115
123116 """
117+ if stream is None :
118+ raise ValueError ("stream cannot be None, stream must either be a Stream object or support __cuda_stream__" )
119+ if not isinstance (stream , Stream ):
120+ try :
121+ stream = Stream ._init (stream )
122+ except Exception as e :
123+ raise ValueError ("stream must either be a Stream object or support __cuda_stream__" ) from e
124124 if not isinstance (kernel , Kernel ):
125125 raise ValueError
126126 config = check_or_create_options (LaunchConfig , config , "launch config" )
127- if config .stream is None :
128- raise CUDAError ("stream cannot be None" )
129127
130128 # TODO: can we ensure kernel_args is valid/safe to use here?
131129 # TODO: merge with HelperKernelParams?
@@ -141,7 +139,7 @@ def launch(kernel, config, *kernel_args):
141139 drv_cfg = driver .CUlaunchConfig ()
142140 drv_cfg .gridDimX , drv_cfg .gridDimY , drv_cfg .gridDimZ = config .grid
143141 drv_cfg .blockDimX , drv_cfg .blockDimY , drv_cfg .blockDimZ = config .block
144- drv_cfg .hStream = config . stream .handle
142+ drv_cfg .hStream = stream .handle
145143 drv_cfg .sharedMemBytes = config .shmem_size
146144 attrs = [] # TODO: support more attributes
147145 if config .cluster :
@@ -157,6 +155,6 @@ def launch(kernel, config, *kernel_args):
157155 # TODO: check if config has any unsupported attrs
158156 handle_return (
159157 driver .cuLaunchKernel (
160- int (kernel ._handle ), * config .grid , * config .block , config .shmem_size , config . stream ._handle , args_ptr , 0
158+ int (kernel ._handle ), * config .grid , * config .block , config .shmem_size , stream ._handle , args_ptr , 0
161159 )
162160 )
0 commit comments