tvm android_rpc_test.py执行报错解决

执行 python3 tests/android_rpc_test.py

报错:

Run CPU test ...
Traceback (most recent call last):
  File "tests/android_rpc_test.py", line 129, in <module>
    test_rpc_module()
  File "tests/android_rpc_test.py", line 73, in test_rpc_module
    f2 = remote.load_module("cpu_lib.tar")
  File "/root/.local/lib/python3.8/site-packages/tvm-0.13.0-py3.8-linux-x86_64.egg/tvm/rpc/client.py", line 161, in load_module
    return _ffi_api.LoadRemoteModule(self._sess, path)
  File "/root/.local/lib/python3.8/site-packages/tvm-0.13.0-py3.8-linux-x86_64.egg/tvm/_ffi/_ctypes/packed_func.py", line 238, in __call__
    raise get_last_ffi_error()
tvm.error.InternalError: Traceback (most recent call last):
  4: TVMFuncCall
  3: _ZN3tvm7runtime13PackedFuncObj9ExtractorINS0_16PackedFuncSubObjIZNS0_15TypedPackedFuncIFNS0_6ModuleES5_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE17AssignTypedLambdaINS0_UlS5_SB_E3_EEEvT_SB_EUlRKNS0_7TVMArgsEPNS0_11TVMRetValueEE_EEE4CallEPKS1_SH_SL_
  2: tvm::runtime::RPCWrappedFunc::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
  1: tvm::runtime::RPCClientSession::CallFunc(void*, TVMValue const*, int const*, int, std::function<void (tvm::runtime::TVMArgs)> const&)
  0: tvm::runtime::RPCEndpoint::CallFunc(void*, TVMValue const*, int const*, int, std::function<void (tvm::runtime::TVMArgs)>)
  File "/home/tt/project/docker_tvm2/tvm/src/runtime/rpc/rpc_endpoint.cc", line 808
InternalError: Check failed: (code == RPCCode::kReturn) is false: code=kShutdown
 

解决方法:

把cpu_lib.tar改为cpu_lib.so;并且在export_library添加ndk.create_shared,如下:

path_dso_cpu = temp.relpath("cpu_lib.so")

f.export_library(path_dso_cpu, ndk.create_shared)

原因:

没有添加ndk.create_shared,使用默认的编译器,在android上不能跑

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TVM的te(Tensor Expression)中,`tvm.te.if_then_else` 函数用于实现条件语句,根据一个布尔条件选择执行不同的计算逻辑。 `if_then_else` 函数的基本语法如下: ```python tvm.te.if_then_else(condition, then_expr, else_expr) ``` 参数说明: - `condition`:布尔条件表达式,用于决定选择哪个分支的计算逻辑。 - `then_expr`:当条件为真时执行的计算表达式。 - `else_expr`:当条件为假时执行的计算表达式。 下面是一个示例代码,演示如何使用 `if_then_else` 函数: ```python import tvm from tvm import te def if_then_else_example(): # 输入张量形状 shape = (4, ) # 创建输入和输出张量 input_tensor = te.placeholder(shape, name='input_tensor', dtype='float32') output_tensor = te.placeholder(shape, name='output_tensor', dtype='float32') # 定义计算 def compute(i): # 根据输入张量的值判断条件 condition = input_tensor[i] > 0 # 根据条件选择执行计算逻辑 then_expr = input_tensor[i] * 2 else_expr = input_tensor[i] / 2 # 使用 if_then_else 函数实现条件选择 return tvm.te.if_then_else(condition, then_expr, else_expr) # 创建计算描述 output = te.compute(shape, compute, name='output') return output.op.body[0] # 创建一个范围上下文 with tvm.target.Target('llvm'): # 构造计算图 stmt = if_then_else_example() # 打印生成的计算图 print(stmt) ``` 在上述示例中,我们定义了一个 `if_then_else_example()` 函数,创建了输入张量和输出张量。然后在 `compute()` 中,根据输入张量的值判断条件,并使用 `if_then_else` 函数实现条件选择:当输入张量大于0时,执行乘以2的计算逻辑;否则,执行除以2的计算逻辑。最后通过 `te.compute()` 创建计算描述,并返回计算图的第一个操作节点。 希望这能解答您的疑问!如果您还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值