Title: cuda.core: Replace string literals with enums in public API · Issue #1995 · NVIDIA/cuda-python · GitHub
Open Graph Title: cuda.core: Replace string literals with enums in public API · Issue #1995 · NVIDIA/cuda-python
X Title: cuda.core: Replace string literals with enums in public API · Issue #1995 · NVIDIA/cuda-python
Description: This is just a result of a sweep for using strings where enums could be used. This is just to aid the discussion about whether they should be addressed. Several places in the cuda.core public API accept or return string values chosen fro...
Open Graph Description: This is just a result of a sweep for using strings where enums could be used. This is just to aid the discussion about whether they should be addressed. Several places in the cuda.core public API a...
X Description: This is just a result of a sweep for using strings where enums could be used. This is just to aid the discussion about whether they should be addressed. Several places in the cuda.core public API a...
Opengraph URL: https://github.com/NVIDIA/cuda-python/issues/1995
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"cuda.core: Replace string literals with enums in public API","articleBody":"> This is just a result of a sweep for using strings where enums could be used. This is just to aid the discussion about whether they should be addressed.\n\nSeveral places in the `cuda.core` public API accept or return string values chosen from a small, fixed vocabulary. These are candidates for replacement with proper Python `enum` types, which would improve discoverability, IDE autocompletion, `isinstance` checking, and catch typos at the call site rather than at runtime.\n\n---\n\n## Findings\n\n### Compilation / Linking pipeline\n\n| Location | Kind | Values |\n|---|---|---|\n| `Program.__init__(code_type)` | arg | `\"c++\"`, `\"ptx\"`, `\"nvvm\"` |\n| `Program.compile(target_type)` | arg | `\"ptx\"`, `\"cubin\"`, `\"ltoir\"` |\n| `Program.backend` | return | `\"NVRTC\"`, `\"NVVM\"`, `\"nvJitLink\"`, `\"driver\"` |\n| `Program.pch_status` | return | `\"created\"`, `\"not_attempted\"`, `\"failed\"` |\n| `Linker.link(target_type)` | arg | `\"cubin\"`, `\"ptx\"` |\n| `Linker.backend` | return | `\"nvJitLink\"`, `\"driver\"` |\n| `ObjectCode.code_type` | return | `\"cubin\"`, `\"ptx\"`, `\"ltoir\"`, `\"fatbin\"`, `\"object\"`, `\"library\"` |\n\n### Memory\n\n| Location | Kind | Values |\n|---|---|---|\n| `ManagedMemoryResourceOptions.preferred_location_type` | arg | `\"device\"`, `\"host\"`, `\"host_numa\"` |\n| `ManagedMemoryResource.preferred_location` | return (tuple[0]) | `\"device\"`, `\"host\"`, `\"host_numa\"` |\n| `VirtualMemoryResourceOptions.allocation_type` | arg | `\"pinned\"`, `\"managed\"` |\n| `VirtualMemoryResourceOptions.location_type` | arg | `\"device\"`, `\"host\"`, `\"host_numa\"`, `\"host_numa_current\"` |\n| `VirtualMemoryResourceOptions.handle_type` | arg | `\"posix_fd\"`, `\"generic\"`, `\"win32_kmt\"`, `\"fabric\"` |\n| `VirtualMemoryResourceOptions.granularity` | arg | `\"recommended\"`, `\"minimum\"` |\n| `VirtualMemoryResourceOptions.self_access` / `peer_access` | arg | `\"rw\"`, `\"r\"` |\n\nNote: the `VirtualMemoryResourceOptions` fields already use `Literal[...]` type hints, which partially addresses the issue, but proper enums would still improve iteration, `isinstance` checks, and user discoverability.\n\n### Graph API\n\n| Location | Kind | Values |\n|---|---|---|\n| `GraphAllocOptions.memory_type` | arg | `\"device\"`, `\"host\"`, `\"managed\"` |\n| `AllocNode.memory_type` | return | `\"device\"`, `\"host\"`, `\"managed\"` |\n| `ConditionalNode.cond_type` | return | `\"if\"`, `\"while\"`, `\"switch\"` |\n\n---\n\n## Proposed enum groupings\n\n| Enum name | Values | Consumers |\n|---|---|---|\n| `CodeType` | `cubin`, `ptx`, `ltoir`, `fatbin`, `object`, `library` | `ObjectCode.code_type`, `Linker.link`, `Program.compile` |\n| `SourceType` | `c++`, `ptx`, `nvvm` | `Program.__init__` |\n| `CompilerBackend` | `NVRTC`, `NVVM`, `nvJitLink`, `driver` | `Program.backend`, `Linker.backend` |\n| `PchStatus` | `created`, `not_attempted`, `failed` | `Program.pch_status` |\n| `MemoryType` | `device`, `host`, `managed` | `GraphAllocOptions`, `AllocNode`, `ManagedMemoryResource` |\n| `LocationType` | `device`, `host`, `host_numa`, `host_numa_current` | `VirtualMemoryResourceOptions`, `ManagedMemoryResourceOptions` |\n| `ConditionalType` | `if_`, `while_`, `switch_` | `ConditionalNode.cond_type` |\n| `HandleType` | `posix_fd`, `generic`, `win32_kmt`, `fabric` | `VirtualMemoryResourceOptions` |\n| `Granularity` | `recommended`, `minimum` | `VirtualMemoryResourceOptions` |\n| `AccessMode` | `rw`, `r` | `VirtualMemoryResourceOptions` |\n\n---\n\n## Discussion points\n\n- The compilation/linking pipeline (`Program`, `Linker`, `ObjectCode`) is the highest-impact area since string values flow across multiple API boundaries.\n- Switching from `str` to `enum` would be a breaking change for existing callers. One migration path is to accept both `str` and the enum type during a deprecation window.\n- Some values (`\"c++\"`, `\"if\"`, `\"while\"`) are not valid Python identifiers and would need renaming (e.g. `SourceType.CPP`, `ConditionalType.IF`).","author":{"url":"https://github.com/mdboom","@type":"Person","name":"mdboom"},"datePublished":"2026-04-30T14:09:56Z","url":"https://github.com/NVIDIA/cuda-python/issues/1995"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e0eb2a39-1681-feb3-9cf8-8b173db36122 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83AA:1E4D9D:4F098C:6D4525:6AF8459B |
| html-safe-nonce | 58a0f3c6bf0beff8c754f2bc10791dd20f9e2397e06121a156499f8d7f861a6e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0FBOjFFNEQ5RDo0RjA5OEM6NkQ0NTI1OjZBRjg0NTlCIiwidmlzaXRvcl9pZCI6IjI5MzY1NzU2NzQ0Mzg2NjU2MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0a25c595180d0bae3ff82fa0c0647ef979ef2a4d6c6c4e80e21d4fb9506c1770 |
| hovercard-subject-tag | issue:4358762558 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NVIDIA/cuda-python/1995/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ef6cf87fdaaaae8507374d835018b5d9397bca133b58d2900a941f3f4905f07f/NVIDIA/cuda-python/issues/1995 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ef6cf87fdaaaae8507374d835018b5d9397bca133b58d2900a941f3f4905f07f/NVIDIA/cuda-python/issues/1995 |
| og:image:alt | This is just a result of a sweep for using strings where enums could be used. This is just to aid the discussion about whether they should be addressed. Several places in the cuda.core public API a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mdboom |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5713ecd83001b2f55c3509fb7a292bf7d66d0f167c7ae87a9f7eaec5a52bf8db |
| turbo-cache-control | no-preview |
| go-import | github.com/NVIDIA/cuda-python git https://github.com/NVIDIA/cuda-python.git |
| octolytics-dimension-user_id | 1728152 |
| octolytics-dimension-user_login | NVIDIA |
| octolytics-dimension-repository_id | 381173759 |
| octolytics-dimension-repository_nwo | NVIDIA/cuda-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 381173759 |
| octolytics-dimension-repository_network_root_nwo | NVIDIA/cuda-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 653be32ff5c755082a4db662491bfbbcfc9112c1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width