VS2022+libtorch+Cuda11.3安裝測試教程詳解(調(diào)用cuda)
以下內(nèi)容默認(rèn)cuda已經(jīng)安裝完成并添加至系統(tǒng)環(huán)境變量
1.下載libtorch
在官網(wǎng)下載壓縮包, 可以選擇Release版或者Debug版(根據(jù)自己需要):

下載完成之后選擇安裝軟件的位置進(jìn)行解壓
2.配置VC++目錄:
VS新建空項(xiàng)目
2.1添加包含目錄:
D:\soft\libtorch\libtorch\include
D:\soft\libtorch\libtorch\include\torch\csrc\api\include

2.2添加庫目錄:
D:\soft\libtorch\libtorch\lib

3.配置環(huán)境變量:
PATH=D:\soft\libtorch\libtorch\lib;%PATH%

4.配置鏈接器: 4.1鏈接器--input
D:\soft\libtorch\libtorch\lib\*.lib

4.2鏈接器--Command Line
/INCLUDE:?warp_size@cuda@at@@YAHXZ /INCLUDE:?_torch_cuda_cu_linker_symbol_op_cuda@native@at@@YA?AVTensor@2@AEBV32@@Z

5.測試配置結(jié)果:
#include<torch/torch.h>
#include<torch/script.h>
#include<iostream>
int main() {
std::cout << "cuda::is_available():" << torch::cuda::is_available() << std::endl;
std::cout << "torch::cuda::cudnn_is_available():" << torch::cuda::cudnn_is_available() << std::endl;
std::cout << "torch::cuda::device_count():" << torch::cuda::device_count() << std::endl;
torch::Device device(torch::kCUDA);
torch::Tensor tensor1 = torch::eye(3); // (A) tensor-cpu
torch::Tensor tensor2 = torch::eye(3, device); // (B) tensor-cuda
std::cout << tensor1 << std::endl;
std::cout << tensor2 << std::endl;
}正常結(jié)果輸出如下:

參考:
Libtorch + vs 2019安裝及配置_開拓者5號的博客-CSDN博客_vs2019配置libtorch
Win10+libtorch+CUDA+vs2017_大智若魚.AI的博客-CSDN博客
win10系統(tǒng)上LibTorch的安裝和使用(cuda10.1版本)_*匿名*的博客-CSDN博客_cuda libtorch
c10::NotImplementedError with minimal example - C++ - PyTorch Forums
到此這篇關(guān)于VS2022+libtorch+Cuda11.3安裝測試(調(diào)用cuda)的文章就介紹到這了,更多相關(guān)VS2022 libtorch Cuda11.3安裝內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C語言實(shí)例問題探究字符串函數(shù)的應(yīng)用
字符串函數(shù)(String processing function)也叫字符串處理函數(shù),指的是編程語言中用來進(jìn)行字符串處理的函數(shù),如C,pascal,Visual以及LotusScript中進(jìn)行字符串拷貝,計(jì)算長度,字符查找等的函數(shù)2022-04-04
深入解析C++11?lambda表達(dá)式/包裝器/線程庫
這篇文章主要介紹了C++11?lambda表達(dá)式/包裝器/線程庫的相關(guān)知識,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05
C++?通過pqxxlib庫鏈接?PostgreSql數(shù)據(jù)庫的詳細(xì)過程
這篇文章主要介紹了C++?通過pqxxlib庫鏈接?PostgreSql數(shù)據(jù)庫,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04

