diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index de74f1605..0b48dbe58 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -1,9 +1,12 @@ + + name: Presubmit Checks on: pull_request: types: [opened, synchronize, reopened] jobs: + title_format: name: Check PR Title if: ${{ github.event.pull_request }} @@ -40,7 +43,6 @@ jobs: git remote add upstream https://github.com/taichi-dev/taichi.git git fetch upstream master sudo apt install clang-format-10 - - name: Cache PIP uses: actions/cache@v2 with: @@ -50,7 +52,6 @@ jobs: - name: Install requirements run: | python3 -m pip install --user -r requirements_dev.txt - - name: Check code format run: | python3 misc/code_format.py @@ -58,232 +59,32 @@ jobs: git commit -am "enforce code format" || true # exit with 1 if there were differences: git diff _fake_squash _enforced_format --exit-code - - - name: Pylint - run: | - # Make sure pylint doesn't regress - pylint python/taichi/ --disable=all --enable=C0121,C0415 - if [ $? -eq 0 ] - then - echo "PASSED: pylint is happy" - exit 0 - else - echo "FAILED: please run the pylint command above and make sure it passes" - exit 1 - fi - - build_and_test_cpu_required: - # This job will be required to pass before merging to master branch. - name: Required Build and Test (CPU) - needs: check_code_format + + performance_monitoring: + name: Performance monitoring (NVGPU) timeout-minutes: 60 - strategy: - matrix: - include: - - os: ubuntu-latest - python: 3.6 - runs-on: ${{ matrix.os }} + runs-on: [self-hosted, x64, cuda, linux, benchmark] steps: - uses: actions/checkout@v2 with: - submodules: "recursive" - - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Download Pre-Built LLVM 10.0.0 - run: python misc/ci_download.py - env: - CI_PLATFORM: ${{ matrix.os }} + submodules: 'recursive' - name: Build & Install - run: .github/workflows/scripts/unix_build.sh - env: - CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CC:BOOL=ON -DTI_WITH_VULKAN:BOOL=OFF -DTI_BUILD_TESTS:BOOL=ON - CXX: clang++ - - - name: Test - run: .github/workflows/scripts/unix_test.sh - env: - RUN_CPP_TESTS: ON - - build_and_test_cpu: - name: Build and Test (CPU) - needs: build_and_test_cpu_required - timeout-minutes: 60 - strategy: - matrix: - include: - - os: macos-latest - python: 3.7 - with_cc: OFF - with_cpp_tests: ON - - os: ubuntu-latest - python: 3.9 - with_cc: OFF - with_cpp_tests: OFF - - os: ubuntu-latest - python: 3.8 - with_cc: ON - with_cpp_tests: OFF - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - with: - submodules: "recursive" - - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Download Pre-Built LLVM 10.0.0 - run: python misc/ci_download.py - env: - CI_PLATFORM: ${{ matrix.os }} - - - name: Build & Install - run: .github/workflows/scripts/unix_build.sh - env: - CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CC:BOOL=${{ matrix.with_cc }} -DTI_WITH_VULKAN:BOOL=OFF -DTI_BUILD_TESTS:BOOL=${{ matrix.with_cpp_tests }} - CXX: clang++ - # [DEBUG] Copy this step around to enable debugging inside Github Action instances. - #- name: Setup tmate session - # uses: mxschmitt/action-tmate@v3 - # with: - # limit-access-to-actor: true - - - name: Test - run: .github/workflows/scripts/unix_test.sh - env: - RUN_CPP_TESTS: ${{ matrix.with_cpp_tests }} - - build_and_test_gpu_linux: - name: Build and Test (GPU) - needs: check_code_format - runs-on: [self-hosted, cuda, vulkan, cn] - timeout-minutes: 60 - steps: - - uses: actions/checkout@v2 - with: - submodules: "recursive" - - - name: Build run: | export PATH=$PATH:/usr/local/cuda/bin .github/workflows/scripts/unix_build.sh env: LLVM_LIB_ROOT_DIR: /opt/taichi-llvm-10.0.0 - CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=ON -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=ON -DTI_BUILD_TESTS:BOOL=ON - BUILD_NUM_THREADS: 8 LLVM_PATH: /opt/taichi-llvm-10.0.0/bin LLVM_DIR: /opt/taichi-llvm-10.0.0/lib/cmake/llvm - CXX: clang++-8 - - - name: Test - run: .github/workflows/scripts/unix_test.sh - env: - DISPLAY: :1 - GPU_TEST: ON - RUN_CPP_TESTS: ON - - build_and_test_windows: - name: Build and Test (Windows) - needs: check_code_format - runs-on: windows-latest - timeout-minutes: 90 - steps: - - name: Install 7Zip PowerShell - shell: powershell - run: Install-Module 7Zip4PowerShell -Force -Verbose - - - uses: actions/checkout@v2 - with: - submodules: "recursive" - - - uses: actions/setup-python@v2 - with: - python-version: 3.7 - - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.0.2 - - - name: Download And Install Vulkan - shell: powershell - run: | - Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/1.2.189.0/windows/VulkanSDK-1.2.189.0-Installer.exe" -OutFile VulkanSDK.exe - $installer = Start-Process -FilePath VulkanSDK.exe -Wait -PassThru -ArgumentList @("/S"); - $installer.WaitForExit(); - - - name: Build - shell: powershell - run: | - $env:Path += ";C:/VulkanSDK/1.2.189.0/Bin" - cd C:\ - Remove-item alias:curl - curl --retry 10 --retry-delay 5 https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/taichi-llvm-10.0.0-msvc2019.zip -LO - 7z x taichi-llvm-10.0.0-msvc2019.zip -otaichi_llvm - curl --retry 10 --retry-delay 5 https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/clang-10.0.0-win.zip -LO - 7z x clang-10.0.0-win.zip -otaichi_clang - $env:PATH = ";C:\taichi_llvm\bin;C:\taichi_clang\bin;" + $env:PATH - clang --version - cd D:\a\taichi\taichi - python -m pip install -r requirements_dev.txt - cd python - git fetch origin master - $env:TAICHI_CMAKE_ARGS = $env:CI_SETUP_CMAKE_ARGS - python build.py build - cd ..\dist - $env:WHL = $(dir *.whl) - python -m pip install $env:WHL - env: - PYTHON: C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe - CI_SETUP_CMAKE_ARGS: -G "Visual Studio 16 2019" -A x64 -DLLVM_DIR=C:\taichi_llvm\lib\cmake\llvm -DTI_WITH_VULKAN:BOOL=ON - VULKAN_SDK: C:/VulkanSDK/1.2.189.0 - - - name: Test - shell: powershell - run: | - $env:PATH = ";C:\taichi_llvm\bin;C:\taichi_clang\bin;" + $env:PATH - python -c "import taichi" - python examples/algorithm/laplace.py - python bin/taichi diagnose - python bin/taichi changelog - python bin/taichi test -vr2 -t2 - env: - PYTHON: C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe - - build_and_test_m1: - name: Build and Test (Apple M1) - needs: check_code_format - timeout-minutes: 60 - strategy: - matrix: - include: - - os: macos-latest - python: 3.8 - defaults: - run: - # https://github.com/actions/runner/issues/805#issuecomment-844426478 - shell: "/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}" - runs-on: [self-hosted, m1] - steps: - - uses: actions/checkout@v2 - with: - submodules: "recursive" + CUDA_TOOLKIT_ROOT_DIR: /usr/local/cuda/ + CI_SETUP_CMAKE_ARGS: -DTI_WITH_CUDA_TOOLKIT:BOOL=ON + BUILD_NUM_THREADS: 8 + CXX: clang++-10 - - name: Build - run: | - rm -rf $HOME/Library/Python/3.8/lib/python/site-packages/taichi - .github/workflows/scripts/unix_build.sh + - name: Dump GitHub context env: - CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CUDA:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=OFF -DTI_BUILD_TESTS:BOOL=ON - CXX: clang++ - - - name: Test + GITHUB_CONTEXT: ${{ toJson(github) }} run: | - export PATH=$PATH:$HOME/Library/Python/3.8/bin - python3 examples/algorithm/laplace.py - TI_LIB_DIR=`python3 -c "import taichi;print(taichi.__path__[0])" | tail -1` - TI_LIB_DIR="$TI_LIB_DIR/lib" ./build/taichi_cpp_tests - ti test -vr2 -t4 -x + python3 benchmarks/misc/test.py + python3 benchmarks/misc/print.py \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33a82fea0..03956a923 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,9 +20,9 @@ jobs: - id: set-matrix run: | # For nightly release, we only run on python 3.8 - [ -z "${{ github.event.action }}" ] && matrix="[{\"name\":\"taichi-nightly\",\"python\":\"3.8\"}]" + [ -z "${{ github.event.action }}" ] && matrix="[{\"name\":\"taichi-nightly\",\"python\":\"3.8\",\"conda_python\":\"py38\"}]" # For production release, we run on four python versions. - [ -z "${{ github.event.action }}" ] || matrix="[{\"name\":\"taichi\",\"python\":\"3.6\"},{\"name\":\"taichi\",\"python\":\"3.7\"},{\"name\":\"taichi\",\"python\":\"3.8\"},{\"name\":\"taichi\",\"python\":\"3.9\"}]" + [ -z "${{ github.event.action }}" ] || matrix="[{\"name\":\"taichi\",\"python\":\"3.6\",\"conda_python\":\"py36\"},{\"name\":\"taichi\",\"python\":\"3.7\",\"conda_python\":\"py37\"},{\"name\":\"taichi\",\"python\":\"3.8\",\"conda_python\":\"py38\"},{\"name\":\"taichi\",\"python\":\"3.9\",\"conda_python\":\"py39\"}]" echo ::set-output name=matrix::{\"include\":$(echo $matrix)}\" # M1 only supports py38 and py39(conda), so change matrix. [ -z "${{ github.event.action }}" ] && matrix_osx="[{\"name\":\"taichi-nightly\",\"python\":\"3.8\"}]" @@ -41,56 +41,37 @@ jobs: with: submodules: "recursive" - - name: Create Python Wheel + - name: Build run: | - # We hacked here because conda activate in CI won't update python PATH - # automatically. So we don't activate and use desired python version - # directly. - export PATH=/home/buildbot/miniconda3/envs/$PYTHON/bin:$PATH - TAICHI_REPO_DIR=`pwd` - export PATH=$LLVM_LIB_ROOT_DIR/bin:/usr/local/cuda/bin:$PATH - export LLVM_DIR=$LLVM_LIB_ROOT_DIR/lib/cmake/llvm - export CXX=clang++-8 - python3 -m pip uninstall taichi taichi-nightly -y - python3 -m pip install -r requirements_dev.txt - python3 -m pip install twine - cd python - git fetch origin master - export TAICHI_CMAKE_ARGS=$CI_SETUP_CMAKE_ARGS - python3 build.py build --project_name $PROJECT_NAME - cd .. - NUM_WHL=`ls dist/*.whl | wc -l` - if [ $NUM_WHL -ne 1 ]; then echo 'ERROR: created more than 1 whl.' && exit 1; fi - python3 -m pip install dist/*.whl + mkdir -m777 wheel + + docker create -v `pwd`/wheel:/wheel --user dev --name taichi_build --gpus all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix registry.taichigraphics.com/taichidev-ubuntu18.04:v0.1.1 /home/dev/test_actions/.github/workflows/scripts/unix_docker_build.sh $PY $GPU_BUILD $PROJECT_NAME "$CI_SETUP_CMAKE_ARGS" + tar -cf - ../${{ github.event.repository.name }} --mode u=+rwx,g=+rwx,o=+rwx --owner dev --group dev | docker cp - taichi_build:/home/dev/ + docker start -a taichi_build env: - LLVM_LIB_ROOT_DIR: /opt/taichi-llvm-10.0.0 - BUILD_NUM_THREADS: 8 - CI_SETUP_CMAKE_ARGS: -DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_OPENGL:BOOL=ON -DTI_WITH_CC:BOOL=OFF -DTI_BUILD_TESTS:BOOL=${{ matrix.with_cpp_tests }} + PY: ${{ matrix.conda_python }} + GPU_BUILD: ON + CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=ON -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=ON -DTI_BUILD_TESTS:BOOL=ON PROJECT_NAME: ${{ matrix.name }} - PYTHON: ${{ matrix.python }} + DISPLAY: :1 - name: Archive Wheel Artifacts uses: actions/upload-artifact@v2 with: name: ${{ matrix.name }}-py${{ matrix.python }}-linux.whl - path: dist/*.whl + path: wheel/*.whl retention-days: 20 - name: Test run: | - export PATH=/home/buildbot/miniconda3/envs/$PYTHON/bin:$PATH - python3 examples/algorithm/laplace.py - export DISPLAY=:1 - hash -r - glewinfo - ti diagnose - ti changelog - ti test -vr2 -t2 -k "not ndarray and not torch" - # ndarray test might OOM if run with -t2. - # FIXME: unify this with presubmit.yml to avoid further divergence - ti test -vr2 -t1 -k "ndarray or torch" + docker create --user dev --name taichi_test --gpus all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix registry.taichigraphics.com/taichidev-ubuntu18.04:v0.1.1 /home/dev/unix_docker_test.sh $PY $GPU_TEST + docker cp .github/workflows/scripts/unix_docker_test.sh taichi_test:/home/dev/unix_docker_test.sh + docker cp wheel/*.whl taichi_test:/home/dev/ + docker start -a taichi_test env: - PYTHON: ${{ matrix.python }} + PY: ${{ matrix.conda_python }} + GPU_TEST: ON + DISPLAY: :1 - name: Upload PyPI env: @@ -100,11 +81,17 @@ jobs: PROJECT_NAME: ${{ matrix.name }} PYTHON: ${{ matrix.python }} run: | - export PATH=/home/buildbot/miniconda3/envs/$PYTHON/bin:$PATH + mkdir dist + cp wheel/*.whl dist/ cd python if [ $PROJECT_NAME == "taichi-nightly" ]; then export PYPI_PWD="$NIGHT_PWD" && python3 build.py upload --skip_build --testpypi --project_name $PROJECT_NAME elif [ $PROJECT_NAME == "taichi" ]; then export PYPI_PWD="$PROD_PWD" && python3 build.py upload --skip_build; fi + - name: clean docker container + if: always() + run: | + docker rm taichi_build taichi_test -f + build_and_upload_mac: name: Build and Upload (macOS only) needs: matrix_prep @@ -132,6 +119,7 @@ jobs: export PATH=$TAICHI_REPO_DIR/taichi-llvm/bin/:$PATH export CXX=clang++ python -m pip install -r requirements_dev.txt + python -m pip install -r requirements_test.txt cd python git fetch origin master export TAICHI_CMAKE_ARGS=$CI_SETUP_CMAKE_ARGS @@ -141,7 +129,7 @@ jobs: if [ $NUM_WHL -ne 1 ]; then echo 'ERROR: created more than 1 whl.' && exit 1; fi pip install dist/*.whl env: - CI_SETUP_CMAKE_ARGS: -DTI_WITH_VULKAN:BOOL=OFF -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_BUILD_TESTS:BOOL=${{ matrix.with_cpp_tests }} + CI_SETUP_CMAKE_ARGS: -DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_BUILD_TESTS:BOOL=${{ matrix.with_cpp_tests }} PROJECT_NAME: ${{ matrix.name }} - name: Archive Wheel Artifacts @@ -155,7 +143,7 @@ jobs: run: | python examples/algorithm/laplace.py ti diagnose - ti test -vr2 -t2 + ti test -vr2 -t2 -a cpu,metal - name: Upload PyPI env: @@ -193,6 +181,7 @@ jobs: git --version export CXX=clang++ python3 -m pip install -r requirements_dev.txt + python3 -m pip install -r requirements_test.txt cd python git fetch origin master export TAICHI_CMAKE_ARGS=$CI_SETUP_CMAKE_ARGS @@ -202,7 +191,7 @@ jobs: if [ $NUM_WHL -ne 1 ]; then echo 'ERROR: created more than 1 whl.' && exit 1; fi python3 -m pip install dist/*.whl env: - CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CUDA:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=OFF -DTI_WITH_TESTS:BOOL=ON + CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CUDA:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_TESTS:BOOL=ON PROJECT_NAME: ${{ matrix.name }} PYTHON: ${{ matrix.python }} @@ -250,6 +239,7 @@ jobs: git --version export CXX=clang++ python3 -m pip install -r requirements_dev.txt + python3 -m pip install -r requirements_test.txt cd python git fetch origin master export TAICHI_CMAKE_ARGS=$CI_SETUP_CMAKE_ARGS @@ -259,7 +249,7 @@ jobs: if [ $NUM_WHL -ne 1 ]; then echo 'ERROR: created more than 1 whl.' && exit 1; fi python3 -m pip install dist/*.whl env: - CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CUDA:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=OFF -DTI_WITH_TESTS:BOOL=ON + CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CUDA:BOOL=OFF -DTI_WITH_CC:BOOL=OFF -DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_TESTS:BOOL=ON PROJECT_NAME: ${{ matrix.name }} PYTHON: ${{ matrix.python }} @@ -336,6 +326,7 @@ jobs: clang --version cd D:\a\taichi\taichi python -m pip install -r requirements_dev.txt + python -m pip install -r requirements_test.txt cd python git fetch origin master $env:TAICHI_CMAKE_ARGS = $env:CI_SETUP_CMAKE_ARGS diff --git a/.github/workflows/scripts/unix_docker_build.sh b/.github/workflows/scripts/unix_docker_build.sh new file mode 100755 index 000000000..e69de29bb diff --git a/.github/workflows/scripts/unix_docker_test.sh b/.github/workflows/scripts/unix_docker_test.sh new file mode 100755 index 000000000..d3df0c2b5 --- /dev/null +++ b/.github/workflows/scripts/unix_docker_test.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -ex + +# Parse ARGs +PY=$1 +GPU_TEST=$2 + +source /home/dev/miniconda/etc/profile.d/conda.sh +conda activate $PY + +python3 -m pip install ./*.whl + +if [[ $GPU_TEST == "OFF" ]] +then + python3 -m pip install -r requirements_test.txt +fi + +export TI_IN_DOCKER=true +ti diagnose +ti changelog + +if [[ $GPU_TEST == "OFF" ]] +then + ti test -vr2 -t2 +else + ti test -vr2 -t2 -k "not ndarray and not torch" + ti test -vr2 -t1 -k "ndarray or torch" +fi diff --git a/.github/workflows/scripts/unix_test.sh b/.github/workflows/scripts/unix_test.sh index 907c52160..53bf5d07e 100755 --- a/.github/workflows/scripts/unix_test.sh +++ b/.github/workflows/scripts/unix_test.sh @@ -1,5 +1,6 @@ set -ex TAICHI_REPO_DIR=`pwd` +python3 -m pip install -r requirements_test.txt TI_LIB_DIR=`python3 -c "import taichi;print(taichi.__path__[0])" | tail -1` [[ $RUN_CPP_TESTS == "ON" ]] && TI_LIB_DIR="$TI_LIB_DIR/lib" ./build/taichi_cpp_tests export PATH=$TAICHI_REPO_DIR/taichi-llvm/bin/:$PATH diff --git a/benchmarks/misc/membound.py b/benchmarks/misc/membound.py index 6f1952857..8b1378917 100644 --- a/benchmarks/misc/membound.py +++ b/benchmarks/misc/membound.py @@ -1,78 +1 @@ -import time -from membound_cases import memory_bound_cases_list -from utils import (arch_name, dtype2str, geometric_mean, kibibyte, - md_table_header, size2str) - -import taichi as ti - - -class MemoryBound: - suite_name = 'memorybound' - supported_archs = [ti.cpu, ti.cuda] - test_cases = memory_bound_cases_list - test_dtype_list = [ti.i32, ti.i64, ti.f32, ti.f64] - test_dsize_list = [(4**i) * kibibyte - for i in range(1, 10)] #[4KB,16KB...256MB] - basic_repeat_times = 10 - evaluator = [geometric_mean] - - def __init__(self, arch): - self.arch = arch - self.cases_impl = [] - for case in self.test_cases: - for dtype in self.test_dtype_list: - impl = CaseImpl(case, arch, dtype, self.test_dsize_list, - self.evaluator) - self.cases_impl.append(impl) - - def run(self): - for case in self.cases_impl: - case.run() - - def get_markdown_lines(self): - lines = [] - lines += md_table_header(self.suite_name, self.arch, - self.test_dsize_list, self.basic_repeat_times, - self.evaluator) - - result_header = '|kernel elapsed time(ms)' + ''.join( - '|' for i in range( - len(self.test_dsize_list) + len(MemoryBound.evaluator))) - lines += [result_header] - for case in self.cases_impl: - lines += case.get_markdown_lines() - lines.append('') - return lines - - -class CaseImpl: - def __init__(self, func, arch, test_dtype, test_dsize_list, evaluator): - self.func = func - self.name = func.__name__ - self.arch = arch - self.test_dtype = test_dtype - self.test_dsize_list = test_dsize_list - self.min_time_in_us = [] #test results - self.evaluator = evaluator - - def run(self): - ti.init(kernel_profiler=True, arch=self.arch) - print("TestCase[%s.%s.%s]" % (self.func.__name__, arch_name( - self.arch), dtype2str[self.test_dtype])) - for test_dsize in self.test_dsize_list: - print("test_dsize = %s" % (size2str(test_dsize))) - self.min_time_in_us.append( - self.func(self.arch, self.test_dtype, test_dsize, - MemoryBound.basic_repeat_times)) - time.sleep(0.2) - ti.reset() - - def get_markdown_lines(self): - string = '|' + self.name + '.' + dtype2str[self.test_dtype] + '|' - string += ''.join( - str(round(time, 4)) + '|' for time in self.min_time_in_us) - string += ''.join( - str(round(item(self.min_time_in_us), 4)) + '|' - for item in self.evaluator) - return [string] diff --git a/benchmarks/misc/membound_cases.py b/benchmarks/misc/membound_cases.py index 5792a85a2..8b1378917 100644 --- a/benchmarks/misc/membound_cases.py +++ b/benchmarks/misc/membound_cases.py @@ -1,79 +1 @@ -from utils import dtype_size, scaled_repeat_times -import taichi as ti - - -def init_const(x, dtype, num_elements): - @ti.kernel - def init_const(x: ti.template(), n: ti.i32): - for i in range(n): - x[i] = ti.cast(0.7, dtype) - - init_const(x, num_elements) - - -def membound_benchmark(func, num_elements, repeat): - # compile the kernel first - func(num_elements) - ti.clear_kernel_profile_info() - for i in range(repeat): - func(num_elements) - kernelname = func.__name__ - quering_result = ti.query_kernel_profile_info(kernelname) - return quering_result.min - - -def fill(arch, dtype, dsize, repeat=10): - - repeat = scaled_repeat_times(arch, dsize, repeat) - num_elements = dsize // dtype_size[dtype] - - x = ti.field(dtype, shape=num_elements) - - @ti.kernel - def fill_const(n: ti.i32): - for i in range(n): - x[i] = ti.cast(0.7, dtype) - - return membound_benchmark(fill_const, num_elements, repeat) - - -def saxpy(arch, dtype, dsize, repeat=10): - - repeat = scaled_repeat_times(arch, dsize, repeat) - num_elements = dsize // dtype_size[dtype] // 3 #z=x+y - - x = ti.field(dtype, shape=num_elements) - y = ti.field(dtype, shape=num_elements) - z = ti.field(dtype, shape=num_elements) - - @ti.kernel - def saxpy(n: ti.i32): - for i in range(n): - z[i] = 17 * x[i] + y[i] - - init_const(x, dtype, num_elements) - init_const(y, dtype, num_elements) - - return membound_benchmark(saxpy, num_elements, repeat) - - -def reduction(arch, dtype, dsize, repeat=10): - - repeat = scaled_repeat_times(arch, dsize, repeat) - num_elements = dsize // dtype_size[dtype] - - x = ti.field(dtype, shape=num_elements) - y = ti.field(dtype, shape=()) - y[None] = 0 - - @ti.kernel - def reduction(n: ti.i32): - for i in range(n): - y[None] += x[i] - - init_const(x, dtype, num_elements) - return membound_benchmark(reduction, num_elements, repeat) - - -memory_bound_cases_list = [fill, saxpy, reduction] diff --git a/benchmarks/misc/print.py b/benchmarks/misc/print.py new file mode 100644 index 000000000..8b5c01809 --- /dev/null +++ b/benchmarks/misc/print.py @@ -0,0 +1,13 @@ +import json +import os +import re +import sys + + +def main(): + num = os.environ.get('PULL_REQUEST_NUMBER') + print(f'PULL_REQUEST_NUMBER = {num}') + + +if __name__ == '__main__': + main() diff --git a/benchmarks/misc/run.py b/benchmarks/misc/run.py index 4922e043d..8b1378917 100644 --- a/benchmarks/misc/run.py +++ b/benchmarks/misc/run.py @@ -1,78 +1 @@ -import os -import warnings -from membound import MemoryBound -from taichi.core import ti_core as _ti_core -from utils import arch_name, datatime_with_format - -import taichi as ti - -benchmark_suites = [MemoryBound] -benchmark_archs = [ti.cpu, ti.cuda] - - -class CommitInfo: - def __init__(self, pull_request_id, commit_hash): - self.pull_request_id = pull_request_id - self.commit_hash = commit_hash #str - self.archs = [] #['x64','cuda','vulkan', ...] - self.datetime = [] #[start, end] - - -class BenchmarkSuites: - def __init__(self, arch): - self.suites = [] - self.arch = arch - for suite in benchmark_suites: - if self.check_supported(arch, suite): - self.suites.append(suite(arch)) - - def check_supported(self, arch, suite): - if arch in suite.supported_archs: - return True - else: - warnings.warn( - f'Arch [{arch_name(arch)}] does not exist in {suite.__name__}.supported_archs.', - UserWarning, - stacklevel=2) - return False - - def run(self): - print(f'Arch [{arch_name(self.arch)}] Running...') - for suite in self.suites: - suite.run() - - def save_to_markdown(self, arch_dir='./'): - current_time = datatime_with_format() - commit_hash = _ti_core.get_commit_hash() #[:8] - for suite in self.suites: - file_name = f'{suite.suite_name}.md' - path = os.path.join(arch_dir, file_name) - with open(path, 'w') as f: - lines = [ - f'commit_hash: {commit_hash}\n', - f'datatime: {current_time}\n' - ] - lines += suite.get_markdown_lines() - for line in lines: - print(line, file=f) - - -def main(): - - benchmark_dir = os.path.join(os.getcwd(), 'results') - os.makedirs(benchmark_dir) - - for arch in benchmark_archs: - #make dir - arch_dir = os.path.join(benchmark_dir, arch_name(arch)) - os.makedirs(arch_dir) - #init & run - suites = BenchmarkSuites(arch) - suites.run() - #save result - suites.save_to_markdown(arch_dir) - - -if __name__ == '__main__': - main() diff --git a/benchmarks/misc/test.py b/benchmarks/misc/test.py new file mode 100644 index 000000000..7f550176b --- /dev/null +++ b/benchmarks/misc/test.py @@ -0,0 +1,17 @@ +import json +import os +import re +import sys + + +def main(): + github_context = os.environ.get('GITHUB_CONTEXT') + github_info_dict = {} + github_info_dict = json.loads(github_context) + pr_number = re.sub("\D", "", github_info_dict["ref"]) + os.environ['PULL_REQUEST_NUMBER'] = pr_number + print(os.environ.get('PULL_REQUEST_NUMBER')) + + +if __name__ == '__main__': + main() diff --git a/benchmarks/misc/utils.py b/benchmarks/misc/utils.py index 3548151ec..8b1378917 100644 --- a/benchmarks/misc/utils.py +++ b/benchmarks/misc/utils.py @@ -1,68 +1 @@ -import datetime -import taichi as ti - -kibibyte = 1024 - -bls2str = {False: "BLS_off", True: "BLS_on"} -dense2str = {False: "Struct_for", True: "Range_for"} - -dtype2str = {ti.i32: "i32", ti.i64: "i64", ti.f32: "f32", ti.f64: "f64"} -dtype_size = {ti.i32: 4, ti.i64: 8, ti.f32: 4, ti.f64: 8} - -# for output string -size_subsection = [(0.0, 'B'), (1024.0, 'KB'), (1048576.0, 'MB'), - (1073741824.0, 'GB'), (float('inf'), 'INF')] #B KB MB GB - - -def arch_name(arch): - return str(arch).replace('Arch.', '') - - -def datatime_with_format(): - return datetime.datetime.now().isoformat() - - -def size2str(size_in_byte): - for dsize, units in reversed(size_subsection): - if size_in_byte >= dsize: - return str(round(size_in_byte / dsize, 4)) + units - - -def geometric_mean(data_array): - product = 1 - for data in data_array: - product *= data - return pow(product, 1.0 / len(data_array)) - - -def scaled_repeat_times(arch, datasize, repeat=1): - if (arch == ti.gpu) | (arch == ti.opengl) | (arch == ti.cuda): - repeat *= 10 - if datasize <= 4 * 1024 * 1024: - repeat *= 10 - return repeat - - -def md_table_header(suite_name, arch, test_dsize, test_repeat, - results_evaluation): - header = '|' + suite_name + '.' + ti.core.arch_name(arch) + '|' - header += ''.join('|' for i in range(len(test_dsize))) - header += ''.join(item.__name__ + '|' for item in results_evaluation) - - layout = '|:--:|' - layout += ''.join( - ':--:|' for i in range(len(test_dsize) + len(results_evaluation))) - - size = '|**data size**|' - size += ''.join(size2str(size) + '|' for size in test_dsize) - size += ''.join('|' for i in range(len(results_evaluation))) - - repeat = '|**repeat**|' - repeat += ''.join( - str(scaled_repeat_times(arch, size, test_repeat)) + '|' - for size in test_dsize) - repeat += ''.join('|' for i in range(len(results_evaluation))) - - lines = [header, layout, size, repeat] - return lines