QMCPACK
MemoryUsage.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "MemoryUsage.h"
14 #include <cstring>
15 #include <string>
16 #include <iomanip>
17 #include "Host/sysutil.h"
19 #ifdef ENABLE_CUDA
20 #include "CUDA/CUDAallocator.hpp"
21 #include "CUDA/CUDAruntime.hpp"
22 #endif
23 #ifdef ENABLE_SYCL
24 #include "SYCL/SYCLallocator.hpp"
25 #include "SYCL/SYCLruntime.hpp"
26 #endif
27 
28 namespace qmcplusplus
29 {
30 void print_mem(const std::string& title, std::ostream& log)
31 {
32  std::string line_separator;
33  for (int i = 0; i < title.size() + 30; i++)
34  line_separator += "=";
35  log << line_separator << std::endl;
36  log << "--- Memory usage report : " << title << " ---" << std::endl;
37  log << line_separator << std::endl;
38  log << std::right;
39  log << "Available memory on node 0, free + buffers : " << std::setw(7) << (freemem() >> 20) << " MiB" << std::endl;
40  log << "Memory footprint by rank 0 on node 0 : " << std::setw(7) << (memusage() >> 10) << " MiB" << std::endl;
41 #ifdef ENABLE_OFFLOAD
42  log << "Device memory allocated via OpenMP offload : " << std::setw(7) << (getOMPdeviceMemAllocated() >> 20) << " MiB"
43  << std::endl;
44 #endif
45 #ifdef ENABLE_CUDA
46  log << "Device memory allocated via CUDA allocator : " << std::setw(7) << (getCUDAdeviceMemAllocated() >> 20)
47  << " MiB" << std::endl;
48  log << "Free memory on the default device : " << std::setw(7) << (getCUDAdeviceFreeMem() >> 20) << " MiB"
49  << std::endl;
50 #endif
51 #ifdef ENABLE_SYCL
52  log << "Device memory allocated via SYCL allocator : " << std::setw(7) << (getSYCLdeviceMemAllocated() >> 20)
53  << " MiB" << std::endl;
54  log << "Free memory on the default device : " << std::setw(7) << (getSYCLdeviceFreeMem() >> 20) << " MiB"
55  << std::endl;
56 #endif
57  log << line_separator << std::endl;
58 }
59 
60 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
handle CUDA/HIP runtime selection.
size_t getOMPdeviceMemAllocated()
void print_mem(const std::string &title, std::ostream &log)
Definition: MemoryUsage.cpp:30
this file provides three C++ memory allocators using CUDA specific memory allocation functions...
size_t getCUDAdeviceFreeMem()
Definition: CUDAruntime.cpp:15
size_t getSYCLdeviceFreeMem()
query free memory on the default device
Definition: SYCLruntime.cpp:31
size_t getSYCLdeviceMemAllocated()
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
size_t memusage()
Definition: sysutil.cpp:66
size_t freemem()
Definition: sysutil.cpp:53
this file provides three C++ memory allocators using SYCL specific memory allocation functions...
size_t getCUDAdeviceMemAllocated()