File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -310,14 +310,18 @@ def create_program(self):
310310 self .prog = _ti_core .Program ()
311311
312312 def materialize_root_fb (self , is_first_call ):
313- if not root .finalized and not root .empty :
314- root .finalize ()
315- elif is_first_call :
316- root .finalize (raise_warning = False )
317-
318313 if root .finalized :
319- global _root_fb
320- _root_fb = FieldsBuilder ()
314+ return
315+ if not is_first_call and root .empty :
316+ # We have to forcefully finalize when `is_first_call` is True (even
317+ # if the root itself is empty), so that there is a valid struct
318+ # llvm::Module, if no field has been declared before the first kernel
319+ # invocation. Example case:
320+ # https://github.com/taichi-dev/taichi/blob/27bb1dc3227d9273a79fcb318fdb06fd053068f5/tests/python/test_ad_basics.py#L260-L266
321+ return
322+ root .finalize (raise_warning = not is_first_call )
323+ global _root_fb
324+ _root_fb = FieldsBuilder ()
321325
322326 def _finalize_root_fb_for_aot (self ):
323327 if _root_fb .finalized :
You can’t perform that action at this time.
0 commit comments