Emit CUDA kernels concurrently/prior to LLVM graph emission
Currently the gpu_emitter emits code that is compiled at runtime by LLVM. This compiled code then generates CUDA kernels which are compiled at RT and then run. Thus, the compiled graph execution includes runtime compilation of CUDA kernels.
As far as I can tell, there isn't anything that constrains the functionality to proceed in this way. For performance optimization purposes and benchmarking, I believe it would be better to have the gpu_emitter handle the cuda kernel runtime compilation first, prior to LLVM compilation, so that when the LLVM compiled function is executed, the computations that occur are primarily based on executing the graph and not generating CUDA.
I have checked with some of the MKLDNN folks and they originally also used our current method but eventually switched to having the MKLDNN generated prior/concurrently to the LLVM compilation. This is achievable by passing a context variable from the generating code to the LLVM compiled function (m_compiled_function) which contains pointers and other information that the emitted code can use to make the appropriate CUDA kernel calls. This is how it is currently performed on the CPU transformer side, see for example CPURuntimeContext.
In neon, the compiled kernels are cached, so they don't get compiled after the first time.
In neon, the compiled kernels are cached, so they don't get compiled after the first time. @diyessi
They are also currently cached in the GPU transformer, but this is happening from the call of the LLVM compiled function, so the first compilation occurs during the graph execution.
For some context, it was originally done that way in the IA backend because the initial design aimed to generate "standalone" code that could be executed independently of the ngraph DSO (and only dependent on numeric backends and the standard library/platform runtime). I believe that goal/direction has mostly been abandoned since for various reasons. Infact, one could just directly emit an LLVM module that chains calls to various operators and get rid of almost all of the compilation overhead though that's not done yet because quite a few operators rely on the optimizers/vectorizers from llvm+clang
It's not abandoned for inference.
Should we target standalone functionality for inference in the GPU transformer, then?
Is their a desire for the enhancement this issue raises?
When I brought this up in the ngraph-mxnet vertical it was suggested that runtime compilation of the cuda kernels would preferably occur prior to graph execution.
It's not abandoned for inference.
This raises quite a few questions. It'd be good to discuss how we plan to address this. We also want negligible compilation overhead for inference in addition to execution latency. And the current IA-side codegen definitely does not allow for this "standalone" use-case at any rate. If we end up leveraging external kernels (ex. Halide-based) for most (if not all) performance-sensitive ops, then compiling code on-the-fly adds zero value in addition to not being "standalone".
There is always some trade off, even for inference. Some might require to start faster, some require to run faster, and other might want some balanced load. All lead to different approach.
Compile time emission of cudnn and ngraph compilation of cuda kernels (prior to clang JIT) is now possible as of PR #837. Please open a new issue for further discussion of standalone binary support.