-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic LLVM-IR shading code can be achieved by using AdaptiveCpp #33
Comments
fyi, this could be interesting in this context: AdaptiveCpp/AdaptiveCpp#1467 |
Very interesting, thank you! The only concern I'm having right now is that Adaptivecpp dynamic functions require the function body to be defined at compile time, so I don't know how I could fit a runtime loaded function. I managed to bypass the function pointer limitation (// Not allowed: auto* myfuncptr = &myfunc; dynamic_function{myfuncptr};) by manually registering it with the wranggled id of the function definition Now I need to find a way to include my LLVM code to the module passed to LLVMToBackendTranslator. Just to make it clear, I managed to make the function ptr works with this code:
|
What do you mean by a runtime-loaded function? The set of instructions in an IR is finite, so if you define your dynamic functions appropriately (in an extreme case, on an instruction level, like add, subtract etc) you can have this feature operate at almost arbitrary granularity. If you want even more control, I'm also looking into adding an optional user callback right before the IR optimization stage, so that users can inject their own LLVM transformations.
Don't do this, it's not exactly the same. You're only registering the function with the symbol resolution logic, but the compiler won't know that If you need more control and need to pass around functions more freely, the way to do it is
The downside of using If you still want type-safety, you can also directly use the
See the API reference in that PR for a full list of all overloads. |
My objective is to load a function from an LLVM Module loaded at runtime, my definition of runtime function is a function which definition is not known until the execution of the program
That would fit perfect in my use case as I could add a transformation pass which would merge the main module with a loaded one. I'm doing right now something similar but hardcoding the LLVM module load and merge directly in the AdaptiveCpp code as a concept. I was thinking that maybe I can play around with specialized constants with sycl::specialized? If I understood well it's purpose, JIT will read sycl::specialized values and will generate device code with the runtime value of such variable. I tried to set a sycl::specialized function pointer but it only worked in the OMP backend, I guess that's maybe because OMP runs in the host, and the device code is not defined for such function? I know about the function ptrs and virtual functions limitations of SYCL, but maybe using a functor object could do the trick? |
The problem is that a) some devices may not support function pointers and even more fundamental b) the pointer address that you obtain outside the kernel code refers to the address of the host code, but inside the kernel you are on device - function pointer addresses, even if supported, will in general be different there. A functor object will either boil down to function pointers as well if it uses some form of type erasure, or it will rely on different data types, i.e. require templates. In the latter case, JIT techniques won't help you because templates are evaluated in the frontend at compile time. |
As a remainder to myself, it's also possible to inject LLVM-IR payload in DPC++ by slightly modifying their kernel fusion extension as is the only place they do JIT for real. I don't know if they perform an optimization pass after the merge as they work with Spir-V after that, or if I should provide a pre-optimized code. |
I had a conversation with @illuhad about how this could be achieved with a couple tweaks
The text was updated successfully, but these errors were encountered: