Skip to content

Commit

Permalink
refactor the test script into stages and remove redundant functions
Browse files Browse the repository at this point in the history
  • Loading branch information
leofang committed Nov 24, 2024
1 parent 681654b commit 97a8bba
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 5 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ jobs:
CUPY_CACHE_DIR: "${{ env.CACHE_DIR }}\\.cupy"
GPU: 1
run: |
echo "test"
ni -force -ItemType File -Path "$env:CUPY_CACHE_DIR\\abc"
#echo "test"
#ni -force -ItemType File -Path "$env:CUPY_CACHE_DIR\\abc"
# The next step requires this environment variable to be visible
echo "CUPY_CACHE_DIR=$env:CUPY_CACHE_DIR" >> $env:GITHUB_ENV
#.pfnci\windows\run.bat 12.0 3.10 test
# FIXME: get the version strings from a test matrix
.pfnci\windows\GHA-test.ps1 -stage setup -python 3.10 -cuda 12.6
.pfnci\windows\GHA-test.ps1 -stage build
.pfnci\windows\GHA-test.ps1 -stage test
- name: Prepare cache
id: prepare-cache
Expand Down
94 changes: 94 additions & 0 deletions .pfnci/windows/GHA-test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Param(
[Parameter(Mandatory=$true)]
[String]$stage,
[Parameter(Mandatory=$false)]
[String]$python,
[Parameter(Mandatory=$false)]
[String]$cuda
)

$ErrorActionPreference = "Stop"
. "$PSScriptRoot\_error_handler.ps1"

. "$PSScriptRoot\_flexci.ps1"


function Main {
# Setup environment
if ($stage -eq "setup") {
echo "Using CUDA $cuda and Python $python"
ActivateCUDA $cuda
if ($cuda -eq "10.2") {
ActivateCuDNN "8.6" $cuda
} else {
ActivateCuDNN "8.8" $cuda
}
ActivateNVTX1
ActivatePython $python
echo "Setting up test environment"
RunOrDie python -V
RunOrDie python -m pip install -U pip setuptools wheel
RunOrDie python -m pip freeze

return
}
elseif ($stage -eq "build") {
# Setup build environment variables
$Env:CUPY_NUM_BUILD_JOBS = "16"
$Env:CUPY_NVCC_GENERATE_CODE = "current"
echo "Environment:"
RunOrDie cmd.exe /C set

echo "Building..."
$build_retval = 0
RunOrDie python -m pip install -U "numpy" "scipy==1.12.*"
python -m pip install ".[all,test]" -v
if (-not $?) {
$build_retval = $LastExitCode
}

if ($build_retval -ne 0) {
throw "Build failed with status $build_retval"
}

return
}
elseif ($stage -eq "test") {
$pytest_opts = "-m", '"not slow"'
}
elseif ($stage -eq "slow") {
$pytest_opts = "-m", "slow"
}
else {
throw "Unsupported stage: $stage"
}

$Env:CUPY_TEST_GPU_LIMIT = $Env:GPU
$Env:CUPY_DUMP_CUDA_SOURCE_ON_ERROR = "1"

# # TODO: update this function?
# $is_pull_request = IsPullRequestTest
# if (-Not $is_pull_request) {
# $Env:CUPY_TEST_FULL_COMBINATION = "1"
# }

# # TODO: do we still need zlib these days?
# # Install dependency for cuDNN 8.3+
# echo ">> Installing zlib"
# InstallZLIB

pushd tests
echo "CuPy Configuration:"
RunOrDie python -c "import cupy; print(cupy); cupy.show_config()"
echo "Running test..."
$pytest_tests = "cupy_tests/core_tests/test*.py" # TODO: remove me
# TODO: pass timeout as a function argument?
$test_retval = RunWithTimeout -timeout 18000 -- python -m pytest -rfEX @pytest_opts @pytest_tests
popd

if ($test_retval -ne 0) {
throw "Test failed with status $test_retval"
}
}

Main
8 changes: 6 additions & 2 deletions .pfnci/windows/_error_handler.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ function RunWithTimeout {
param(
[Parameter(Mandatory=$true)]
[int]$timeout,
[Parameter(Mandatory=$true)]
[Parameter(Mandatory=$false)]
[string]$output,
[Parameter(Mandatory=$true)]
[string]$command,
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)]
[string[]]$params
)
$process = Start-Process -PassThru -NoNewWindow -RedirectStandardOutput $output -FilePath $command -ArgumentList $params
if ($PSBoundParameters.ContainsKey('output')) {
$process = Start-Process -PassThru -NoNewWindow -RedirectStandardOutput $output -FilePath $command -ArgumentList $params
} else {
$process = Start-Process -PassThru -NoNewWindow -FilePath $command -ArgumentList $params
}
try {
$process | Wait-Process -Timeout $timeout
} catch [TimeoutException] {
Expand Down

0 comments on commit 97a8bba

Please sign in to comment.