Commit 40b32e95 authored by PanZezhong's avatar PanZezhong
Browse files

issue/134/refactor CI使用统一python脚本

parent c4b3a157
......@@ -30,36 +30,13 @@ jobs:
with:
xmake-version: latest
- name: Build & Install (Linux)
if: matrix.os == 'ubuntu-latest'
run: bash scripts/install.sh . --omp=y
- name: Build & Install (Windows)
if: matrix.os == 'windows-latest'
run: scripts/install.bat . --omp=y
- name: Build & Install
run: python scripts/install.py --omp=y
- name: install python packages
run: |
pip install numpy
pip install torch
- name: Python Test (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
export LD_LIBRARY_PATH=$HOME/.infini/lib:$LD_LIBRARY_PATH
python test/infiniop/gemm.py --cpu
python test/infiniop/rms_norm.py --cpu
python test/infiniop/causal_softmax.py --cpu
python test/infiniop/swiglu.py --cpu
python test/infiniop/random_sample.py --cpu
- name: Python Test (Windows)
if: matrix.os == 'windows-latest'
run: |
set PATH=$env:USERPROFILE\.infini\bin;$env:PATH
python test\infiniop\gemm.py --cpu
python test\infiniop\rms_norm.py --cpu
python test\infiniop\causal_softmax.py --cpu
python test\infiniop\swiglu.py --cpu
python test\infiniop\random_sample.py --cpu
- name: Python Test
run: python scripts/python_test.py --cpu
......@@ -15,18 +15,30 @@ InfiniCore 是一个跨平台统一编程工具集,为不同芯片平台的功
## 配置和使用
### 软件依赖
- XMake编译器
XMake配置选项(`XMAKE_CONFIG_FLAGS`)以及含义
- `--omp=[y|n]` 是否使用OpenMP,默认开启
- `--cpu=[y|n]` 是否编译CPU接口实现,默认开启
- `--nv-gpu=[y|n]` 是否编译英伟达GPU接口实现
- `--ascend-npu=[y|n]` 是否编译昇腾NPU接口实现
- `--cambricon-mlu=[y|n]` 是否编译寒武纪MLU接口实现
- `--metax-gpu=[y|n]` 是否编译沐曦GPU接口实现
- `--moore-gpu=[y|n]` 是否编译摩尔线程GPU接口实现
- `--sugon-dcu=[y|n]` 是否编译曙光DCU接口实现
- `--kunlun-xpu=[y|n]` 是否编译昆仑XPU接口实现
### 一键安装
`script/` 目录中分别提供了 `install.bat` windows安装脚本和 `install.sh` linux安装脚本。使用方式如下:
`script/` 目录中提供了 `install.py` 安装脚本。使用方式如下:
```shell
cd InfiniCore
# Windows
.\scripts\install.bat . --nv-gpu=true
# Linux
source ./scripts/install.sh . --nv-gpu=true
python scripts/install.py [XMAKE_CONFIG_FLAGS]
```
### 手动安装
......@@ -75,9 +87,15 @@ source ./scripts/install.sh . --nv-gpu=true
#### 运行Python算子测试
```shell
python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend]
```
```shell
python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend]
```
#### 一键运行所有Python算子测试
```shell
python scripts/python_test.py [--cpu | --nvidia | --cambricon | --ascend]
```
#### 算子测试框架
......
@echo off
setlocal
:: Check if project path is provided
if "%~0"=="" (
echo Usage: install.bat PROJECT_PATH [XMAKE_CONFIG_FLAGS]
exit /b 1
)
:: Set INFINI_ROOT
set "INFINI_ROOT=%USERPROFILE%\.infini"
:: Check if INFINI_ROOT\bin is already in PATH, if not, add it
echo %PATH% | findstr /I /C:"%INFINI_ROOT%\bin" >nul
if %errorlevel% neq 0 set "PATH=%INFINI_ROOT%\bin;%PATH%"
:: Convert relative path to absolute path
for %%I in ("%~1") do set ABS_PATH=%%~fI
:: Change to the project directory
cd %ABS_PATH%
:: Build xmake config flags
set XMAKE_FLAGS=
set i=0
for %%A in (%*) do (
if !i! gtr set XMAKE_FLAGS=!XMAKE_FLAGS! %%A
set /a i+=1
)
:: Start installation
xmake clean -a
if %errorlevel% neq 0 exit /b %errorlevel%
xmake f %XMAKE_FLAGS% -cv
if %errorlevel% neq 0 exit /b %errorlevel%
xmake
if %errorlevel% neq 0 exit /b %errorlevel%
xmake install
if %errorlevel% neq 0 exit /b %errorlevel%
xmake build infiniop-test
if %errorlevel% neq 0 exit /b %errorlevel%
xmake install infiniop-test
if %errorlevel% neq 0 exit /b %errorlevel%
import os
import subprocess
import platform
import sys
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
os.chdir(PROJECT_DIR)
def set_env():
if os.environ.get("INFINI_ROOT", "") == "":
os.environ["INFINI_ROOT"] = os.path.expanduser("~/.infini")
if platform.system() == "Windows":
new_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/bin")
if new_path not in os.environ.get("PATH", ""):
os.environ["PATH"] = f"{new_path};{os.environ.get('PATH', '')}"
elif platform.system() == "Linux":
new_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/bin")
if new_path not in os.environ.get("PATH", ""):
os.environ["PATH"] = f"{new_path}:{os.environ.get('PATH', '')}"
new_lib_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/lib")
if new_lib_path not in os.environ.get("LD_LIBRARY_PATH", ""):
os.environ["LD_LIBRARY_PATH"] = (
f"{new_lib_path}:{os.environ.get('LD_LIBRARY_PATH', '')}"
)
else:
raise RuntimeError("Unsupported platform.")
def run_cmd(cmd):
subprocess.run(cmd, text=True, encoding="utf-8", check=True, shell=True)
def install(xmake_config_flags=""):
run_cmd(f"xmake f {xmake_config_flags} -cv")
run_cmd("xmake")
run_cmd("xmake install")
run_cmd("xmake build infiniop-test")
run_cmd("xmake install infiniop-test")
if __name__ == "__main__":
set_env()
install(" ".join(sys.argv[1:]))
#!/bin/bash
set -e # Exit on error
# Check if project path is provided
if [ -z "$1" ]; then
echo "Usage: source deploy.sh PROJECT_PATH [XMAKE_CONFIG_FLAGS]"
exit 1
fi
# Set INFINI_ROOT
export INFINI_ROOT="$HOME/.infini"
# Check if INFINI_ROOT/bin is already in PATH, if not, add it
case ":$PATH:" in
*":$INFINI_ROOT/bin:"*) ;; # Already in PATH, do nothing
*) export PATH="$INFINI_ROOT/bin:$PATH" ;; # Add to PATH
esac
# Check if INFINI_ROOT/lib is already in LD_LIBRARY_PATH, if not, add it
case ":$LD_LIBRARY_PATH:" in
*":$INFINI_ROOT/lib:"*) ;; # Already in LD_LIBRARY_PATH, do nothing
*) export LD_LIBRARY_PATH="$INFINI_ROOT/lib:$LD_LIBRARY_PATH" ;; # Add to LD_LIBRARY_PATH
esac
# Change to project directory
cd "$1"
# Shift first argument (project path) and pass the rest to xmake
shift
xmake clean -a
xmake f "$@" -cv
xmake
xmake install
xmake build infiniop-test
xmake install infiniop-test
import os
import subprocess
import platform
import sys
PROJECT_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "test", "infiniop")
)
os.chdir(PROJECT_DIR)
def set_env():
if os.environ.get("INFINI_ROOT", "") == "":
os.environ["INFINI_ROOT"] = os.path.expanduser("~/.infini")
if platform.system() == "Windows":
new_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/bin")
if new_path not in os.environ.get("PATH", ""):
os.environ["PATH"] = f"{new_path};{os.environ.get('PATH', '')}"
elif platform.system() == "Linux":
new_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/bin")
if new_path not in os.environ.get("PATH", ""):
os.environ["PATH"] = f"{new_path}:{os.environ.get('PATH', '')}"
new_lib_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/lib")
if new_lib_path not in os.environ.get("LD_LIBRARY_PATH", ""):
os.environ["LD_LIBRARY_PATH"] = (
f"{new_lib_path}:{os.environ.get('LD_LIBRARY_PATH', '')}"
)
else:
raise RuntimeError("Unsupported platform.")
def run_tests(args):
failed = []
for test in [
"gemm.py",
"rms_norm.py",
"causal_softmax.py",
"swiglu.py",
"random_sample.py",
]:
result = subprocess.run(
f"python {test} {args}", text=True, encoding="utf-8", shell=True
)
if result.returncode != 0:
failed.append(test)
return failed
if __name__ == "__main__":
set_env()
failed = run_tests(" ".join(sys.argv[1:]))
if len(failed) == 0:
print("\033[92mAll tests passed!\033[0m")
else:
print("\033[91mThe following tests failed:\033[0m")
for test in failed:
print(f"\033[91m - {test}\033[0m")
exit(len(failed))
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