Skip to content

Commit a98e42d

Browse files
authored
Upgrade libtorch v2.0.0 (#108)
* Upgrade to libtorch v2.0.0. * Add torch cxx flags. * Add pthread cxx flag on Linux.
1 parent 7a5d057 commit a98e42d

File tree

5 files changed

+391
-236
lines changed

5 files changed

+391
-236
lines changed

CMakeLists.txt

Lines changed: 6 additions & 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.13.1")
10+
set(PYTORCH_VERSION "2.0.0")
1111
set(PYTORCH_MIN_VERSION "1.12.0")
1212

1313
find_package(Torch QUIET PATHS "${CMAKE_SOURCE_DIR}/libtorch")
@@ -20,6 +20,11 @@ if((NOT Torch_FOUND) OR (("${Torch_VERSION}" VERSION_LESS "${PYTORCH_MIN_VERSION
2020
endif()
2121

2222
message(STATUS "Torch version ${Torch_VERSION}")
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
24+
25+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
27+
endif()
2328

2429
if(CREATE_SCRIPTMODULES)
2530
find_package(Python3 COMPONENTS Interpreter REQUIRED)

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.13.1
35-
ARG TORCHVISION_VERSION=0.14.1
34+
ARG PYTORCH_VERSION=2.0.0
35+
ARG TORCHVISION_VERSION=0.15.1
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: 6 additions & 6 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.13.1-ee4c2c">
8+
<img src="https://img.shields.io/badge/libtorch-2.0.0-ee4c2c">
99
<img src="https://img.shields.io/badge/cmake-3.14-064f8d">
1010
</p>
1111

1212

13-
| OS (Compiler)\\LibTorch | 1.13.1 |
13+
| OS (Compiler)\\LibTorch | 2.0.0 |
1414
| :--------------------- | :--------------------------------------------------------------------------------------------------- |
1515
| macOS (clang 11, 12, 13) | [![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 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 version >= 1.12.0 and <= 1.13.1](https://pytorch.org/cppdocs/installing.html)
55+
3. [LibTorch version >= 1.12.0 and <= 2.0.0](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,7 +89,7 @@ Some useful options:
8989

9090
| Option | Default | Description |
9191
| :------------- |:------------|-----:|
92-
| `-D CUDA_V=(11.6\|11.7\|none)` | `none` | Download LibTorch for a CUDA version (`none` = download CPU version). |
92+
| `-D CUDA_V=(11.7\|11.8\|none)` | `none` | Download LibTorch for a CUDA version (`none` = download CPU version). |
9393
| `-D LIBTORCH_DOWNLOAD_BUILD_TYPE=(Release\|Debug)` | `Release` | Determines which libtorch build type version to download (only relevant on **Windows**).|
9494
| `-D DOWNLOAD_DATASETS=(OFF\|ON)` | `ON` | Download required datasets during build (only if they do not already exist in `pytorch-cpp/data`). |
9595
|`-D CREATE_SCRIPTMODULES=(OFF\|ON)` | `OFF` | Create all required scriptmodule files for prelearned models / weights during build. Requires installed python3 with pytorch and torchvision. |
@@ -116,14 +116,14 @@ cmake -B build \
116116
<summary><b>Example Windows</b></summary>
117117

118118
##### Aim
119-
* Automatically download LibTorch for CUDA 11.7 (Release version) and all necessary datasets.
119+
* Automatically download LibTorch for CUDA 11.8 (Release version) and all necessary datasets.
120120
* Do not create scriptmodule files.
121121

122122
##### Command
123123
```bash
124124
cmake -B build \
125125
-A x64 \
126-
-D CUDA_V=11.7
126+
-D CUDA_V=11.8
127127
```
128128
</details>
129129

cmake/fetch_libtorch.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ 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 (11.6, 11.7 or none).")
5+
set(CUDA_V "none" CACHE STRING "Determines libtorch CUDA version to download (11.7, 11.8 or none).")
66

77
if(${CUDA_V} STREQUAL "none")
88
set(LIBTORCH_DEVICE "cpu")
9-
elseif(${CUDA_V} STREQUAL "11.6")
10-
set(LIBTORCH_DEVICE "cu116")
119
elseif(${CUDA_V} STREQUAL "11.7")
1210
set(LIBTORCH_DEVICE "cu117")
11+
elseif(${CUDA_V} STREQUAL "11.8")
12+
set(LIBTORCH_DEVICE "cu118")
1313
else()
14-
message(FATAL_ERROR "Invalid CUDA version specified, must be 11.6, 11.7 or none!")
14+
message(FATAL_ERROR "Invalid CUDA version specified, must be 11.7, 11.8 or none!")
1515
endif()
1616

1717
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")

0 commit comments

Comments
 (0)