Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
squarefk authored Jul 22, 2021
2 parents 023e462 + c229465 commit 450ba98
Show file tree
Hide file tree
Showing 69 changed files with 2,152 additions and 308 deletions.
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Related issue = #
<!--
Thank you for your contribution!
If it is your first time contributing to Taichi, please read our Contributor Guideline:
https://taichi.graphics/contribution/
If it is your first time contributing to Taichi, please read our Contributor Guidelines:
https://docs.taichi.graphics/docs/lang/articles/contribution/contributor_guide
- Please always prepend your PR title with tags such as [CUDA], [Lang], [Doc], [Example]. For a complete list of valid PR tags, please check out https://github.com/taichi-dev/taichi/blob/master/misc/prtags.json.
- Use upper-case tags (e.g., [Metal]) for PRs that change public APIs. Otherwise, please use lower-case tags (e.g., [metal]).
- More details: https://taichi.graphics/contribution/contributor_guide.html#pr-title-format-and-tags
- More details: https://docs.taichi.graphics/docs/lang/articles/contribution/contributor_guide#pr-title-format-and-tags
- Please fill in the issue number that this PR relates to.
- If your PR fixes the issue **completely**, use the `close` or `fixes` prefix so that GitHub automatically closes the issue when the PR is merged. For example,
Expand Down
39 changes: 24 additions & 15 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

- name: Build
run: |
export TAICHI_REPO_DIR=`pwd`
TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/taichi-llvm/bin/:$PATH
export CXX=clang++
python misc/ci_setup.py ci
Expand All @@ -81,13 +81,16 @@ jobs:

- name: Test
run: |
export TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/bin:$PATH
TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/taichi-llvm/bin/:$PATH
export PYTHONPATH=$TAICHI_REPO_DIR/python
# Note we only need this since we cannot write into system python package.
export PATH=$PATH:$HOME/.local/bin
hash -r
python examples/algorithm/laplace.py
ti diagnose
./build/taichi_cpp_tests
# TODO: make cpp tests work in both release & dev mode.
# Currently cpp tests only works in dev mode since it depends on the path set there.
TAICHI_REPO_DIR=$TAICHI_REPO_DIR ./build/taichi_cpp_tests
ti test -vr2 -t2
build_and_test_cpu:
Expand Down Expand Up @@ -126,22 +129,30 @@ jobs:

- name: Build
run: |
export TAICHI_REPO_DIR=`pwd`
TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/taichi-llvm/bin/:$PATH
export CXX=clang++
python misc/ci_setup.py ci
env:
CI_SETUP_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=OFF -DTI_WITH_CC:BOOL=${{ matrix.with_cc }} -DTI_BUILD_TESTS:BOOL=${{ matrix.with_cpp_tests }}

