个人环境配置--安装记录

news2025/2/23 13:02:30

根据显卡下载对应的cuda和cudnn
我使用的是docker,首先拉取镜像,我用的是ubuntu20.04
加速:pull hub.1panel.dev/
devel是开发版本

sudo docker pull hub.1panel.dev/nvidia/cuda:11.6.1-devel-ubuntu20.04

先测试一下cuda有没有安装好

nvcc -V

更新,安装 vim、 wget

apt update
apt install vim wget

安装cudnn
cudnn下载网址:https://developer.nvidia.com/rdp/cudnn-archive

# 解压
tar -xf cudnn-linux-x86_64-8.9.7.29_cuda11-archive.tar.xz
# cd进入文件
cd cudnn-linux-x86_64-8.9.7.29_cuda11-archive 
# 将include/cudnn.h文件复制到usr/local/cuda/include文件夹
cp include/cudnn.h /usr/local/cuda-11.6/include
#将lib下所有文件复制到/usr/local/cuda/lib64文件夹中
cp lib/libcudnn* /usr/local/cuda-11.6/lib64 
# 添加读取权限
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

安装cmake
直接参考之前的博客:https://blog.csdn.net/qq_42102546/article/details/135014765

安装minni conda3

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

激活环境

source /root/miniconda3/bin/activate

创建虚拟环境

conda create -n py_17 python=3.9

进入虚拟环境

conda activate py_17

安装yolo环境

pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple

安装onnxruntime-gpu

pip install onnxruntime-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple

安装cv2的依赖

apt install libglib2.0-0 libgl1-mesa-glx

测试:

import torch
import os
import cv2

print(torch.__version__)  # 确认 PyTorch 版本
cuda_available = torch.cuda.is_available()
if cuda_available:
    print("安装的是 GPU 版本的 PyTorch,当前可用的 GPU 数量为:", torch.cuda.device_count())
    print("当前使用的 GPU 名称为:", torch.cuda.get_device_name(0))
else:
    print("安装的是 CPU 版本的 PyTorch")
    
#  使用GPU进行计算
os.environ['CUDA_LAUNCH_BLOCKING'] = "0"
print(torch.rand(1).cuda())
a = torch.Tensor([1, 2])
a = a.cuda()
print(a)
# 查看 torch版本
print(torch.__version__)
# 查看cuda是否可用
device = torch.device('cuda')
print(torch.cuda.is_available())
print("结束")


print(cv2.__version__)
print(cv2.cuda.getCudaEnabledDeviceCount())

import onnxruntime as ort
import tensorrt
print(ort.get_device())
print(ort.get_available_providers())
print(tensorrt.__version__ )

tensorRT还没有安装,报错没有关系,等都安装好了还用这个做测试。
安装c++的opencv 可以直接看之前的博客:https://blog.csdn.net/qq_42102546/article/details/145717954

tensorRT 下载网址:https://developer.nvidia.cn/tensorrt
根据你的cuda版本去下载,我的是cuda11.6
在这里插入图片描述
下载后解压

tar -zxvf TensorRT-8.6.0.12.Linux.x86_64-gnu.cuda-11.8.tar.gz

然后复制到 /usr/local 这只是个人喜好,你可以直接配置环境变量

