Skip to content

Commit

Permalink
[Fix] Add ConstantNode to IsAtomic (apache#5457)
Browse files Browse the repository at this point in the history
* add constantnode to atomic

* Add ToANormalForm to FoldConstant
  • Loading branch information
zhiics committed Jun 17, 2020
1 parent 85af4a9 commit ae5bb00
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/dlpack
2 changes: 1 addition & 1 deletion 3rdparty/dmlc-core
Submodule dmlc-core updated 57 files
+38 −0 .github/workflows/githubci.yml
+0 −1 .gitignore
+0 −82 .travis.yml
+122 −111 CMakeLists.txt
+201 −13 LICENSE
+1 −1 README.md
+19 −6 appveyor.yml
+13 −0 cmake/Modules/FindASan.cmake
+13 −0 cmake/Modules/FindLSan.cmake
+13 −0 cmake/Modules/FindTSan.cmake
+13 −0 cmake/Modules/FindUBSan.cmake
+63 −0 cmake/Sanitizer.cmake
+4 −1 cmake/build_config.h.in
+1 −1 cmake/gtest_cmake.in
+175 −263 doc/Doxyfile
+29 −1 include/dmlc/base.h
+4 −1 include/dmlc/build_config_default.h
+4 −0 include/dmlc/concurrency.h
+18 −18 include/dmlc/concurrentqueue.h
+1 −1 include/dmlc/data.h
+3 −2 include/dmlc/json.h
+53 −22 include/dmlc/logging.h
+1 −1 include/dmlc/omp.h
+10 −0 include/dmlc/optional.h
+106 −23 include/dmlc/parameter.h
+1 −1 include/dmlc/registry.h
+1 −3 include/dmlc/thread_group.h
+4 −2 include/dmlc/thread_local.h
+74 −46 include/dmlc/threadediter.h
+0 −2 make/dmlc.mk
+2 −2 scripts/lint.py
+12 −19 scripts/packages.mk
+0 −0 scripts/s390x/Dockerfile
+0 −0 scripts/s390x/build_via_cmake.sh
+1 −1 scripts/s390x/ci_build.sh
+0 −0 scripts/s390x/entrypoint.sh
+0 −32 scripts/setup_nvcc.sh
+66 −0 scripts/test_script.sh
+0 −3 scripts/travis/travis_before_cache.sh
+0 −9 scripts/travis/travis_osx_install.sh
+0 −57 scripts/travis/travis_script.sh
+0 −40 scripts/travis/travis_setup_env.sh
+0 −16 src/build_config.cc
+7 −3 src/data/csv_parser.h
+1 −1 test/logging_test.cc
+4 −0 test/unittest/CMakeLists.txt
+2 −1 test/unittest/unittest_env.cc
+11 −0 test/unittest/unittest_logging_throw.cc
+30 −0 test/unittest/unittest_param.cc
+80 −56 test/unittest/unittest_parser.cc
+0 −1 test/unittest/unittest_thread_group.cc
+2 −2 test/unittest/unittest_threaditer.cc
+19 −15 test/unittest/unittest_threaditer_exc_handling.cc
+4 −0 tracker/dmlc_tracker/launcher.py
+7 −0 tracker/dmlc_tracker/ssh.py
+13 −0 tracker/dmlc_tracker/util.py
+4 −2 tracker/dmlc_tracker/yarn.py
1 change: 1 addition & 0 deletions src/relay/pass/fold_constant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class ConstantFolder : public ExprMutator {
// Constant evaluate a expression.
Expr ConstEvaluate(Expr expr) {
std::vector<transform::Pass> passes = {transform::FuseOps(0),
transform::ToANormalForm(),
transform::InferType()};
Function func;
if (expr.as<FunctionNode>()) {
Expand Down
19 changes: 19 additions & 0 deletions tests/python/relay/test_pass_fold_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ def run_opt_pass(expr, opt_pass):
return entry if isinstance(expr, relay.Function) else entry.body


def test_concatenate_const():
def before():
data = tvm.nd.array(np.array([1.0, 2.0, 3.0]))
const = relay.const(data)
concat = relay.op.concatenate([const, const], axis=0)
func = relay.Function([], concat)
return func

def expected():
data = tvm.nd.array(np.array([1.0, 2.0, 3.0, 1.0, 2.0, 3.0]))
const = relay.const(data)
func = relay.Function([], const)
return func

zz = run_opt_pass(before(), transform.FoldConstant())
zexpected = run_opt_pass(expected(), transform.InferType())
assert relay.analysis.alpha_equal(zz, zexpected)


def test_fold_const():
c_data = np.array([1, 2, 3]).astype("float32")
t = relay.TensorType([1, 2, 3], "float32")
Expand Down

0 comments on commit ae5bb00

Please sign in to comment.