|
| 1 | +@REM Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +@REM or more contributor license agreements. See the NOTICE file |
| 3 | +@REM distributed with this work for additional information |
| 4 | +@REM regarding copyright ownership. The ASF licenses this file |
| 5 | +@REM to you under the Apache License, Version 2.0 (the |
| 6 | +@REM "License"); you may not use this file except in compliance |
| 7 | +@REM with the License. You may obtain a copy of the License at |
| 8 | +@REM |
| 9 | +@REM http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +@REM |
| 11 | +@REM Unless required by applicable law or agreed to in writing, |
| 12 | +@REM software distributed under the License is distributed on an |
| 13 | +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +@REM KIND, either express or implied. See the License for the |
| 15 | +@REM specific language governing permissions and limitations |
| 16 | +@REM under the License. |
| 17 | +@echo off |
| 18 | +setlocal enabledelayedexpansion |
| 19 | + |
| 20 | +set arch=%~1 |
| 21 | +set python_version=%~2 |
| 22 | + |
| 23 | +set tvm_ffi=%cd% |
| 24 | +set torch_c_dlpack_ext=%tvm_ffi%\addons\torch_c_dlpack_ext |
| 25 | + |
| 26 | +if not exist "%tvm_ffi%\.venv" mkdir "%tvm_ffi%\.venv" |
| 27 | +if not exist "%tvm_ffi%\lib" mkdir "%tvm_ffi%\lib" |
| 28 | +for %%P in (2.4 2.5 2.6 2.7 2.8 2.9) do ( |
| 29 | + call :build_libs %%P |
| 30 | +) |
| 31 | + |
| 32 | +copy %tvm_ffi%\lib\*.dll %torch_c_dlpack_ext%\torch_c_dlpack_ext |
| 33 | +uv venv %tvm_ffi%\.venv\build --python %python_version% |
| 34 | +call %tvm_ffi%\.venv\build\Scripts\activate |
| 35 | +uv pip install build wheel |
| 36 | +cd %torch_c_dlpack_ext% |
| 37 | +python -m build -w |
| 38 | +dir dist |
| 39 | +for %%f in (dist\*.whl) do python -m wheel tags "%%f" --python-tag=%python_version% --abi-tag=%python_version% --platform-tag=win_amd64 |
| 40 | +dir dist |
| 41 | +mkdir wheelhouse |
| 42 | +copy dist\*-win_amd64.whl wheelhouse |
| 43 | +dir wheelhouse |
| 44 | +endlocal |
| 45 | +exit /b |
| 46 | + |
| 47 | +:build_libs |
| 48 | + set torch_version=%1 |
| 49 | + call :check_availability |
| 50 | + if %errorlevel%==0 ( |
| 51 | + call :get_torch_url |
| 52 | + uv venv %tvm_ffi%\.venv\torch%torch_version% --python %python_version% |
| 53 | + call %tvm_ffi%\.venv\torch%torch_version%\Scripts\activate |
| 54 | + uv pip install setuptools ninja |
| 55 | + uv pip install torch==%torch_version% --index-url !torch_url! |
| 56 | + uv pip install -v . |
| 57 | + python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir %tvm_ffi%\lib |
| 58 | + python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir %tvm_ffi%\lib --build-with-cuda |
| 59 | + call deactivate |
| 60 | + rmdir -s -q %tvm_ffi%\.venv\torch%torch_version% |
| 61 | + ) else ( |
| 62 | + echo Skipping build for torch %torch_version% on %arch% with python %python_version% as it is not available. |
| 63 | + ) |
| 64 | + exit /b 0 |
| 65 | + |
| 66 | + |
| 67 | +:check_availability |
| 68 | + if %torch_version%==2.4 ( |
| 69 | + if %python_version%==cp313 exit /b 1 |
| 70 | + if %python_version%==cp314 exit /b 1 |
| 71 | + exit /b 0 |
| 72 | + ) |
| 73 | + if %torch_version%==2.5 ( |
| 74 | + if %python_version%==cp314 exit /b 1 |
| 75 | + exit /b 0 |
| 76 | + ) |
| 77 | + if %torch_version%==2.6 ( |
| 78 | + if %python_version%==cp314 exit /b 1 |
| 79 | + exit /b 0 |
| 80 | + ) |
| 81 | + if %torch_version%==2.7 ( |
| 82 | + if %python_version%==cp314 exit /b 1 |
| 83 | + exit /b 0 |
| 84 | + ) |
| 85 | + if %torch_version%==2.8 ( |
| 86 | + if %python_version%==cp314 exit /b 1 |
| 87 | + exit /b 0 |
| 88 | + ) |
| 89 | + if %torch_version%==2.9 ( |
| 90 | + if %python_version%==cp39 exit /b 1 |
| 91 | + exit /b 0 |
| 92 | + ) |
| 93 | + echo Unknown or unsupported torch version: %torch_version% >&2 |
| 94 | + exit /b 1 |
| 95 | + |
| 96 | +:get_torch_url |
| 97 | + set cuda_version= |
| 98 | + if %torch_version%==2.4 set cuda_version=cu124 |
| 99 | + if %torch_version%==2.5 set cuda_version=cu124 |
| 100 | + if %torch_version%==2.6 set cuda_version=cu126 |
| 101 | + if %torch_version%==2.7 set cuda_version=cu128 |
| 102 | + if %torch_version%==2.8 set cuda_version=cu129 |
| 103 | + if %torch_version%==2.9 set cuda_version=cu129 |
| 104 | + if defined cuda_version ( |
| 105 | + set torch_url=https://download.pytorch.org/whl/%cuda_version% |
| 106 | + exit /b 0 |
| 107 | + ) |
| 108 | + echo Unknown or unsupported torch version: %torch_version% >&2 |
| 109 | + exit /b 1 |
0 commit comments