# [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: |
export TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/bin:$PATH
TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/taichi-llvm/bin/:$PATH
export PYTHONPATH=$TAICHI_REPO_DIR/python
export PATH=$PATH:$HOME/.local/bin
hash -r
python examples/algorithm/laplace.py
ti diagnose
[ "$RUN_CPP_TESTS" = "ON" ] && ./build/taichi_cpp_tests
# TODO: make cpp tests work in both release & dev mode.
# Currently cpp tests only works in dev mode since it depends on the path set there.
[ "$RUN_CPP_TESTS" = "ON" ] && TAICHI_REPO_DIR=$TAICHI_REPO_DIR ./build/taichi_cpp_tests
ti test -vr2 -t2
env:
RUN_CPP_TESTS: ${{ matrix.with_cpp_tests }}
Expand All @@ -156,7 +167,6 @@ jobs:
- name: Build
run: |
git --version
export TAICHI_REPO_DIR=`pwd`
export PATH=/home/github/taichi-llvm/bin/:$PATH
export CXX=clang++-8
export PYTHON=/usr/bin/python3
Expand All @@ -167,11 +177,10 @@ jobs:
- name: Test
run: |
export PYTHON=/usr/bin/python3
export TAICHI_REPO_DIR=`pwd`
export PATH=$TAICHI_REPO_DIR/bin:$PATH
export PATH=/home/github/taichi-llvm/bin/:$PATH
export PYTHONPATH=$TAICHI_REPO_DIR/python
export PATH=$PATH:$HOME/.local/bin
export DISPLAY=:1
hash -r
glewinfo
$PYTHON examples/algorithm/laplace.py
ti diagnose
Expand Down Expand Up @@ -215,7 +224,7 @@ jobs:
python misc/ci_setup.py ci
mkdir build
cd build
cmake .. -G"Visual Studio 16 2019" -A x64 -DPYTHON_EXECUTABLE="$env:PYTHON" -DLLVM_DIR="C:\taichi_llvm\lib\cmake\llvm"
cmake .. -G"Visual Studio 16 2019" -A x64 -DPYTHON_EXECUTABLE="$env:PYTHON" -DLLVM_DIR="C:\taichi_llvm\lib\cmake\llvm"
msbuild /p:Configuration=RelWithDebInfo /p:Platform=x64 /m taichi.sln
cd ..
env:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ runtimes/*.png
runtimes/taichi_core*
runtimes/libtaichi_core*
.pypirc
python/dist
dist/
python/MANIFEST
build/
bin/
Expand All @@ -54,6 +54,8 @@ __pycache__
*.ppm
*.png
*.jpg
!docs/**/*.jpg
!docs/**/*.png
*.egg-info
.tlang_cache
/taichi/common/version.h
Expand All @@ -76,3 +78,4 @@ _build
*.yml
*.dot
*.json
!docs/**/*.json
31 changes: 28 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ cmake_minimum_required(VERSION 3.12)

project(taichi)

SET(TI_VERSION_MAJOR 0)
SET(TI_VERSION_MINOR 7)
SET(TI_VERSION_PATCH 25)
SET(TI_VERSION_MAJOR ${TI_VERSION_MAJOR})
SET(TI_VERSION_MINOR ${TI_VERSION_MINOR})
SET(TI_VERSION_PATCH ${TI_VERSION_PATCH})

set(CMAKE_CXX_STANDARD 17)

Expand Down Expand Up @@ -76,6 +76,31 @@ add_custom_target(
)
add_dependencies(${CORE_LIBRARY_NAME} generate_commit_hash)

if (TI_WITH_CUDA)
set(CUDA_ARCH "cuda")
endif()

find_program(CLANG_EXECUTABLE NAMES clang clang-7 clang-8 clang-9 clang-10)
if (NOT CLANG_EXECUTABLE)
message(FATAL_ERROR "Cannot find any clang executable.")
endif()

find_program(LLVM_AS_EXECUTABLE NAMES llvm-as)
if (NOT LLVM_AS_EXECUTABLE)
message(FATAL_ERROR "Cannot find llvm-as executable.")
endif()

# Build llvm-runtime for host arch and cuda (if available)
foreach(arch IN LISTS HOST_ARCH CUDA_ARCH)
add_custom_target(
"generate_llvm_runtime_${arch}"
COMMAND ${CLANG_EXECUTABLE} -S runtime.cpp -o runtime.ll -fno-exceptions -emit-llvm -std=c++17 -D "ARCH_${arch}" -I ${PROJECT_SOURCE_DIR};
COMMAND ${LLVM_AS_EXECUTABLE} runtime.ll -o "runtime_${arch}.bc"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/taichi/runtime/llvm"
)
add_dependencies(${CORE_LIBRARY_NAME} "generate_llvm_runtime_${arch}")
endforeach()

