Skip to content

Commit 8027e04

Browse files
authored
Upgrade to libtorch v1.10.1 (#93)
* Upgrade to libtorch v1.10.1. * Add option to download libtorch 1.10.1 for CUDA 11.1.
1 parent 424f23b commit 8027e04

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
77
option(DOWNLOAD_DATASETS "Automatically download required datasets at build-time." ON)
88
option(CREATE_SCRIPTMODULES "Automatically create all required scriptmodule files at build-time (requires python3)." OFF)
99

10-
set(PYTORCH_VERSION "1.9.0")
10+
set(PYTORCH_VERSION "1.10.1")
1111

1212
find_package(Torch ${PYTORCH_VERSION} EXACT QUIET PATHS "${CMAKE_SOURCE_DIR}/libtorch")
1313

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ RUN curl --silent --show-error --location --output ~/miniconda.sh https://repo.a
3131

3232
FROM conda AS conda-installs
3333
# Install pytorch for CPU and torchvision.
34-
ARG PYTORCH_VERSION=1.9.0
35-
ARG TORCHVISION_VERSION=0.10.0
34+
ARG PYTORCH_VERSION=1.10.1
35+
ARG TORCHVISION_VERSION=0.11.2
3636
ENV NO_CUDA=1
3737
RUN conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cpuonly -y -c pytorch && conda clean -ya
3838

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
C++ Implementation of PyTorch Tutorials for Everyone
66
<br />
77
<img src="https://img.shields.io/github/license/prabhuomkar/pytorch-cpp">
8-
<img src="https://img.shields.io/badge/libtorch-1.9.0-ee4c2c">
8+
<img src="https://img.shields.io/badge/libtorch-1.10.1-ee4c2c">
99
<img src="https://img.shields.io/badge/cmake-3.14-064f8d">
1010
</p>
1111

1212

13-
| OS (Compiler)\\LibTorch | 1.9.0 |
13+
| OS (Compiler)\\LibTorch | 1.10.1 |
1414
| :--------------------- | :--------------------------------------------------------------------------------------------------- |
1515
| macOS (clang 10.0, 11.0, 12.0) | [![Status](https://github.com/prabhuomkar/pytorch-cpp/actions/workflows/build_macos.yml/badge.svg?branch=master)](https://github.com/prabhuomkar/pytorch-cpp/actions?query=workflow%3Aci-build-macos) |
1616
| Linux (gcc 8, 9, 10, 11) | [![Status](https://github.com/prabhuomkar/pytorch-cpp/actions/workflows/build_ubuntu.yml/badge.svg?branch=master)](https://github.com/prabhuomkar/pytorch-cpp/actions?query=workflow%3Aci-build-ubuntu) |
@@ -52,7 +52,7 @@ This repository provides tutorial code in C++ for deep learning researchers to l
5252

5353
1. [C++-17](http://www.cplusplus.com/doc/tutorial/introduction/) compatible compiler
5454
2. [CMake](https://cmake.org/download/) (minimum version 3.14)
55-
3. [LibTorch v1.9.0](https://pytorch.org/cppdocs/installing.html)
55+
3. [LibTorch v1.10.1](https://pytorch.org/cppdocs/installing.html)
5656
4. [Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html)
5757

5858

@@ -89,11 +89,12 @@ Some useful options:
8989

9090
| Option | Default | Description |
9191
| :------------- |:------------|-----:|
92-
| `-D CUDA_V=(\|10.2\|11.1\|none)` | `none` | Download LibTorch for a CUDA version (`none` = download CPU version). |
92+
| `-D CUDA_V=(10.2\|11.1\|11.3\|none)` | `none` | Download LibTorch for a CUDA version (`none` = download CPU version). |
93+
| `-D LIBTORCH_DOWNLOAD_BUILD_TYPE=(Release\|Debug)` | `Release` | Determines which libtorch build type version to download (only relevant on **Windows**).|
9394
| `-D DOWNLOAD_DATASETS=(OFF\|ON)` | `ON` | Download required datasets during build (only if they do not already exist in `pytorch-cpp/data`). |
9495
|`-D CREATE_SCRIPTMODULES=(OFF\|ON)` | `OFF` | Create all required scriptmodule files for prelearned models / weights during build. Requires installed python3 with pytorch and torchvision. |
9596
| `-D CMAKE_PREFIX_PATH=path/to/libtorch/share/cmake/Torch` | `<empty>` | Skip the downloading of LibTorch and use your own local version (see [Requirements](#requirements)) instead. |
96-
| `-D CMAKE_BUILD_TYPE=(Release\|Debug)` | `<empty>` (`Release` when downloading LibTorch on Windows) | Set the build type (`Release` = compile with optimizations).|
97+
| `-D CMAKE_BUILD_TYPE=(Release\|Debug\|...)` | `<empty>` | Determines the CMake build-type for single-configuration generators (see [CMake docs](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html)).|
9798

9899
<details>
99100
<summary><b>Example Linux</b></summary>
@@ -115,14 +116,14 @@ cmake -B build \
115116
<summary><b>Example Windows</b></summary>
116117

117118
##### Aim
118-
* Automatically download LibTorch for CUDA 11.1 and all necessary datasets.
119+
* Automatically download LibTorch for CUDA 11.3 (Release version) and all necessary datasets.
119120
* Do not create scriptmodule files.
120121

121122
##### Command
122123
```bash
123124
cmake -B build \
124125
-A x64 \
125-
-D CUDA_V=11.1
126+
-D CUDA_V=11.3
126127
```
127128
</details>
128129

cmake/fetch_libtorch.cmake

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

33
include(FetchContent)
44

5-
set(CUDA_V "none" CACHE STRING "Determines libtorch CUDA version to download (10.2, 11.1 or none).")
5+
set(CUDA_V "none" CACHE STRING "Determines libtorch CUDA version to download (10.2, 11.1, 11.3 or none).")
66

77
if(${CUDA_V} STREQUAL "none")
88
set(LIBTORCH_DEVICE "cpu")
99
elseif(${CUDA_V} STREQUAL "10.2")
1010
set(LIBTORCH_DEVICE "cu102")
1111
elseif(${CUDA_V} STREQUAL "11.1")
1212
set(LIBTORCH_DEVICE "cu111")
13+
elseif(${CUDA_V} STREQUAL "11.3")
14+
set(LIBTORCH_DEVICE "cu113")
1315
else()
14-
message(FATAL_ERROR "Invalid CUDA version specified, must be 10.2, 11.1 or none!")
15-
endif()
16-
17-
if(NOT ${LIBTORCH_DEVICE} STREQUAL "cu102")
18-
set(LIBTORCH_DEVICE_TAG "%2B${LIBTORCH_DEVICE}")
16+
message(FATAL_ERROR "Invalid CUDA version specified, must be 10.2, 11.1, 11.3 or none!")
1917
endif()
2018

2119
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
22-
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/${LIBTORCH_DEVICE}/libtorch-win-shared-with-deps-${PYTORCH_VERSION}${LIBTORCH_DEVICE_TAG}.zip")
23-
set(CMAKE_BUILD_TYPE "Release")
20+
set(LIBTORCH_DOWNLOAD_BUILD_TYPE "Release" CACHE STRING "Determines whether to download Release (default) or Debug libtorch version.")
21+
22+
if(${LIBTORCH_DOWNLOAD_BUILD_TYPE} STREQUAL "Debug")
23+
set(LIBTORCH_DOWNLOAD_BUILD_TYPE_TAG "debug-")
24+
elseif(${LIBTORCH_DOWNLOAD_BUILD_TYPE} STREQUAL "Release")
25+
set(LIBTORCH_DOWNLOAD_BUILD_TYPE_TAG "")
26+
else()
27+
message(FATAL_ERROR "Invalid libtorch build type, must be either Release or Debug.")
28+
endif()
29+
30+
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/${LIBTORCH_DEVICE}/libtorch-win-shared-with-deps-${LIBTORCH_DOWNLOAD_BUILD_TYPE_TAG}${PYTORCH_VERSION}%2B${LIBTORCH_DEVICE}.zip")
2431
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
25-
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/${LIBTORCH_DEVICE}/libtorch-shared-with-deps-${PYTORCH_VERSION}${LIBTORCH_DEVICE_TAG}.zip")
32+
set(LIBTORCH_URL "https://download.pytorch.org/libtorch/${LIBTORCH_DEVICE}/libtorch-shared-with-deps-${PYTORCH_VERSION}%2B${LIBTORCH_DEVICE}.zip")
2633
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
2734
if(NOT ${LIBTORCH_DEVICE} STREQUAL "cpu")
2835
message(WARNING "MacOS binaries do not support CUDA, will download CPU version instead.")

0 commit comments

Comments
 (0)