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
相关推荐
deepdata_cn1 分钟前
从弱AI到强AI:符号推理是实现通用人工智能AGI的关键钥匙
人工智能·agi·符号推理
richard_first2 分钟前
第5章 Attention 的思想
人工智能·深度学习·transformer
AI英德西牛仔2 分钟前
秘塔 导出word指令之外:AI导出鸭电脑版的底层逻辑与批量交付哲学
人工智能·word·excel·deepseek·ai导出鸭
老白说数智化升级6 分钟前
AI与人工如何并行,Operation Agent Brain如何让制造运营持续优化?
人工智能·制造
小小测试开发7 分钟前
AI 安全测试:腾讯开源 A.I.G 平台拆解——2000+ CVE 规则与 LLM 审计的双引擎协作
人工智能·开源
guwentian14 分钟前
从0到1手写 AI Agent Harness:为什么护城河不在模型,而在工程外壳
人工智能·python·安全·deepseek·harness
独隅15 分钟前
从 Copilot 到 Agent:AI 驱动下的开发工作流重构实战
人工智能·重构·copilot
Summer-Bright15 分钟前
独立 AI 浏览器之死与「内嵌化」之生:Atlas 关停、Comet 免费化、豆包虚拟桌面,入口之争的终局
人工智能·ai·ai 浏览器
淳悦qiqi17 分钟前
2026依托技术优势高准确率语音识别软件多场景让信息整理更省事更清晰
人工智能·语音识别
云浪18 分钟前
给大模型装上"手":三分钟看懂 AI Agent 的 Tool 工具调用
javascript·人工智能·node.js