Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ def find_visual_studio(version_ranges):
for version_range in version_ranges:
command = [
str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"-property", "installationPath", "-prerelease"
"-products", "*", "-property", "installationPath", "-prerelease"
]

try:
output = subprocess.check_output(command, text=True).strip()
if output:
return output
return output.split("\n")[0]
except subprocess.CalledProcessError:
continue

Expand All @@ -146,6 +146,13 @@ def set_env_vars(vs_path, arch="x64"):
os.environ[var] = value


def initialize_visual_studio_env(version_ranges, arch="x64"):
vs_path = find_visual_studio(version_ranges)
if not vs_path:
raise EnvironmentError("Visual Studio not found in specified version ranges.")
set_env_vars(vs_path, arch)


# Taken from https://github.com/pytorch/pytorch/blob/master/tools/setup_helpers/env.py
def check_env_flag(name: str, default: str = "") -> bool:
return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"]
Expand Down
16 changes: 7 additions & 9 deletions python/triton/runtime/CLFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def find_visual_studio(version_ranges):
for version_range in version_ranges:
command = [
str(vswhere), "-version", version_range, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"-property", "installationPath", "-prerelease"
"-products", "*", "-property", "installationPath", "-prerelease"
]

try:
output = subprocess.check_output(command, text=True).strip()
if output:
return output
return output.split("\n")[0]
except subprocess.CalledProcessError:
continue

Expand All @@ -37,7 +37,7 @@ def set_env_vars(vs_path, arch="x64"):
if not vcvarsall_path.exists():
raise FileNotFoundError(f"vcvarsall.bat not found in expected path: {vcvarsall_path}")

command = f'call "{vcvarsall_path}" {arch} && set'
command = ["call", vcvarsall_path, arch, "&&", "set"]
output = subprocess.check_output(command, shell=True, text=True)

for line in output.splitlines():
Expand All @@ -47,9 +47,7 @@ def set_env_vars(vs_path, arch="x64"):


def initialize_visual_studio_env(version_ranges, arch="x64"):
# Check if the environment variable that vcvarsall.bat sets is present
if os.environ.get('VSCMD_ARG_TGT_ARCH') != arch:
vs_path = find_visual_studio(version_ranges)
if not vs_path:
raise EnvironmentError("Visual Studio not found in specified version ranges.")
set_env_vars(vs_path, arch)
vs_path = find_visual_studio(version_ranges)
if not vs_path:
raise EnvironmentError("Visual Studio not found in specified version ranges.")
set_env_vars(vs_path, arch)
Loading