【OnnxRuntime】在linux下编译并安装C++版本的onnx-runtime

目录

安装C++接口的onnx-runtime

安装依赖项:

安装CMake:可以通过包管理器(如apt、yum等)安装CMake。

安装C++编译器:确保系统中已安装C++编译器,如GCC或Clang。

下载源文件

克隆ONNX Runtime的GitHub仓库,指定版本是为了适配python3.8:

bash 复制代码
git clone --branch v1.5.2 --recursive https://gitee.com/lee-zq/onnxruntime.git

构建ONNX Runtime

进入ONNX Runtime的源代码目录:

// 首先创建一个conda环境,因为./build.sh实际上调用的是./tools/cl_build/build.py

bash 复制代码
cd onnxruntime
conda create -n onnxruntime python=3.8
./build.sh --skip_tests --config Release --build_shared_lib --parallel

注意,若配合cuda使用,命令行末尾应添加

bash 复制代码
-cuda_home /usr/local/cuda-11.3 --cudnn_home /usr/local/cuda-11.3

注意,编译前,确保机器装有linux环境:

bash 复制代码
sudo apt-get install build-essential

这将使用所有可用的CPU核心进行编译。如果希望使用指定数量的核心,可以将$(nproc)替换为所需的核心数量。

安装ONNX Runtime

运行以下命令进行安装:

bash 复制代码
cd /build/Linux/Release
sudo make install

通过按照上述步骤,您应该能够在Linux上成功安装ONNX Runtime。请注意,安装过程中可能需要根据您的系统和需求进行适当的调整。

cpp 复制代码
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/include/onnxruntime/core/common
-- Installing: /usr/local/include/onnxruntime/core/common/code_location.h
-- Installing: /usr/local/include/onnxruntime/core/common/common.h
-- Installing: /usr/local/include/onnxruntime/core/common/const_pointer_container.h
-- Installing: /usr/local/include/onnxruntime/core/common/eigen_common_wrapper.h
-- Installing: /usr/local/include/onnxruntime/core/common/exceptions.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging
-- Installing: /usr/local/include/onnxruntime/core/common/logging/capture.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/isink.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/logging.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/macros.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/severity.h
-- Installing: /usr/local/include/onnxruntime/core/common/make_unique.h
-- Installing: /usr/local/include/onnxruntime/core/common/optional.h
-- Installing: /usr/local/include/onnxruntime/core/common/status.h
-- Installing: /usr/local/include/onnxruntime/core/graph
-- Installing: /usr/local/include/onnxruntime/core/graph/basic_types.h
-- Installing: /usr/local/include/onnxruntime/core/graph/constants.h
-- Installing: /usr/local/include/onnxruntime/core/graph/function.h
-- Installing: /usr/local/include/onnxruntime/core/graph/graph.h
-- Installing: /usr/local/include/onnxruntime/core/graph/graph_nodes.h
-- Installing: /usr/local/include/onnxruntime/core/graph/graph_viewer.h
-- Installing: /usr/local/include/onnxruntime/core/graph/indexed_sub_graph.h
-- Installing: /usr/local/include/onnxruntime/core/graph/node_arg.h
-- Installing: /usr/local/include/onnxruntime/core/graph/onnx_protobuf.h
-- Installing: /usr/local/include/onnxruntime/core/graph/schema_registry.h
-- Installing: /usr/local/include/onnxruntime/core/framework
-- Installing: /usr/local/include/onnxruntime/core/framework/alloc_kind.h
-- Installing: /usr/local/include/onnxruntime/core/framework/allocator.h
-- Installing: /usr/local/include/onnxruntime/core/framework/customregistry.h
-- Installing: /usr/local/include/onnxruntime/core/framework/data_types.h
-- Installing: /usr/local/include/onnxruntime/core/framework/data_types_internal.h
-- Installing: /usr/local/include/onnxruntime/core/framework/endian.h
-- Installing: /usr/local/include/onnxruntime/core/framework/execution_provider.h
-- Installing: /usr/local/include/onnxruntime/core/framework/fence.h
-- Installing: /usr/local/include/onnxruntime/core/framework/framework_common.h
-- Installing: /usr/local/include/onnxruntime/core/framework/func_api.h
-- Installing: /usr/local/include/onnxruntime/core/framework/kernel_def_builder.h
-- Installing: /usr/local/include/onnxruntime/core/framework/kernel_registry.h
-- Installing: /usr/local/include/onnxruntime/core/framework/ml_value.h
-- Installing: /usr/local/include/onnxruntime/core/framework/op_kernel.h
-- Installing: /usr/local/include/onnxruntime/core/framework/op_kernel_info.h
-- Installing: /usr/local/include/onnxruntime/core/framework/op_node_proto_helper.h
-- Installing: /usr/local/include/onnxruntime/core/framework/ortdevice.h
-- Installing: /usr/local/include/onnxruntime/core/framework/ortmemoryinfo.h
-- Installing: /usr/local/include/onnxruntime/core/framework/run_options.h
-- Installing: /usr/local/include/onnxruntime/core/framework/sparse_tensor.h
-- Installing: /usr/local/include/onnxruntime/core/framework/tensor.h
-- Installing: /usr/local/include/onnxruntime/core/framework/tensor_shape.h
-- Installing: /usr/local/include/onnxruntime/core/providers/cpu
-- Installing: /usr/local/include/onnxruntime/core/providers/cpu/cpu_provider_factory.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer
-- Installing: /usr/local/include/onnxruntime/core/optimizer/graph_transformer.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/graph_transformer_level.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/graph_transformer_utils.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/rewrite_rule.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/rule_based_graph_transformer.h
-- Installing: /usr/local/include/onnxruntime/core/session
-- Installing: /usr/local/include/onnxruntime/core/session/automl_data_containers.h
-- Installing: /usr/local/include/onnxruntime/core/session/environment.h
-- Installing: /usr/local/include/onnxruntime/core/session/experimental_onnxruntime_cxx_api.h
-- Installing: /usr/local/include/onnxruntime/core/session/experimental_onnxruntime_cxx_inline.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_c_api.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_cxx_api.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_cxx_inline.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
-- Installing: /usr/local/lib/libonnxruntime.so.1.5.2
-- Installing: /usr/local/lib/libonnxruntime.so
-- Installing: /usr/local/bin/onnx_test_runner

安装完成。

相关推荐
Alidme25 分钟前
cs106x-lecture14(Autumn 2017)-SPL实现
c++·学习·算法·codestepbystep·cs106x
小王努力学编程26 分钟前
【算法与数据结构】单调队列
数据结构·c++·学习·算法·leetcode
reset20211 小时前
ubuntu离线安装ollama
linux·ubuntu·ollama
放氮气的蜗牛1 小时前
Linux命令终极指南:从入门到精通掌握150+核心指令
linux·运维·服务器
Zfox_2 小时前
【QT】信号与槽 & 窗口坐标
开发语言·c++·qt·qt5
DC_BLOG2 小时前
Linux-Ansible模块进阶
linux·运维·服务器·ansible
Imagine Miracle2 小时前
【Deepseek】Linux 本地部署 Deepseek
linux·运维·服务器
SuperPurse2 小时前
linux下查看当前用户、所有用户的方法
linux·运维·服务器
Once_day2 小时前
linux之perf(17)PMU事件采集脚本
linux·运维·perf
m0_747124532 小时前
Linux 驱动入门(5)—— DHT11(温湿度传感器)驱动
linux·linux驱动