Skip to content

Commit

Permalink
Merge branch 'master' of github.com:taichi-dev/taichi into taichi_spa…
Browse files Browse the repository at this point in the history
…rse_test
  • Loading branch information
jim19930609 committed Jul 28, 2022
2 parents 58bcdf4 + 43a7448 commit f293309
Show file tree
Hide file tree
Showing 47 changed files with 522 additions and 123 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ jobs:
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix_prep.outputs.matrix) }}
runs-on: macos-10.15
runs-on: [self-hosted, macos-10.15]
env:
PY: ${{ matrix.python }}
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -215,19 +217,16 @@ jobs:
restore-keys: |
sccache-mac-
- 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: macos-10.15
CI_PLATFORM: macos

- name: Create Python Wheel
run: |
brew install molten-vk
export PATH=$(pwd)/taichi-llvm/bin/:$PATH
export PATH=$(ls -d ~/mini*/envs/$PY/bin):$PATH
bash .github/workflows/scripts/unix_build.sh
brew uninstall molten-vk
env:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/scripts/unix_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ EOF
python3 taichi-release-tests/run.py --log=DEBUG --runners 1 taichi-release-tests/timelines
fi

python3 tests/run_tests.py --cpp

if [ ! -z $TI_SKIP_CPP_TESTS ]; then
python3 tests/run_tests.py --cpp
fi

if [ -z "$GPU_TEST" ]; then
if [[ $PLATFORM == *"m1"* ]]; then
Expand Down
33 changes: 20 additions & 13 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ concurrency:
group: ${{ github.event.number || github.run_id }}
cancel-in-progress: true

env:
TI_CI: "1"

jobs:
check_files:
name: Check files
Expand Down Expand Up @@ -192,16 +195,16 @@ jobs:
with_cc: OFF
with_cpp_tests: ON
wanted_archs: 'cpu'
runs-on: ${{ matrix.os }}
runs-on:
- self-hosted
- ${{ matrix.os }}
env:
PY: ${{ matrix.python }}
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Get sccache cache
uses: actions/cache@v2
with:
Expand All @@ -210,23 +213,27 @@ jobs:
restore-keys: |
sccache-mac-
- name: Download Pre-Built LLVM 10.0.0
- name: Setup Python PATH && Download Pre-Built LLVM 10.0.0
run: |
if [[ ${{needs.check_files.outputs.run_job}} == false ]]; then
export PATH=`pwd`/taichi-llvm/bin/:$PATH
# miniconda / miniforge
export PATH=$(ls -d ~/mini*/envs/$PY/bin):$PATH
if [[ "${{needs.check_files.outputs.run_job}}" == "false" ]]; then
exit 0
fi
python misc/ci_download.py
echo PATH=$PATH >> $GITHUB_ENV
#
env:
CI_PLATFORM: ${{ matrix.os }}
CI_PLATFORM: macos

- name: Build & Install
run: |
brew install molten-vk
if [[ ${{needs.check_files.outputs.run_job}} == false ]]; then
if [[ "${{needs.check_files.outputs.run_job}}" == "false" ]]; then
exit 0
fi
brew install molten-vk
mkdir -p sccache_cache
export PATH=`pwd`/taichi-llvm/bin/:$PATH
.github/workflows/scripts/unix_build.sh
brew uninstall molten-vk
env:
Expand All @@ -242,13 +249,13 @@ jobs:
- name: Test
id: test
run: |
if [[ ${{needs.check_files.outputs.run_job}} == false ]]; then
if [[ "${{needs.check_files.outputs.run_job}}" == "false" ]]; then
exit 0
fi
.github/workflows/scripts/unix_test.sh
env:
TI_WANTED_ARCHS: ${{ matrix.wanted_archs }}
TI_CI: 1
TI_SKIP_CPP_TESTS: Disabled because Vulkan is supported but not working on buildbot4

- name: Save wheel if test failed
if: failure() && steps.test.conclusion == 'failure'
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The Taichi Programming Language
#*********************************************************************

cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.17)

project(taichi)

Expand Down
17 changes: 4 additions & 13 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,10 @@ add_subdirectory(taichi/util)
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE taichi_util)

