Repository navigation
feat(llvm-export): support i8/u8/i16/u16/f16/bool in device extern signatures - #412
Merged
nihalpasham merged 3 commits intoJul 22, 2026
Merged
Conversation
honeyspoon
force-pushed
the
add-device-extern-small-types
branch
from
July 20, 2026 13:15
4c425e3 to
bd746b2
Compare
…gnatures Remove the hard errors that reject small types in device extern function signatures and emit proper LLVM signext/zeroext ABI attributes for sub-32-bit integer types. Changes: - rustc-codegen-cuda (device_codegen.rs): replace rejection errors with proper type mapping -- signed types use SignExtInteger(32), unsigned use ZeroExtInteger(32), f16 uses Float16, bool uses ZeroExtInteger(32) - llvm-export (externs.rs): add SignExtInteger(u32) and ZeroExtInteger(u32) variants to DeviceExternType, add write_llvm_with_attr() for attribute emission - llvm-export (module.rs, ops.rs): emit signext/zeroext attributes on both declarations and call sites - cuda-oxide-codegen (lower.rs): handle new variants in device_extern_type_to_pliron() Signed-off-by: abder <[email protected]>
honeyspoon
force-pushed
the
add-device-extern-small-types
branch
from
July 22, 2026 01:16
bd746b2 to
f7ec081
Compare
…vice externs Redo the small-scalar device-extern ABI on top of the previous commit. Widening the declared IR type to i32 mismatched both the clang/nvcc LTOIR definitions the declaration must resolve against at nvJitLink LTO time and cuda-oxide's own narrow i8/i16/i1 SSA values, so every by-value integer/bool extern still failed to compile, just later and with a worse error. Follow the clang NVPTXABIInfo / rustc nvptx64 shape instead: SignExtInteger/ZeroExtInteger store the ORIGINAL width (signed 8/16, unsigned 8/16, bool as zeroext width 1), the declaration keeps the narrow LLVM type, and only the attribute marks the NVPTX .param.b32 widening, so no value conversions are needed anywhere. Also fix return-position attribute placement: LLVM's grammar requires the attribute BEFORE the type there (declare signext i8 @f(), call signext i8 @f()); the previous suffix form did not parse. Parameter position (i8 signext inside the parens) was already correct. The legacy LLVM 7 libNVVM dialect now rejects sub-32-bit by-value externs with a clean diagnostic mirroring the existing half rejection instead of silently emitting unvalidated attributes. Tests assert the canonical strings and add an llvm-as parse gate over an emitted module with small params and a small return in both declare and call positions. Signed-off-by: nihalp <[email protected]>
honeyspoon
force-pushed
the
add-device-extern-small-types
branch
from
July 22, 2026 13:28
e56b4b4 to
79b065a
Compare
nihalpasham
force-pushed
the
add-device-extern-small-types
branch
from
July 22, 2026 15:09
79b065a to
e56b4b4
Compare
Collaborator
|
Thanks for the PR. This is the right direction, the old rejection message itself invited this ("rejected until their signext or zeroext attributes can be emitted"). The ABI shape needed a redo, which I pushed as maintainer commits on top.
For example: Reviewer note: llvm-export, mir-lower, and backend tests pass; the emitted module parses under llvm-as-21; |
… NVVM path Exercise the narrow-type signext/zeroext extern ABI end to end against nvcc-compiled LTOIR: i8/u8/i16/u16/bool/f16 parameters AND returns. The kernel checks sign extension of a negative i8, zero extension of a high-bit u16, small-return round-trips for all four integer widths, bool in both directions, and an f16 add returned as half. Verified on sm_120 through the nvJitLink LTO pipeline. This lives in a new standalone example, small_type_ffi_test, instead of device_ffi_test: CI's examples-compile job builds the ltoir category GPU-less with --emit-nvvm-ir --arch=sm_90, i.e. the legacy CUDA 12 LLVM 7 dialect, whose guards deliberately reject these externs: legacy NVVM IR cannot contain scalar f16 because cuda-oxide supports the CUDA 12 LLVM 7 dialect; use f32/f64 or the modern NVVM/PTX path The test can only ever compile on the modern NVVM path, so smoketest gains an ltoir-modern category that runs it with --emit-nvvm-ir at the host arch on Blackwell+ hosts (CC >= 10.0), where execution must succeed, and compiles it for the sm_100 floor elsewhere, requiring only the NVVM IR plus its .target sidecar. device_ffi_test stays on the legacy-compatible ltoir leg, unchanged. The example's build_ltoir.sh makes the optional nvvm-dis text dump best-effort: an nvvm-dis older than the CUDA toolkit cannot parse newer LTOIR and, under set -e, would abort the build of an otherwise valid binary LTOIR. Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
add-device-extern-small-types
branch
from
July 22, 2026 15:56
e56b4b4 to
9286c6d
Compare
5 tasks done
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.
Summary
Remove the hard errors that reject small types (
i8,u8,i16,u16,f16,bool) in device extern function signatures. Emit proper LLVMsignext/zeroextABI attributes for sub-32-bit integer types, enabling clean FFI boundaries for INT8 and FP16 kernels without pointer indirection.Motivation
Device extern functions currently reject any parameter or return type smaller than 32 bits. This forces users to widen all arguments to
i32/u32on both sides of the FFI boundary, adding unnecessary casting and losing type safety. INT8 quantized inference and FP16 kernels are common use cases that need clean small-type signatures.Implementation
device_codegen.rs): replace rejection errors with proper type mapping -- signed types (i8,i16) map toSignExtInteger(32), unsigned types (u8,u16) map toZeroExtInteger(32),f16maps toFloat16,boolmaps toZeroExtInteger(32)externs.rs): addSignExtInteger(u32)andZeroExtInteger(u32)variants toDeviceExternType, addwrite_llvm_with_attr()for attribute emissionmodule.rs,ops.rs): emitsignext/zeroextattributes on both declarations and call siteslower.rs): handle new variants indevice_extern_type_to_pliron()Testing
Validated on RTX A2000 (sm_86), nightly-2026-04-03: