I need a flexibility to use programming language functions that runs in CPU as machine code. But the place to put these functions is inside GPU shaders.
I suggest to add a way to add CPU function callbacks to shaders, and the callbacks can be called from within shaders.
I have thought of a way to implement executing the callback from within shaders. When the shaders are about to execute the callback, control flow returns back to driver, the driver execute the callback, then control flow return back to GPU.
Yeah, that’s not a reasonable thing to do. Let’s ignore the vast differences in the resourcing models of these two processors. You’re talking about taking a highly multiprocessed architecture and slaving its work to the execution of a processor that has far fewer execution units. That’s just not a viable thing to be doing.
If you want to do something like this, then you need to explicitly pay the price for it. You need to break up your shader operation into two parts: the generation part which generates data for the CPU operation, and the resumption part which uses the results of the CPU computations. Between those two, you need to transfer the data back to memory the CPU can access, do your various processes on them and collect the results, then upload the results back to where the GPU can access them.
That’s probably the most efficient way to handle this. Halting the execution of shader invocations for the many time it would take to shell out 16 or 32 CPU computations and return the results is not an efficient use of GPU resources.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.