ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
cuda/init.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "config/config.hpp"
23
24#ifdef ESPRESSO_CUDA
25
26#include "utils.hpp"
27
28#include <boost/serialization/access.hpp>
29
30#include <cstddef>
31#include <string>
32#include <utility>
33#include <vector>
34
35/** Struct to hold information relevant to ESPResSo
36 * about GPUs. Should contain only fixed-length plain
37 * old datatypes, as it is intended for MPI communication.
38 */
40 /** Local CUDA device id */
41 int id;
42 /** Local CUDA device name */
43 std::string name;
44 /** Node identification */
45 std::string proc_name;
46 /** MPI process identification */
47 int node;
48 /** Compute capability (major) */
50 /** Compute capability (minor) */
52 /** Total Memory */
53 std::size_t total_memory;
54 /** Number of cores */
56
57private:
58 friend boost::serialization::access;
59 template <typename Archive>
60 void serialize(Archive &ar, unsigned int const /* version */) {
63 }
64};
65
66/** Initializes the CUDA stream.
67 */
68void cuda_init();
69
70/** Get the number of CUDA devices on the local host.
71 *
72 * @return the number of GPUs.
73 */
74int cuda_get_n_gpus();
75
76/** Check that a given GPU has compute capability.
77 * The minimal compute capability required by ESPResSo is
78 * \ref computeCapabilityMinMajor . \ref computeCapabilityMinMinor .
79 *
80 * @param dev CUDA device number
81 * @return @c false if the GPU meets the requirements, else @c true.
82 */
84
85/** Get the name of a CUDA device.
86 *
87 * @param[in] dev the CUDA device number to ask the name for
88 */
89std::string cuda_get_gpu_name(int dev);
90
91/** Choose a device for future CUDA computations.
92 *
93 * @param dev the device to use
94 */
95void cuda_set_device(int dev);
96
97/** Get the current CUDA device.
98 *
99 * @return the current device's number.
100 */
101int cuda_get_device();
102
103/** Test if communication to the CUDA device works.
104 * @return @c false on success, else @c true.
105 */
107
108/**
109 * Check that a device is available, that its compute capability
110 * is sufficient for ESPResSo, and that data can be written to
111 * and read from it. Otherwise, throw an exception.
112 */
113void cuda_check_device();
114
115/** Gather unique list of CUDA devices on all nodes.
116 * @return vector of device properties.
117 */
118std::vector<EspressoGpuDevice> cuda_gather_gpus();
119
120/** Get properties of a CUDA device
121 * @param dev CUDA device number
122 */
124
125/** @brief Called on program start. */
127
128namespace detail {
129std::pair<int, std::string> get_node_info();
130} // namespace detail
131
132#endif // ESPRESSO_CUDA
std::vector< EspressoGpuDevice > cuda_gather_gpus()
Gather unique list of CUDA devices on all nodes.
Definition cuda/init.cpp:56
void cuda_on_program_start()
Called on program start.
Definition cuda/init.cpp:91
void cuda_check_device()
Check that a device is available, that its compute capability is sufficient for ESPResSo,...
Definition init_cuda.cu:102
bool cuda_check_gpu_compute_capability(int dev)
Check that a given GPU has compute capability.
Definition init_cuda.cu:50
bool cuda_test_device_access()
Test if communication to the CUDA device works.
Definition init_cuda.cu:90
std::string cuda_get_gpu_name(int dev)
Get the name of a CUDA device.
Definition init_cuda.cu:58
EspressoGpuDevice cuda_get_device_props(int dev)
Get properties of a CUDA device.
Definition init_cuda.cu:64
int cuda_get_device()
Get the current CUDA device.
Definition init_cuda.cu:84
void cuda_set_device(int dev)
Choose a device for future CUDA computations.
Definition init_cuda.cu:78
int cuda_get_n_gpus()
Get the number of CUDA devices on the local host.
Definition init_cuda.cu:44
void cuda_init()
Initializes the CUDA stream.
Definition init_cuda.cu:42
Struct to hold information relevant to ESPResSo about GPUs.
Definition cuda/init.hpp:39
std::string proc_name
Node identification.
Definition cuda/init.hpp:45
std::size_t total_memory
Total Memory.
Definition cuda/init.hpp:53
int compute_capability_major
Compute capability (major)
Definition cuda/init.hpp:49
int compute_capability_minor
Compute capability (minor)
Definition cuda/init.hpp:51
int node
MPI process identification.
Definition cuda/init.hpp:47
int n_cores
Number of cores.
Definition cuda/init.hpp:55
std::string name
Local CUDA device name.
Definition cuda/init.hpp:43
int id
Local CUDA device id.
Definition cuda/init.hpp:41