Skip to content

Commit 29b0367

Browse files
committed
unit test for bytes allocated
1 parent 1103a6c commit 29b0367

3 files changed

Lines changed: 264 additions & 155 deletions

File tree

include/tensor.cuh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef TENSOR_CUH
2+
#define TENSOR_CUH
3+
14
#include <random>
25
#include <algorithm>
36
#include <iterator>
@@ -13,8 +16,6 @@
1316
#include <cassert>
1417
#include <fstream>
1518

16-
#ifndef TENSOR_CUH
17-
#define TENSOR_CUH
1819

1920
/**
2021
* Define defaults

main.cu

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
int main() {
99
/* Write to binary file */
1010
auto r = DTensor<double>::createRandomTensor(3, 6, 4, -1, 1);
11+
auto r2 = DTensor<double>::createRandomTensor(300, 600, 4, -1, 1);
1112
std::string fName = "tensor.bt"; // binary tensor file extension: .bt
1213
r.saveToFile(fName);
1314

1415
/* Parse binary file */
1516
auto recov = DTensor<double>::parseFromFile(fName);
1617
auto err = r - recov;
17-
std::cout << "max error : " << err.maxAbs();
18-
std::cout << "Memory: " << Session::getInstance().totalAllocatedBytes() << " B" << std::endl;
18+
std::cout << "max error : " << err.maxAbs() << std::endl;
19+
std::cout << "Memory: " << std::setprecision(3)
20+
<< (float) Session::getInstance().totalAllocatedBytes() / 1e6
21+
<< " MB" << std::endl;
1922
return 0;
2023
}

0 commit comments

Comments
 (0)