mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
593 stars 43 forks source link

TensorXf<->Vector3f failed in drjit loop under megakernal #166

Closed andyyankai closed 1 year ago

andyyankai commented 1 year ago

I tried to convert a Vector3fD into TensorXf under drjit loop. However, it failed under megakernal Is there anyway I can do that(I am trying to converge to TensorXf and call warp_ad function) Here is how to reproduce

import drjit as dr
import mitsuba as mi

# dr.set_flag(dr.JitFlag.LoopRecord, False)
# dr.set_flag(dr.JitFlag.VCallRecord, False)

mi.set_variant('cuda_ad_rgb')

opt = mi.Vector3f.zero_(1000)
active = dr.mean(opt) < 0.5
loop = mi.Loop('Bug loop', lambda: (active, opt))
print("start")
while loop(active):
    test = mi.TensorXf(dr.ravel(opt), shape=[dr.width(opt),3])
    test = dr.unravel(mi.Vector3f, test)
    opt = test
    opt += 0.1
    active = dr.mean(opt) < 0.5
print(opt)
print("end")

exit()

error message: Critical Dr.Jit compiler failure: jit_var_gather(): operand r40 remains dirty following evaluation!

njroussel commented 1 year ago

Hi @andyyankai

Using the @wrap_ad decorator inside a recorded loop is not (and most likely never will be) supported. In order to pass data to/form other frameworks we need to evaluate variables which breaks the entire purpose of the recorded loop where we just want to record the graph of computations.