Introduce TORCH_ABI_VERSION and a runtime aoti_torch_abi_version C shim ABI (#148892)

Importable https://github.com/pytorch/pytorch/pull/148836

Pull Request resolved: https://github.com/pytorch/pytorch/pull/148892
Approved by: https://github.com/albanD
This commit is contained in:
Jane Xu
2025-03-10 22:22:05 +00:00
committed by PyTorch MergeBot
parent 98b3f1db9f
commit fcb633fafa
3 changed files with 23 additions and 1 deletions

View File

@ -9,6 +9,18 @@
/// Indicates the patch version of LibTorch.
#define TORCH_VERSION_PATCH @TORCH_VERSION_PATCH@
/// Indicates the version of LibTorch.
/// Indicates the ABI version tag of LibTorch.
#define TORCH_VERSION_ABI_TAG 0
/// Indicates the version of LibTorch as a string literal.
#define TORCH_VERSION \
"@TORCH_VERSION_MAJOR@.@TORCH_VERSION_MINOR@.@TORCH_VERSION_PATCH@"
/// Indicates the ABI version of LibTorch as a single uint64.
/// [ byte ][ byte ][ byte ][ byte ][ byte ][ byte ][ byte ][ byte ]
/// [ MAJ ][ MIN ][ PATCH][ ABI TAG ]
#define TORCH_ABI_VERSION \
(uint64_t)TORCH_VERSION_MAJOR << 56 | \
(uint64_t)TORCH_VERSION_MINOR << 48 | \
(uint64_t)TORCH_VERSION_PATCH << 40 | \
TORCH_VERSION_ABI_TAG << 0

View File

@ -143,6 +143,9 @@ AOTI_TORCH_EXPORT int32_t aoti_torch_memory_format_channels_last();
AOTI_TORCH_EXPORT int32_t aoti_torch_memory_format_channels_last_3d();
AOTI_TORCH_EXPORT int32_t aoti_torch_memory_format_preserve_format();
// Get TORCH_ABI_VERSION of the built libtorch.so
AOTI_TORCH_EXPORT uint64_t aoti_torch_abi_version();
// Functions for converting a single-element tensor to a scalar value
AOTI_TORCH_EXPORT AOTITorchError
aoti_torch_item_float16(AtenTensorHandle tensor, c10::Half* ret_value);

View File

@ -231,6 +231,13 @@ AOTI_TORCH_SCALAR_TO_TENSOR_IMPL(
ComplexDouble)
#undef AOTI_TORCH_SCALAR_TO_TENSOR_IMPL
#ifndef C10_MOBILE
#include <torch/version.h>
uint64_t aoti_torch_abi_version() {
return TORCH_ABI_VERSION;
}
#endif // C10_MOBILE
bool aoti_torch_grad_mode_is_enabled() {
return c10::GradMode::is_enabled();
}