Closed
Description
I tried this code (compiling with rustc +nightly main_rs.rs --target nvptx64-nvidia-cuda --crate-type=cdylib --emit=asm
):
#![feature(abi_ptx)]
#![no_std]
#[panic_handler]
unsafe fn breakpoint_panic_handler(_: &::core::panic::PanicInfo) -> ! {
loop {}
core::hint::unreachable_unchecked();
}
#[derive(Clone, Copy)]
pub struct Foo {
a: u8,
b: u8,
c: u8,
}
#[inline(never)]
fn device(v: u8) -> Foo {
Foo {
a: v,
b: v,
c: v,
}
}
#[no_mangle]
pub unsafe extern "ptx-kernel" fn kernel(input: *const u8, output: *mut Foo) {
*output = device(input.read());
}
I expected to see this happen: A well formed .ptx file
Instead, this happened: The following error (from ptx linker)
LLVM ERROR: Cannot select: 0x7f8743a820d0: ch = NVPTXISD::StoreRetval<(store (s24), align 1)> 0x7f8743a82410, Constant:i32<0>, 0x7f8743a827b8
0x7f8743a822d8: i32 = Constant<0>
0x7f8743a827b8: i32 = or 0x7f8743a82a28, 0x7f8743a829c0
0x7f8743a82a28: i32 = or 0x7f8743a82000, 0x7f8743a824e0
0x7f8743a82000: i32 = shl 0x7f8743a82340, Constant:i32<8>
0x7f8743a82340: i32,ch = load<(dereferenceable load (s8) from %ir.6 + 1), zext from i8> 0x7f8743a82618, 0x7f8743a82820, undef:i64
0x7f8743a82820: i64 = or FrameIndex:i64<0>, Constant:i64<1>
0x7f8743a82c98: i64 = FrameIndex<0>
0x7f8743a82a90: i64 = Constant<1>
0x7f8743a823a8: i64 = undef
0x7f8743a826e8: i32 = Constant<8>
0x7f8743a824e0: i32,ch = load<(dereferenceable load (s8) from %ir.6), zext from i8> 0x7f8743a82618, FrameIndex:i64<0>, undef:i64
0x7f8743a82c98: i64 = FrameIndex<0>
0x7f8743a823a8: i64 = undef
0x7f8743a829c0: i32 = shl 0x7f8743a82478, Constant:i32<16>
0x7f8743a82478: i32,ch = load<(dereferenceable load (s8) from %ir.6 + 2), anyext from i8> 0x7f8743a82618, 0x7f8743a82750, undef:i64
0x7f8743a82750: i64 = or FrameIndex:i64<0>, Constant:i64<2>
0x7f8743a82c98: i64 = FrameIndex<0>
0x7f8743a82888: i64 = Constant<2>
0x7f8743a823a8: i64 = undef
0x7f8743a82c30: i32 = Constant<16>
In function: _ZN7main_rs6device17h13d51938dd622c57E
Meta
rustc --version --verbose
:
rustc 1.63.0-nightly (4c5f6e627 2022-05-17)
Comment
It seems like there are problems with the NVPTXISD::StoreRetval
being used with a s24
. I assume the problem is that a s24
is not a valid type at all. If anyone knows where this problems originate, and if it's on the rustc or LLVM side I'm very thankful.
I will do some experiments with clang, possibly this weekend, to see how device functions are being called with such types.