Passing data between Futhark and other GPU code? #2510
|
Is it easy to pass data between GPU-compiled Futhark programs and other GPU code? As an example, consider the task of building a game like CodeParade's 4D Golf. The rendering algorithm would look roughly as follows:
Would it be possible to implement step 2 in Futhark? Or would passing the 3D slice from Futhark to OpenGL require round-tripping through the CPU? A similar, but simpler question, would be to ask if a Futhark-implemented raytracer can output directly to the framebuffer. If passing data around like this is possible, I'd appreciate it if you could add a section to https://futhark-lang.org/examples.html, demonstrating how this is done. If it isn't, it would still be useful to clearly state that somewhere, so I don't waste my time trying. |
Replies: 1 comment 1 reply
|
I don't know much about OpenGL specifically. If you use the CUDA (or HIP, or OpenCL) backends you can create a Futhark array directly from a "raw" CUDA/OpenCL/HIP pointer. Since those APIs can interoperate with OpenGL, then you can pass GPU data to Futhark. This is not a particularly well-exercised feature (I think we may have no unit tests for it at all), but I have seen people do it before.
This is not possible, and generally it is not possible to make Futhark put anything in specific memory without paying the cost of copying it there. You can easily enough write a Futhark raytracer that writes to GPU memory, and then you can blit from there to the framebuffer. |
I don't know much about OpenGL specifically. If you use the CUDA (or HIP, or OpenCL) backends you can create a Futhark array directly from a "raw" CUDA/OpenCL/HIP pointer. Since those APIs can interoperate with OpenGL, then you can pass GPU data to Futhark. This is not a particularly well-exercised feature (I think we may have no unit tests for it at all), but I have seen people do it before.
This is not possible, and generally it is not possible to make Futhark put anything in specific memory without paying the cost of copying it there. You can easily enough write…