Commit c9900cbf authored by panning's avatar panning
Browse files

add dcu_version

parent d36dd763
...@@ -32,6 +32,19 @@ with open(version_txt) as f: ...@@ -32,6 +32,19 @@ with open(version_txt) as f:
sha = "Unknown" sha = "Unknown"
package_name = "torchvision" package_name = "torchvision"
dcu_version = version
def get_abi():
try:
command = "echo '#include <string>' | gcc -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
output = result.stdout.strip()
abi = "abi" + output.split(" ")[-1]
return abi
except Exception:
return 'abiUnknown'
try: try:
sha = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd).decode("ascii").strip() sha = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd).decode("ascii").strip()
except Exception: except Exception:
...@@ -39,14 +52,29 @@ except Exception: ...@@ -39,14 +52,29 @@ except Exception:
if os.getenv("BUILD_VERSION"): if os.getenv("BUILD_VERSION"):
version = os.getenv("BUILD_VERSION") version = os.getenv("BUILD_VERSION")
elif sha != "Unknown": #elif sha != "Unknown":
version += "+" + sha[:7] # version += "+" + sha[:7]
if sha != 'Unknown':
dcu_version += '+git' + sha[:7]
dcu_version += "." + get_abi()
if os.getenv("ROCM_PATH"):
rocm_path = os.getenv('ROCM_PATH', "")
rocm_version_path = os.path.join(rocm_path, '.info', "version-dev")
with open(rocm_version_path, 'r',encoding='utf-8') as file:
lines = file.readlines()
rocm_version=lines[0][:-2].replace(".", "")
dcu_version += ".dtk" + rocm_version
# torch version
dcu_version += ".torch" + torch.__version__[:-2]
def write_version_file(): def write_version_file():
version_path = os.path.join(cwd, "torchvision", "version.py") version_path = os.path.join(cwd, "torchvision", "version.py")
with open(version_path, "w") as f: with open(version_path, "w") as f:
f.write(f"__version__ = '{version}'\n") f.write(f"__version__ = '{version}'\n")
f.write("__dcu_version__ = '{}'\n".format(dcu_version))
f.write(f"git_version = {repr(sha)}\n") f.write(f"git_version = {repr(sha)}\n")
f.write("from torchvision.extension import _check_cuda_version\n") f.write("from torchvision.extension import _check_cuda_version\n")
f.write("if _check_cuda_version() > 0:\n") f.write("if _check_cuda_version() > 0:\n")
...@@ -530,7 +558,7 @@ if __name__ == "__main__": ...@@ -530,7 +558,7 @@ if __name__ == "__main__":
setup( setup(
# Metadata # Metadata
name=package_name, name=package_name,
version=version, version=dcu_version,
author="PyTorch Core Team", author="PyTorch Core Team",
author_email="soumith@pytorch.org", author_email="soumith@pytorch.org",
url="https://github.com/pytorch/vision", url="https://github.com/pytorch/vision",
......
...@@ -11,6 +11,11 @@ try: ...@@ -11,6 +11,11 @@ try:
except ImportError: except ImportError:
pass pass
try:
from .version import __dcu_version__ # noqa: F401
except ImportError:
pass
# Check if torchvision is being imported within the root folder # Check if torchvision is being imported within the root folder
if not _HAS_OPS and os.path.dirname(os.path.realpath(__file__)) == os.path.join( if not _HAS_OPS and os.path.dirname(os.path.realpath(__file__)) == os.path.join(
os.path.realpath(os.getcwd()), "torchvision" os.path.realpath(os.getcwd()), "torchvision"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment