Skip to content

Commit fa254a5

Browse files
leofangclaude
andcommitted
Polish green context API: docs, error handling, simplification
- dev.create_context raises ValueError (not NotImplementedError) when options or resources are missing. - Cache version checks (_check_green_ctx_support, _check_workqueue_support) at module level; raise ValueError instead of NotImplementedError. - Simplify _device_resources.pyx: merge _as_uint and _count_to_sm_count into _to_sm_count; inline unsigned int casts for coscheduled params. - Add green context classes to api.rst (Context, ContextOptions, DeviceResources, SMResource, SMResourceOptions, WorkqueueResource, WorkqueueResourceOptions). - Update all docstrings to NumPy style with Attributes/Parameters/Returns sections matching the existing codebase convention. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 340506e commit fa254a5

6 files changed

Lines changed: 171 additions & 94 deletions

File tree

cuda_core/cuda/core/_context.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ cdef class ContextOptions:
149149
150150
Attributes
151151
----------
152-
resources : :obj:`~_context.DeviceResourcesT`
152+
resources : :obj:`~cuda.core.typing.DeviceResourcesT`
153153
Device resources used to create a green context.
154154
"""
155155
resources: DeviceResourcesT

cuda_core/cuda/core/_device.pyx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,11 +1302,15 @@ class Device:
13021302
cdef GreenCtxHandle h_green
13031303

13041304
if options is None:
1305-
raise NotImplementedError("WIP: https://github.com/NVIDIA/cuda-python/issues/189")
1305+
raise ValueError(
1306+
"options with device resources must be provided to create a green context"
1307+
)
13061308

13071309
options = check_or_create_options(ContextOptions, options, "Context options")
13081310
if options.resources is None:
1309-
raise NotImplementedError("WIP: https://github.com/NVIDIA/cuda-python/issues/189")
1311+
raise ValueError(
1312+
"ContextOptions.resources must be provided to create a green context"
1313+
)
13101314

13111315
resources = tuple(options.resources)
13121316
if len(resources) == 0:
@@ -1334,9 +1338,9 @@ class Device:
13341338

13351339
h_green = create_green_ctx_handle(
13361340
c_resources,
1337-
<unsigned int>n_resources,
1338-
<cydriver.CUdevice>self._device_id,
1339-
<unsigned int>cydriver.CUgreenCtxCreate_flags.CU_GREEN_CTX_DEFAULT_STREAM,
1341+
<unsigned int>(n_resources),
1342+
<cydriver.CUdevice>(self._device_id),
1343+
<unsigned int>(cydriver.CUgreenCtxCreate_flags.CU_GREEN_CTX_DEFAULT_STREAM),
13401344
)
13411345
if h_green.get() == NULL:
13421346
HANDLE_RETURN(get_last_error())

0 commit comments

Comments
 (0)