From 153e36ceb53e9040b6014b890d4ba36dc4858c9d Mon Sep 17 00:00:00 2001 From: Yuanming Hu Date: Thu, 27 Aug 2020 18:55:19 -0400 Subject: [PATCH 1/3] [ir] [autodiff] Initialize ADStack with a zero --- taichi/transforms/auto_diff.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/taichi/transforms/auto_diff.cpp b/taichi/transforms/auto_diff.cpp index 9771ca7d59085..cc645e9c7bff5 100644 --- a/taichi/transforms/auto_diff.cpp +++ b/taichi/transforms/auto_diff.cpp @@ -200,9 +200,18 @@ class ReplaceLocalVarWithStacks : public BasicStmtVisitor { }) .empty(); if (!load_only) { - alloc->replace_with(Stmt::make( - alloc->ret_type.data_type, - get_current_program().config.ad_stack_size)); + auto dtype = alloc->ret_type.data_type; + auto stack_alloca = Stmt::make( + dtype, alloc->get_kernel()->program.config.ad_stack_size); + auto stack_alloca_ptr = stack_alloca.get(); + + alloc->replace_with(std::move(stack_alloca)); + + // Note that unlike AllocStmt, StackAllocaStmt does NOT have an 0 as + // initial value. Therefore here we push an initial 0 value. + auto zero = stack_alloca_ptr->insert_after_me( + Stmt::make(TypedConstant(dtype, 0))); + zero->insert_after_me(Stmt::make(stack_alloca_ptr, zero)); } } From 6da39784b48873326b7eccdd0c7f8f29f3082a06 Mon Sep 17 00:00:00 2001 From: Yuanming Hu Date: Thu, 27 Aug 2020 19:13:29 -0400 Subject: [PATCH 2/3] format_all --- Dockerfile | 2 +- cmake/PythonNumpyPybind11.cmake | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b87987f97fcef..02e043bc2ec49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,7 +34,7 @@ ENV CC=/usr/bin/clang-8 ENV CXX=/usr/bin/clang++-8 RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz RUN tar xvJf llvm-10.0.0.src.tar.xz -RUN cd llvm-10.0.0.src && mkdir build +RUN cd llvm-10.0.0.src && mkdir build WORKDIR /llvm-10.0.0.src/build RUN cmake .. -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" -DLLVM_ENABLE_ASSERTIONS=ON RUN make -j 8 diff --git a/cmake/PythonNumpyPybind11.cmake b/cmake/PythonNumpyPybind11.cmake index 2e20ab3919464..bb3696a7f5199 100644 --- a/cmake/PythonNumpyPybind11.cmake +++ b/cmake/PythonNumpyPybind11.cmake @@ -87,4 +87,3 @@ else () endif () include_directories(${PYBIND11_INCLUDE_DIR}) - From 84da1cb20434eb70507f72497f0c04dbe73442ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BA=8E=E6=96=8C?= <1931127624@qq.com> Date: Fri, 28 Aug 2020 17:07:28 +0800 Subject: [PATCH 3/3] [skip ci] Apply suggestions from code review --- taichi/transforms/auto_diff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/transforms/auto_diff.cpp b/taichi/transforms/auto_diff.cpp index cc645e9c7bff5..08e9f976967f8 100644 --- a/taichi/transforms/auto_diff.cpp +++ b/taichi/transforms/auto_diff.cpp @@ -207,7 +207,7 @@ class ReplaceLocalVarWithStacks : public BasicStmtVisitor { alloc->replace_with(std::move(stack_alloca)); - // Note that unlike AllocStmt, StackAllocaStmt does NOT have an 0 as + // Note that unlike AllocaStmt, StackAllocaStmt does NOT have an 0 as // initial value. Therefore here we push an initial 0 value. auto zero = stack_alloca_ptr->insert_after_me( Stmt::make(TypedConstant(dtype, 0)));