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

How to check the value of drjit:: when debugging? #91

Closed JiangGuotai closed 2 years ago

JiangGuotai commented 2 years ago

When I try to debug my code, I found that I cannot see the value of dr::. And I also cannot print them. So what should I do to get their value,,, image

njroussel commented 2 years ago

Hi @JiangGuotai

It is expected that during debugging you will not be able to see the value of most variables with Dr.Jit types. Remember that Dr.Jit is a just-in-time compiler, hence any computation is not immediately evaluated but rather traced/recorded for later.

The only thing we can see in your screenshot are the values of m_index. These are the indices of the JIT variables used internally to represent your C++ variables. Of course, the JIT variables are mostly just "empty" nodes: they do not hold the actual value of the variable but rather the operation(s) that are needed to compute it. I magine that during your program execution, Dr.Jit is just recording everything you're asking it to compute into some graph. It does this until it has no other choice than to evaluate this graph, like if you try to print some variable for example.

If this is still not clear, I highly recommend you go over the documentation and the paper.

And I also cannot print them.

This most likely means that you're in some recorded loop or virtual function call. You can disable these wth jit_set_flag in C++ or drjit.set_flag in Python, the possible values are described here.