Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some quesion about aot-interp mix execute mode on ios #97610

Open
srxqds opened this issue Jan 28, 2024 · 10 comments
Open

some quesion about aot-interp mix execute mode on ios #97610

srxqds opened this issue Jan 28, 2024 · 10 comments
Labels
area-Codegen-AOT-mono question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@srxqds
Copy link
Contributor

srxqds commented Jan 28, 2024

I found in interp_jit_call_can_be_supported method

if (!is_llvm_only && method->is_inflated)

the generic method only support aot in llvmonly?

we want to use aot-interp mode, full aot System.Private.CoreLib.dll, and use interp for our code.

  1. what params should i use to build aot file
  2. what excecute mode should I set? MONO_AOT_MODE_INTERP will not enable llvmonly ?

how can I did it?

@vargaz @BrzVlad

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 28, 2024
@srxqds
Copy link
Contributor Author

srxqds commented Jan 29, 2024

and this lines set MONO_OPT_GSHAREDVT option are conflict:

if (acfg->aot_opts.llvm_only) {
if (!mono_aot_mode_is_interp (&acfg->aot_opts))
acfg->jit_opts |= MONO_OPT_GSHAREDVT;
} else if (mono_aot_mode_is_full (&acfg->aot_opts) || mono_aot_mode_is_hybrid (&acfg->aot_opts))
acfg->jit_opts |= MONO_OPT_GSHAREDVT;
#endif
#if !defined(ENABLE_LLVM)
if (acfg->aot_opts.llvm_only) {
aot_printerrf (acfg, "--aot=llvmonly requires a runtime compiled with llvm support.\n");
return 1;
}
if (mono_use_llvm || acfg->aot_opts.llvm) {
aot_printerrf (acfg, "--aot=llvm requires a runtime compiled with llvm support.\n");
return 1;
}
#endif
if (acfg->aot_opts.llvm_only)
acfg->jit_opts |= MONO_OPT_GSHAREDVT;

@lambdageek lambdageek added the question Answer questions and provide assistance, not an issue with source code or documentation. label Jan 29, 2024
@srxqds
Copy link
Contributor Author

srxqds commented Jan 30, 2024

I have try to use llvm to not

/monoinstaller/bin/mono-aot-cross -O=gsharedvt,float32 --debug --llvm --aot=mtriple=arm64-ios,static,dwarfdebug,mattr=+crc,direct-icalls,deterministic,nimt-trampolines=2000,ntrampolines=10000,nrgctx-fetch-trampolines=256,ngsharedvt-trampolines=4400,nftnptr-arg-trampolines=4000,nrgctx-trampolines=21000,nodebug,full,interp,asmonly,internal-logfile=/monoinstaller/log.txt,dump,data-outfile=/Users/game-netease/monoinstaller/native/System.Private.CoreLib.aotdata,llvm-path=/monoinstaller/bin,outfile=/monoinstaller/native/System.Private.CoreLib.dll.s,llvm-outfile=/monoinstaller/native/System.Private.CoreLib.dll-llvm.o /monoinstaller/native/System.Private.CoreLib.dll

and use lib tool to generate static library:

libtool -static -arch_only arm64 -o /monoinstaller/native/System.Private.CoreLib.dll.a /monoinstaller/native/System.Private.CoreLib.dll-llvm.o

it will generate System.Private.CoreLib.dll.a success,
but it error on link:

ld: warning: no platform load command found in '/Users/game-netease/dotnet/benchmarks/runmonoonios/mono-8.0.0/native/System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)', assuming: iOS
ld: Undefined symbols:
  _mono_aot_corlibglobals, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibjit_code_end, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibjit_code_start, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibjit_got, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibmethod_addresses, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibplt, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibplt_end, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibunbox_trampoline_addresses, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibunbox_trampolines, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)
  _mono_aot_corlibunbox_trampolines_end, referenced from:
      _mono_aot_file_info in System.Private.CoreLib.dll.a[2](System.Private.CoreLib.dll-llvm.o)

@srxqds
Copy link
Contributor Author

srxqds commented Jan 30, 2024

System.Private.CoreLib.zip

this is the System.Private.CoreLib.dll.a and System.Private.CoreLib.dll.aotdata files

@srxqds
Copy link
Contributor Author

srxqds commented Jan 30, 2024

and if replace aot mode with llvmonly

