@@ -950,16 +950,16 @@ TEST_F(TensorTest, tensorTranspose) {
950
950
}
951
951
952
952
/* ---------------------------------------
953
- * Tensor: transpose
953
+ * Tensor: total bytes allocated
954
954
* --------------------------------------- */
955
955
TEMPLATE_WITH_TYPE_T
956
956
void tensorBytesAllocated () {
957
- size_t previouslyAllocatedBytes = Session::getInstance ().totalAllocatedBytes ();
957
+ const size_t previouslyAllocatedBytes = Session::getInstance ().totalAllocatedBytes ();
958
958
size_t m = 10 , n = 10 , k = 20 ;
959
959
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;
963
963
EXPECT_EQ (expectedBytes, allocatedBytes);
964
964
}
965
965
@@ -969,6 +969,30 @@ TEST_F(TensorTest, tensorBytesAllocated) {
969
969
tensorBytesAllocated<int >();
970
970
}
971
971
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
+
972
996
/* ================================================================================================
973
997
* LEAST SQUARES TESTS
974
998
* ================================================================================================ */
0 commit comments