Skip to content

Commit 80dc3ec

Browse files
committed
accept dict in public APIs' type hints for options
Widen the type annotations for option/config parameters that already accept a dict at runtime (via check_or_create_options).
1 parent 6177de4 commit 80dc3ec

13 files changed

Lines changed: 19 additions & 17 deletions

‎cuda_core/cuda/core/_device.pyi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ class Device:
798798
799799
"""
800800

801-
def create_context(self, options: ContextOptions | None=None) -> Context:
801+
def create_context(self, options: ContextOptions | dict[str, object] | None=None) -> Context:
802802
"""Create a new :obj:`~_context.Context` object.
803803
804804
Note
@@ -846,7 +846,7 @@ class Device:
846846
847847
"""
848848

849-
def create_event(self, options: EventOptions | None=None) -> Event:
849+
def create_event(self, options: EventOptions | dict[str, object] | None=None) -> Event:
850850
"""Create an :obj:`~_event.Event` object without recording it to a :obj:`~_stream.Stream`.
851851
852852
Note

‎cuda_core/cuda/core/_device.pyx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ class Device:
12831283
self._has_inited = True
12841284
self._context = Context._from_handle(Context, h_context, self._device_id) # Store owning context
12851285

1286-
def create_context(self, options: ContextOptions | None = None) -> Context:
1286+
def create_context(self, options: ContextOptions | dict[str, object] | None = None) -> Context:
12871287
"""Create a new :obj:`~_context.Context` object.
12881288

12891289
Note
@@ -1381,7 +1381,7 @@ class Device:
13811381
self._check_context_initialized()
13821382
return Stream._init(obj=obj, options=options, device_id=self._device_id, ctx=self._context)
13831383

1384-
def create_event(self, options: EventOptions | None = None) -> Event:
1384+
def create_event(self, options: EventOptions | dict[str, object] | None = None) -> Event:
13851385
"""Create an :obj:`~_event.Event` object without recording it to a :obj:`~_stream.Stream`.
13861386

13871387
Note

‎cuda_core/cuda/core/_device_resources.pyi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class SMResource:
8080
def flags(self) -> int:
8181
"""Raw flags from the underlying SM resource."""
8282

83-
def split(self, options: SMResourceOptions, *, dry_run: bool=False) -> tuple[list[SMResource], SMResource]:
83+
def split(self, options: SMResourceOptions | dict[str, object], *, dry_run: bool=False) -> tuple[list[SMResource], SMResource]:
8484
"""Split this SM resource into groups and a remainder.
8585
8686
Parameters
@@ -114,7 +114,7 @@ class WorkqueueResource:
114114
def handle(self) -> int:
115115
"""Return the address of the underlying config ``CUdevResource`` struct."""
116116

117-
def configure(self, options: WorkqueueResourceOptions) -> None:
117+
def configure(self, options: WorkqueueResourceOptions | dict[str, object]) -> None:
118118
"""Configure the workqueue resource in place.
119119
120120
Parameters

‎cuda_core/cuda/core/_device_resources.pyx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ cdef class SMResource:
473473

474474
def split(
475475
self,
476-
options: SMResourceOptions,
476+
options: SMResourceOptions | dict[str, object],
477477
*,
478478
bint dry_run=False
479479
) -> tuple[list[SMResource], SMResource]:
@@ -534,7 +534,7 @@ cdef class WorkqueueResource:
534534
"""Return the address of the underlying config ``CUdevResource`` struct."""
535535
return <intptr_t>(&self._wq_config_resource)
536536

537-
def configure(self, options: WorkqueueResourceOptions) -> None:
537+
def configure(self, options: WorkqueueResourceOptions | dict[str, object]) -> None:
538538
"""Configure the workqueue resource in place.
539539

540540
Parameters

‎cuda_core/cuda/core/_launcher.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from cuda.core.graph import GraphBuilder
99
from cuda.core.typing import IsStreamType
1010

1111

12-
def launch(stream: Stream | GraphBuilder | IsStreamType, config: LaunchConfig, kernel: Kernel, *kernel_args) -> None:
12+
def launch(stream: Stream | GraphBuilder | IsStreamType, config: LaunchConfig | dict[str, object], kernel: Kernel, *kernel_args) -> None:
1313
"""Launches a :obj:`~_module.Kernel`
1414
object with launch-time configuration.
1515

‎cuda_core/cuda/core/_launcher.pyx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if TYPE_CHECKING:
2727

2828
def launch(
2929
stream: Stream | GraphBuilder | IsStreamType,
30-
config: LaunchConfig,
30+
config: LaunchConfig | dict[str, object],
3131
kernel: Kernel,
3232
*kernel_args
3333
) -> None:

‎cuda_core/cuda/core/_linker.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Linker:
3232
Options for the linker. If not provided, default options will be used.
3333
"""
3434

35-
def __init__(self, options: LinkerOptions | None=None, *object_codes: ObjectCode):
35+
def __init__(self, options: LinkerOptions | dict[str, object] | None=None, *object_codes: ObjectCode):
3636
...
3737

3838
def link(self, target_type: ObjectCodeFormatType | str) -> ObjectCode:

‎cuda_core/cuda/core/_linker.pyx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ cdef class Linker:
7878
Options for the linker. If not provided, default options will be used.
7979
"""
8080

81-
def __init__(self, *object_codes: ObjectCode, options: LinkerOptions | None = None):
81+
def __init__(self, *object_codes: ObjectCode, options: LinkerOptions | dict[str, object] | None = None):
8282
Linker_init(self, object_codes, options)
8383

8484
def link(self, target_type: ObjectCodeFormatType | str) -> ObjectCode:

‎cuda_core/cuda/core/_memory/_virtual_memory_resource.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ class VirtualMemoryResource(MemoryResource):
165165
in cuda.core should already meet the common needs.
166166
"""
167167

168-
def __init__(self, device_id: Device | int, config: VirtualMemoryResourceOptions | None = None) -> None:
168+
def __init__(
169+
self, device_id: Device | int, config: VirtualMemoryResourceOptions | dict[str, object] | None = None
170+
) -> None:
169171
self.device: Device | None = Device(device_id)
170172
self.config: VirtualMemoryResourceOptions = check_or_create_options( # type: ignore[assignment]
171173
VirtualMemoryResourceOptions, config, "VirtualMemoryResource options", keep_none=False

‎cuda_core/cuda/core/_program.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Program:
3636
Options to customize the compilation process.
3737
"""
3838

39-
def __init__(self, code: str | bytes | bytearray, code_type: SourceCodeType | str, options: ProgramOptions | None=None):
39+
def __init__(self, code: str | bytes | bytearray, code_type: SourceCodeType | str, options: ProgramOptions | dict[str, object] | None=None):
4040
...
4141

4242
def close(self) -> None:

0 commit comments

Comments
 (0)