From 0ec62a4d6a928410ae4d970b155492721ffc63de Mon Sep 17 00:00:00 2001 From: Joe Evans Date: Fri, 17 Jul 2020 17:03:17 -0700 Subject: [PATCH 1/7] Fix linalg_potri operator for large tensor. --- src/operator/tensor/la_op-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator/tensor/la_op-inl.h b/src/operator/tensor/la_op-inl.h index d580cced4ec5..af3ece33d9e9 100644 --- a/src/operator/tensor/la_op-inl.h +++ b/src/operator/tensor/la_op-inl.h @@ -36,7 +36,7 @@ using namespace mshadow; // Copies lower/upper triangular part to upper/lower, i.e. to the opposite side. struct CopyTriangularToOppositeSide { template - MSHADOW_XINLINE static void Map(int i, int matrix_size, int stride, DType* data, bool to_lower) { + MSHADOW_XINLINE static void Map(int i, size_t matrix_size, int stride, DType* data, bool to_lower) { // Below computation works even when we are dealing with a batch of matrices. const int row((i % matrix_size) / stride), col(i % stride); if (row > col) { From eed5ac39c223f0c97ccf13f9e9356ad61bfeb680 Mon Sep 17 00:00:00 2001 From: Joe Evans Date: Fri, 17 Jul 2020 17:10:55 -0700 Subject: [PATCH 2/7] Update other variables to support large tensors. --- src/operator/tensor/la_op-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operator/tensor/la_op-inl.h b/src/operator/tensor/la_op-inl.h index af3ece33d9e9..c915347c00a6 100644 --- a/src/operator/tensor/la_op-inl.h +++ b/src/operator/tensor/la_op-inl.h @@ -36,9 +36,9 @@ using namespace mshadow; // Copies lower/upper triangular part to upper/lower, i.e. to the opposite side. struct CopyTriangularToOppositeSide { template - MSHADOW_XINLINE static void Map(int i, size_t matrix_size, int stride, DType* data, bool to_lower) { + MSHADOW_XINLINE static void Map(index_t i, size_t matrix_size, index_t stride, DType* data, bool to_lower) { // Below computation works even when we are dealing with a batch of matrices. - const int row((i % matrix_size) / stride), col(i % stride); + const index_t row((i % matrix_size) / stride), col(i % stride); if (row > col) { if (to_lower) { data[i] = data[i + (col - row) * (stride - 1)]; From a6bd57827059eae142dbc2b90398564f62ad705a Mon Sep 17 00:00:00 2001 From: Joe Evans Date: Fri, 17 Jul 2020 17:12:40 -0700 Subject: [PATCH 3/7] Add to contributors. --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 81b20d4b092d..bd7f966aaa5f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -251,6 +251,7 @@ List of Contributors * [Piljae Chae](https://github.com/IHateMint) * [Oliver Kowalke](https://github.com/olk) * [Connor Goggins](https://github.com/connorgoggins) +* [Joe Evans](https://github.com/josephevans) Label Bot --------- From bb07c180167578d12b9b83a0749c90b30a4e756c Mon Sep 17 00:00:00 2001 From: Joe Evans Date: Fri, 17 Jul 2020 18:14:16 -0700 Subject: [PATCH 4/7] Fix whitespace. --- src/operator/tensor/la_op-inl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/operator/tensor/la_op-inl.h b/src/operator/tensor/la_op-inl.h index c915347c00a6..fd2cf88c6521 100644 --- a/src/operator/tensor/la_op-inl.h +++ b/src/operator/tensor/la_op-inl.h @@ -36,7 +36,8 @@ using namespace mshadow; // Copies lower/upper triangular part to upper/lower, i.e. to the opposite side. struct CopyTriangularToOppositeSide { template - MSHADOW_XINLINE static void Map(index_t i, size_t matrix_size, index_t stride, DType* data, bool to_lower) { + MSHADOW_XINLINE static void Map(index_t i, size_t matrix_size, index_t stride, + DType* data, bool to_lower) { // Below computation works even when we are dealing with a batch of matrices. const index_t row((i % matrix_size) / stride), col(i % stride); if (row > col) { From d959e3d756a33d81c494c0d7097bdd49fc0d67d5 Mon Sep 17 00:00:00 2001 From: Joe Evans Date: Tue, 21 Jul 2020 14:21:18 -0700 Subject: [PATCH 5/7] Update ZeroTriangular to support large tensors. --- src/operator/tensor/la_op-inl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/operator/tensor/la_op-inl.h b/src/operator/tensor/la_op-inl.h index fd2cf88c6521..7a5a602425fe 100644 --- a/src/operator/tensor/la_op-inl.h +++ b/src/operator/tensor/la_op-inl.h @@ -53,9 +53,9 @@ struct CopyTriangularToOppositeSide { // Zero's lower/upper triangular part of a matrix. struct ZeroTriangular { template - MSHADOW_XINLINE static void Map(int i, int matrix_size, int stride, DType* data, - bool zero_lower) { - const int row((i % matrix_size) / stride), col(i % stride); + MSHADOW_XINLINE static void Map(index_t i, size_t matrix_size, index_t stride, + DType* data, bool zero_lower) { + const index_t row((i % matrix_size) / stride), col(i % stride); if ((!zero_lower && (row < col)) || (zero_lower && (row > col))) data[i] = 0; } }; From a392b127c4ca5ab5407816f03c9c2f897b5f6936 Mon Sep 17 00:00:00 2001 From: Joe Evans Date: Tue, 21 Jul 2020 14:21:55 -0700 Subject: [PATCH 6/7] Add large tensor unit tests for linalg_potrf and linalg_potri. --- tests/nightly/test_large_array.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/nightly/test_large_array.py b/tests/nightly/test_large_array.py index d50f3ff7e539..4925e54c247b 100644 --- a/tests/nightly/test_large_array.py +++ b/tests/nightly/test_large_array.py @@ -37,6 +37,7 @@ LARGE_X = 100000000 SMALL_X = 100 SMALL_Y = 50 +LARGE_SQ_X = 80000 LARGE_SIZE = LARGE_X * SMALL_Y LARGE_TENSOR_SHAPE = 2**32 RNN_LARGE_TENSOR = 2**28 @@ -1167,6 +1168,32 @@ def check_correctness(mxnet_op, numpy_op, atol=1e-3): check_gather() check_binary_broadcast() +def test_linalg(): + def check_potrf(): + # creating an identity matrix input + A = nd.zeros((LARGE_SQ_X, LARGE_SQ_X)) + for i in range(LARGE_SQ_X): + A[i,i] = 1 + + out = nd.linalg.potrf(A) + # output should be an identity matrix + for i in range(LARGE_SQ_X): + assert out[i,i] == 1 + + def check_potri(): + # creating an identity matrix input + A = nd.zeros((LARGE_SQ_X, LARGE_SQ_X)) + for i in range(LARGE_SQ_X): + A[i,i] = 1 + + out = nd.linalg.potri(A) + # output should be an identity matrix + for i in range(LARGE_SQ_X): + assert out[i,i] == 1 + + check_potrf() + check_potri() + def test_basic(): def check_elementwise(): From 373d4146b2fa9887c57989a2524a0c9aec1c6f1e Mon Sep 17 00:00:00 2001 From: Przemyslaw Tredak Date: Thu, 23 Jul 2020 14:10:08 -0700 Subject: [PATCH 7/7] Fix crash when accessing already destructed static variables (#18768) (#18778) --- src/c_api/c_api.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index b9511aef15f7..fdc794231465 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1315,6 +1315,7 @@ int MXNotifyShutdown() { API_BEGIN(); mxnet::op::custom::CustomOperator::Get()->Stop(); Engine::Get()->NotifyShutdown(); + Engine::Get()->WaitForAll(); API_END(); }