Skip to content

#[cuda_module] and #[kernel] emit host-only code, so a device-only kernel crate still needs cuda.h #701

Closed

Description

@nh13

What problem does this solve?

#[cuda_module] and #[kernel] emit host-only code into the consumer crate — LoadedModule, load/load_named/from_module, the launch/prepare-launch/constant methods, and the CudaKernel marker impl. All of it names ::cuda_host / ::cuda_core, so a crate that only compiles kernels and never loads or launches anything still has to depend on cuda-host → cuda-core → cuda-bindings → cuda.h. That makes a device-only kernel crate unbuildable anywhere without a CUDA toolkit, including on a developer machine doing a type-check.

Proposed API / behavior

[dependencies]
cuda-device = "0.2"
cuda-macros = { version = "0.2", default-features = false }  # no `host`
#[kernel]
pub fn scale(out: *mut f32, n: usize) { /* ... */ }   // compiles with no cuda-host in the tree

Alternatives considered

Adding cuda-host purely to satisfy the expansion, which is what we do today; it pulls bindgen and a cuda.h requirement into a crate that emits no host code. Splitting the kernels into a crate that avoids #[cuda_module] doesn't help, because bare #[kernel] emits impl cuda_host::CudaKernel too.

Additional context

The async feature in cuda-macros/src/lib.rs already gates emitted host items the same way, so there is an in-file precedent for the shape.

Activity

  1. added
    enhancement
    host-apis
    build-related
    on Aug 8, 2026
  2. vyncint commented on Aug 12, 2026

    @vyncint
    Contributor

    This appears to be resolved by #702, which put the generated host surface behind a default-on host feature — the exact shape proposed here.

    Verified on 15fa9d9d with a throwaway crate outside the repo, taking the dependency lines from this issue verbatim:

    [dependencies]
    cuda-device = { path = ".../crates/cuda-device" }
    cuda-macros = { path = ".../crates/cuda-macros", default-features = false }
    #![no_std]
    use cuda_device::{DisjointSlice, kernel, thread};
    
    #[kernel]
    pub fn scale(input: &[f32], mut out: DisjointSlice<f32>) {
        let idx = thread::index_1d();
        let i = idx.get();
        if let Some(o) = out.get_mut(idx) { *o = input[i] * 2.0; }
    }

    Both halves of the ask hold:

    • No host crates in the graph. cargo metadata resolves 8 packages — cuda-device, cuda-macros, reserved-oxide-symbols, proc-macro2, quote, syn, unicode-ident, and the crate itself. cuda-host, cuda-core and cuda-bindings are absent, so there is no cuda.h requirement to inherit.
    • It type-checks with no CUDA toolkit. cargo check succeeds with CUDA_HOME, CUDA_TOOLKIT_PATH and LIBRARY_PATH all unset. (It needs the pinned nightly from rust-toolchain.toml, since cuda-macros uses proc_macro_def_site — unrelated to this issue.)

    The manifest comment added by #702 also documents the mixed-graph trap this shape carries: proc-macro features unify per build graph, so a device-only crate consumed by a host application has to forward the feature itself (host = ["dep:cuda-host", "cuda-macros/host"]) or the expansion emits cuda_host:: paths it cannot resolve.

    One gap worth noting, which is why I am commenting rather than just asking you to close: nothing in the tree exercises the device-only configuration. No example or CI leg builds with default-features = false, and the failure mode above is exactly the kind that returns quietly. Happy to add a fixture crate plus a guard script wired into check-guards / status-guard.yml if you want that; it needs no GPU and no toolkit, which is the point.

  3. added a commit that references this issue on Aug 13, 2026
  4. nihalpasham commented on Aug 13, 2026

    @nihalpasham
    Collaborator

    Closing: the behavior this asked for landed in #702 (device-only kernel crates build with --no-default-features, no cuda.h needed), and the one item left in this thread was coverage, which #844 adds:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    build-relatedenhancementhost-apis

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions