Skip to content

Conversation

@tehrengruber
Copy link
Contributor

@tehrengruber tehrengruber commented Jan 10, 2026

Temporary fix for a segfault with at least nanobind 2.10.2. The circumstances of the environment are not really clear yet, but this looks like a nanobind issue on first sight. I could reproduce the error with python 3.10 & 3.12.

Error message:

Fatal Python error: Segmentation fault

Current thread 0x00007d4596caeb80 (most recent call first):
  File "/home/tille/Development/gt4py_functional/src/gt4py/next/program_processors/runners/gtfn.py", line 67 in decorated_program
  File "/home/tille/Development/gt4py_functional/src/gt4py/next/backend.py", line 161 in __call__
  File "/home/tille/Development/gt4py_functional/src/gt4py/next/ffront/decorator.py", line 724 in __call__

Source of the error:
This innocent looking line in src/gt4py/next/otf/compilation/compiler.py triggers the error

getattr(importer.import_from_path(src_dir / new_data.module), new_data.entry_point_name)

After the getattr call the module importer.import_from_path(src_dir / new_data.module) is garbage collected resulting in a call to nanobind::detail::nb_module_clear. This function (for unknown reasons) garbage collects the value stored in static_pyobjects[pyobj_name::dl_version_tpl] which is used in nanobind/include/nanobind/ndarray.h when calling the compiled program in src/gt4py/next/program_processors/runners/gtfn.py.

Steps to debug:

  1. Make sure you have python with debug symbols and the python extensions for gdb installed
  2.  set args -m pytest tests/next_tests/integration_tests/feature_tests/ffront_tests/test_execution.py -k test_copy
     break init_pyobjects
     run
     # stop when `static_pyobjects[pyobj_name::dl_version_tpl]` changes
     watch static_pyobjects[pyobj_name::dl_version_tpl]
     # ignore first change in init_pyobjects to the value
     continue
     # now you should land in `nanobind::detail::nb_module_clear`, printing
     # a python backtrace reveals the line in which the problem occurs
     py-bt
    

@tehrengruber tehrengruber marked this pull request as draft January 10, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant