SIRIUS 7.5.0
Electronic structure library and applications
acc.cpp
Go to the documentation of this file.
1// Copyright (c) 2013-2023 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file acc.cpp
21 *
22 * \brief Definition of the functions for the acc:: namespace.
23 *
24 */
25#include <atomic>
26#include "acc.hpp"
27
28namespace sirius {
29
30namespace acc {
31
33{
34#if defined(SIRIUS_CUDA) || defined(SIRIUS_ROCM)
35 static std::atomic<int> count(-1);
36 if (count.load(std::memory_order_relaxed) == -1) {
37 int c;
38 if (GPU_PREFIX(GetDeviceCount)(&c) != GPU_PREFIX(Success)) {
39 count.store(0, std::memory_order_relaxed);
40 } else {
41 count.store(c, std::memory_order_relaxed);
42 }
43 }
44 return count.load(std::memory_order_relaxed);
45#else
46 return 0;
47#endif
48}
49
50std::vector<acc_stream_t>& streams()
51{
52 static std::vector<acc_stream_t> streams_;
53 return streams_;
54}
55
56} // namespace acc
57
58} // namespace sirius
Interface to accelerators API.
int num_devices()
Get the number of devices.
Definition: acc.cpp:32
std::vector< acc_stream_t > & streams()
Vector of device streams.
Definition: acc.cpp:50
Namespace of the SIRIUS library.
Definition: sirius.f90:5