You’re right that there’s no fundamental reason why it would be impossible, I just don’t think it’s supported currently.
Combining multiple PTX files is one limitation. This would require a linker, and as far as I can tell there is no well-supported linker that works for PTX files (rust-ptx-linker links LLVM bitcode and then uses it to generate PTX files, and the only other one I can find appears to be abandoned).
It is possible to link PTX files together at runtime. There are functions in the CUDA driver API for it, at least. However, I don’t think accel exposes this feature. Accel also doesn’t easily expose the PTX files that it generates, so that’s another problem. I also don’t know if every CUDA driver supports this feature.
I’d like to say that you could just use my RustaCUDA library instead, with rust-ptx-builder to compile your Rust code to PTX, but RustaCUDA also doesn’t expose the runtime linking feature yet. I probably won’t get around to building that out any time soon, either.
That being the case, I think your options are as follows:
cuda-sys functions directly to do your linking at runtime.
- Contribute support for just-in-time linking to Accel or RustaCUDA, and then use that
- Write your kernels in CUDA C and then load and launch them with RustaCUDA
Honestly, my recommendation would be that last one (though I might be biased). Support for compiling Rust to PTX is really limited and unstable at this point, and it’s missing important features like shared memory, volatile reads, vector loads/stores, and even basic things like the
syncthreads intrinsic doesn’t work. There’s an unofficial group working on improving this (and I am part of that group) but it’s still early days yet - we’re still trying to make sure that the compiler even works reliably.