[BUG] Kernel caching false positives
Bug Description
Constructs involving function pointers that depend on a type or constant value may lead to caching false positives (functions being omitted from the hash computation). See examples of such constructs below.
This seems to be stemming from a difference between how the hash computation Adjoint.get_references resolve static expressions compared to the actual codegen (e.g. emit_Call); the hash computation uses a more lightweight approach.
Repro:
Run once, change message and re-run; kernels will be loaded from cache and output won't have changed. Manually clear cache, re-run; output is properly updated.
import warp as wp
# wp.clear_kernel_cache()
@wp.func
def message():
wp.print("A") # Run once, then change this and rerun
# Repro 1 (type-dependent)
@wp.struct
class A:
fn = message
@wp.kernel
def kn1(a: A):
a.fn()
@wp.kernel
def kn2(a: A):
type(a).fn()
wp.launch(kn1, dim=1, inputs=[A()])
wp.launch(kn2, dim=1, inputs=[A()])
wp.synchronize()
# Repro 2 (constant-dependent)
funcs = [message]
@wp.kernel
def kn3():
for fn in range(wp.static(len(funcs))):
wp.static(funcs[fn])()
@wp.kernel
def kn4():
FN = 0
wp.static(funcs[FN])()
wp.launch(kn3, dim=1, inputs=[])
wp.launch(kn4, dim=1, inputs=[])
wp.synchronize()
### System Information
_No response_
Second case has been fixed by @eric-heiden in 3c6388890e7a18c0164504b68b53ccb60859cbc0