在ubuntu 20.04 上 安装 onnxruntime CUDA

onnxruntime 可以加速模型的部署,同时可以跨框架,例如
源码项目位置:https://github.com/microsoft/onnxruntime

里面有一些依赖,这里直接打包,提供百度网盘的下载:

链接:https://pan.baidu.com/s/1sTryvfX0sLKIoHm8aMm4Sg
提取码:be9o

解压后:
执行命令:

git  init

git submodule sync

git submodule update --init --recursive

1.然后进行编译:使用CUDA

./build.sh --skip_tests --use_cuda --config Release --build_shared_lib --parallel --cuda_home /usr/local/cuda --cudnn_home /usr/local/cuda

2.如果不使用CUDA,用默认的CPU

./build.sh --skip_tests  --config Release --build_shared_lib --parallel

3.使用TensorRT:

./build.sh --build_shared_lib --skip_tests --config Release --use_cuda --cudnn_home /usr/local/cuda/ --cuda_home /usr/local/cuda  --use_tensorrt --tensorrt_home /home/TensorRT-version/

安装成功。
 
 

因为微软没用提供find_package()的用法,所以这里CMAKE写法:

#onnxruntime
set(ONNXRUNTIME_ROOT_PATH your_path_to_onnxruntime_source_dir)
set(ONNXRUNTIME_INCLUDE_DIRS ${ONNXRUNTIME_ROOT_PATH}/include/onnxruntime
                             ${ONNXRUNTIME_ROOT_PATH}/onnxruntime
                             ${ONNXRUNTIME_ROOT_PATH}/include/onnxruntime/core/session/)
set(ONNXRUNTIME_LIB ${ONNXRUNTIME_ROOT_PATH}/build/Linux/Release/libonnxruntime.so)
include_directories(${ONNXRUNTIME_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${ONNXRUNTIME_LIB})

在C++里面头文件:

#include <core/session/onnxruntime_cxx_api.h>
#include <core/providers/cuda/cuda_provider_factory.h>
#include <core/session/onnxruntime_c_api.h>

另外可以编译tensorRT版本的,加速模型推理。

  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值