/monoinstaller/bin/mono-aot-cross -O=gsharedvt,float32 --debug --llvm --aot=mtriple=arm64-ios,static,dwarfdebug,mattr=+crc,direct-icalls,deterministic,nimt-trampolines=2000,ntrampolines=10000,nrgctx-fetch-trampolines=256,ngsharedvt-trampolines=4400,nftnptr-arg-trampolines=4000,nrgctx-trampolines=21000,nodebug,llvmonly,asmonly,internal-logfile=/monoinstaller/log.txt,dump,data-outfile=/Users/game-netease/monoinstaller/native/System.Private.CoreLib.aotdata,llvm-path=/monoinstaller/bin,outfile=/monoinstaller/native/System.Private.CoreLib.dll.s,llvm-outfile=/monoinstaller/native/System.Private.CoreLib.dll-llvm.o /monoinstaller/native/System.Private.CoreLib.dll

it don't generate the System.Private.CoreLib.dll.s file, and can't found any error in log.txt file

@srxqds
Copy link
Contributor Author

srxqds commented Jan 30, 2024

@vargaz @BrzVlad could you have time to help?

we want to use aot generic method such as Dictionary<int, int>, Dictionary<int, string> in the interp assembly.

for example

// game.dll

class GameLogic
{
public void Test()
{
Dictionary<int, int> a = new Dictionary<int, int>();
a.Add(1, 2);  
}
}

I want to use interp mode to excecute game.dll and aot the System.Private.CoreLib.dll, so it can find in aot method.
because the dictionary operator (add element, or iterator) are slow, we want use aot to speed up.

how can I make it work?

@BrzVlad
Copy link
Member

BrzVlad commented Jan 30, 2024

I would first try to get things going without llvm, it might be a bit easier. The important flags to use are --aot=full,interp for aot compilation of SPC.dll, and --full-aot-interp when running (MONO_AOT_MODE_INTERP). In this scenario, only methods that are not found in aot images are interpreted. I'm not familiar with the toolchain setup when using mono-aot-cross, might want to replicate what our build tasks for iOS are doing.

@srxqds
Copy link
Contributor Author

srxqds commented Jan 30, 2024

I would first try to get things going without llvm, it might be a bit easier. The important flags to use are --aot=full,interp for aot compilation of SPC.dll, and --full-aot-interp when running (MONO_AOT_MODE_INTERP). In this scenario, only methods that are not found in aot images are interpreted. I'm not familiar with the toolchain setup when using mono-aot-cross, might want to replicate what our build tasks for iOS are doing.

yes, if not use llvm, it can work, but the generic method can't use aot method because it will skip by interp_jit_call_can_be_supported

if (!is_llvm_only && method->is_inflated)

this line said the generic method only work in llvmonly

@BrzVlad
Copy link
Member

BrzVlad commented Jan 30, 2024

I see, it seems that we haven't yet implemented passing of the generic context in the non-llvmonly case, when transitioning from interpreter. I'm not really familiar with running in llvmonly mode, but I would have assumed that passing similarly the llvmonly flag should have done the trick.

@srxqds
Copy link
Contributor Author

srxqds commented Jan 31, 2024

yes, I have try it, there are many mono_llvm_only conditional statements, I just comment out this line

if (!is_llvm_only && method->is_inflated)

but I will crash

