Skip to content

Commit 2ea2302

Browse files
aryanputtamdboom
andauthored
docs(cuda.core): use PEP 604 unions in docstrings (#2601)
Docstrings across cuda_core still spelled parameter types with the pre-3.10 typing generics. Replace Union[...] and Optional[...] with the | form the rest of the package already uses, e.g. `stream : Stream | None, optional` in _memoryview.pyx. Docstrings only, so the .pyi changes are the stubgen-pyx output for the edited .pyx files and no runtime behavior moves. In _module.pyx this also realigns the max_potential_block_size docstring with its signature, which already reads int | driver.CUoccupancyB2DSize. Two code-level spellings stay as they are: - LinkerHandleT in _linker.pyx is a runtime value, not an annotation. _program.pyx builds ProgramHandleT from it with `nvrtc.nvrtcProgram | int | LinkerHandleT`, and PEP 604 `|` on the forward-reference strings it holds raises TypeError. - The union_type literal in _process_define_macro is error-message text rather than a docstring. Sequence[...] and Iterable[...] elsewhere in cuda_core are collections.abc generics and are unaffected. Signed-off-by: Aryan <aryansputta@gmail.com> Co-authored-by: Michael Droettboom <mdboom@gmail.com>
1 parent 9c7f19d commit 2ea2302

6 files changed

Lines changed: 66 additions & 66 deletions

File tree

cuda_core/cuda/core/_launch_config.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class LaunchConfig:
1818
1919
Attributes
2020
----------
21-
grid : Union[tuple, int]
21+
grid : tuple | int
2222
Collection of threads that will execute a kernel function. When cluster
2323
is not specified, this represents the number of blocks, otherwise
2424
this represents the number of clusters.
25-
cluster : Union[tuple, int]
25+
cluster : tuple | int
2626
Group of blocks (Thread Block Cluster) that will execute on the same
2727
GPU Processing Cluster (GPC). Blocks within a cluster have access to
2828
distributed shared memory and can be explicitly synchronized.
29-
block : Union[tuple, int]
29+
block : tuple | int
3030
Group of threads (Thread Block) that will execute on the same
3131
streaming multiprocessor (SM). Threads within a thread blocks have
3232
access to shared memory and can be explicitly synchronized.
@@ -46,11 +46,11 @@ class LaunchConfig:
4646
4747
Parameters
4848
----------
49-
grid : Union[tuple, int], optional
49+
grid : tuple | int, optional
5050
Grid dimensions (number of blocks or clusters if cluster is specified)
51-
cluster : Union[tuple, int], optional
51+
cluster : tuple | int, optional
5252
Cluster dimensions (Thread Block Cluster)
53-
block : Union[tuple, int], optional
53+
block : tuple | int, optional
5454
Block dimensions (threads per block)
5555
shmem_size : int, optional
5656
Dynamic shared memory size in bytes (default: 0)

cuda_core/cuda/core/_launch_config.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ cdef class LaunchConfig:
3838
3939
Attributes
4040
----------
41-
grid : Union[tuple, int]
41+
grid : tuple | int
4242
Collection of threads that will execute a kernel function. When cluster
4343
is not specified, this represents the number of blocks, otherwise
4444
this represents the number of clusters.
45-
cluster : Union[tuple, int]
45+
cluster : tuple | int
4646
Group of blocks (Thread Block Cluster) that will execute on the same
4747
GPU Processing Cluster (GPC). Blocks within a cluster have access to
4848
distributed shared memory and can be explicitly synchronized.
49-
block : Union[tuple, int]
49+
block : tuple | int
5050
Group of threads (Thread Block) that will execute on the same
5151
streaming multiprocessor (SM). Threads within a thread blocks have
5252
access to shared memory and can be explicitly synchronized.
@@ -77,11 +77,11 @@ cdef class LaunchConfig:
7777

7878
Parameters
7979
----------
80-
grid : Union[tuple, int], optional
80+
grid : tuple | int, optional
8181
Grid dimensions (number of blocks or clusters if cluster is specified)
82-
cluster : Union[tuple, int], optional
82+
cluster : tuple | int, optional
8383
Cluster dimensions (Thread Block Cluster)
84-
block : Union[tuple, int], optional
84+
block : tuple | int, optional
8585
Block dimensions (threads per block)
8686
shmem_size : int, optional
8787
Dynamic shared memory size in bytes (default: 0)

cuda_core/cuda/core/_module.pyi

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class KernelOccupancy:
158158
159159
Parameters
160160
----------
161-
dynamic_shared_memory_needed: Union[int, driver.CUoccupancyB2DSize]
161+
dynamic_shared_memory_needed: int | driver.CUoccupancyB2DSize
162162
The amount of dynamic shared memory in bytes needed by block.
163163
Use `0` if block does not need shared memory. Use C-callable
164164
represented by :obj:`~driver.CUoccupancyB2DSize` to encode
@@ -343,13 +343,13 @@ class ObjectCode:
343343
344344
Parameters
345345
----------
346-
module : Union[bytes, str, os.PathLike]
346+
module : bytes | str | os.PathLike
347347
Either a bytes object containing the in-memory cubin to load, or
348348
a file path object (or its string representation) pointing to the
349349
on-disk cubin to load.
350-
name : Optional[str]
350+
name : str | None
351351
A human-readable identifier representing this code object.
352-
symbol_mapping : Optional[dict]
352+
symbol_mapping : dict | None
353353
A dictionary specifying how the unmangled symbol names (as keys)
354354
should be mapped to the mangled names before trying to retrieve
355355
them (default to no mappings).
@@ -361,13 +361,13 @@ class ObjectCode:
361361
362362
Parameters
363363
----------
364-
module : Union[bytes, str, os.PathLike]
364+
module : bytes | str | os.PathLike
365365
Either a bytes object containing the in-memory ptx code to load, or
366366
a file path object (or its string representation) pointing to the
367367
on-disk ptx file to load.
368-
name : Optional[str]
368+
name : str | None
369369
A human-readable identifier representing this code object.
370-
symbol_mapping : Optional[dict]
370+
symbol_mapping : dict | None
371371
A dictionary specifying how the unmangled symbol names (as keys)
372372
should be mapped to the mangled names before trying to retrieve
373373
them (default to no mappings).
@@ -379,13 +379,13 @@ class ObjectCode:
379379
380380
Parameters
381381
----------
382-
module : Union[bytes, str, os.PathLike]
382+
module : bytes | str | os.PathLike
383383
Either a bytes object containing the in-memory ltoir code to load,
384384
or a file path object (or its string representation) pointing to the
385385
on-disk ltoir file to load.
386-
name : Optional[str]
386+
name : str | None
387387
A human-readable identifier representing this code object.
388-
symbol_mapping : Optional[dict]
388+
symbol_mapping : dict | None
389389
A dictionary specifying how the unmangled symbol names (as keys)
390390
should be mapped to the mangled names before trying to retrieve
391391
them (default to no mappings).
@@ -397,13 +397,13 @@ class ObjectCode:
397397
398398
Parameters
399399
----------
400-
module : Union[bytes, str, os.PathLike]
400+
module : bytes | str | os.PathLike
401401
Either a bytes object containing the in-memory fatbin to load, or
402402
or a file path object (or its string representation) pointing to the
403403
on-disk fatbin to load.
404-
name : Optional[str]
404+
name : str | None
405405
A human-readable identifier representing this code object.
406-
symbol_mapping : Optional[dict]
406+
symbol_mapping : dict | None
407407
A dictionary specifying how the unmangled symbol names (as keys)
408408
should be mapped to the mangled names before trying to retrieve
409409
them (default to no mappings).
@@ -415,12 +415,12 @@ class ObjectCode:
415415
416416
Parameters
417417
----------
418-
module : Union[bytes, str]
418+
module : bytes | str
419419
Either a bytes object containing the in-memory object code to load, or
420420
a file path string pointing to the on-disk object code to load.
421-
name : Optional[str]
421+
name : str | None
422422
A human-readable identifier representing this code object.
423-
symbol_mapping : Optional[dict]
423+
symbol_mapping : dict | None
424424
A dictionary specifying how the unmangled symbol names (as keys)
425425
should be mapped to the mangled names before trying to retrieve
426426
them (default to no mappings).
@@ -432,12 +432,12 @@ class ObjectCode:
432432
433433
Parameters
434434
----------
435-
module : Union[bytes, str]
435+
module : bytes | str
436436
Either a bytes object containing the in-memory library to load, or
437437
a file path string pointing to the on-disk library to load.
438-
name : Optional[str]
438+
name : str | None
439439
A human-readable identifier representing this code object.
440-
symbol_mapping : Optional[dict]
440+
symbol_mapping : dict | None
441441
A dictionary specifying how the unmangled symbol names (as keys)
442442
should be mapped to the mangled names before trying to retrieve
443443
them (default to no mappings).

cuda_core/cuda/core/_module.pyx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ cdef class KernelOccupancy:
300300

301301
Parameters
302302
----------
303-
dynamic_shared_memory_needed: Union[int, driver.CUoccupancyB2DSize]
303+
dynamic_shared_memory_needed: int | driver.CUoccupancyB2DSize
304304
The amount of dynamic shared memory in bytes needed by block.
305305
Use `0` if block does not need shared memory. Use C-callable
306306
represented by :obj:`~driver.CUoccupancyB2DSize` to encode
@@ -669,13 +669,13 @@ cdef class ObjectCode:
669669

670670
Parameters
671671
----------
672-
module : Union[bytes, str, os.PathLike]
672+
module : bytes | str | os.PathLike
673673
Either a bytes object containing the in-memory cubin to load, or
674674
a file path object (or its string representation) pointing to the
675675
on-disk cubin to load.
676-
name : Optional[str]
676+
name : str | None
677677
A human-readable identifier representing this code object.
678-
symbol_mapping : Optional[dict]
678+
symbol_mapping : dict | None
679679
A dictionary specifying how the unmangled symbol names (as keys)
680680
should be mapped to the mangled names before trying to retrieve
681681
them (default to no mappings).
@@ -688,13 +688,13 @@ cdef class ObjectCode:
688688

689689
Parameters
690690
----------
691-
module : Union[bytes, str, os.PathLike]
691+
module : bytes | str | os.PathLike
692692
Either a bytes object containing the in-memory ptx code to load, or
693693
a file path object (or its string representation) pointing to the
694694
on-disk ptx file to load.
695-
name : Optional[str]
695+
name : str | None
696696
A human-readable identifier representing this code object.
697-
symbol_mapping : Optional[dict]
697+
symbol_mapping : dict | None
698698
A dictionary specifying how the unmangled symbol names (as keys)
699699
should be mapped to the mangled names before trying to retrieve
700700
them (default to no mappings).
@@ -707,13 +707,13 @@ cdef class ObjectCode:
707707

708708
Parameters
709709
----------
710-
module : Union[bytes, str, os.PathLike]
710+
module : bytes | str | os.PathLike
711711
Either a bytes object containing the in-memory ltoir code to load,
712712
or a file path object (or its string representation) pointing to the
713713
on-disk ltoir file to load.
714-
name : Optional[str]
714+
name : str | None
715715
A human-readable identifier representing this code object.
716-
symbol_mapping : Optional[dict]
716+
symbol_mapping : dict | None
717717
A dictionary specifying how the unmangled symbol names (as keys)
718718
should be mapped to the mangled names before trying to retrieve
719719
them (default to no mappings).
@@ -726,13 +726,13 @@ cdef class ObjectCode:
726726

727727
Parameters
728728
----------
729-
module : Union[bytes, str, os.PathLike]
729+
module : bytes | str | os.PathLike
730730
Either a bytes object containing the in-memory fatbin to load, or
731731
or a file path object (or its string representation) pointing to the
732732
on-disk fatbin to load.
733-
name : Optional[str]
733+
name : str | None
734734
A human-readable identifier representing this code object.
735-
symbol_mapping : Optional[dict]
735+
symbol_mapping : dict | None
736736
A dictionary specifying how the unmangled symbol names (as keys)
737737
should be mapped to the mangled names before trying to retrieve
738738
them (default to no mappings).
@@ -745,12 +745,12 @@ cdef class ObjectCode:
745745

746746
Parameters
747747
----------
748-
module : Union[bytes, str]
748+
module : bytes | str
749749
Either a bytes object containing the in-memory object code to load, or
750750
a file path string pointing to the on-disk object code to load.
751-
name : Optional[str]
751+
name : str | None
752752
A human-readable identifier representing this code object.
753-
symbol_mapping : Optional[dict]
753+
symbol_mapping : dict | None
754754
A dictionary specifying how the unmangled symbol names (as keys)
755755
should be mapped to the mangled names before trying to retrieve
756756
them (default to no mappings).
@@ -763,12 +763,12 @@ cdef class ObjectCode:
763763

764764
Parameters
765765
----------
766-
module : Union[bytes, str]
766+
module : bytes | str
767767
Either a bytes object containing the in-memory library to load, or
768768
a file path string pointing to the on-disk library to load.
769-
name : Optional[str]
769+
name : str | None
770770
A human-readable identifier representing this code object.
771-
symbol_mapping : Optional[dict]
771+
symbol_mapping : dict | None
772772
A dictionary specifying how the unmangled symbol names (as keys)
773773
should be mapped to the mangled names before trying to retrieve
774774
them (default to no mappings).

cuda_core/cuda/core/_program.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class ProgramOptions:
166166
Enable device code optimization. When specified along with '-G', enables limited debug information generation
167167
for optimized device code.
168168
Default: None
169-
ptxas_options : Union[str, list[str]], optional
169+
ptxas_options : str | list[str], optional
170170
Specify one or more options directly to ptxas, the PTX optimizing assembler. Options should be strings.
171171
For example ["-v", "-O2"].
172172
Default: None
@@ -200,17 +200,17 @@ class ProgramOptions:
200200
gen_opt_lto : bool, optional
201201
Run the optimizer passes before generating the LTO IR.
202202
Default: False
203-
define_macro : Union[str, tuple[str, str], list[Union[str, tuple[str, str]]]], optional
203+
define_macro : str | tuple[str, str] | list[str | tuple[str, str]], optional
204204
Predefine a macro. Can be either a string, in which case that macro will be set to 1, a 2 element tuple of
205205
strings, in which case the first element is defined as the second, or a list of strings or tuples.
206206
Default: None
207-
undefine_macro : Union[str, list[str]], optional
207+
undefine_macro : str | list[str], optional
208208
Cancel any previous definition of a macro, or list of macros.
209209
Default: None
210-
include_path : Union[str, list[str]], optional
210+
include_path : str | list[str], optional
211211
Add the directory or directories to the list of directories to be searched for headers.
212212
Default: None
213-
pre_include : Union[str, list[str]], optional
213+
pre_include : str | list[str], optional
214214
Preinclude one or more headers during preprocessing. Can be either a string or a list of strings.
215215
Default: None
216216
no_source_include : bool, optional
@@ -243,13 +243,13 @@ class ProgramOptions:
243243
no_display_error_number : bool, optional
244244
Disable the display of a diagnostic number for warning messages.
245245
Default: False
246-
diag_error : Union[int, list[int]], optional
246+
diag_error : int | list[int], optional
247247
Emit error for a specified diagnostic message number or comma-separated list of numbers.
248248
Default: None
249-
diag_suppress : Union[int, list[int]], optional
249+
diag_suppress : int | list[int], optional
250250
Suppress a specified diagnostic message number or comma-separated list of numbers.
251251
Default: None
252-
diag_warn : Union[int, list[int]], optional
252+
diag_warn : int | list[int], optional
253253
Emit warning for a specified diagnostic message number or comma-separated list of numbers.
254254
Default: None
255255
brief_diagnostics : bool, optional

cuda_core/cuda/core/_program.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class ProgramOptions:
319319
Enable device code optimization. When specified along with '-G', enables limited debug information generation
320320
for optimized device code.
321321
Default: None
322-
ptxas_options : Union[str, list[str]], optional
322+
ptxas_options : str | list[str], optional
323323
Specify one or more options directly to ptxas, the PTX optimizing assembler. Options should be strings.
324324
For example ["-v", "-O2"].
325325
Default: None
@@ -353,17 +353,17 @@ class ProgramOptions:
353353
gen_opt_lto : bool, optional
354354
Run the optimizer passes before generating the LTO IR.
355355
Default: False
356-
define_macro : Union[str, tuple[str, str], list[Union[str, tuple[str, str]]]], optional
356+
define_macro : str | tuple[str, str] | list[str | tuple[str, str]], optional
357357
Predefine a macro. Can be either a string, in which case that macro will be set to 1, a 2 element tuple of
358358
strings, in which case the first element is defined as the second, or a list of strings or tuples.
359359
Default: None
360-
undefine_macro : Union[str, list[str]], optional
360+
undefine_macro : str | list[str], optional
361361
Cancel any previous definition of a macro, or list of macros.
362362
Default: None
363-
include_path : Union[str, list[str]], optional
363+
include_path : str | list[str], optional
364364
Add the directory or directories to the list of directories to be searched for headers.
365365
Default: None
366-
pre_include : Union[str, list[str]], optional
366+
pre_include : str | list[str], optional
367367
Preinclude one or more headers during preprocessing. Can be either a string or a list of strings.
368368
Default: None
369369
no_source_include : bool, optional
@@ -396,13 +396,13 @@ class ProgramOptions:
396396
no_display_error_number : bool, optional
397397
Disable the display of a diagnostic number for warning messages.
398398
Default: False
399-
diag_error : Union[int, list[int]], optional
399+
diag_error : int | list[int], optional
400400
Emit error for a specified diagnostic message number or comma-separated list of numbers.
401401
Default: None
402-
diag_suppress : Union[int, list[int]], optional
402+
diag_suppress : int | list[int], optional
403403
Suppress a specified diagnostic message number or comma-separated list of numbers.
404404
Default: None
405-
diag_warn : Union[int, list[int]], optional
405+
diag_warn : int | list[int], optional
406406
Emit warning for a specified diagnostic message number or comma-separated list of numbers.
407407
Default: None
408408
brief_diagnostics : bool, optional

0 commit comments

Comments
 (0)