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
相关推荐
临床数据科学和人工智能兴趣组1 分钟前
399元现在超值!学R语言,订阅我们专栏就够了,包括了所有的内容,不断更新!
人工智能·数据挖掘·r语言·r语言-4.2.1·临床研究
sjh7524229692 分钟前
Deepseek Harness的四种模式
人工智能
一比七品牌咨询3 分钟前
科技企业品牌定位:如何把技术优势转化为品牌优势?
大数据·人工智能·品牌策划·品牌全案策划·深圳品牌策划公司·品牌定位
一木 之林3 分钟前
深度学习-计算优化与分布式训练-111-128
人工智能·深度学习
BingoGo6 分钟前
一个ChatGPT 超级省额度方案!用 TaskQuay 连接网页 ChatGPT 和本地 Codex
人工智能·后端
万象新讯7 分钟前
自筹资金、加速器孵化和获得融资的创业公司,可以分别申请哪些AWS扶持政策?
人工智能
Thomas.Sir7 分钟前
第49课:TensorFlow|项目性能调优全方案【训练提速、推理提速、资源占用优化】
人工智能·python·tensorflow
海宇数据8 分钟前
零信任架构实战:基于海宇对外投资历史查询服务构建自动化异动企业筛查网关
运维·人工智能·架构·自动化
郝学胜-神的一滴10 分钟前
C++11 工程级应用 12:编译期类型魔法,干掉重复与臃肿的代码
开发语言·数据结构·c++·软件工程·visual studio