Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:16

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // CUDA plugin include(s).
0010 #include "Acts/Plugins/Cuda/Utilities/Info.hpp"
0011 
0012 #include "ErrorCheck.cuh"
0013 
0014 // System include(s).
0015 #include <cmath>
0016 #include <iostream>
0017 
0018 namespace Acts {
0019 namespace Cuda {
0020 
0021 Info& Info::instance() {
0022   static Info info;
0023   return info;
0024 }
0025 
0026 const std::vector<Info::Device>& Info::devices() const {
0027   return m_devices;
0028 }
0029 
0030 Info::Info() {
0031   // Collect all information about all the available devices on
0032   // construction. Note that we explicitly ignore the return value of the call,
0033   // in case the code is executed without any available CUDA devices.
0034   int nDevices = 0;
0035   static_cast<void>(cudaGetDeviceCount(&nDevices));
0036 
0037   for (int i = 0; i < nDevices; ++i) {
0038     // Retrieve all properties of this device.
0039     cudaDeviceProp properties;
0040     ACTS_CUDA_ERROR_CHECK(cudaGetDeviceProperties(&properties, i));
0041 
0042     // Create an @c Acts::Cuda::Info::Device object from the information.
0043     m_devices.push_back({i, properties.name, properties.maxThreadsPerBlock,
0044                          static_cast<bool>(properties.concurrentKernels),
0045                          properties.totalGlobalMem});
0046   }
0047 }
0048 
0049 std::ostream& operator<<(std::ostream& out, const Info::Device& device) {
0050   out << " /-- Device ID " << device.id << " " << std::string(31, '-') << "\\"
0051       << std::endl;
0052   out << " | Name: " << device.name
0053       << std::string(
0054              (39 > device.name.length() ? 39 - device.name.length() : 0), ' ')
0055       << "|" << std::endl;
0056   const std::size_t threadDigits =
0057       static_cast<std::size_t>(std::log10(device.maxThreadsPerBlock)) + 1;
0058   out << " | Max. threads per block: " << device.maxThreadsPerBlock
0059       << std::string((21 > threadDigits ? 21 - threadDigits : 0), ' ') << "|"
0060       << std::endl;
0061   out << " | Concurrent kernels: "
0062       << (device.concurrentKernels ? "true " : "false") << std::string(20, ' ')
0063       << "|" << std::endl;
0064   static constexpr double MEGABYTES = 1.0 / (1024 * 1024);
0065   const double totalMem = device.totalMemory * MEGABYTES;
0066   const std::size_t memDigits =
0067       static_cast<std::size_t>(std::log10(totalMem)) + 1;
0068   out << " | Total memory: " << totalMem << " MB"
0069       << std::string((25 > memDigits ? 25 - memDigits : 0), ' ') << "|"
0070       << std::endl;
0071   out << " \\" << std::string(46, '-') << "/";
0072 
0073   return out;
0074 }
0075 
0076 }  // namespace Cuda
0077 }  // namespace Acts