if (TI_WITH_CUDA_TOOLKIT)
if("$ENV{CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "")
message(FATAL_ERROR "TI_WITH_CUDA_TOOLKIT is ON but CUDA_TOOLKIT_ROOT_DIR not found")
else()
message(STATUS "TI_WITH_CUDA_TOOLKIT = ON")
message(STATUS "CUDA_TOOLKIT_ROOT_DIR=$ENV{CUDA_TOOLKIT_ROOT_DIR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_CUDA_TOOLKIT")
target_include_directories(${CORE_LIBRARY_NAME} PRIVATE $ENV{CUDA_TOOLKIT_ROOT_DIR}/include)
target_link_directories(${CORE_LIBRARY_NAME} PRIVATE $ENV{CUDA_TOOLKIT_ROOT_DIR}/lib64)
#libraries for cuda kernel profiler CuptiToolkit
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE cupti nvperf_host)
endif()
else()
message(STATUS "TI_WITH_CUDA_TOOLKIT = OFF")
find_package(CUDAToolkit REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_CUDA_TOOLKIT")
target_include_directories(${CORE_LIBRARY_NAME} PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
target_link_libraries(${CORE_LIBRARY_NAME} PUBLIC CUDA::cupti)
endif()

if (TI_WITH_METAL)
Expand Down
14 changes: 9 additions & 5 deletions cmake/TaichiExamples.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ if (WIN32)
set_target_properties(${EXAMPLES_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${EXAMPLES_OUTPUT_DIR})
set_target_properties(${EXAMPLES_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${EXAMPLES_OUTPUT_DIR})
endif()

target_link_libraries(${EXAMPLES_NAME} PRIVATE taichi_core)
target_link_libraries(${EXAMPLES_NAME} PRIVATE
metal_program_impl
metal_runtime
metal_codegen
)

if (TI_WITH_METAL)
target_link_libraries(${EXAMPLES_NAME} PRIVATE
metal_program_impl
metal_runtime
metal_codegen
)
endif()

# TODO 4832: be specific on the header dependencies here, e.g., ir
target_include_directories(${EXAMPLES_NAME}
Expand Down
2 changes: 2 additions & 0 deletions cmake/TaichiExportCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.0)

set(TAICHI_EXPORT_CORE_NAME taichi_export_core)

message(WARNING "You are trying to build the taichi_export_core target, support for this target will be deprecated in the future, please considering using the taichi_c_api target.")

add_library(${TAICHI_EXPORT_CORE_NAME} SHARED)
target_link_libraries(${TAICHI_EXPORT_CORE_NAME} PRIVATE taichi_core)
set_target_properties(${TAICHI_EXPORT_CORE_NAME} PROPERTIES
Expand Down
12 changes: 12 additions & 0 deletions python/taichi/aot/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from taichi.lang._ndarray import ScalarNdarray
from taichi.lang._texture import Texture
from taichi.lang.enums import Layout
from taichi.lang.exception import TaichiCompilationError
from taichi.lang.matrix import Matrix, MatrixNdarray, MatrixType, VectorNdarray
from taichi.lang.util import cook_dtype
from taichi.types.annotations import template
from taichi.types.ndarray_type import NdarrayType
from taichi.types.texture_type import RWTextureType, TextureType

template_types = (NdarrayType, template)

Expand Down Expand Up @@ -85,6 +87,16 @@ def produce_injected_args(kernel, symbolic_args=None):
layout=Layout.AOS))
else:
raise RuntimeError('')
elif isinstance(anno, (TextureType, RWTextureType)):
if symbolic_args is None:
raise RuntimeError(
'Texture type annotation doesn\'t have enough information for aot. Please either specify the channel_format, shape and num_channels in the graph arg declaration.'
)
texture_shape = tuple(symbolic_args[i].texture_shape)
channel_format = symbolic_args[i].channel_format()
num_channels = symbolic_args[i].num_channels
injected_args.append(
Texture(channel_format, num_channels, texture_shape))
elif isinstance(anno, MatrixType):
if not isinstance(symbolic_args[i], list):
raise RuntimeError('Expected a symbolic arg with Matrix type.')
Expand Down
93 changes: 93 additions & 0 deletions python/taichi/examples/graph/texture_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from taichi.examples.patterns import taichi_logo

import taichi as ti

ti.init(arch=ti.vulkan)

res = (512, 512)
img = ti.Vector.field(4, dtype=float, shape=res)
pixels_arr = ti.Vector.ndarray(4, dtype=float, shape=res)

texture = ti.Texture(ti.f32, 1, (128, 128))


@ti.kernel
def make_texture(tex: ti.types.rw_texture(num_dimensions=2,
num_channels=1,
channel_format=ti.f32,
lod=0)):
for i, j in ti.ndrange(128, 128):
ret = ti.cast(taichi_logo(ti.Vector([i, j]) / 128), ti.f32)
tex.store(ti.Vector([i, j]), ti.Vector([ret, 0.0, 0.0, 0.0]))


@ti.kernel
def paint(t: ti.f32, pixels: ti.types.ndarray(field_dim=2),
tex: ti.types.texture(num_dimensions=2)):
for i, j in pixels:
uv = ti.Vector([i / res[0], j / res[1]])
warp_uv = uv + ti.Vector(
[ti.cos(t + uv.x * 5.0),
ti.sin(t + uv.y * 5.0)]) * 0.1
c = ti.math.vec4(0.0)
if uv.x > 0.5:
c = tex.sample_lod(warp_uv, 0.0)
else:
c = tex.fetch(ti.cast(warp_uv * 128, ti.i32), 0)
pixels[i, j] = [c.r, c.r, c.r, 1.0]


@ti.kernel
def copy_to_field(pixels: ti.types.ndarray(field_dim=2)):
for I in ti.grouped(pixels):
img[I] = pixels[I]


def main():
_t = ti.graph.Arg(ti.graph.ArgKind.SCALAR, 't', ti.f32)
_pixels_arr = ti.graph.Arg(ti.graph.ArgKind.NDARRAY,
'pixels_arr',
ti.f32,
field_dim=2,
element_shape=(4, ))

_rw_tex = ti.graph.Arg(ti.graph.ArgKind.RWTEXTURE,
'rw_tex',
channel_format=ti.f32,
shape=(128, 128),
num_channels=1)
g_init_builder = ti.graph.GraphBuilder()
g_init_builder.dispatch(make_texture, _rw_tex)
g_init = g_init_builder.compile()

g_init.run({'rw_tex': texture})
_tex = ti.graph.Arg(ti.graph.ArgKind.TEXTURE,
'tex',
channel_format=ti.f32,
shape=(128, 128),
num_channels=1)
g_builder = ti.graph.GraphBuilder()
g_builder.dispatch(paint, _t, _pixels_arr, _tex)
g = g_builder.compile()

aot = False
if aot:
tmpdir = 'shaders'
mod = ti.aot.Module(ti.vulkan)
mod.add_graph('g', g)
mod.add_graph('g_init', g_init)
mod.save(tmpdir, '')
else:
t = 0.0
window = ti.ui.Window('UV', res)
canvas = window.get_canvas()
while window.running:
g.run({'t': t, 'pixels_arr': pixels_arr, 'tex': texture})
copy_to_field(pixels_arr)
canvas.set_image(img)
window.show()
t += 0.03


if __name__ == '__main__':
main()
22 changes: 21 additions & 1 deletion python/taichi/graph/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from taichi.aot.utils import produce_injected_args
from taichi.lang import kernel_impl
from taichi.lang._ndarray import Ndarray
from taichi.lang._texture import Texture
from taichi.lang.exception import TaichiRuntimeError
from taichi.lang.matrix import Matrix, MatrixType

Expand Down Expand Up @@ -66,6 +67,8 @@ def run(self, args):
for k, v in args.items():
if isinstance(v, Ndarray):
flattened[k] = v.arr
elif isinstance(v, Texture):
flattened[k] = v.tex
elif isinstance(v, Matrix):
mat_val_id = 0
for a in range(v.n):
Expand All @@ -82,7 +85,14 @@ def run(self, args):
self._compiled_graph.run(flattened)


def Arg(tag, name, dtype, field_dim=0, element_shape=()):
def Arg(tag,
name,
dtype=None,
field_dim=0,
element_shape=(),
channel_format=None,
shape=(),
num_channels=None):
if isinstance(dtype, MatrixType):
if len(element_shape) > 0:
raise TaichiRuntimeError(
Expand All @@ -101,6 +111,16 @@ def Arg(tag, name, dtype, field_dim=0, element_shape=()):
arg_list.append(arg_sublist)
return arg_list

if tag == ArgKind.TEXTURE or tag == ArgKind.RWTEXTURE:
if channel_format is None or len(shape) == 0 or num_channels is None:
raise TaichiRuntimeError(
'channel_format, num_channels and shape arguments are required for texture arguments'
)
return _ti_core.Arg(tag,
name,
channel_format=channel_format,
num_channels=num_channels,
shape=shape)
return _ti_core.Arg(tag, name, dtype, field_dim, element_shape)


Expand Down
3 changes: 2 additions & 1 deletion python/taichi/lang/ast/ast_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,8 @@ def build_While(ctx, node):
"'else' clause for 'while' not supported in Taichi kernels")

with ctx.loop_scope_guard():
ctx.ast_builder.begin_frontend_while(expr.Expr(1).ptr)
ctx.ast_builder.begin_frontend_while(
expr.Expr(1, dtype=primitive_types.i32).ptr)
while_cond = build_stmt(ctx, node.test)
impl.begin_frontend_if(ctx.ast_builder, while_cond)
ctx.ast_builder.begin_frontend_if_true()
Expand Down
1 change: 0 additions & 1 deletion python/taichi/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Window:
def __init__(self, name, res, vsync=False, show_window=True):
check_ggui_availability()
package_path = str(pathlib.Path(__file__).parent.parent)

ti_arch = default_cfg().arch
is_packed = default_cfg().packed
self.window = _ti_core.PyWindow(get_runtime().prog, name, res, vsync,
Expand Down
Loading

0 comments on commit f293309

Please sign in to comment.