How to prevent recompiling kernel for randomized input?
sleepyeye opened this issue · 2 comments
Hello.
Currently, I'm rendering a large number of images using the aov
integrator from randomized scenes with the CUDA backend. (I simply randomize camera and surface parameters, such as Kd
, if it is a constant/vector value.) The results are as expected, and the rendering itself is extremely fast.
However, LuisaRender
recompiles the ray tracing kernel for every randomized input (even though it has rendered the same scene but with different surface parameters). Due to the compilation overhead, the total overhead is increased drastically.
I want to remove or minimize this JIT compilation overhead (by reusing the compiled kernel). From my understanding, the generated code has different hashes because different constants (due to randomized material and camera nodes) are generated during dependency injection. This different hash causes a cache miss of the kernel.
I tried many ways to overcome the issue but no luck due to my short understanding of dependency injection.
Would you give me any comments or advice for the issue?
Any suggestions or advice would be appreciated.
Thanks!
Hi, @sleepyeye
For ConstantTexture
, I added a new property inline
in commit 8dcaccc, which controls whether the value of the texture should be embedded directly in code (when set to true
) or read from a buffer at render time (when false
). Now, to ensure cache hit with randomized scenes, you could set inline { false }
for all randomized surface parameters, e.g.,
Kd : Constant {
v { ... }
inline { false } // disable constant texture inlining
}
The camera parameters already are stored in buffers by default, so I suppose no changes are necessary for them. Nevertheless, LuisaRender supports using multiple cameras in a single scene file, which would help reduce the scene loading time when rendering the same scene with different camera poses.
Thanks! It works like a charm!