forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.hh
138 lines (117 loc) · 4.48 KB
/
Types.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//----------------------------------*-C++-*----------------------------------//
// Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
/*!
* \file corecel/Types.hh
* \brief Type definitions for common Celeritas functionality.
*
* This file includes types and properties particular to the build
* configuration.
*/
//---------------------------------------------------------------------------//
#pragma once
#include <cstddef>
#include <string>
#include "celeritas_config.h"
#include "Macros.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
#if CELER_USE_DEVICE || defined(__DOXYGEN__)
//! Standard type for container sizes, optimized for GPU use
using size_type = unsigned int;
#else
using size_type = std::size_t;
#endif
#if CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_DOUBLE
//! Numerical type for real numbers
using real_type = double;
#elif CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_FLOAT
using real_type = float;
#else
using real_type = void;
#endif
//! Equivalent to std::size_t but compatible with CUDA atomics
using ull_int = unsigned long long int;
//---------------------------------------------------------------------------//
// ENUMERATIONS
//---------------------------------------------------------------------------//
//! Memory location of data
enum class MemSpace
{
host, //!< CPU memory
device, //!< GPU memory
mapped, //!< Unified virtual address space (both host and device)
size_,
#ifdef CELER_DEVICE_SOURCE
native = device, //!< When included by a CUDA/HIP file; else 'host'
#else
native = host,
#endif
};
//! Data ownership flag
enum class Ownership
{
value, //!< Ownership of the data, only on host
reference, //!< Mutable reference to the data
const_reference, //!< Immutable reference to the data
};
//---------------------------------------------------------------------------//
//! Unit system used by Celeritas
enum class UnitSystem
{
none, //!< Invalid unit system
cgs, //!< Gaussian CGS
si, //!< International System
clhep, //!< Geant4 native
size_,
native = CELERITAS_UNITS, //!< Compile time selected system
};
#if !defined(SWIG) || SWIG_VERSION > 0x050000
//---------------------------------------------------------------------------//
//!@{
//! \name Convenience typedefs for params and states.
//! Managed host memory
template<template<Ownership, MemSpace> class P>
using HostVal = P<Ownership::value, MemSpace::host>;
//! Immutable reference to host memory
template<template<Ownership, MemSpace> class P>
using HostCRef = P<Ownership::const_reference, MemSpace::host>;
//! Mutable reference to host memory
template<template<Ownership, MemSpace> class S>
using HostRef = S<Ownership::reference, MemSpace::host>;
//! Immutable reference to device memory
template<template<Ownership, MemSpace> class P>
using DeviceCRef = P<Ownership::const_reference, MemSpace::device>;
//! Mutable reference to device memory
template<template<Ownership, MemSpace> class S>
using DeviceRef = S<Ownership::reference, MemSpace::device>;
//! Immutable reference to native memory
template<template<Ownership, MemSpace> class P>
using NativeCRef = P<Ownership::const_reference, MemSpace::native>;
//! Mutable reference to native memory
template<template<Ownership, MemSpace> class S>
using NativeRef = S<Ownership::reference, MemSpace::native>;
template<class T, MemSpace M>
class ObserverPtr;
//! Pointer to same-memory *const* collection group
template<template<Ownership, MemSpace> class P, MemSpace M>
using CRefPtr = ObserverPtr<P<Ownership::const_reference, M> const, M>;
//! Pointer to same-memory *mutable* collection group
template<template<Ownership, MemSpace> class S, MemSpace M>
using RefPtr = ObserverPtr<S<Ownership::reference, M>, M>;
//!@}
#endif
//---------------------------------------------------------------------------//
// HELPER FUNCTIONS (HOST)
//---------------------------------------------------------------------------//
// Get a string corresponding to a memory space
char const* to_cstring(MemSpace m);
// Get a string corresponding to a unit system
char const* to_cstring(UnitSystem);
// Get a unit system corresponding to a string
UnitSystem to_unit_system(std::string const& s);
//---------------------------------------------------------------------------//
} // namespace celeritas