Skip to content

Commit fefb546

Browse files
mikaylagawareckipytorchmergebot
authored andcommitted
Add TORCH_TARGET_VERSION for stable ABI (pytorch#164356)
And update it so comparisons can be done by the preprocessor **Note: We also need to gate in shim.h and figure out how to enforce this** Differential Revision: [D85683549](https://our.internmc.facebook.com/intern/diff/D85683549) Pull Request resolved: pytorch#164356 Approved by: https://github.com/janeyx99
1 parent d6d6fa2 commit fefb546

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

torch/csrc/stable/ops.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,10 @@ inline torch::stable::Tensor clone(const torch::stable::Tensor& self) {
245245
return torch::stable::detail::to<torch::stable::Tensor>(stack[0]);
246246
}
247247

248+
#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_10_0
249+
250+
// New ops should be added here if they use a brand new shim API
251+
252+
#endif
253+
248254
HIDDEN_NAMESPACE_END(torch, stable)

torch/csrc/stable/version.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <torch/headeronly/version.h>
4+
5+
// Stable ABI Version Targeting
6+
//
7+
// This header provides version targeting capabilities for the PyTorch Stable
8+
// ABI. Users can define TORCH_TARGET_VERSION to target a specific stable ABI
9+
// version instead of using the current TORCH_ABI_VERSION of libtorch at
10+
// compile time.
11+
//
12+
// Usage:
13+
// Default behavior (uses current ABI version):
14+
// #include <torch/csrc/stable/library.h>
15+
//
16+
// Target a specific stable version (major.minor) (e.g. PyTorch 2.9):
17+
// (1) Pass a compiler flag -DTORCH_TARGET_VERSION=0x0209000000000000
18+
// (2) Alternatively, define TORCH_TARGET_VERSION in the source code before
19+
// including any header files:
20+
// #define TORCH_TARGET_VERSION (((0ULL + 2) << 56) | ((0ULL + 9) << 48))
21+
// #include <torch/csrc/stable/library.h>
22+
23+
#ifdef TORCH_TARGET_VERSION
24+
#define TORCH_FEATURE_VERSION TORCH_TARGET_VERSION
25+
#else
26+
#define TORCH_FEATURE_VERSION TORCH_ABI_VERSION
27+
#endif
28+
29+
#define TORCH_VERSION_2_10_0 (((0ULL + 2) << 56) | ((0ULL + 10) << 48))

torch/headeronly/version.h.in

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
/// Indicates the ABI version of LibTorch as a single uint64.
2020
/// [ byte ][ byte ][ byte ][ byte ][ byte ][ byte ][ byte ][ byte ]
2121
/// [ MAJ ][ MIN ][ PATCH][ ABI TAG ]
22-
#define TORCH_ABI_VERSION \
23-
(uint64_t)TORCH_VERSION_MAJOR << 56 | \
24-
(uint64_t)TORCH_VERSION_MINOR << 48 | \
25-
(uint64_t)TORCH_VERSION_PATCH << 40 | \
26-
TORCH_VERSION_ABI_TAG << 0
22+
#define TORCH_ABI_VERSION ( \
23+
((0ULL + TORCH_VERSION_MAJOR) << 56) | \
24+
((0ULL + TORCH_VERSION_MINOR) << 48) | \
25+
((0ULL + TORCH_VERSION_PATCH) << 40) | \
26+
((0ULL + TORCH_VERSION_ABI_TAG) << 0))

0 commit comments

Comments
 (0)