FILE(WRITE ${CMAKE_CURRENT_LIST_DIR}/taichi/common/version.h
"#pragma once\n"
"#define TI_VERSION_MAJOR \"${TI_VERSION_MAJOR}\"\n"
Expand Down
14 changes: 14 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include MANIFEST.in
include python/*.txt
include python/*.py
include *.cfg
include python/taichi/*.md
include python/taichi/assets/*
include python/taichi/examples/*
include python/taichi/tests/*
include python/taichi/lib/*.so
include python/taichi/lib/*.pyd
include python/taichi/lib/*.bc

global-exclude *.pyc *.pyo
global-exclude ffmpeg
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img width="500px" src="https://github.com/taichi-dev/taichi/raw/master/misc/logo.png">
<h3> <a href="https://taichi.readthedocs.io/en/stable/hello.html"> Tutorial </a> | <a href="https://github.com/taichi-dev/taichi/tree/master/examples"> Examples </a> | <a href="https://forum.taichi.graphics/"> Forum </a> | <a href="http://hub.taichi.graphics/"> Playground </a> </h3>
<h3> <a href="https://taichi.readthedocs.io/en/stable/"> Documentation </a> | <a href="https://taichi.readthedocs.io/zh_CN/latest/"> 简体中文文档 </a> | <a href="https://taichi.readthedocs.io/en/stable/contributor_guide.html"> Contributor Guidelines </a> </h3>
<h3> <a href="https://docs.taichi.graphics/"> Tutorial </a> | <a href="https://github.com/taichi-dev/taichi/tree/master/examples"> Examples </a> | <a href="https://forum.taichi.graphics/"> Forum </a><!-- | <a href="http://hub.taichi.graphics/"> Playground </a> --></h3>
<h3> <a href="https://docs.taichi.graphics/"> Documentation </a> | <a href="https://docs.taichi.graphics/zh-Hans/docs/"> 简体中文文档 </a> | <a href="https://docs.taichi.graphics/docs/lang/articles/contribution/contributor_guide"> Contributor Guidelines </a> </h3>
</div>

[![AppVeyor Status](https://img.shields.io/appveyor/build/yuanming-hu/taichi?logo=AppVeyor&label=AppVeyor)](https://ci.appveyor.com/project/yuanming-hu/taichi/branch/master)
Expand All @@ -13,20 +13,20 @@

**Taichi** (太极) is a programming language designed for *high-performance computer graphics*. It is deeply embedded in **Python**, and its **just-in-time compiler** offloads compute-intensive tasks to multi-core CPUs and massively parallel GPUs.

<a href="https://github.com/taichi-dev/taichi/blob/master/examples/fractal.py#L1-L31"> <img src="https://github.com/taichi-dev/public_files/raw/master/taichi/fractal_code.png" height="270px"></a> <img src="https://raw.githubusercontent.com/taichi-dev/public_files/master/taichi/fractal_small.gif" height="270px">
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/simulation/fractal.py#L1-L31"> <img src="https://github.com/taichi-dev/public_files/raw/master/taichi/fractal_code.png" height="270px"></a> <img src="https://raw.githubusercontent.com/taichi-dev/public_files/master/taichi/fractal_small.gif" height="270px">

Advanced features of Taichi include [spatially sparse computing](https://taichi.readthedocs.io/en/latest/sparse.html) and [differentiable programming](https://taichi.readthedocs.io/en/latest/differentiable_programming.html) [[examples]](https://github.com/yuanming-hu/difftaichi).
Advanced features of Taichi include [spatially sparse computing](https://docs.taichi.graphics/docs/lang/articles/advanced/sparse) and [differentiable programming](https://docs.taichi.graphics/docs/lang/articles/advanced/differentiable_programming) [[examples]](https://github.com/yuanming-hu/difftaichi).

**Please check out our SIGGRAPH 2020 course on Taichi basics:** [YouTube](https://youtu.be/Y0-76n3aZFA), [Bilibili](https://www.bilibili.com/video/BV1kA411n7jk/), [slides (pdf)](https://yuanming.taichi.graphics/publication/2020-taichi-tutorial/taichi-tutorial.pdf).

**中文视频教程:** [[哔哩哔哩]](https://www.bilibili.com/video/BV1gA411j7H5), [[幻灯片]](https://yuanming.taichi.graphics/publication/2020-taichi-tutorial/taichi-tutorial.pdf)

## Examples ([More...](misc/examples.md))

<a href="https://github.com/taichi-dev/taichi/blob/master/examples/mpm128.py"><img src="https://github.com/taichi-dev/public_files/raw/master/taichi/mpm128.gif" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/stable_fluid.py"> <img src="https://github.com/taichi-dev/public_files/raw/master/taichi/stable_fluids.gif" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/sdf_renderer.py"><img src="https://github.com/taichi-dev/public_files/raw/master/taichi/sdf_renderer.jpg" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/euler.py"><img src="https://github.com/taichi-dev/public_files/raw/master/taichi/euler.gif" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/simulation/mpm128.py"><img src="https://github.com/taichi-dev/public_files/raw/master/taichi/mpm128.gif" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/simulation/stable_fluid.py"> <img src="https://github.com/taichi-dev/public_files/raw/master/taichi/stable_fluids.gif" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/rendering/sdf_renderer.py"><img src="https://github.com/taichi-dev/public_files/raw/master/taichi/sdf_renderer.jpg" height="192px"></a>
<a href="https://github.com/taichi-dev/taichi/blob/master/examples/simulation/euler.py"><img src="https://github.com/taichi-dev/public_files/raw/master/taichi/euler.gif" height="192px"></a>

## Installation [![Downloads](https://pepy.tech/badge/taichi)](https://pepy.tech/project/taichi)

Expand Down Expand Up @@ -67,3 +67,7 @@ If you use Taichi in your research, please cite our papers:
- [Taichi Conference](https://github.com/taichi-dev/taichicon): Taichi developer conferences.
- [GAMES 201 Lectures](https://github.com/taichi-dev/games201): (Chinese) A hands-on course on building advanced physics engines, based on Taichi.
- [More...](misc/links.md)

## Security

Please disclose security issues responsibly by contacting [email protected].
8 changes: 7 additions & 1 deletion cmake/PythonNumpyPybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ endif ()

if (WIN32)
execute_process(COMMAND where ${PYTHON_EXECUTABLE}
OUTPUT_VARIABLE PYTHON_EXECUTABLE_PATH)
OUTPUT_VARIABLE PYTHON_EXECUTABLE_PATHS)
if (${PYTHON_EXECUTABLE_PATHS})
string(FIND ${PYTHON_EXECUTABLE_PATHS} "\n" _LINE_BREAK_LOC)
string(SUBSTRING ${PYTHON_EXECUTABLE_PATHS} 0 ${_LINE_BREAK_LOC} PYTHON_EXECUTABLE_PATH)
else ()
set(PYTHON_EXECUTABLE_PATH ${PYTHON_EXECUTABLE})
endif ()
else ()
execute_process(COMMAND which ${PYTHON_EXECUTABLE}
OUTPUT_VARIABLE PYTHON_EXECUTABLE_PATH)
Expand Down
3 changes: 3 additions & 0 deletions cmake/TaichiCXXFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}"
message("Setting -march=nehalem for x86_64 processors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=nehalem -DTI_ARCH_x64")
endif()
set(ARCH "x64")
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_ARCH_ARM")
set(ARCH "arm64")
else()
message(FATAL_ERROR "Unknown processor type ${CMAKE_SYSTEM_PROCESSOR}")
endif()
set(HOST_ARCH ${ARCH} CACHE INTERNAL "Host arch")

if (USE_STDCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
Expand Down
9 changes: 9 additions & 0 deletions cmake/TaichiTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ include_directories(
)

add_executable(${TESTS_NAME} ${TAICHI_TESTS_SOURCE})
if (WIN32)
# Output the executable to bin/ instead of build/Debug/...
set(TESTS_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUTPUT_DIR})
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${TESTS_OUTPUT_DIR})
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${TESTS_OUTPUT_DIR})
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${TESTS_OUTPUT_DIR})
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${TESTS_OUTPUT_DIR})
endif()
target_link_libraries(${TESTS_NAME} taichi_isolated_core)
target_link_libraries(${TESTS_NAME} gtest_main)

Expand Down
4 changes: 4 additions & 0 deletions docs/lang/api/reference/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "API Reference",
"position": 99
}
4 changes: 4 additions & 0 deletions docs/lang/articles/advanced/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Advanced Programming",
"position": 3
}
4 changes: 4 additions & 0 deletions docs/lang/articles/basic/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Taichi Language Basic Concepts",
"position": 2
}
4 changes: 4 additions & 0 deletions docs/lang/articles/contribution/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Contribution Guide",
"position": 5
}
2 changes: 1 addition & 1 deletion docs/lang/articles/contribution/contributor_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ This design is terrible.
`yapf v0.29.0` locally before you use `ti format`.

- If you don't have these formatting tools locally, feel free to
leverage GitHub actions: simply comment `\format` in a PR
leverage GitHub actions: simply comment `/format` in a PR
(e.g., [#2481](https://github.com/taichi-dev/taichi/pull/2481#issuecomment-872226701))
and then [Taichi Gardener](https://github.com/taichi-gardener)
will automatically format the code for you.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/lang/articles/contribution/writing_cpp_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ make
./taichi_cpp_tests
```

:::note
On Windows, `taichi_cpp_tests.exe` will be placed inside the `%TAICHI_REPO_DIR%\bin` directory,
so you can directly run it after adding the directory to `PATH` in [Setting up Taichi for development](dev_install.md#setting-up-taichi-for-development-3).
:::

:::note
Consider polishing the CPP test infrastructure:

Expand Down
4 changes: 4 additions & 0 deletions docs/lang/articles/misc/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Miscellaneous Topics",
"position": 4
}
30 changes: 24 additions & 6 deletions examples/rendering/cornell_box.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import time

import numpy as np
from numpy.lib.function_base import average

import taichi as ti

ti.init(arch=ti.gpu)
res = (800, 800)
color_buffer = ti.Vector.field(3, dtype=ti.f32, shape=res)
count_var = ti.field(ti.i32, shape=(1, ))
tonemapped_buffer = ti.Vector.field(3, dtype=ti.f32, shape=res)

max_ray_depth = 10
eps = 1e-4
Expand Down Expand Up @@ -482,18 +484,34 @@ def render():
count_var[0] = (count_var[0] + 1) % (stratify_res * stratify_res)


gui = ti.GUI('Cornell Box', res)
@ti.kernel
def tonemap(accumulated: ti.f32) -> ti.f32:
sum = 0.0
sum_sq = 0.0
for i, j in color_buffer:
luma = color_buffer[i, j][0] * 0.2126 + color_buffer[
i, j][1] * 0.7152 + color_buffer[i, j][2] * 0.0722
sum += luma
sum_sq += ti.pow(luma / accumulated, 2.0)
mean = sum / (res[0] * res[1])
var = sum_sq / (res[0] * res[1]) - ti.pow(mean / accumulated, 2.0)
for i, j in tonemapped_buffer:
tonemapped_buffer[i, j] = ti.sqrt(color_buffer[i, j] / mean * 0.6)
return var


gui = ti.GUI('Cornell Box', res, fast_gui=True)
gui.fps_limit = 300
last_t = time.time()
i = 0
while gui.running:
render()
interval = 10
if i % interval == 0 and i > 0:
img = color_buffer.to_numpy() * (1 / (i + 1))
img = np.sqrt(img / img.mean() * 0.24)
if i % interval == 0:
var = tonemap(i)
print("{:.2f} samples/s ({} iters, var={})".format(
interval / (time.time() - last_t), i, np.var(img)))
interval / (time.time() - last_t), i, var))
last_t = time.time()
gui.set_image(img)
gui.set_image(tonemapped_buffer)
gui.show()
i += 1
Loading

0 comments on commit 450ba98

Please sign in to comment.