Question on euler2d example.
I'm going through euler2d example, and I'm having trouble understanding how accessing elements in the field works. There doesn't seem to be any checks to ensure correct access when i or j equal 0, or the dimension length. But the example works without error. How does the example ensure these access work?
https://github.com/taichi-dev/taichi/blob/19672ccace254409f2bd4698b436df8d78e5b80a/python/taichi/examples/simulation/eulerfluid2d.py#L103-L106
Maybe it's a bug? If you change the init to:
ti.init(arch=ti.cpu, debug=True)
then the result is:
File "/Users/hugh/git/taichi-play/euler_fluid.py", line 303, in <module>
voricity_step()
File "/Users/hugh/git/taichi-play/euler_fluid.py", line 276, in voricity_step
curl(velocities_pair.cur, curlField)
File "/Users/hugh/git/taichi/python/taichi/lang/kernel_impl.py", line 1117, in wrapped
raise type(e)("\n" + str(e)) from None
taichi.lang.exception.TaichiAssertionError:
(kernel=curl_c84_0) Accessing field (S5place<f32>) of size (512, 512) with indices (-1, 0)
Note that on gpu there is NO bounds checking. The bounds checking is: did the program crash? 😅
Thanks for the response. Wasn't aware of the debug flag. However, I did try the same access pattern without the debug flag in the python console and got cuda illegal memory access errors. This does sound like a logic bug with UB when running without any debug assertions.
My best guess is these accesses should have gone through the _with_boundary functions. The pressure_projection kernel does this already.
Yeah, e.g. something like c_with_boundary, https://github.com/taichi-dev/taichi/blob/19672ccace254409f2bd4698b436df8d78e5b80a/python/taichi/examples/simulation/eulerfluid2d.py#L194 perhaps ?