60 karma · joined Nov 22, 2021 (5y ago) · 7 submissions
comment 5y ago · link · parent
That is not totally true, there are two main things that can make kernels generated by this codegen faster:
- noalias, which is the LLVM equivalent of __restrict__, CUDA can take massive advantage of noalias by using readonly cache if the pointer does not alias. If you don't believe me just take a look at nvidia's blog post: https://developer.nvidia.com/blog/cuda-pro-tip-optimize-poin...
- CUDA builds all the .cu files and links the PTX of them together, this means no LTO happens by default. I do something different where i actually lazily-load every module using dependency graphs, which gives you the benefit of LTO by default. Its not perfect because right now it leaves behind a lot of dead code, but i know how to fix it.
comment 5y ago · link · parent
comment 5y ago · link · parent
pub fn get_shared_mem_ptr<const Bytes: usize>() -> \*mut u8 {
__nvvm_get_shared_mem_ptr(Bytes)
}
For the raw version, the codegen internally intercepts the call to the intrinsic and declares an extern global in the shared addrspace, which is what libnvvm wants you to do, basically like __shared__ int foo[5];
Dynamic shared mem is a bit more weird because if you query the ptr for the dynamic smem it yields the same ptr every time.comment 5y ago · link · parent
My idea for shared memory is that it will always be unsafe and the only thing i can do is: - expose raw low level "give me a pointer to 70 bytes of shared mem" function because this needs codegen support.
- Then expose a higher level "give me an array of 50 u16s in shared memory"
- Make as much of it as possible usable behind an abstraction, like block reduce, stuff like that.
But i want to make it clear that shared memory will always be unsafe, shared memory semantics are literally impossible to statically prove. I dont think this is the end of the world, high performance GPU programming will always require people to really know what they're doing
comment 5y ago · link · parent
comment 5y ago · link · parent
So please do not be surprised that an early project does not contain every single feature of cuda, something thats been around for decades