ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1#ifndef MODULE_DEVICE_H_
2#define MODULE_DEVICE_H_
3
4#include "types.h"
5#include <fstream>
6
7#ifdef __MPI
8#include "mpi.h"
9#endif
10
11namespace base_device
12{
13
14// struct CPU;
15// struct GPU;
16
17// enum AbacusDevice_t
18// {
19// UnKnown,
20// CpuDevice,
21// GpuDevice
22// };
23
24template <typename Device>
26
27template <typename T>
28std::string get_current_precision(const T* var);
29
30namespace information
31{
32
37std::string get_device_info(std::string device_flag);
38
43int get_device_kpar(const int& kpar, const int& bndpar);
44
49std::string get_device_flag(const std::string& device,
50 const std::string& basis_type);
51
52#if __MPI
59int get_node_rank();
60int get_node_rank_with_mpi_shared(const MPI_Comm mpi_comm = MPI_COMM_WORLD);
61int stringCmp(const void* a, const void* b);
62
63#ifdef __CUDA
64
65int set_device_by_rank(const MPI_Comm mpi_comm = MPI_COMM_WORLD);
66#endif
67
68#endif
69
70template <typename Device>
71void print_device_info(const Device* dev, std::ofstream& ofs_device)
72{
73 return;
74}
75
76template <typename Device>
77void record_device_memory(const Device* dev, std::ofstream& ofs_device, std::string str, size_t size)
78{
79 return;
80}
81
82} // end of namespace information
83} // end of namespace base_device
84
89#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600 && !defined(__CUDA_ON_DCU)
90static __inline__ __device__ double atomicAdd(double* address, double val)
91{
92 unsigned long long int* address_as_ull = (unsigned long long int*)address;
93 unsigned long long int old = *address_as_ull, assumed;
94 do
95 {
96 assumed = old;
97 old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val + __longlong_as_double(assumed)));
98 // Note: uses integer comparison to avoid hang in case of NaN (since NaN !=
99 // NaN) } while (assumed != old);
100 } while (assumed != old);
101 return __longlong_as_double(old);
102}
103#endif
104
105#endif // MODULE_DEVICE_H_
#define T
Definition exp.cpp:237
std::string get_device_info(std::string device_flag)
Get the device info object for source_esolver.
Definition device.cpp:227
std::string get_device_flag(const std::string &device, const std::string &basis_type)
Get the device flag object for source_io PARAM.inp.device.
Definition device.cpp:150
void record_device_memory(const Device *dev, std::ofstream &ofs_device, std::string str, size_t size)
Definition device.h:77
int get_node_rank()
Get the rank of current node Note that GPU can only be binded with CPU in the same node.
Definition device.cpp:67
void print_device_info(const Device *dev, std::ofstream &ofs_device)
Definition device.h:71
int get_device_kpar(const int &kpar, const int &bndpar)
Get the device kpar object for source_io GlobalV::KPAR.
Definition device.cpp:199
int get_node_rank_with_mpi_shared(const MPI_Comm mpi_comm)
Definition device.cpp:114
int stringCmp(const void *a, const void *b)
Definition device.cpp:52
Definition device.cpp:21
base_device::AbacusDevice_t get_device_type(const Device *dev)
std::string get_current_precision(const float *var)
Definition device.cpp:36
AbacusDevice_t
Definition types.h:12
string device_flag
Definition pw_test.cpp:13