Repository navigation
fix: standardize non-negative enum types for windows msvc - #1473
Merged
Merged
Conversation
temotskipa
requested review from
elibol,
kkraus14,
nihalpasham and
rparolin
as code owners
October 10, 2026 14:05
2 of 4 tasks
6 tasks done
## Summary Standardizes non-negative CUDA enums generated in `cuda-bindings/build.rs` to `::core::ffi::c_uint` (`u32`) across all platforms, enabling native compilation and execution on Windows MSVC. Also fixes minor Windows-specific test runner paths. ## Root Cause On Windows MSVC (`x86_64-pc-windows-msvc`), Clang adheres to the MSVC ABI where unscoped C enums default to signed `c_int` (`i32`). On Linux (System V AMD64 ABI), Clang maps enums with only non-negative values to `c_uint` (`u32`). Because `cuda-core` (notably in `src/simt/`) directly consumes these enum constants (`CUstream_flags_enum`, `CUlaunchAttributeID_enum`, `CUctx_flags_enum`, `CUevent_flags_enum`, `CUevent_wait_flags_enum`, `cudaError_enum`, etc.) in APIs expecting `u32` without explicit type casts, building on Windows MSVC previously failed with 18 type-mismatch compilation errors (`expected u32, found i32`). Previous PR NVlabs/cutile-rs#204 had patched a subset of calls in `cudarc_shim.rs`, but subsequent additions in `simt/` re-introduced the issue for uncast enum constants. Standardizing non-negative enums at the `cuda-bindings` generation level resolves the issue across the entire crate workspace without requiring ad-hoc casts across downstream crates. ## Changes 1. **`cuda-bindings/build.rs`**: Post-process generated `types.rs` to map non-negative CUDA enums (`CUstream_flags_enum`, `CUlaunchAttributeID_enum`, `CUctx_flags_enum`, `CUevent_flags_enum`, `CUevent_wait_flags_enum`, `cudaError_enum`, `CUdevice_attribute_enum`, `CUfunction_attribute_enum`, `CUjit_option_enum`) to `::core::ffi::c_uint`. Enums with negative values (e.g., `CUshared_carveout_enum` with `-1`) remain signed. 2. **`cutile-compiler/src/cuda_tile_runtime_utils.rs`**: Use `tileiras_executable_name()` instead of hardcoded `"tileiras"` in path resolution tests. 3. **`cutile-ir/tests/bytecode_validate.rs`**: Output to `NUL` instead of `/dev/null` on Windows when running `tileiras`. 4. **`cutile-ir/tests/requirements.rs`**: Normalize CRLF line endings when validating documented requirement matrices. ## Validation - **Native Windows (MSVC) Build:** Entire workspace (`cuda-bindings`, `cuda-core`, `cuda-async`, `cutile-compiler`, `cutile-macro`, `cutile-ir`, `cutile`, `cutile-kernels`, `cutile-examples`) compiles with 0 errors. - **Unit Tests:** - `cargo test -p cutile-ir` (all 63 unit tests, 2 determinism tests, 22 bytecode validation tests, 10 version tests, 89 per-op roundtrip tests pass) - `cargo test -p cutile-compiler --lib` (all 132 tests pass) - `cargo test -p cuda-core --lib` (all 45 tests pass) - **Formatting & Clippy:** `cargo fmt --all -- --check` and `cargo clippy --all-targets` pass. - **GPU Execution:** Ran `cargo run -p cutile-examples --example saxpy` on native Windows with NVIDIA GeForce RTX 4070 Ti and CUDA Toolkit 13.3; kernel JIT-compiled through native `tileiras.exe` and executed successfully with verified outputs. Signed-off-by: Temo Tskipuri <[email protected]>
nihalpasham
force-pushed
the
fix/windows-msvc-enums
branch
from
November 11, 2026 12:33
0136ab4 to
b401a52
Compare
nihalpasham
added a commit
that referenced
this pull request
Nov 11, 2026
## Summary Adds native Windows (`x86_64-pc-windows-msvc`) support for `cuda-oxide` across the artifact writer, CUDA Toolkit discovery, `cargo-oxide` backend build and runtime loader paths, and smoke test infrastructure (pairs with #1473 for shared `cuda-bindings` enum signedness; closes #139): - **`oxide-artifacts` and `rustc-codegen-cuda`**: - Emits COFF `.oxart` relocatable object sections (`IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ`) for `x86_64-pc-windows-msvc` and `aarch64-pc-windows-msvc` alongside Linux ELF. - Uses `.obj` object extensions on Windows host targets in `rustc-codegen-cuda` and patches the isolated backend workspace to consume the in-tree COFF writer while keeping host runtimes on the crates.io release. - **`cuda-toolkit-discovery`, `libnvvm-sys`, `nvjitlink-sys`, and `cuda-artifact-finalizer`**: - Adds workspace-private `cuda-toolkit-discovery` for Linux and Windows CUDA Toolkit roots (`CUDA_TOOLKIT_PATH`, `CUDA_HOME`, `CUDA_PATH`, `CUDA_PATH_V*`, and `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v*`) and versioned `nvvm64_*.dll` / `nvJitLink_*.dll` discovery. - Handles Windows file identities, path separators, executable suffixes, and CRLF normalization in `cuda-host`, `cuda-oxide-codegen`, and `cuda-intrinsics-gen`. - **`cargo-oxide` and `cuda-macros`**: - Adds target-aware dylib/executable/loader helpers (`platform.rs`), builds `rustc_codegen_cuda.dll` in `--release` with `lld-link` and `ffi.lib` lookup on Windows MSVC, and fixes `cargo oxide doctor` `llc.exe` detection on Windows. - Emits a COFF `/alternatename` fallback stub on Windows MSVC in `#[device] extern "C"` blocks so host binaries do not fail to link device-only LTOIR extern symbols. - **Smoke tests and documentation**: - Updates `scripts/smoketest.sh` to support Windows under Git Bash (`pwd -W`, `ptxas -o NUL`, and `release/rustc_codegen_cuda.dll` backend pinning), adds `scripts/smoketest.ps1`, and adds the Windows setup guide in `cuda-oxide-book/getting-started/windows.md`. ## Test plan - [x] `just -f cuda-oxide/Justfile fmt-check` - [x] `just -f cuda-oxide/Justfile check-guards` - [x] `just -f cuda-oxide/Justfile clippy` - [x] `cargo test -p oxide-artifacts --features object` - [x] `cargo test -p cuda-toolkit-discovery -p libnvvm-sys -p nvjitlink-sys -p cuda-artifact-finalizer -p cargo-oxide` - [x] Validated on Windows 11 24H2 (`x86_64-pc-windows-msvc`, Blackwell `sm_120a`): `cargo oxide setup`, `cargo oxide doctor`, `scripts/smoketest.ps1`, `bash scripts/smoketest.sh`, and `cargo oxide sanitize vecadd --arch sm_120a` --------- Signed-off-by: ansidium <[email protected]> Signed-off-by: nihalpasham <[email protected]> Co-authored-by: ansidium <[email protected]>
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Transplanted from
NVlabs/cutile-rs#318ontoNVIDIA/cuda-rustmain(closes #1441) and pairs with #1770 to complete native Windows (x86_64-pc-windows-msvc) support.Overview
On Linux (
x86_64-unknown-linux-gnu), Clang maps unscoped C enums whose enumerators are all non-negative to unsignedc_uint(u32). On Windows MSVC (x86_64-pc-windows-msvc), the MSVC C ABI defaults all unscoped C enums to signedc_int(i32), causing 18 type-mismatch errors (expected u32, found i32) when compilingcuda-core:Standardizing the 9 non-negative CUDA driver enums to
::core::ffi::c_uint(u32) incuda-bindings/build.rsresolves the mismatch once at the binding generation boundary without scattering platform casts acrosscuda-coreor downstream crates. Enums with negative values (such asCUshared_carveout_enumwith-1) remain signedc_int.Changes
cuda-bindings/build.rsc_intto::core::ffi::c_uintcutile-rs/cutile-compiler/src/cuda_tile_runtime_utils.rstileiras_executable_name()(tileiras.exeon Windows) in path testscutile-rs/cutile-ir/tests/bytecode_validate.rstileirasvalidation output toNULinstead of/dev/nullon Win32cutile-rs/cutile-ir/tests/requirements.rs\r\nline endings before comparing requirement tablesStandardized Enums (
cuda-bindings/build.rs)CUstream_flags_enumCUlaunchAttributeID_enumCUctx_flags_enumCUevent_flags_enumCUevent_wait_flags_enumcudaError_enumCUdevice_attribute_enumCUfunction_attribute_enumCUjit_option_enumValidation
cargo check --workspace --all-targets(root host workspace on Windows 11 24H2x86_64-pc-windows-msvc)cargo test -p cuda-core --lib(49 / 49 passed on Windows Blackwellsm_120a)cargo test -p cutile-compiler --lib(132 / 132 passed on Windows)cargo test -p cutile-ir(all unit, determinism, bytecode validation, and roundtrip suites passed on Windows)cuda-oxideWindows smoke suite (scripts/smoketest.sh: 257 / 257 examples passed on Windows Blackwellsm_120awith feat(cuda-oxide): add Windows x86_64 MSVC support #1770)