te_version.py 1.92 KB
Newer Older
1
# Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
3
4
5
6
7
8
9
#
# See LICENSE for license information.

"""Transformer Engine version string."""
import os
from pathlib import Path
import subprocess

yuguo's avatar
yuguo committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
DAS_VERSION="1.6"

def abi_value():
    try:
        return (
            subprocess.check_output("echo '#include <string>' | gcc -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI", shell=True)
            .decode('ascii')
            .strip()[-1]
        )
    except Exception:
        return abiUNKNOWN

def dtk_version_value():
    try:
       dtk_path=os.getenv('ROCM_PATH')
       dtk_version_path = os.path.join(dtk_path, '.info', "version-dev")
       with open(dtk_version_path, 'r',encoding='utf-8') as file:
           lines = file.readlines()
       dtk_version="dtk"+lines[0][:].replace(".", "")
       return dtk_version
    except Exception:
       return UNKNOWN
32

33
34
35
36
37
38
39
40
def te_version() -> str:
    """Transformer Engine version string

    Includes Git commit as local version, unless suppressed with
    NVTE_NO_LOCAL_VERSION environment variable.

    """
    root_path = Path(__file__).resolve().parent
41
    with open(root_path / "VERSION.txt", "r") as f:
42
        version = f.readline().strip()
43
44
45
    if not int(os.getenv("NVTE_NO_LOCAL_VERSION", "0")) and not bool(
        int(os.getenv("NVTE_RELEASE_BUILD", "0"))
    ):
46
47
        try:
            output = subprocess.run(
48
                ["git", "rev-parse", "--short", "HEAD"],
49
50
51
52
53
54
55
56
57
                capture_output=True,
                cwd=root_path,
                check=True,
                universal_newlines=True,
            )
        except (subprocess.CalledProcessError, OSError):
            pass
        else:
            commit = output.stdout.strip()
yuguo's avatar
yuguo committed
58
59
60
            version += "+das"+ DAS_VERSION + f".git{commit}"+ ".abi"+str(abi_value()) + "." +str(dtk_version_value())
    else:
        version += "+das"+ DAS_VERSION + f".opt1"+ "." +str(dtk_version_value())
61
    return version