Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
printCudaMemInfo.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file printCudaMemInfo.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
12 
13 #ifndef ACTS_EXATRKX_CPUONLY
14 #include <cuda_runtime_api.h>
15 #endif
16 
17 #include <cstdint>
18 
19 #include <torch/torch.h>
20 
21 namespace {
22 
23 inline void printCudaMemInfo(const Acts::Logger& logger) {
24 #ifndef ACTS_EXATRKX_CPUONLY
25  if (torch::cuda::is_available()) {
26  constexpr float kb = 1024;
27  constexpr float mb = kb * kb;
28 
29  int device;
30  std::size_t free, total;
31  cudaMemGetInfo(&free, &total);
32  cudaGetDevice(&device);
33 
34  ACTS_VERBOSE("Current CUDA device: " << device);
35  ACTS_VERBOSE("Memory (used / total) [in MB]: " << (total - free) / mb
36  << " / " << total / mb);
37  } else {
38  ACTS_VERBOSE("No memory info, CUDA disabled");
39  }
40 #else
41  ACTS_VERBOSE("No memory info, CUDA disabled");
42 #endif
43 }
44 
45 } // namespace