@@ -950,16 +950,16 @@ TEST_F(TensorTest, tensorTranspose) {
950950}
951951
952952/* ---------------------------------------
953- * Tensor: transpose
953+ * Tensor: total bytes allocated
954954 * --------------------------------------- */
955955TEMPLATE_WITH_TYPE_T
956956void tensorBytesAllocated () {
957- size_t previouslyAllocatedBytes = Session::getInstance ().totalAllocatedBytes ();
957+ const size_t previouslyAllocatedBytes = Session::getInstance ().totalAllocatedBytes ();
958958 size_t m = 10 , n = 10 , k = 20 ;
959959 DTensor<T> A (m, n, k);
960- size_t allocatedBytes = Session::getInstance ().totalAllocatedBytes ();
961- size_t currentAllocatedBytes = m * n * k * sizeof (T) + k * sizeof (T *);
962- size_t expectedBytes = currentAllocatedBytes + previouslyAllocatedBytes;
960+ const size_t allocatedBytes = Session::getInstance ().totalAllocatedBytes ();
961+ const size_t currentAllocatedBytes = m * n * k * sizeof (T) + k * sizeof (T *);
962+ const size_t expectedBytes = currentAllocatedBytes + previouslyAllocatedBytes;
963963 EXPECT_EQ (expectedBytes, allocatedBytes);
964964}
965965
@@ -969,6 +969,30 @@ TEST_F(TensorTest, tensorBytesAllocated) {
969969 tensorBytesAllocated<int >();
970970}
971971
972+
973+ /* ---------------------------------------
974+ * Tensor: total bytes allocated
975+ * --------------------------------------- */
976+ TEMPLATE_WITH_TYPE_T
977+ void tensorBytesAllocatedDeallocated () {
978+ const size_t previouslyAllocatedBytes = Session::getInstance ().totalAllocatedBytes ();
979+ size_t m = 10 , n = 10 , k = 20 ;
980+ auto *A = new DTensor<T>(m, n, k); // new allocation (increments session)
981+ const size_t allocatedBytes = Session::getInstance ().totalAllocatedBytes ();
982+ const size_t expectedBytes = previouslyAllocatedBytes + m * n * k * sizeof (T) + k * sizeof (T *);
983+ EXPECT_EQ (expectedBytes, allocatedBytes);
984+ delete A;
985+ EXPECT_EQ (previouslyAllocatedBytes, Session::getInstance ().totalAllocatedBytes ());
986+ }
987+
988+ TEST_F (TensorTest, tensorBytesAllocatedDeallocated) {
989+ tensorBytesAllocatedDeallocated<float >();
990+ tensorBytesAllocatedDeallocated<double >();
991+ tensorBytesAllocatedDeallocated<int >();
992+ }
993+
994+
995+
972996/* ================================================================================================
973997 * LEAST SQUARES TESTS
974998 * ================================================================================================ */
0 commit comments