dotnet / TorchSharp

A .NET library that provides access to the library that powers PyTorch.
MIT License
1.4k stars 180 forks source link

invalid pointer and segmentation fault in mono runtime (Unity3D) #1009

Closed kcarlson closed 4 months ago

kcarlson commented 1 year ago

We are trying to use this library in unity and are able to load and compile. However, when calling the library, we get a segmentation fault:

TrimDiskCacheJob: Current cache size 2mb
free(): invalid pointer
Caught fatal signal - signo:6 code:-6 errno:0 addr:0x3e80024c729
Obtained 57 stack frames.
#0  0x007fdaa5a36520 in __sigaction
#1  0x007fdaa5a8aa7c in pthread_kill
#2  0x007fdaa5a36476 in raise
#3  0x007fdaa5a1c7f3 in abort
#4  0x007fdaa5a7d6f6 in __fsetlocking
#5  0x007fdaa5a94d7c in timer_settime
#6  0x007fdaa5a96ac4 in __default_morecore
#7  0x007fdaa5a994d3 in free
#8  0x007fd6a779b34a in c10::QualifiedName::QualifiedName(std::string const&)
#9  0x007fd6a779a111 in torch::detail::class_base::class_base(std::string const&, std::string const&, std::string, std::type_info const&, std::type_info const&)
#10 0x007fd6a7e94a0a in register_linear_params()
#11 0x007fd6a7483675 in _GLOBAL__sub_I_RNN.cpp
#12 0x007fdaaea4847e in __nptl_change_stack_perm
#13 0x007fdaaea48568 in __nptl_change_stack_perm
#14 0x007fdaa5b68c85 in _dl_catch_exception
#15 0x007fdaaea4fff6 in _dl_rtld_di_serinfo
#16 0x007fdaa5b68c28 in _dl_catch_exception
#17 0x007fdaaea5034e in _dl_find_dso_for_object
#18 0x007fdaa5a846bc in dlmopen
#19 0x007fdaa5b68c28 in _dl_catch_exception
#20 0x007fdaa5b68cf3 in _dl_catch_error
#21 0x007fdaa5a841ae in dlerror
#22 0x007fdaa5a84748 in dlopen
#23 0x0055566a6a202c in LoadPluginExecutable(char const*, bool)
#24 0x0055566a6a3b25 in FindAndLoadUnityPlugin(char const*, void**, bool)
#25 0x007fd8c0a2c54f in mono_lookup_pinvoke_call
#26 0x007fd8c0a2cef3 in mono_lookup_pinvoke_call
#27 0x007fd8c0841f03 in mono_jit_set_domain
#28 0x007fd8c08c0433 in mono_install_ftnptr_eh_callback
#29 0x007fd8c08bfe9c in mono_install_ftnptr_eh_callback
#30 0x00000040576396 in (Unknown)
#31 0x000000421446f8 in TorchSharp.torch:_randn (System.ReadOnlySpan`1<long>,System.Nullable`1<TorchSharp.torch/ScalarType>,TorchSharp.torch/Device,bool,TorchSharp.torch/Generator,string[])
#32 0x00000042143c3c in TorchSharp.torch:randn (int,int,System.Nullable`1<TorchSharp.torch/ScalarType>,TorchSharp.torch/Device,bool,TorchSharp.torch/Generator,string[])

Just wondering if there is anything that sticks out off hand or if torch sharp just isn't compatible with the mono runtime in unity?

Ubuntu 22.04.02 LTS Unity Version: 2021.3.25f1 torchsharp: 0.100.0 libtorch-cpu: linux-x64.2.0.1.1

NiklasGustafsson commented 1 year ago

Interesting.

TorchSharp has not been tested with any version of the Mono runtime. Seems like it would be a useful community contribution to make it work.