Title: Non-externed Cython type definitions cause redefinition errors with transitive header includes · Issue #1663 · NVIDIA/cuda-python · GitHub
Open Graph Title: Non-externed Cython type definitions cause redefinition errors with transitive header includes · Issue #1663 · NVIDIA/cuda-python
X Title: Non-externed Cython type definitions cause redefinition errors with transitive header includes · Issue #1663 · NVIDIA/cuda-python
Description: Summary Several cuda.bindings Cython interfaces (cynvvm, cynvml, cynvjitlink, cynvfatbin) define types using Cython's quoted C name syntax without cdef extern from blocks. This causes C compilation errors when a user cimports these types...
Open Graph Description: Summary Several cuda.bindings Cython interfaces (cynvvm, cynvml, cynvjitlink, cynvfatbin) define types using Cython's quoted C name syntax without cdef extern from blocks. This causes C compilation...
X Description: Summary Several cuda.bindings Cython interfaces (cynvvm, cynvml, cynvjitlink, cynvfatbin) define types using Cython's quoted C name syntax without cdef extern from blocks. This causes C compila...
Opengraph URL: https://github.com/NVIDIA/cuda-python/issues/1663
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Non-externed Cython type definitions cause redefinition errors with transitive header includes","articleBody":"## Summary\n\nSeveral `cuda.bindings` Cython interfaces (`cynvvm`, `cynvml`, `cynvjitlink`, `cynvfatbin`) define types using Cython's quoted C name syntax without `cdef extern from` blocks. This causes C compilation errors when a user `cimport`s these types in a module that also transitively includes the corresponding C header.\n\n## Problem\n\nThe externed interfaces (`cynvrtc`, `cydriver`, `cyruntime`) use `cdef extern from \"header.h\"` blocks, so Cython emits a `#include` directive and the header's include guards prevent duplicate definitions.\n\nThe non-externed interfaces instead define types inline:\n\n```cython\n# cynvvm.pxd (current)\nctypedef enum nvvmResult \"nvvmResult\":\n NVVM_SUCCESS \"NVVM_SUCCESS\" = 0\n NVVM_ERROR_OUT_OF_MEMORY \"NVVM_ERROR_OUT_OF_MEMORY\" = 1\n ...\n```\n\nWhen Cython compiles a `.pyx` that `cimport`s these types, it generates its own enum/typedef definitions in the C output. If any `cdef extern from` block in the same module (directly or via its `.pxd`) includes a header that transitively includes `nvvm.h`, the C compiler sees duplicate enum constant definitions and fails.\n\n## Minimal Reproducer\n\n**`nvvm.h`** (or the real one from the CUDA Toolkit):\n```c\n#ifndef NVVM_H\n#define NVVM_H\n\ntypedef enum {\n NVVM_SUCCESS = 0,\n NVVM_ERROR_OUT_OF_MEMORY = 1,\n NVVM_ERROR_PROGRAM_CREATION_FAILURE = 2,\n NVVM_ERROR_INVALID_INPUT = 4,\n NVVM_ERROR_INVALID_PROGRAM = 5,\n} nvvmResult;\n\ntypedef void *nvvmProgram;\n\n#endif\n```\n\n**`example.h`** — a user header that happens to transitively include `nvvm.h`:\n```c\n#ifndef EXAMPLE_H\n#define EXAMPLE_H\n\n#include \"nvvm.h\"\n\nint test_func(int a);\n\n#endif\n```\n\n**`example.pxd`** — declares the user's C function:\n```cython\ncdef extern from \"example.h\":\n int test_func(int a)\n```\n\n**`example.pyx`** — cimports the nvvm types from cuda.bindings:\n```cython\nfrom cuda.bindings.cynvvm cimport nvvmResult\n\ndef call_test(int x):\n return test_func(x)\n```\n\n### Build Output\n\n```\nexample.c:1541:3: error: redeclaration of enumerator 'NVVM_SUCCESS'\n 1541 | NVVM_SUCCESS = 0,\n | ^~~~~~~~~~~~\nIn file included from example.h:4,\n from example.c:1138:\nnvvm.h:5:5: note: previous definition of 'NVVM_SUCCESS' with type 'enum \u003canonymous>'\n 5 | NVVM_SUCCESS = 0,\n | ^~~~~~~~~~~~\nexample.c:1542:3: error: redeclaration of enumerator 'NVVM_ERROR_OUT_OF_MEMORY'\n...\nexample.c:1547:25: error: conflicting types for 'nvvmResult'; have 'enum nvvmResult'\n```\n\nThe generated C file first emits `#include \"example.h\"` (which transitively includes `nvvm.h`), then later emits Cython's own `enum nvvmResult { NVVM_SUCCESS = 0, ... }` from the `cimport`. The duplicate enum constants are a hard C compilation error.\n\n## Impact\n\nAny downstream Cython project that wants to:\n1. Use types from `cynvvm`, `cynvml`, `cynvjitlink`, or `cynvfatbin` via `cimport`, **and**\n2. Has any `cdef extern from` that transitively includes the corresponding C header\n\n...will fail to compile. The user doesn't need to redeclare any types themselves — the mere transitive include is sufficient.\n\nThis does **not** affect the externed interfaces (`cynvrtc`, `cydriver`, `cyruntime`) since they use `cdef extern from`, which emits `#include` directives that are deduplicated by include guards.\n\n## Affected Interfaces\n\n| Interface | Style | Affected |\n|-----------|-------|----------|\n| `cynvvm.pxd` | Non-externed (quoted names) | Yes |\n| `cynvml.pxd` | Non-externed (quoted names) | Yes |\n| `cynvjitlink.pxd` | Non-externed (quoted names) | Yes |\n| `cynvfatbin.pxd` | Non-externed (quoted names) | Yes |\n| `cynvrtc.pxd` | `cdef extern from \"nvrtc.h\"` | No |\n| `cydriver.pxd` | `cdef extern from \"cuda.h\"` | No |\n| `cyruntime.pxd` | `cdef extern from \"driver_types.h\"` | No |\n\n## Suggested Fix\n\nSwitch the non-externed interfaces to use `cdef extern from` blocks, consistent with `cynvrtc.pxd`, `cydriver.pxd`, and `cyruntime.pxd`. This causes Cython to emit `#include` directives instead of generating its own type definitions, allowing include guards to deduplicate.\n\n**Edit:** On further analysis, this is **not** believed to be an ABI break. The `.pxd` file is purely a compile-time artifact — it is not referenced at runtime by already-compiled extensions. Since the quoted C names already produce the exact same C type identifiers and enum constant values as the header, the generated machine code is identical regardless of declaration style. Already-compiled downstream extensions would continue to work without recompilation against an updated `cuda.bindings` that makes this change.\n","author":{"url":"https://github.com/kkraus14","@type":"Person","name":"kkraus14"},"datePublished":"2026-02-19T22:57:24Z","url":"https://github.com/NVIDIA/cuda-python/issues/1663"}
| 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:dca676d1-d918-b25b-121a-de3c22058a0a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9178:39CFE8:6B153C:8C76AB:6AF83D22 |
| html-safe-nonce | 1b22d9b39ba00b659af5234b082158872eb5a39979af8fb3cfccd3a194403343 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTc4OjM5Q0ZFODo2QjE1M0M6OEM3NkFCOjZBRjgzRDIyIiwidmlzaXRvcl9pZCI6IjgzNjQ3OTIwNjg4MzU5MTcwOTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9ae3f2a91120c303adc1c8274127cc6118a8daa5993989c86e21aca47dc2d176 |
| hovercard-subject-tag | issue:3965570566 |
| 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/1663/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b70c08dc5087f8b7409df7da669538dd576af6a974eb65852511c7557cf1b136/NVIDIA/cuda-python/issues/1663 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b70c08dc5087f8b7409df7da669538dd576af6a974eb65852511c7557cf1b136/NVIDIA/cuda-python/issues/1663 |
| og:image:alt | Summary Several cuda.bindings Cython interfaces (cynvvm, cynvml, cynvjitlink, cynvfatbin) define types using Cython's quoted C name syntax without cdef extern from blocks. This causes C compilation... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kkraus14 |
| 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