Closed steinraf closed 1 month ago
Hi @steinraf, thank you for reporting this issue!
Regarding the division by 0, you could try setting wp.config.verify_fp = True
, which should catch such issues and log them.
As for accessing that scoped variable, when the if
condition can be evaluated to False
at compile time, as it is the case in your example, we should be able to discard the dead code altogether, which is something that @eric-heiden's current work around static expressions might help addressing.
However, if the if
condition requires to be evaluated at runtime, then it's tricky. The issue is that Python has different scoping rules than the C++/CUDA languages that Warp is transpiling that Python code to, so it's not really possible to nicely map between both in this case.
Yes, the floating point verification catches that error during runtime, I was wondering more if there was a way to catch these errors (or other ones) by getting a warning/error during compilation. Is there any way to access the compilation logs in general?
The work on static expressions sounds exciting, looking forward to that!
I agree, the both languages don't interact nicely regarding that. At this point it would be most helpful for me if I looked at the code generation to see how these cases are handled. Until then its probably best just not to initialize variables in branches.
The most logs that Warp can currently output can be enabled with the following configuration values:
wp.config.mode = "debug"
wp.config.verbose = True
wp.config.verify_fp = True
wp.config.verify_cuda = True
That includes compilation warnings/errors, if any.
Bug Description
In some circumstances its possible to create code which should raise an error when run in python, but gets transformed in a way that does not produce an error in the autogenerated cuda kernel code.
If a variable is initialized in a branch that is not taken, no error is raised and the value gets initialized anyways
The kernel is translated to the following:
Expected behaviour:
UnboundLocalError: local variable 'a' referenced before assignment
orerror: identifier "a" is undefined
Another, arguably less relevant but similar, example is when computing divisions by zero with known constants. In python this usually causes a runtime error and in C/C++ it is undefined behaviour and creates a warning if the constant is known to be 0 at compile time.
This produces the following kernel code
Expected behaviour:
ZeroDivisionError: float division by zero
orwarning #39-D: division by zero
System Information
Warp 1.3.0 initialized: CUDA Toolkit 12.5, Driver 12.2