Trouble building examples on RPI4 & MacOS for Cpp

We’re trying to use the example app “howto_deploy” on the RPI4b (8GB RAM). TVM libraries build correctly and the environment is set up properly (as far as I know). Here’s the error that the script displays after successfully running the prepare_test_libs.py program:

Run the example Run the deployment with all in one packed library… [14:07:53] cpp_deploy.cc:77: Verify dynamic loading from test_addone_dll.so [14:07:53] cpp_deploy.cc:69: Finish verification… [14:07:53] cpp_deploy.cc:81: Verify load function from system lib terminate called after throwing an instance of ‘tvm::runtime::InternalError’ what(): [14:07:53] cpp_deploy.cc:34: InternalError: Check failed: (f != nullptr) is false:

This same thing happens on MacOS (x64 and arm64). Is there a simple fix to get past this error?

Thank you

I found many similar questions.

The simplest way is modifying the following lines in apps/howto_deploy/prepare_test_libs.py


    # fadd_syslib = tvm.build(s, [A, B], "llvm", name="addonesys")
    fadd_mod = tvm.lower(s, [A, B], name="addonesys")
    from tvm.runtime import String
    fadd_mod = fadd_mod.with_attr("system_lib_prefix", String(""))

    fadd_syslib = tvm.build(fadd_mod, target="llvm", name="addonesys")

    syslib_path = os.path.join(base_path, "test_addone_sys.o")
    fadd_syslib.save(syslib_path)

The reason is that currently TVM implicitly identifies a module as “system-lib” according to whether it has the attribute system_lib_prefix. If not, the function used to register the symbols TVMBackendRegisterSystemLibSymbol won’t be included in the compiled library (“test_addone_sys.o”).

So a direct solution is to explicitly set the attribute to the IRModule lowered from te.Schedule, before the codegen process.

Hope this could help and more elegant solutions could be provided.

1 Like

I tried that change to the prepare_test_libs.py, but it didn’t fix the problem. The error changed slightly:

Run the example Run the deployment with all in one packed library… [08:38:00] cpp_deploy.cc:77: Verify dynamic loading from test_addone_dll.so [08:38:00] cpp_deploy.cc:69: Finish verification… [08:38:00] cpp_deploy.cc:81: Verify load function from system lib terminate called after throwing an instance of ‘tvm::runtime::InternalError’ what(): [08:38:00] cpp_deploy.cc:34: InternalError: Check failed: (f != nullptr) is false: Stack trace: [bt] (0) lib/cpp_deploy_pack(+0x13c4c) [0x5559233c4c] [bt] (1) lib/cpp_deploy_pack(+0xdca4) [0x555922dca4] [bt] (2) lib/cpp_deploy_pack(+0xb5b8) [0x555922b5b8] [bt] (3) lib/cpp_deploy_pack(+0xba44) [0x555922ba44] [bt] (4) lib/cpp_deploy_pack(+0xbd98) [0x555922bd98] [bt] (5) lib/cpp_deploy_pack(+0x75dc) [0x55592275dc] [bt] (6) /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe8) [0x7f97bc9e18] [bt] (7) lib/cpp_deploy_pack(+0xb3e8) [0x555922b3e8]

./run_example.sh: line 26: 1762 Aborted lib/cpp_deploy_pack Run the cpp deployment with all in normal library… [08:38:00] cpp_deploy.cc:77: Verify dynamic loading from test_addone_dll.so [08:38:00] cpp_deploy.cc:69: Finish verification… [08:38:00] cpp_deploy.cc:81: Verify load function from system lib terminate called after throwing an instance of ‘tvm::runtime::InternalError’ what(): [08:38:00] cpp_deploy.cc:34: InternalError: Check failed: (f != nullptr) is false: Stack trace: 0: _ZN3tvm7runtime6deta 1: Verify(tvm::runtime::Module, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) 2: DeploySingleOp() 3: main 4: 0x000000557ec83907

Looks strange. I tested the solution on my MAC(intel x64). It works well.

BTW, I used the latest version of TVM-unity. I’m not sure whether it matters. Maybe you can provide more clues like:

  • Your modified prepare_test_libs.py
  • TVM version you use (which commit).

The change to the python script did work on my M1 Mac, but did not work on the RPI4.

I have no more ideas about RPI4. The codegen workflow should be almost the same on RPI4 and MAC with LLVM. Did you try the target tvm.target.arm_cpu("rasp4b") or tvm.target.arm_cpu("rasp4b64")?