弹道导弹的点点滴滴的点点滴滴的点点滴滴的
立即下载
资源介绍:
弹道导弹的点点滴滴的点点滴滴的点点滴滴的
import numpy as np
from tvm import te
import onnx
import numpy as np
import tvm
import tvm.relay as relay
from tvm import rpc
from tvm.contrib import utils
x = np.zeros((1,3, 640, 640))
from tvm.contrib import graph_executor
# target = tvm.target.Target('llvm -mtriple=riscv64-unknown-linux-gnu -mcpu=generic-rv64 -mfloat-abi=hard')
#target = "llvm -mtriple=riscv64-unknown-linux-gnu -mcpu=generic-rv64" -mcpu=sifive-u54 -mcpu=sifive-u54 -device=arm_cpu
target = 'llvm -mtriple=riscv64-unknown-linux-gnu -mcpu=generic-rv64 -device=arm_cpu'
input_name = "input.1"
shape_dict = {input_name: x.shape}
#导入onnx模型
onnx_model = onnx.load('resnet18.onnx')
mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)
# 这里利用TVM构建出优化后模型的信息
# with relay.build_config(opt_level=3):
# lib = relay.build_module.build(sym, target, params=params)
with tvm.transform.PassContext(opt_level=3):
graph, lib, params = relay.build(mod, target=target, params=params)
lib.save("model.ll")
#这个relay.build_module.build与relay.build一样;
dtype = 'float32'
from tvm.contrib import graph_runtime
# 下面的函数导出我们需要的动态链接库,地址可自定义
print("Output model files")
libpath = "model1.so"
#with tvm.transform.PassContext(opt_level=3):
# graph, lib, params = relay.build(mod, target=target, params=params)
#lib.save("model.ll")
from tvm.contrib import cc
##################### Test code start ##############################
# import subprocess
# def c_compile(file_name, objects, **kwargs):
# cmd = "/usr/bin/riscv64-linux-gnu-gcc"
# options = ["-march=rv64g", "-mabi=lp64", "-o", file_name] + objects
# subprocess.check_call(cmd + " " + " ".join(options), shell=True)
# lib.export_library(libpath, fcompile=c_compile)
##################### Test code end ##############################
lib.export_library(libpath, cc="/usr/bin/riscv64-linux-gnu-gcc")
#lib.export_library("model.so", cc="riscv64-unknown-linux-gnu-g++", options=["-march=rv64gc", "-mabi=lp64d", "-static-libstdc++"])