Skip to content

fix: standardize non-negative enum types for windows msvc - #1473

Merged
elibol merged 1 commit into
NVIDIA:mainfrom
temotskipa:fix/windows-msvc-enums
Nov 11, 2026
Merged

elibol merged 1 commit into
NVIDIA:mainfrom
temotskipa:fix/windows-msvc-enums

Conversation

@temotskipa

@temotskipa temotskipa commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Transplanted from NVlabs/cutile-rs#318 onto NVIDIA/cuda-rust main (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 unsigned c_uint (u32). On Windows MSVC (x86_64-pc-windows-msvc), the MSVC C ABI defaults all unscoped C enums to signed c_int (i32), causing 18 type-mismatch errors (expected u32, found i32) when compiling cuda-core:

CUDA C Header (`cuda.h`)
  enum CUstream_flags_enum { CU_STREAM_DEFAULT = 0x0, ... };
        │
        ├──► Linux SysV ABI (Clang / bindgen)
        │      pub type CUstream_flags_enum = c_uint; (u32) ──► matches cuda-core u32 APIs
        │
        └──► Windows MSVC ABI (Clang / bindgen)
               Before: pub type CUstream_flags_enum = c_int;  (i32) ──► 18 type-mismatch errors in cuda-core
               After:  pub type CUstream_flags_enum = c_uint; (u32) ──► matches Linux & cuda-core u32 APIs

Standardizing the 9 non-negative CUDA driver enums to ::core::ffi::c_uint (u32) in cuda-bindings/build.rs resolves the mismatch once at the binding generation boundary without scattering platform casts across cuda-core or downstream crates. Enums with negative values (such as CUshared_carveout_enum with -1) remain signed c_int.

Changes

File Change
cuda-bindings/build.rs Maps 9 non-negative CUDA driver enums from c_int to ::core::ffi::c_uint
cutile-rs/cutile-compiler/src/cuda_tile_runtime_utils.rs Uses tileiras_executable_name() (tileiras.exe on Windows) in path tests
cutile-rs/cutile-ir/tests/bytecode_validate.rs Writes tileiras validation output to NUL instead of /dev/null on Win32
cutile-rs/cutile-ir/tests/requirements.rs Normalizes \r\n line endings before comparing requirement tables

Standardized Enums (cuda-bindings/build.rs)

  • 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

Validation

  • cargo check --workspace --all-targets (root host workspace on Windows 11 24H2 x86_64-pc-windows-msvc)
  • cargo test -p cuda-core --lib (49 / 49 passed on Windows Blackwell sm_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)
  • End-to-end cuda-oxide Windows smoke suite (scripts/smoketest.sh: 257 / 257 examples passed on Windows Blackwell sm_120a with feat(cuda-oxide): add Windows x86_64 MSVC support #1770)

@copy-pr-bot

copy-pr-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

## 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
nihalpasham force-pushed the fix/windows-msvc-enums branch from 0136ab4 to b401a52 Compare November 11, 2026 12:33
@nihalpasham nihalpasham added runtime Shared runtime crates: cuda-bindings, cuda-core, cuda-core-derive, cuda-async; Tile and SIMT co-own cuda-bindings Raw FFI bindings to the CUDA driver/runtime cutile-rs Tile programming model: cutile crates, compiler, macros, IR, kernels, and book platform-support OS / target platform support (Windows, macOS, non-Linux toolchains) windows Windows (x86_64-pc-windows-msvc) platform and toolchain support labels Nov 11, 2026
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]>
@nihalpasham

Copy link
Copy Markdown
Collaborator

@elibol could you please review and merge this? It's the last host-crate piece needed for Windows MSVC support (#1770).

@elibol elibol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@elibol
elibol merged commit d9430b0 into NVIDIA:main Nov 11, 2026
@temotskipa
temotskipa deleted the fix/windows-msvc-enums branch November 15, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda-bindings Raw FFI bindings to the CUDA driver/runtime cutile-rs Tile programming model: cutile crates, compiler, macros, IR, kernels, and book platform-support OS / target platform support (Windows, macOS, non-Linux toolchains) runtime Shared runtime crates: cuda-bindings, cuda-core, cuda-core-derive, cuda-async; Tile and SIMT co-own windows Windows (x86_64-pc-windows-msvc) platform and toolchain support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: standardize non-negative enum types for windows msvc

3 participants