visual studio配置libtorch

1、libtorch找到与自己cuda相匹配的版本;

2、配置visual studio:

1)配置包含目录

2)配置库目录:

3)配置链接器:

也可以输入自己所需的lib文件名:

复制代码
asmjit.lib
c10.lib
c10_cuda.lib
caffe2_nvrtc.lib
cpuinfo.lib
dnnl.lib
fbgemm.lib
fmt.lib
kineto.lib
libprotobuf.lib
libprotobuf-lite.lib
libprotoc.lib
microkernels-prod.lib
pthreadpool.lib
sleef.lib
torch.lib
torch_cpu.lib
torch_cuda.lib
XNNPACK.lib

4)配置动态链接库:

动态链接库需要放入指定位置,有三种做法:

【1】直接将libtorch所需的dll文件放入与生成的exe文件同一个文件夹内;

【2】将libtorch的bin目录配置到windows的系统环境变量的path中,注意需要刷新系统环境变量或者重启系统才能生效。

【3】将libtorch的bin目录配置到visual studio的"环境"属性中:

复制代码
PATH=E:\vs_prj\3rdparty\libtorch2.6.0_cu11.8\bin\release;%PATH%

4、libtorch的测试代码:

cpp 复制代码
#include<torch/torch.h>
#include<torch/script.h>

int main() 
{
    std::cout << "cuda::is_available():\t" << torch::cuda::is_available() << "\n";
    std::cout << "cuda::cudnn is_available():\t" << torch::cuda::cudnn_is_available() << "\n";
    std::cout << "cuda::device():\t" << torch::cuda::device_count() << "\n";

    auto a = torch::rand({ 8, 16 });
    if (torch::cuda::is_available()) 
    {
        std::cout << "cuda available" << std::endl;
    }
    else
    {
        std::cout << "cuda not available" << std::endl;
    }
    std::cout << a << std::endl;

    torch::Tensor tensor = torch::eye(3);
    std::cout << tensor << std::endl;

    return 0;
}

运行结果:

5、最后,如果发现配置好了libtorch后,libtorch的cuda仍然是不可用的,那么只需要添加

复制代码
/INCLUDE:?warp_size@cuda@at@@YAHXZ
相关推荐
一点一一2 小时前
nestjs+langchain:大模型的基本调用、对message的
人工智能·后端
昊星自动化2 小时前
以房间为单元,筑稳GMP安全屏障-洁净区域风量压差控制技术方案概述
人工智能·国产替代·文丘里阀·实验室通风系统·蝶阀
总写bug的程序员2 小时前
用 AI 蒸馏球员的思维操作系统:qiuyuan-skill 技术解析
人工智能·unity·游戏引擎
超级AI_mes2 小时前
化工MES解决方案:从配方管控到安全追溯的智慧转型
大数据·人工智能·5g·能源·制造·业界资讯·设备采集
光影少年2 小时前
Python+LangGraph学习路线及发展前景
开发语言·人工智能·python·学习
七夜zippoe2 小时前
OpenClaw Webhook 与 Hooks 机制详解
人工智能·架构·webhook·hooks·openclaw
天天进步20152 小时前
不止于 UI:OpenWork 的核心哲学与“引擎+外壳”架构全景图
人工智能·ui·架构
刘 大 望2 小时前
RAG相关技术介绍及Spring AI中使用--第三期
java·人工智能·后端·spring·机器学习·ai·aigc
Mr数据杨2 小时前
成人收入预测建模与信用评估应用
大数据·人工智能·机器学习·数据分析·kaggle