diff --git a/build.bat b/build.bat new file mode 100644 index 00000000000..26da2718182 --- /dev/null +++ b/build.bat @@ -0,0 +1,77 @@ +@echo off +REM Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +REM FastDeploy Windows build script +REM Usage: build.bat [BUILD_MODE] [PYTHON] +REM BUILD_MODE: 0 = build custom ops only, 1 = full build (default) +REM PYTHON: Python executable (default: python) +REM +REM Requires: Visual Studio Build Tools, CUDA Toolkit, Python 3.10+ +REM Run from a Developer Command Prompt or ensure cl.exe is on PATH. + +setlocal enabledelayedexpansion + +set BUILD_MODE=%~1 +if "%BUILD_MODE%"=="" set BUILD_MODE=1 + +set PYTHON=%~2 +if "%PYTHON%"=="" set PYTHON=python + +echo ============================================ +echo FastDeploy Windows Build +echo Mode: %BUILD_MODE% (0=ops only, 1=full) +echo Python: %PYTHON% +echo ============================================ + +REM Step 1: Build custom ops +echo. +echo [1] Building custom ops... +pushd custom_ops +%PYTHON% setup_ops.py install +if !ERRORLEVEL! neq 0 ( + echo [FAIL] Custom ops build failed. + popd + exit /b 1 +) +popd +echo [OK] Custom ops built successfully. + +if "%BUILD_MODE%"=="0" ( + echo. + echo Build complete (ops only). + exit /b 0 +) + +REM Step 2: Build and install FastDeploy wheel +echo. +echo [2] Building FastDeploy wheel... +%PYTHON% setup.py bdist_wheel +if !ERRORLEVEL! neq 0 ( + echo [FAIL] Wheel build failed. + exit /b 1 +) + +echo [3] Installing FastDeploy wheel... +for %%w in (dist\fastdeploy*.whl) do ( + %PYTHON% -m pip install "%%w" + if !ERRORLEVEL! neq 0 ( + echo [FAIL] pip install failed for %%w + exit /b 1 + ) +) + +echo. +echo Build complete. +exit /b 0 diff --git a/custom_ops/setup_ops.py b/custom_ops/setup_ops.py index 109028af6ec..d95e2044ea9 100644 --- a/custom_ops/setup_ops.py +++ b/custom_ops/setup_ops.py @@ -562,13 +562,19 @@ def find_end_files(directory, end_str): # appended explicitly for SM75 and also discovered by later directory globs. sources = list(dict.fromkeys(sources)) + cuda_libraries = ["cublasLt"] + if sys.platform == "win32": + cuda_link_args = ["/DEFAULTLIB:cuda.lib", "/DEFAULTLIB:nvml.lib"] + else: + cuda_link_args = ["-lcuda", "-lnvidia-ml"] + setup( name="fastdeploy_ops", ext_modules=CUDAExtension( sources=sources, extra_compile_args={"cxx": cc_compile_args, "nvcc": nvcc_compile_args}, - libraries=["cublasLt"], - extra_link_args=["-lcuda", "-lnvidia-ml"], + libraries=cuda_libraries, + extra_link_args=cuda_link_args, ), packages=find_packages(where="third_party/DeepGEMM"), package_dir={"": "third_party/DeepGEMM"},