cd TensorRT-8.6.0.12
cp ./* /usr/local

配置环境变量

vim ~/.bashrc

键盘大写“G”,在最末端输入

export LD_LIBRARY_PATH=$PATH:/usr/local/TensorRT-8.6.0.12/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$PATH:/usr/local/TensorRT-8.6.0.12/lib::$LIBRARY_PATH

cuda也可以加上

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

使其生效:

source ~/.bashrc

测试

cd /usr/local/TensorRT-8.6.0.12/samples/sampleOnnxMNIST; make; ../../bin/sample_onnx_mnist

输出结果:
在这里插入图片描述
c++测试
CMakeLists.txt 文件内容

cmake_minimum_required(VERSION 3.16)
project(first_cmake)

# 查找 OpenCV
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV version: ${OpenCV_VERSION}")
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
message(STATUS "OpenCV include path: ${OpenCV_INCLUDE_DIRS}")

# 查找 CUDA
find_package(CUDA REQUIRED)
message(STATUS "CUDA version: ${CUDA_VERSION}")
message(STATUS "CUDA libraries: ${CUDA_LIBRARIES}")
message(STATUS "CUDA include path: ${CUDA_INCLUDE_DIRS}")

# 查找线程库
find_package(Threads REQUIRED)

# 设置 TensorRT 路径
set(TENSORRT_INCLUDE_DIR /usr/local/TensorRT-8.6.0.12/include)
set(TENSORRT_LIBRARY_DIR /usr/local/TensorRT-8.6.0.12/lib)

# 包含 TensorRT 头文件路径
include_directories(${TENSORRT_INCLUDE_DIR})

# 链接 TensorRT 库路径
link_directories(${TENSORRT_LIBRARY_DIR})

# 添加可执行文件
add_executable(first_cmake open_ce.cpp)

# 链接库
target_link_libraries(first_cmake ${OpenCV_LIBS} Threads::Threads nvinfer nvinfer_plugin ${CUDA_LIBRARIES})

# 包含头文件目录
target_include_directories(first_cmake PRIVATE ${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} ${TENSORRT_INCLUDE_DIR})

open_ce.cpp 文件内容

#include <iostream>
#include <NvInfer.h>
#include <cuda_runtime_api.h>

// 自定义日志记录器
class Logger : public nvinfer1::ILogger {
    void log(Severity severity, const char* msg) noexcept override {
        if (severity != Severity::kINFO) {
            std::cerr << msg << std::endl;
        }
    }
};

int main() {
    // 创建日志记录器
    Logger logger;

    // 创建构建器
    nvinfer1::IBuilder* builder = nvinfer1::createInferBuilder(logger);
    if (!builder) {
        std::cerr << "Failed to create TensorRT builder." << std::endl;
        return -1;
    }

    // 创建网络定义
    const auto explicitBatch = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
    nvinfer1::INetworkDefinition* network = builder->createNetworkV2(explicitBatch);
    if (!network) {
        std::cerr << "Failed to create TensorRT network." << std::endl;
        builder->destroy();
        return -1;
    }

    // 创建输入张量
    nvinfer1::ITensor* input = network->addInput("input", nvinfer1::DataType::kFLOAT, nvinfer1::Dims4{1, 1, 1, 1});
    if (!input) {
        std::cerr << "Failed to create input tensor." << std::endl;
        network->destroy();
        builder->destroy();
        return -1;
    }

    // 添加一个恒等层(Identity Layer)
    nvinfer1::IIdentityLayer* identityLayer = network->addIdentity(*input);
    if (!identityLayer) {
        std::cerr << "Failed to add identity layer." << std::endl;
        network->destroy();
        builder->destroy();
        return -1;
    }

    // 获取恒等层的输出张量
    nvinfer1::ITensor* output = identityLayer->getOutput(0);
    output->setName("output");

    // 标记输出张量
    network->markOutput(*output);

    // 创建构建配置
    nvinfer1::IBuilderConfig* config = builder->createBuilderConfig();
    if (!config) {
        std::cerr << "Failed to create TensorRT builder config." << std::endl;
        network->destroy();
        builder->destroy();
        return -1;
    }

    // 构建引擎
    nvinfer1::ICudaEngine* engine = builder->buildEngineWithConfig(*network, *config);
    if (!engine) {
        std::cerr << "Failed to build TensorRT engine." << std::endl;
        config->destroy();
        network->destroy();
        builder->destroy();
        return -1;
    }

    // 创建推理上下文
    nvinfer1::IExecutionContext* context = engine->createExecutionContext();
    if (!context) {
        std::cerr << "Failed to create TensorRT execution context." << std::endl;
        engine->destroy();
        return -1;
    }

    // 准备输入和输出数据
    float inputData[1] = {1.0f};  // 输入数据
    float outputData[1];          // 输出数据

    // 分配 CUDA 内存
    void* d_input;
    void* d_output;
    cudaMalloc(&d_input, sizeof(float));
    cudaMalloc(&d_output, sizeof(float));

    // 将输入数据从主机内存复制到设备内存
    cudaMemcpy(d_input, inputData, sizeof(float), cudaMemcpyHostToDevice);

    // 定义输入和输出缓冲区指针
    void* buffers[2];
    buffers[0] = d_input;   // 输入缓冲区
    buffers[1] = d_output;  // 输出缓冲区

    // 执行推理
    context->enqueueV2(buffers, 0, nullptr);

    // 将输出数据从设备内存复制到主机内存
    cudaMemcpy(outputData, d_output, sizeof(float), cudaMemcpyDeviceToHost);

    // 输出结果
    std::cout << "Output: " << outputData[0] << std::endl;

    // 释放 CUDA 内存
    cudaFree(d_input);
    cudaFree(d_output);

    // 释放资源
    context->destroy();
    engine->destroy();
    config->destroy();
    network->destroy();
    builder->destroy();

    return 0;
}

在这里插入图片描述
在这里插入图片描述
Trying to load shared library libnvinfer_builder_resource.so.8.6.0
Loaded shared library libnvinfer_builder_resource.so.8.6.0
CUDA lazy loading is enabled.
Original: 1 layers
After dead-layer removal: 1 layers
Graph construction completed in 0.00158627 seconds.
Running: IdentityToCastTransform on (Unnamed Layer* 0) [Identity]
Swap the layer type of (Unnamed Layer* 0) [Identity] from IDENTITY to CAST
After Myelin optimization: 1 layers
Applying ScaleNodes fusions.
After scale fusion: 1 layers
Running: CastToCopyTransform on (Unnamed Layer* 0) [Identity]
Swap the layer type of (Unnamed Layer* 0) [Identity] from CAST to CAST
After dupe layer removal: 1 layers
After final dead-layer removal: 1 layers
After tensor merging: 1 layers
After vertical fusions: 1 layers
After dupe layer removal: 1 layers
After final dead-layer removal: 1 layers
After tensor merging: 1 layers
After slice removal: 1 layers
After concat removal: 1 layers
Trying to split Reshape and strided tensor
Building graph using backend strategy 2
Constructing optimization profile number 0 [1/1].
Applying generic optimizations to the graph for inference.
Reserving memory for host IO tensors. Host: 0 bytes
=============== Computing reformatting costs
=============== Computing reformatting costs:
*************** Autotuning Reformat: Float(1,1,1,1) -> Float(1,1,1,1) ***************
--------------- Timing Runner: (Unnamed Layer* 0) [Identity] (Reformat[0x80000006])
Tactic: 0x00000000000003e8 Time: 0.0122651
Tactic: 0x00000000000003ea Time: 0.0224988
Tactic: 0x0000000000000000 Time: 0.00841467
(Unnamed Layer* 0) [Identity] (Reformat[0x80000006]) profiling completed in 0.0247727 seconds. Fastest Tactic: 0x0000000000000000 Time: 0.00841467
--------------- Timing Runner: (Unnamed Layer* 0) [Identity] (MyelinReformat[0x80000035])
(foreignNode) Set user’s cuda kernel library
(foreignNode) Pass fuse_conv_padding is currently skipped for dynamic shapes
(foreignNode) Pass pad_conv_channel is currently skipped for dynamic shapes
(foreignNode) Pass fuse_conv_padding is currently skipped for dynamic shapes
(foreignNode) Pass pad_conv_channel is currently skipped for dynamic shapes
Tactic: 0x0000000000000000 Time: 0.00626647
(Unnamed Layer* 0) [Identity] (MyelinReformat[0x80000035]) profiling completed in 0.3183 seconds. Fastest Tactic: 0x0000000000000000 Time: 0.00626647

Chose Runner Type: MyelinReformat Tactic: 0x0000000000000000
Formats and tactics selection completed in 0.343932 seconds.
After reformat layers: 1 layers
Total number of blocks in pre-optimized block assignment: 1
(foreignNode) Set user’s cuda kernel library
(foreignNode) Pass fuse_conv_padding is currently skipped for dynamic shapes
(foreignNode) Pass pad_conv_channel is currently skipped for dynamic shapes
(foreignNode) Pass fuse_conv_padding is currently skipped for dynamic shapes
(foreignNode) Pass pad_conv_channel is currently skipped for dynamic shapes
Layer: (Unnamed Layer* 0) [Identity] Host Persistent: 32 Device Persistent: 0 Scratch Memory: 0
Skipped printing memory information for 0 layers with 0 memory size i.e. Host Persistent + Device Persistent + Scratch Memory == 0.
Total number of blocks in optimized block assignment: 0
Total number of generated kernels selected for the engine: 0
Disabling unused tactic source: EDGE_MASK_CONVOLUTIONS
Disabling unused tactic source: JIT_CONVOLUTIONS
Engine generation completed in 0.522099 seconds.
Deleting timing cache: 1 entries, served 0 hits since creation.
Engine Layer Information:
Layer(MyelinReformat): (Unnamed Layer* 0) [Identity], Tactic: 0x0000000000000000, input (Float[1,1,1,1]) -> output (Float[1,1,1,1])
Total per-runner device persistent memory is 0
Total per-runner host persistent memory is 32
Allocated activation device memory of size 0
CUDA lazy loading is enabled.
Output: 1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2303919.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

win10把c盘docker虚拟硬盘映射迁移到别的磁盘

c盘空间本身就比较小、如果安装了docker服务后&#xff0c;安装的时候没选择其他硬盘&#xff0c;虚拟磁盘也在c盘会占用很大的空间&#xff0c;像我的就三十多个G&#xff0c;把它迁移到其他磁盘一下子节约几十G 1、先输入下面命令查看 docker 状态 wsl -l -v 2、如果没有停止…

开源的 LLM 应用开发平台-Dify 部署和使用

加粗样式 Dify 简介 官网 http://difyai.com/ 生成式 AI 应用创新引擎 开源的 LLM 应用开发平台 Dify 为开发者提供了健全的应用模版和编排框架&#xff0c;你可以基于它们快速构建大型语言模型驱动的生成式 AI 应用&#xff0c;将创意变为现实&#xff0c;也可以随时按需无…

libxls库的编译以及基于Visual studio的配置

最近有一个需求在windows处理xls&#xff0c;所以就需要libxls这个库&#xff0c;调查了一下&#xff0c;基于C的库的解析情况如下&#xff1a; 所以最理想的就是Libxlsd个开源的方案 基于历史整理的 libxls 在 MinGW 下的编译步骤 前提条件 系统&#xff1a;Windows&#…

抗辐照加固CAN FD芯片的商业航天与车规级应用解析

在工业自动化、智能汽车、航空航天及国防装备等关键领域&#xff0c;数据传输的安全性、可靠性与极端环境适应能力是技术升级的核心挑战。国科安芯推出全新一代CANFD&#xff08;Controller Area Network Flexible Data Rate&#xff09;芯片&#xff0c;以高安全、高可靠、断电…

Ollama+Deepseek+AnythingLLM搭建本地知识库

OllamaDeepseek的配置可以参考OllamaDeepseekopen-webui搭建本地知识库-CSDN博客 一&#xff0c;AnythingLLM安装 AnythingLLM官网地址AnythingLLM | The all-in-one AI application for everyone 下载 win64 下载完毕后安装。 二&#xff0c;AnythingLLM 配置 新建工作区 …

再探动态规划--背包问题

背包问题常见类型&#xff1a; 动态规划问题核心就两个&#xff1a;状态转移方程和遍历顺序 如果求组合数就是外层for循环遍历物品&#xff0c;内层for遍历背包。如果求排列数就是外层for遍历背包&#xff0c;内层for循环遍历物品。 状态转移方程是动态规划问题中的核心&…

Javascript使用Sodium库实现 aead_xchacha20poly1305_ietf加密解密,以及与后端的密文交互

Node.js环境安装 sodium-native (其他库可能会出现加密解密失败&#xff0c;如果要使用不一样的库&#xff0c;请自行验证) npm install sodium-native 示例代码&#xff0c;使用的是 sodium-native v4.3.2 (其他版本可能会有变化&#xff0c;如果要使用&#xff0c;请自行验…

【算法与数据结构】单调队列

目录 单调队列 使用单调队列维护滑动窗口 具体过程&#xff1a; 代码实现&#xff1a; 复杂度分析&#xff1a; 使用单调队列优化动态规划 例题 单调队列 单调队列(deque)是一种特殊的队列&#xff0c;队列中的元素始终按严格递增或者递减排列。这样就可以保证队头元素…

Mysql-------事务

事务 一、事务 &#xff08;一&#xff09;什么是事务&#xff1a; MySQL数据库事务&#xff1a;&#xff08;database transaction&#xff09;: 事务是由一组SQL语句组成的逻辑处理单元&#xff0c;这些操作要么全做要么全不做&#xff0c;是一个不可分割的工作单位。 ※…

基于Martin的全国基础底图实现

概述 前面有文章基于Martin实现MapboxGL自定义底图分享了Martin的使用&#xff0c;本文使用网络收集的数据实现了全国基础数据的收集和基础底图。 实现后效果 实现 1. 数据准备 实例中包含如下数据&#xff1a; 边界线和九段线数据省边界面数据省会城市点数据市边界面数据…

网络安全:防范NetBIOS漏洞的攻击

稍微懂点电脑知识的朋友都知道&#xff0c;NetBIOS 是计算机局域网领域流行的一种传输方式&#xff0c;但你是否还知道&#xff0c;对于连接互联网的机器来讲&#xff0c;NetBIOS是一大隐患。 漏洞描述 NetBIOS(Network Basic Input Output System&#xff0c;网络基本输入输…

一周学会Flask3 Python Web开发-客户端状态信息Cookie以及加密

锋哥原创的Flask3 Python Web开发 Flask3视频教程&#xff1a; 2025版 Flask3 Python web开发 视频教程(无废话版) 玩命更新中~_哔哩哔哩_bilibili HTTP是无状态&#xff08;stateless)协议。也就是说&#xff0c;在一次请求响应结束后&#xff0c;服务器不会留下任何关于对…

机器学习面试八股文——决战金三银四

大家好&#xff0c;这里是好评笔记&#xff0c;公主 号&#xff1a;Goodnote&#xff0c;专栏文章私信限时Free。本笔记的任务是解读机器学习实践/面试过程中可能会用到的知识点&#xff0c;内容通俗易懂&#xff0c;入门、实习和校招轻松搞定。 公主号合集地址 点击进入优惠地…

【Akashic Records】THE EGG

博客主页&#xff1a; [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: Akashic Records 文章目录 &#x1f4af;观后感一、宇宙的孤寂与个人成长&#xff1a;二、选择与责任&#xff1a;三、灵性与世界的连接&#xff1a;四、选择如何改变命运&#xff1a;结语&#xff1a; &#x1f4af;…

从零开始用react + tailwindcs + express + mongodb实现一个聊天程序(一)

项目包含5个模块 1.首页 (聊天主页) 2.注册 3.登录 4.个人资料 5.设置主题 一、配置开发环境 建立项目文件夹 mkdir chat-project cd chat-project mkdir server && mkdir webcd server npm init cd web npm create vitelatest 创建前端项目时我们选择javascrip…

ant design 疑惑记录 Dropdown.Button

onMenuClick是点击展开的 子项的点击事件 Actions的点击事件是什么&#xff1f; 解答&#xff1a; 也是个按钮Button&#xff0c;也有自己的onClick事件 const onMenuClick (e) > {console.log(click, e); }; const otherClick (e) > {console.log(其他操作主按钮…

SAP on Microsoft Azure Architecture and Administration (Ravi Kashyap)

SAP on Microsoft Azure Architecture and Administration (Ravi Kashyap)

Missing required prop: “maxlength“

背景&#xff1a; 封装一个使用功能相同使用频率较高的input公共组件作为子组件&#xff0c;大多数长度要求为200&#xff0c;且实时显示统计子数&#xff0c;部分input有输入提示。 代码实现如下&#xff1a; <template><el-input v-model"inputValue" t…

在windows下安装windows+Ubuntu16.04双系统(下)

这篇文章的内容主要来源于这篇文章&#xff0c;为正式安装windowsUbuntu16.04双系统部分。在正式安装前&#xff0c;若还没有进行前期准备工作&#xff08;1.分区2.制作启动u盘&#xff09;&#xff0c;见《在windows下安装windowsUbuntu16.04双系统(上)》 二、正式安装Ubuntu …

数据库驱动免费下载(Oracle、Mysql、达梦、Postgresql)

数据库驱动找起来好麻烦&#xff0c;我整理到了一起&#xff0c;需要的朋友免费下载&#xff1a;驱动下载 目前收录了Oracle、Mysql、达梦、Postgresql的数据库驱动的多个版本&#xff0c;后续可能会分享更多。