* thread #1, name = 'tid_103', queue = 'com.apple.main-thread', stop reason = signal SIGSEGV
    frame #0: 0x0000000102d5cad8 RunMonoOniOS`System_Collections_Generic_Dictionary_2_TKey_GSHAREDVT_TValue_GSHAREDVT__ctor_int_System_Collections_Generic_IEqualityComparer_1_TKey_GSHAREDVT + 72
    frame #1: 0x000000010329583c RunMonoOniOS`wrapper_other_object_gsharedvt_out_sig_int__object__intptr + 60
  * frame #2: 0x000000010249efe0 RunMonoOniOS`do_jit_call(context=0x0000000282e308c0, ret_sp=0x0000000108b58090, sp=0x0000000108b58090, frame=0x000000016dc762e0, rmethod=0x00000001058cf430, error=0x000000016dc76368) at interp.c:2745:3 [opt]
    frame #3: 0x0000000102494bd0 RunMonoOniOS`mono_interp_exec_method(frame=<unavailable>, context=0x0000000282e308c0, clause_args=<unavailable>) at interp.c:4313:4 [opt]
    frame #4: 0x0000000102492444 RunMonoOniOS`interp_runtime_invoke(method=<unavailable>, obj=0x0000000000000000, params=0x0000000000000000, exc=<unavailable>, error=0x000000016dc76fb0) at interp.c:2109:2 [opt]
    frame #5: 0x000000010245cae0 RunMonoOniOS`mono_jit_runtime_invoke(method=0x00000001058a6e50, obj=<unavailable>, params=<unavailable>, exc=<unavailable>, error=0x000000016dc76fb0) at mini-runtime.c:3672:12 [opt]
    frame #6: 0x00000001023fdb74 RunMonoOniOS`mono_runtime_try_invoke [inlined] do_runtime_invoke(method=0x00000001058a6e50, obj=0x0000000000000000, params=0x0000000000000000, exc=0x000000016dc76a38, error=0x000000016dc76fb0) at object.c:2578:11 [opt]
    frame #7: 0x00000001023fdb38 RunMonoOniOS`mono_runtime_try_invoke(method=0x00000001058a6e50, obj=0x0000000000000000, params=0x0000000000000000, exc=0x000000016dc76a38, error=0x000000016dc76fb0) at object.c:2735:9 [opt]
    frame #8: 0x00000001023fc72c RunMonoOniOS`mono_runtime_class_init_full(vtable=0x00000001058c4568, error=0x000000016dc76fb0) at object.c:553:3 [opt]
    frame #9: 0x000000010245ce14 RunMonoOniOS`mono_jit_runtime_invoke(method=0x00000001058a6df0, obj=<unavailable>, params=0x000000016dc76f50, exc=0x0000000000000000, error=0x000000016dc76fb0) at mini-runtime.c:3554:7 [opt]
    frame #10: 0x00000001023fc068 RunMonoOniOS`mono_runtime_invoke_checked [inlined] do_runtime_invoke(method=0x00000001058a6df0, obj=0x0000000000000000, params=0x000000016dc76f50, exc=0x0000000000000000, error=0x000000016dc76fb0) at object.c:2578:11 [opt]
    frame #11: 0x00000001023fc02c RunMonoOniOS`mono_runtime_invoke_checked(method=0x00000001058a6df0, obj=0x0000000000000000, params=0x000000016dc76f50, error=0x000000016dc76fb0) at object.c:2794:9 [opt]
    frame #12: 0x0000000102402db4 RunMonoOniOS`mono_runtime_exec_main_checked [inlined] do_exec_main_checked(method=0x00000001058a6df0, args=<unavailable>, error=0x000000016dc76fb0) at object.c:0 [opt]
    frame #13: 0x0000000102402d78 RunMonoOniOS`mono_runtime_exec_main_checked(method=0x00000001058a6df0, args=<unavailable>, error=0x000000016dc76fb0) at object.c:4781:9 [opt]
    frame #14: 0x0000000102402e60 RunMonoOniOS`mono_runtime_run_main_checked(method=<unavailable>, argc=<unavailable>, argv=<unavailable>, error=<unavailable>) at object.c:4345:9 [opt] [artificial]
    frame #15: 0x0000000102463ab8 RunMonoOniOS`mono_jit_exec at driver.c:1369:13 [opt]
    frame #16: 0x0000000102463aa8 RunMonoOniOS`mono_jit_exec(domain=<unavailable>, assembly=<unavailable>, argc=1, argv=0x000000016dc77210) at driver.c:1314:7 [opt]
    frame #17: 0x000000010218cc58 RunMonoOniOS`TestEntry(argc=2, argv=0x0000000280b38350) at TestInterop.Mono.cpp:280:5
    frame #18: 0x0000000102193228 RunMonoOniOS`static RunMonoOniOSApp.main(self=RunMonoOniOS.RunMonoOniOSApp) at RunMonoOniOSApp.swift:22:9
    frame #19: 0x00000001021937dc RunMonoOniOS`static RunMonoOniOSApp.$main(self=RunMonoOniOS.RunMonoOniOSApp) at <compiler-generated>:0
    frame #20: 0x000000010219381c RunMonoOniOS`main at RunMonoOniOSApp.swift:11:8
    frame #21: 0x00000001e44a9df0 dyld`start + 2096

I don't know what wrong with it.
There should be other places that need to be modified as well.

@srxqds
Copy link
Contributor Author

srxqds commented Jan 31, 2024

@vargaz may you give me some help?

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Codegen-AOT-mono question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

4 participants