diff --git a/playbooks/dependencies/rocm.md b/playbooks/dependencies/rocm.md index 81db11d9..4af6aa8d 100644 --- a/playbooks/dependencies/rocm.md +++ b/playbooks/dependencies/rocm.md @@ -17,36 +17,39 @@ sudo reboot **Install ROCm in the created virtual environment.** > **Note**: Ensure the virtual environment is active before proceeding. + ```bash python -m pip install --upgrade pip python -m pip install --index-url https://repo.amd.com/rocm/whl/gfx1151/ "rocm[libraries,devel]" - ``` + - + ```bash python -m pip install --upgrade pip python -m pip install --index-url https://repo.amd.com/rocm/whl/gfx1152/ "rocm[libraries,devel]" - ``` + - + ```bash python -m pip install --upgrade pip python -m pip install --index-url https://repo.amd.com/rocm/whl/gfx1150/ "rocm[libraries,devel]" - ``` + + ```bash python -m pip install --upgrade pip python -m pip install --index-url https://repo.amd.com/rocm/whl/gfx120x-all/ "rocm[libraries,devel]" ``` + For further installation help, please see this [link](https://rocm.docs.amd.com/en/7.12.0-preview/install/rocm.html?fam=ryzen&gpu=max-pro-395&os=ubuntu&os-version=24.04&i=pip). \ No newline at end of file diff --git a/playbooks/supplemental/pytorch-kernels/README.md b/playbooks/supplemental/pytorch-kernels/README.md index 4c6ecd9b..1f6f01ae 100644 --- a/playbooks/supplemental/pytorch-kernels/README.md +++ b/playbooks/supplemental/pytorch-kernels/README.md @@ -110,53 +110,64 @@ AMD GPUs execute threads in groups of **32** called **wavefronts**. All threads On Windows, open a terminal in the directory of your choice and follow the commands to create a venv with ROCm+Pytorch already installed. + ```bash python -m venv kernel-env --system-site-packages kernel-env\Scripts\activate ``` + > **Tip**: Windows users may need to modify their PowerShell Execution Policy (e.g. > setting it to RemoteSigned or Unrestricted) before running some Powershell commands. + On Linux, open a terminal in the directory of your choice and follow the commands to create a venv with ROCm+Pytorch already installed. + ```bash sudo apt update sudo apt install -y python3-venv python3 -m venv kernel-env --system-site-packages source kernel-env/bin/activate ``` + + On Windows, open a terminal in the directory of your choice and follow the commands to create a venv. -```powershell + +```bash python -m venv kernel-env kernel-env\Scripts\activate ``` + > **Tip**: Windows users may need to modify their PowerShell Execution Policy (e.g. > setting it to RemoteSigned or Unrestricted) before running some Powershell commands. + On Linux, open a terminal in the directory of your choice and follow the commands to create a venv. + ```bash sudo apt update sudo apt install -y python3-venv python3 -m venv kernel-env source kernel-env/bin/activate ``` + + - ### Installing Basic Dependencies @@ -165,25 +176,130 @@ source kernel-env/bin/activate + + +```bash +python -m pip list | grep -E '^(rocm|rocm-sdk|torch|torchvision|torchaudio)' || true +``` + + + + + +```powershell +python -m pip list | Select-String "rocm|torch|torchvision|torchaudio" +``` + + --- ### Installing Additional Dependencies + +Install the Linux C/C++ build toolchain. This is a system-level dependency and is required for the C++ extension walkthroughs because `CUDAExtension` builds native `.so` modules from `.cu` files. + +Run this once on the Linux machine, outside the created Python virtual environment: + +```bash +sudo apt update +sudo apt install -y build-essential gcc g++ +``` + + +After activating the `kernel-env` virtual environment, install the Python build dependencies: + +```bash +python -m pip install "setuptools<82" wheel ninja +``` + + + + ```bash -pip install --upgrade setuptools wheel +set -euo pipefail + +command -v gcc +command -v g++ +gcc --version +g++ --version + +echo "OK: Linux C/C++ build toolchain is available." ``` + + + -Please ensure [Visual Studio 2022](https://aka.ms/vs/17/release/vs_community.exe) is installed. +Please ensure [Visual Studio 2022](https://aka.ms/vs/17/release/vs_community.exe) or newer is installed with the **Desktop development with C++** workload. Open a Powershell terminal and activate Visual Studio environment C++ dependencies. ```powershell -cmd /c '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" >nul 2>&1 && set' | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') { [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process') } } +# Find Visual Studio 2022 or newer with the C++ build tools installed. +$VsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" +$Vcvars = & $VsWhere ` + -latest ` + -products * ` + -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` + -find "VC\Auxiliary\Build\vcvars64.bat" | + Select-Object -First 1 +Write-Host "Using vcvars64.bat from Visual Studio C++ environment: $Vcvars" + +# Run vcvars64.bat and import the Visual Studio compiler environment into this PowerShell session. +# This makes cl.exe, INCLUDE, LIB, LIBPATH, and Windows SDK paths available for extension builds. +$VsEnv = cmd /c "`"$Vcvars`" && where cl && set" 2>&1 +$ExitCode = $LASTEXITCODE +if ($ExitCode -ne 0) { + $VsEnv | Out-Host + throw "Failed to activate the Visual Studio C++ environment. Exit code: $ExitCode" +} + +# Show the important activation lines, without printing every environment variable. +$VsEnv | Select-String "Developer Command Prompt|Environment initialized|cl.exe" | Out-Host + +# Import environment variables from vcvars64.bat into the current PowerShell process. +$VsEnv | ForEach-Object { + if ($_ -match '^([^=]+)=(.*)$') { + [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process') + } +} + +# Verify that the Microsoft C++ compiler is now available. +where.exe cl +``` + + +```powershell +$ErrorActionPreference = "Stop" + +$VsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" +if (-not (Test-Path $VsWhere)) {throw "vswhere.exe was not found. Install Visual Studio 2022 or newer with the Desktop development with C++ workload."} +Write-Host "Detected Visual Studio installations:" +& $VsWhere -all -products * -format table | Out-Host + +$VcvarsList = & $VsWhere ` + -all ` + -products * ` + -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` + -find "VC\Auxiliary\Build\vcvars64.bat" +if (-not $VcvarsList) {throw "Could not find vcvars64.bat. Install Visual Studio 2022 or newer with the Desktop development with C++ workload."} +$Vcvars = $VcvarsList | Select-Object -First 1 +Write-Host "Using vcvars64.bat from Visual Studio C++ environment: $Vcvars" + +$VsEnv = cmd /c "`"$Vcvars`" && where cl && set" 2>&1 +$ExitCode = $LASTEXITCODE +if ($ExitCode -ne 0) { + $VsEnv | Out-Host + throw "Failed to activate the Visual Studio C++ environment. Exit code: $ExitCode" +} + +$VsEnv | Select-String "Developer Command Prompt|Environment initialized|cl.exe" | Out-Host +Write-Host "OK: Visual Studio C++ build environment is available." ``` + #### Set Environment Variables - + ```bash rocm-sdk init # Initialize the devel libraries @@ -192,18 +308,17 @@ PY_MM="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_in export ROCM_HOME="$VIRTUAL_ENV/lib/python${PY_MM}/site-packages/_rocm_sdk_devel" export LD_LIBRARY_PATH="$ROCM_HOME/lib:$LD_LIBRARY_PATH" export PATH="$ROCM_HOME/bin:$PATH" -``` -```bash # Set compiler and build settings export CC=clang export CXX=clang export DISTUTILS_USE_SDK=1 ``` + -#### Windows + ```powershell rocm-sdk init # Initialize the devel libraries @@ -221,6 +336,7 @@ $env:PATH = (($RocmPathEntries + @($env:PATH)) -join ";") $env:ROCM_HOME = $ROCM_ROOT $env:HIP_PATH = $ROCM_ROOT +$env:ROCM_BIN = $ROCM_BIN $env:HIP_PLATFORM = "amd" # Set compiler and build settings @@ -228,34 +344,23 @@ $env:CC = "clang-cl" $env:CXX = "clang-cl" $env:DISTUTILS_USE_SDK = "1" ``` + - + Verify that the AMD GPU is visible with: + ```bash amd-smi ``` + - + ```bash set -euo pipefail -python3 -m venv rocm-env - -VENV="$PWD/rocm-env" -if [ ! -f "$VENV/bin/activate" ]; then - echo "Missing venv at $VENV. Run the setup steps first." - exit 1 -fi - -source "$VENV/bin/activate" - -pip install --upgrade pip setuptools wheel -pip install --index-url https://rocm.nightlies.amd.com/v2/gfx1151/ "rocm[libraries,devel]" -pip install --pre --index-url https://rocm.nightlies.amd.com/v2/gfx1151/ torch==2.10.0 torchaudio torchvision - rocm-sdk init PY_MM="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" @@ -263,6 +368,17 @@ export ROCM_HOME="$VIRTUAL_ENV/lib/python${PY_MM}/site-packages/_rocm_sdk_devel" export LD_LIBRARY_PATH="$ROCM_HOME/lib:${LD_LIBRARY_PATH:-}" export PATH="$ROCM_HOME/bin:$PATH" +export CC=clang +export CXX=clang +export DISTUTILS_USE_SDK=1 + +echo "Installed ROCm/PyTorch packages:" +python -m pip list | grep -E '^(rocm|rocm-sdk|torch|torchvision|torchaudio)' || true + +test -d "$ROCM_HOME" +test -d "$ROCM_HOME/bin" +test -d "$ROCM_HOME/lib" + test -f "$ROCM_HOME/lib/libhiprtc.so" || ls "$ROCM_HOME/lib"/libhiprtc.so* test -f "$ROCM_HOME/lib/libroctx64.so" || ls "$ROCM_HOME/lib"/libroctx64.so* @@ -270,7 +386,6 @@ hipcc --version >/dev/null rocminfo >/dev/null python - <<'PY' -import sys import torch print("torch:", torch.__version__) @@ -287,48 +402,18 @@ print("Device:", torch.cuda.get_device_name(0)) print("OK: ROCm PyTorch environment is ready") PY ``` - - - - - -```bash -source "./rocm-env/bin/activate" -amd-smi -``` - + ```powershell $ErrorActionPreference = "Stop" -python -m venv rocm-env -rocm-env\Scripts\activate - -$Venv = Join-Path (Get-Location) "rocm-env" -$Python = Join-Path $Venv "Scripts\python.exe" - -if (-not (Test-Path $Python)) {throw "Missing venv at $Venv. Run the setup steps first."} - -pip install --upgrade pip setuptools wheel -pip install --index-url https://rocm.nightlies.amd.com/v2/gfx1151/ "rocm[libraries,devel]" -pip install --pre --index-url https://rocm.nightlies.amd.com/v2/gfx1151/ torch==2.10.0 torchaudio torchvision - -$RocmSdk = Join-Path $Venv "Scripts\rocm-sdk.exe" -if (-not (Test-Path $RocmSdk)) {throw "Missing rocm-sdk.exe at $RocmSdk. Run the setup steps first."} -& $RocmSdk init - -$ROCM_ROOT = (& $RocmSdk path --root).Trim() -$ROCM_BIN = (& $RocmSdk path --bin).Trim() +rocm-sdk init -$ExpectedHiprtc = Join-Path $ROCM_BIN "hiprtc0701.dll" -$ActualHiprtc = Join-Path $ROCM_BIN "hiprtc07013.dll" -if ((-not (Test-Path $ExpectedHiprtc)) -and (Test-Path $ActualHiprtc)) { - Copy-Item $ActualHiprtc $ExpectedHiprtc -Force - Write-Host "Created HIPRTC compatibility copy: $ExpectedHiprtc" -} +$ROCM_ROOT = (rocm-sdk path --root).Trim() +$ROCM_BIN = (rocm-sdk path --bin).Trim() $RocmPathEntries = @( $ROCM_BIN, @@ -340,6 +425,7 @@ $env:PATH = (($RocmPathEntries + @($env:PATH)) -join ";") $env:ROCM_HOME = $ROCM_ROOT $env:HIP_PATH = $ROCM_ROOT +$env:ROCM_BIN = $ROCM_BIN $env:HIP_PLATFORM = "amd" $env:CC = "clang-cl" $env:CXX = "clang-cl" @@ -348,6 +434,9 @@ $env:DISTUTILS_USE_SDK = "1" Write-Host "ROCM_ROOT=$ROCM_ROOT" Write-Host "ROCM_BIN=$ROCM_BIN" +Write-Host "Installed ROCm/PyTorch packages:" +python -m pip list | Select-String "rocm|torch|torchvision|torchaudio" + Get-ChildItem -Path $ROCM_ROOT -Recurse -Filter "hiprtc*.dll" | Select-Object -First 10 FullName | Out-Host hipcc --version | Out-Host @@ -356,6 +445,7 @@ hipinfo | Out-Host $code = @' import os import sys +import torch if sys.platform == "win32": for key in ("ROCM_HOME", "HIP_PATH"): @@ -369,7 +459,6 @@ if sys.platform == "win32": rocm_bin = os.environ.get("ROCM_BIN") if rocm_bin and os.path.isdir(rocm_bin): os.add_dll_directory(rocm_bin) -import torch print("torch:", torch.__version__) print("HIP:", torch.version.hip) @@ -385,7 +474,7 @@ print("Device:", torch.cuda.get_device_name(0)) print("OK: ROCm PyTorch environment is ready") '@ -$code | & $Python - +$code | python - ``` @@ -490,7 +579,8 @@ Average GPU Utilization: 65.94% ->**Note**: On Windows, `amd-smi` is not supported. To track GPU utilization, you can use Task Manager, where you should see a brief spike of utilization when you run the program. +> **Note**: On Windows, `amd-smi` is not supported. To track GPU utilization, you can use Task Manager, where you should see a brief spike of utilization when you run the program. + **Expected output:** ``` First 5 elements: tensor([200001., 200001., 200001., 200001., 200001.]) @@ -501,11 +591,10 @@ No GPU Usage captured. **Nice work! You just ran your first GPU kernel.** - + ```bash set -euo pipefail -source "./rocm-env/bin/activate" rocm-sdk init PY_MM="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" @@ -513,6 +602,10 @@ export ROCM_HOME="$VIRTUAL_ENV/lib/python${PY_MM}/site-packages/_rocm_sdk_devel" export LD_LIBRARY_PATH="$ROCM_HOME/lib:${LD_LIBRARY_PATH:-}" export PATH="$ROCM_HOME/bin:$PATH" +export CC=clang +export CXX=clang +export DISTUTILS_USE_SDK=1 + python - <<'PY' import torch @@ -554,25 +647,14 @@ PY - + ```powershell $ErrorActionPreference = "Stop" -rocm-env\Scripts\activate -$Venv = Join-Path (Get-Location) "rocm-env" -$Python = Join-Path $Venv "Scripts\python.exe" -$RocmSdk = Join-Path $Venv "Scripts\rocm-sdk.exe" - -& $RocmSdk init -$ROCM_ROOT = (& $RocmSdk path --root).Trim() -$ROCM_BIN = (& $RocmSdk path --bin).Trim() +rocm-sdk init -$ExpectedHiprtc = Join-Path $ROCM_BIN "hiprtc0701.dll" -$ActualHiprtc = Join-Path $ROCM_BIN "hiprtc07013.dll" -if ((-not (Test-Path $ExpectedHiprtc)) -and (Test-Path $ActualHiprtc)) { - Copy-Item $ActualHiprtc $ExpectedHiprtc -Force - Write-Host "Created HIPRTC compatibility copy: $ExpectedHiprtc" -} +$ROCM_ROOT = (rocm-sdk path --root).Trim() +$ROCM_BIN = (rocm-sdk path --bin).Trim() $RocmPathEntries = @( $ROCM_BIN, @@ -604,6 +686,7 @@ if sys.platform == "win32": rocm_bin = os.environ.get("ROCM_BIN") if rocm_bin and os.path.isdir(rocm_bin): os.add_dll_directory(rocm_bin) + import torch if not torch.cuda.is_available(): @@ -640,7 +723,7 @@ if not torch.allclose(x, torch.full_like(x, 2.0)): print("OK: vector addition JIT kernel compiled and ran correctly") '@ -$code | & $Python - +$code | python - ``` @@ -730,11 +813,10 @@ After: tensor([2., 2., 2., 2., 2., 2., 2., 2., 2., 2.], device='cuda:0') ``` - + ```bash set -euo pipefail -source "./rocm-env/bin/activate" rocm-sdk init PY_MM="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" @@ -768,36 +850,38 @@ PY - + ```powershell $ErrorActionPreference = "Stop" -rocm-env\Scripts\activate -$Venv = Join-Path (Get-Location) "rocm-env" -$Python = Join-Path $Venv "Scripts\python.exe" -$RocmSdk = Join-Path $Venv "Scripts\rocm-sdk.exe" - -$VcvarsCandidates = @( - "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat", - "C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat", - "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat", - "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvars64.bat" -) - -$Vcvars = $VcvarsCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1 -if (-not $Vcvars) { - throw "Could not find vcvars64.bat. Install Visual Studio 2022 C++ Build Tools." +$VsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" +if (-not (Test-Path $VsWhere)) {throw "vswhere.exe was not found. Install Visual Studio 2022 or newer with the Desktop development with C++ workload."} + +$Vcvars = & $VsWhere ` + -latest ` + -products * ` + -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` + -find "VC\Auxiliary\Build\vcvars64.bat" | + Select-Object -First 1 +if (-not $Vcvars) {throw "Could not find vcvars64.bat. Install Visual Studio 2022 or newer with the Desktop development with C++ workload."} +Write-Host "Using Visual Studio C++ environment: $Vcvars" + +$VsEnv = cmd /c "`"$Vcvars`" && where cl && set" 2>&1 +$ExitCode = $LASTEXITCODE +if ($ExitCode -ne 0) { + $VsEnv | Out-Host + throw "Failed to activate the Visual Studio C++ environment. Exit code: $ExitCode" } - -cmd /c "`"$Vcvars`" >nul 2>&1 && set" | ForEach-Object { - if ($_ -match '^([^=]+)=(.*)$') { - [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process') - } +$VsEnv | Select-String "Developer Command Prompt|Environment initialized|cl.exe" | Out-Host +$VsEnv | ForEach-Object { + if ($_ -match '^([^=]+)=(.*)$') {[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')} } +where.exe cl -& $RocmSdk init -$ROCM_ROOT = (& $RocmSdk path --root).Trim() -$ROCM_BIN = (& $RocmSdk path --bin).Trim() +rocm-sdk init + +$ROCM_ROOT = (rocm-sdk path --root).Trim() +$ROCM_BIN = (rocm-sdk path --bin).Trim() $RocmPathEntries = @( $ROCM_BIN, @@ -819,10 +903,10 @@ $env:DISTUTILS_USE_SDK = "1" Push-Location "Vector_Addition" try { - & $Python -m pip install --no-build-isolation -v . + python -m pip install --no-build-isolation -v . $code = @' - import os +import os import sys if sys.platform == "win32": @@ -837,6 +921,7 @@ if sys.platform == "win32": rocm_bin = os.environ.get("ROCM_BIN") if rocm_bin and os.path.isdir(rocm_bin): os.add_dll_directory(rocm_bin) + import torch import add_one_ext @@ -854,7 +939,7 @@ if not torch.allclose(x, expected): print("OK: vector addition C++ extension built, imported, and ran correctly") '@ - $code | & $Python - + $code | python - } finally { Pop-Location @@ -968,7 +1053,8 @@ Average GPU Utilization: 65.94% ->**Note**: On Windows, `amd-smi` is not supported. To track GPU utilization, you can use Task Manager, where you should see a brief spike of utilization when you run the program. +> **Note**: On Windows, `amd-smi` is not supported. To track GPU utilization, you can use Task Manager, where you should see a brief spike of utilization when you run the program. + **Expected output:** ``` Elapsed time: 2.753s @@ -978,11 +1064,10 @@ No GPU Usage captured. - + ```bash set -euo pipefail -source "./rocm-env/bin/activate" rocm-sdk init PY_MM="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" @@ -990,6 +1075,10 @@ export ROCM_HOME="$VIRTUAL_ENV/lib/python${PY_MM}/site-packages/_rocm_sdk_devel" export LD_LIBRARY_PATH="$ROCM_HOME/lib:${LD_LIBRARY_PATH:-}" export PATH="$ROCM_HOME/bin:$PATH" +export CC=clang +export CXX=clang +export DISTUTILS_USE_SDK=1 + python - <<'PY' import torch @@ -1044,25 +1133,14 @@ PY - + ```powershell $ErrorActionPreference = "Stop" -rocm-env\Scripts\activate -$Venv = Join-Path (Get-Location) "rocm-env" -$Python = Join-Path $Venv "Scripts\python.exe" -$RocmSdk = Join-Path $Venv "Scripts\rocm-sdk.exe" - -& $RocmSdk init -$ROCM_ROOT = (& $RocmSdk path --root).Trim() -$ROCM_BIN = (& $RocmSdk path --bin).Trim() +rocm-sdk init -$ExpectedHiprtc = Join-Path $ROCM_BIN "hiprtc0701.dll" -$ActualHiprtc = Join-Path $ROCM_BIN "hiprtc07013.dll" -if ((-not (Test-Path $ExpectedHiprtc)) -and (Test-Path $ActualHiprtc)) { - Copy-Item $ActualHiprtc $ExpectedHiprtc -Force - Write-Host "Created HIPRTC compatibility copy: $ExpectedHiprtc" -} +$ROCM_ROOT = (rocm-sdk path --root).Trim() +$ROCM_BIN = (rocm-sdk path --bin).Trim() $RocmPathEntries = @( $ROCM_BIN, @@ -1094,6 +1172,7 @@ if sys.platform == "win32": rocm_bin = os.environ.get("ROCM_BIN") if rocm_bin and os.path.isdir(rocm_bin): os.add_dll_directory(rocm_bin) + import torch if not torch.cuda.is_available(): @@ -1143,7 +1222,7 @@ if max_err > 1e-3: print(f"OK: matmul JIT kernel compiled and ran correctly; max_err={max_err:.6f}") '@ -$code | & $Python - +$code | python - ``` @@ -1253,11 +1332,10 @@ Result: tensor([[19., 22.], - Transformers - + ```bash set -euo pipefail -source "./rocm-env/bin/activate" rocm-sdk init PY_MM="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" @@ -1295,36 +1373,38 @@ PY - + ```powershell $ErrorActionPreference = "Stop" -rocm-env\Scripts\activate -$Venv = Join-Path (Get-Location) "rocm-env" -$Python = Join-Path $Venv "Scripts\python.exe" -$RocmSdk = Join-Path $Venv "Scripts\rocm-sdk.exe" - -$VcvarsCandidates = @( - "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat", - "C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat", - "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat", - "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvars64.bat" -) - -$Vcvars = $VcvarsCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1 -if (-not $Vcvars) { - throw "Could not find vcvars64.bat. Install Visual Studio 2022 C++ Build Tools." +$VsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" +if (-not (Test-Path $VsWhere)) {throw "vswhere.exe was not found. Install Visual Studio 2022 or newer with the Desktop development with C++ workload."} + +$Vcvars = & $VsWhere ` + -latest ` + -products * ` + -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` + -find "VC\Auxiliary\Build\vcvars64.bat" | + Select-Object -First 1 +if (-not $Vcvars) {throw "Could not find vcvars64.bat. Install Visual Studio 2022 or newer with the Desktop development with C++ workload."} +Write-Host "Using Visual Studio C++ environment: $Vcvars" + +$VsEnv = cmd /c "`"$Vcvars`" && where cl && set" 2>&1 +$ExitCode = $LASTEXITCODE +if ($ExitCode -ne 0) { + $VsEnv | Out-Host + throw "Failed to activate the Visual Studio C++ environment. Exit code: $ExitCode" } - -cmd /c "`"$Vcvars`" >nul 2>&1 && set" | ForEach-Object { - if ($_ -match '^([^=]+)=(.*)$') { - [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process') - } +$VsEnv | Select-String "Developer Command Prompt|Environment initialized|cl.exe" | Out-Host +$VsEnv | ForEach-Object { + if ($_ -match '^([^=]+)=(.*)$') {[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')} } +where.exe cl + +rocm-sdk init -& $RocmSdk init -$ROCM_ROOT = (& $RocmSdk path --root).Trim() -$ROCM_BIN = (& $RocmSdk path --bin).Trim() +$ROCM_ROOT = (rocm-sdk path --root).Trim() +$ROCM_BIN = (rocm-sdk path --bin).Trim() $RocmPathEntries = @( $ROCM_BIN, @@ -1346,10 +1426,10 @@ $env:DISTUTILS_USE_SDK = "1" Push-Location "Matrix_Multiplication" try { - & $Python -m pip install --no-build-isolation -v . + python -m pip install --no-build-isolation -v . $code = @' - import os +import os import sys if sys.platform == "win32": @@ -1364,6 +1444,7 @@ if sys.platform == "win32": rocm_bin = os.environ.get("ROCM_BIN") if rocm_bin and os.path.isdir(rocm_bin): os.add_dll_directory(rocm_bin) + import torch import matmul_ext @@ -1385,7 +1466,7 @@ if max_err > 1e-3: print(f"OK: matmul C++ extension built, imported, and ran correctly; max_err={max_err:.6f}") '@ - $code | & $Python - + $code | python - } finally { Pop-Location diff --git a/playbooks/supplemental/pytorch-kernels/playbook.json b/playbooks/supplemental/pytorch-kernels/playbook.json index 3389fdac..ddb2fbd2 100644 --- a/playbooks/supplemental/pytorch-kernels/playbook.json +++ b/playbooks/supplemental/pytorch-kernels/playbook.json @@ -5,29 +5,44 @@ "time": 120, "supported_platforms": { "halo": [ - "linux" + "linux", + "windows" ], "halo_box": [ - "linux" + "linux", + "windows" ], "stx": [ - "linux" + "linux", + "windows" ], "krk": [ - "linux" + "linux", + "windows" ] }, "required_platforms": { "halo": [ - "linux" + "linux", + "windows" ], "halo_box": [ - "linux" + "linux", + "windows" ] }, "tested_platforms":{ "halo": [ - "linux" + "linux", + "windows" + ], + "stx": [ + "linux", + "windows" + ], + "krk": [ + "linux", + "windows" ] }, "difficulty": "advanced",