Skip to content

Commit

Permalink
Merge branch 'master' of github.com:taichi-dev/taichi into matrix-lib…
Browse files Browse the repository at this point in the history
…s-p2
  • Loading branch information
AD1024 committed Nov 3, 2022
2 parents 2b43ece + b6b4317 commit 13041f5
Show file tree
Hide file tree
Showing 90 changed files with 2,499 additions and 300 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/notify_on_failure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Notification for master failure
on:
workflow_run:
workflows: [Build and Test]
types: [completed]
branches: [master]

jobs:
on-failure:
name: Send message to slack
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Post to slack channel
id: slack
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.TAICHI_BOT_TOKEN }}
with:
# channel #build
channel-id: 'C02BDNMG8MR'
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":bbb: Master is on fire",
"emoji": true
}
},
{"type": "divider"},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Failed at commit : `${{ github.event.workflow_run.head_commit.message }}`"
}
},
]
}
9 changes: 2 additions & 7 deletions .github/workflows/scripts/aot-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ function build-and-smoke-test-android-aot-demo {
export TAICHI_REPO_DIR=$(pwd)/taichi

rm -rf taichi-aot-demo
# IF YOU PIN THIS TO A COMMIT/BRANCH, YOU'RE RESPONSIBLE TO REVERT IT BACK TO MASTER ONCE MERGED.
git clone https://github.com/taichi-dev/taichi-aot-demo

# Normally we checkout the master's commit Id: https://github.com/taichi-dev/taichi-aot-demo/commit/master
# As for why we need this explicit commit Id here, refer to: https://docs.taichi-lang.org/docs/master/contributor_guide#handle-special-ci-failures
pushd taichi-aot-demo
git checkout 6b8d22f2c38318cf7a7333dc17cff4ae7ee5e607
popd

APP_ROOT=taichi-aot-demo/implicit_fem
ANDROID_APP_ROOT=$APP_ROOT/android
JNI_PATH=$ANDROID_APP_ROOT/app/src/main/jniLibs/arm64-v8a/
Expand Down Expand Up @@ -103,7 +98,7 @@ function build-and-test-headless-demo {
popd

rm -rf taichi-aot-demo
git clone --recursive --depth=1 https://github.com/taichi-dev/taichi-aot-demo -b update-aot-module1
git clone --recursive --depth=1 https://github.com/taichi-dev/taichi-aot-demo
cd taichi-aot-demo
mkdir build
pushd build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scripts/common-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function ci-docker-run {
--user dev \
-e PY \
-e PROJECT_NAME \
-e LLVM_VERSION \
-e TAICHI_CMAKE_ARGS \
-e IN_DOCKER=true \
-e TI_CI=1 \
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/scripts/unix-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ set -ex
[[ "$IN_DOCKER" == "true" ]] && cd taichi

# TODO: Move llvm installation from container image to here
if [[ "$LLVM_VERSION" == "15" ]]; then
wget https://github.com/ailzhang/torchhub_example/releases/download/0.2/taichi-llvm-15-linux.zip
unzip taichi-llvm-15-linux.zip && rm taichi-llvm-15-linux.zip
export PATH="$PWD/taichi-llvm-15/bin:$PATH"
export TAICHI_CMAKE_ARGS="$TAICHI_CMAKE_ARGS -DTI_LLVM_15:BOOL=ON"
fi

build_taichi_wheel() {
python3 -m pip install -r requirements_dev.txt
Expand All @@ -15,6 +21,8 @@ build_taichi_wheel() {
EXTRA_ARGS=""
if [ "$PROJECT_NAME" = "taichi-nightly" ]; then
PROJECT_TAGS="egg_info --tag-date"
# Include C-API in nightly builds
TAICHI_CMAKE_ARGS="$TAICHI_CMAKE_ARGS -DTI_WITH_C_API:BOOL=ON"
fi

if [[ $OSTYPE == "linux-"* ]]; then
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jobs:
-DTI_WITH_VULKAN:BOOL=OFF
-DTI_BUILD_TESTS:BOOL=ON
-DTI_WITH_C_API=ON
LLVM_VERSION: 15

- name: Test
id: test
Expand Down Expand Up @@ -382,6 +383,7 @@ jobs:
-DTI_WITH_VULKAN:BOOL=ON
-DTI_BUILD_TESTS:BOOL=ON
-DTI_WITH_C_API=ON
LLVM_VERSION: 15

- name: Test
id: test
Expand Down
2 changes: 2 additions & 0 deletions c_api/docs/taichi/taichi_vulkan.h.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Necessary detail to share the same piece of Vulkan buffer between Taichi and ext
- `structure.vulkan_memory_interop_info.buffer`: Vulkan buffer.
- `structure.vulkan_memory_interop_info.size`: Size of the piece of memory in bytes.
- `structure.vulkan_memory_interop_info.usage`: Vulkan buffer usage. In most of the cases, Taichi requires the `VK_BUFFER_USAGE_STORAGE_BUFFER_BIT`.
- `structure.vulkan_memory_interop_info.memory`: Device memory binded to the Vulkan buffer.
- `structure.vulkan_memory_interop_info.offset`: Offset in `VkDeviceMemory` object to the beginning of this allocation, in bytes.

`structure.vulkan_image_interop_info`

Expand Down
1 change: 1 addition & 0 deletions c_api/include/taichi/cpp/taichi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ class Runtime {

Runtime &operator=(const Runtime &) = delete;
Runtime &operator=(Runtime &&b) {
arch_ = std::exchange(b.arch_, TI_ARCH_MAX_ENUM);
runtime_ = detail::move_handle(b.runtime_);
should_destroy_ = std::exchange(b.should_destroy_, false);
return *this;
Expand Down
5 changes: 5 additions & 0 deletions c_api/include/taichi/taichi_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ typedef struct TiVulkanMemoryInteropInfo {
// Vulkan buffer usage. In most of the cases, Taichi requires the
// `VK_BUFFER_USAGE_STORAGE_BUFFER_BIT`.
VkBufferUsageFlags usage;
// DeviceMemory binded to the buffer.
VkDeviceMemory memory;
// Offset in `VkDeviceMemory` object to the beginning of this allocation, in
// bytes.
uint64_t offset;
} TiVulkanMemoryInteropInfo;

// Structure `TiVulkanImageInteropInfo`
Expand Down
9 changes: 9 additions & 0 deletions c_api/src/taichi_vulkan_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ VulkanRuntimeImported::Workaround::Workaround(
caps.set(taichi::lang::DeviceCapability::spirv_version, 0x10000);
}

// (penguinliong) Will bring it back after devcap.
/*
if (api_version > VK_API_VERSION_1_0) {
caps.set(taichi::lang::DeviceCapability::spirv_has_physical_storage_buffer,
true);
}
*/

vk_device.set_current_caps(std::move(caps));
vk_device.init_vulkan_structs(
Expand Down Expand Up @@ -236,9 +239,15 @@ void ti_export_vulkan_memory(TiRuntime runtime,
VulkanRuntime *runtime2 = ((Runtime *)runtime)->as_vk();
taichi::lang::DeviceAllocation devalloc = devmem2devalloc(*runtime2, memory);
vkapi::IVkBuffer buffer = runtime2->get_vk().get_vkbuffer(devalloc);

auto [vk_mem, offset, __] =
runtime2->get_vk().get_vkmemory_offset_size(devalloc);

interop_info->buffer = buffer.get()->buffer;
interop_info->size = buffer.get()->size;
interop_info->usage = buffer.get()->usage;
interop_info->memory = vk_mem;
interop_info->offset = (uint64_t)offset;
}
TiImage ti_import_vulkan_image(TiRuntime runtime,
const TiVulkanImageInteropInfo *interop_info,
Expand Down
8 changes: 8 additions & 0 deletions c_api/taichi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,14 @@
{
"name": "usage",
"type": "VkBufferUsageFlags"
},
{
"name": "memory",
"type": "VkDeviceMemory"
},
{
"name": "offset",
"type": "uint64_t"
}
]
},
Expand Down
19 changes: 19 additions & 0 deletions c_api/tests/c_api_interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ TEST_F(CapiTest, DryRunMemoryAllocation) {
}
}

TEST_F(CapiTest, FailMapDeviceOnlyMemory) {
if (capi::utils::is_vulkan_available()) {
ti::Runtime runtime(TI_ARCH_VULKAN);

ti::Memory mem = runtime.allocate_memory(100);
mem.map();

char err_msg[1024]{0};
TiError err = ti_get_last_error(sizeof(err_msg), err_msg);

TI_ASSERT(err == TI_ERROR_INVALID_STATE);
TI_ASSERT(std::string(err_msg).find("host_read") != std::string::npos);
TI_ASSERT(std::string(err_msg).find("host_write") != std::string::npos);
TI_ASSERT(std::string(err_msg).find("host_access") != std::string::npos);

ti_set_last_error(TI_ERROR_SUCCESS, nullptr);
}
}

TEST_F(CapiTest, DryRunImageAllocation) {
if (capi::utils::is_vulkan_available()) {
{
Expand Down
3 changes: 2 additions & 1 deletion misc/prtags.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"simt" : "SIMT programming",
"release" : "Release",
"build" : "Build system",
"rfc" : "RFC"
"rfc" : "RFC",
"amdgpu" : "AMDGPU backend"
}
12 changes: 7 additions & 5 deletions python/taichi/examples/rendering/rasterizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ def __init__(self, n):
self.colors = ti.root.dense(ti.i, n).place(self.c0, self.c1, self.c2)

# Tile-based culling
self.block_num_triangles = ti.field(dtype=ti.i32,
shape=(width // tile_size,
height // tile_size))
self.block_num_triangles = ti.field(
dtype=ti.i32,
shape=((width - 1) // tile_size + 1,
(height - 1) // tile_size + 1))
self.block_indicies = ti.field(dtype=ti.i32,
shape=(width // tile_size,
height // tile_size, n))
shape=((width - 1) // tile_size + 1,
(height - 1) // tile_size + 1,
n))

def set_triangle(self, i, v0, v1, v2, c0, c1, c2):
self.A[i] = v0
Expand Down
3 changes: 2 additions & 1 deletion python/taichi/examples/simulation/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def render():
img[p] = 1e-6 / (p / res - ti.Vector([sun.x, sun.y])).norm(1e-4)**3
for i in x:
p = int(ti.Vector([x[i].x, x[i].y]) * res)
img[p] += color[i]
if 0 <= p[0] < res and 0 <= p[1] < res:
img[p] += color[i]


def main():
Expand Down
12 changes: 9 additions & 3 deletions python/taichi/examples/simulation/game_of_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
count = ti.field(int, shape=(n, n)) # count of neighbours


@ti.func
def get_alive(i, j):
return alive[i, j] if 0 <= i < n and 0 <= j < n else 0


@ti.func
def get_count(i, j):
return (alive[i - 1, j] + alive[i + 1, j] + alive[i, j - 1] +
alive[i, j + 1] + alive[i - 1, j - 1] + alive[i + 1, j - 1] +
alive[i - 1, j + 1] + alive[i + 1, j + 1])
return (get_alive(i - 1, j) + get_alive(i + 1, j) + get_alive(i, j - 1) +
get_alive(i, j + 1) + get_alive(i - 1, j - 1) +
get_alive(i + 1, j - 1) + get_alive(i - 1, j + 1) +
get_alive(i + 1, j + 1))


# See https://www.conwaylife.com/wiki/Cellular_automaton#Rules for more rules
Expand Down
2 changes: 1 addition & 1 deletion python/taichi/examples/simulation/mpm_lagrangian_forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
C = ti.Matrix.field(dim, dim, dtype=float, shape=n_particles)
grid_v = ti.Vector.field(dim, dtype=float, shape=(n_grid, n_grid))
grid_m = ti.field(dtype=float, shape=(n_grid, n_grid))
restT = ti.Matrix.field(dim, dim, dtype=float, shape=n_particles)
restT = ti.Matrix.field(dim, dim, dtype=float, shape=n_elements)
total_energy = ti.field(dtype=float, shape=(), needs_grad=True)
vertices = ti.field(dtype=ti.i32, shape=(n_elements, 3))

Expand Down
Loading

0 comments on commit 13041f5

Please sign in to comment.