Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/corecel/Types.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 /*!
0006  * \file corecel/Types.hh
0007  * \brief Type definitions for common Celeritas functionality.
0008  *
0009  * This file includes types and properties particular to the build
0010  * configuration.
0011  */
0012 //---------------------------------------------------------------------------//
0013 #pragma once
0014 
0015 #include <cstddef>
0016 #include <string>
0017 
0018 #include "corecel/Config.hh"
0019 
0020 #include "Macros.hh"
0021 
0022 namespace celeritas
0023 {
0024 //---------------------------------------------------------------------------//
0025 #if CELER_USE_DEVICE || defined(__DOXYGEN__)
0026 //! Standard type for container sizes, optimized for GPU use
0027 using size_type = unsigned int;
0028 #else
0029 using size_type = std::size_t;
0030 #endif
0031 
0032 #if CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_DOUBLE
0033 //! Numerical type for real numbers
0034 using real_type = double;
0035 #elif CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_FLOAT
0036 using real_type = float;
0037 #else
0038 using real_type = void;
0039 #endif
0040 
0041 //! Equivalent to std::size_t but compatible with CUDA atomics
0042 using ull_int = unsigned long long int;
0043 
0044 //---------------------------------------------------------------------------//
0045 // ENUMERATIONS
0046 //---------------------------------------------------------------------------//
0047 //! Memory location of data
0048 enum class MemSpace
0049 {
0050     host,  //!< CPU memory
0051     device,  //!< GPU memory
0052     mapped,  //!< Unified virtual address space (both host and device)
0053     size_,
0054 #if defined(CELER_DEVICE_SOURCE) || defined(__DOXYGEN__)
0055     native = device,  //!< When compiling CUDA files, \c device else \c host
0056 #else
0057     native = host,
0058 #endif
0059 };
0060 
0061 //! Data ownership flag
0062 enum class Ownership
0063 {
0064     value,  //!< The collection \em owns the data
0065     reference,  //!< Mutable reference to data
0066     const_reference,  //!< Immutable reference to data
0067 };
0068 
0069 //---------------------------------------------------------------------------//
0070 //! Unit system used by Celeritas
0071 enum class UnitSystem
0072 {
0073     none,  //!< Invalid unit system
0074     cgs,  //!< Gaussian CGS
0075     si,  //!< International System
0076     clhep,  //!< Geant4 native
0077     size_,
0078     native = CELERITAS_UNITS,  //!< Compile time selected system
0079 };
0080 
0081 //---------------------------------------------------------------------------//
0082 //!@{
0083 //! \name Convenience typedefs for params and states.
0084 
0085 //! Managed host memory
0086 template<template<Ownership, MemSpace> class P>
0087 using HostVal = P<Ownership::value, MemSpace::host>;
0088 //! Immutable reference to host memory
0089 template<template<Ownership, MemSpace> class P>
0090 using HostCRef = P<Ownership::const_reference, MemSpace::host>;
0091 //! Mutable reference to host memory
0092 template<template<Ownership, MemSpace> class S>
0093 using HostRef = S<Ownership::reference, MemSpace::host>;
0094 
0095 //! Immutable reference to device memory
0096 template<template<Ownership, MemSpace> class P>
0097 using DeviceCRef = P<Ownership::const_reference, MemSpace::device>;
0098 //! Mutable reference to device memory
0099 template<template<Ownership, MemSpace> class S>
0100 using DeviceRef = S<Ownership::reference, MemSpace::device>;
0101 
0102 //! Immutable reference to native memory
0103 template<template<Ownership, MemSpace> class P>
0104 using NativeCRef = P<Ownership::const_reference, MemSpace::native>;
0105 //! Mutable reference to native memory
0106 template<template<Ownership, MemSpace> class S>
0107 using NativeRef = S<Ownership::reference, MemSpace::native>;
0108 
0109 template<class T, MemSpace M>
0110 class ObserverPtr;
0111 
0112 //! Pointer to same-memory *const* collection group
0113 template<template<Ownership, MemSpace> class P, MemSpace M>
0114 using CRefPtr = ObserverPtr<P<Ownership::const_reference, M> const, M>;
0115 //! Pointer to same-memory *mutable* collection group
0116 template<template<Ownership, MemSpace> class S, MemSpace M>
0117 using RefPtr = ObserverPtr<S<Ownership::reference, M>, M>;
0118 
0119 //!@}
0120 
0121 //---------------------------------------------------------------------------//
0122 // HELPER FUNCTIONS (HOST)
0123 //---------------------------------------------------------------------------//
0124 
0125 // Get a string corresponding to a memory space
0126 char const* to_cstring(MemSpace m);
0127 
0128 // Get a string corresponding to a unit system
0129 char const* to_cstring(UnitSystem);
0130 
0131 // Get a unit system corresponding to a string
0132 UnitSystem to_unit_system(std::string const& s);
0133 
0134 //---------------------------------------------------------------------------//
0135 }  // namespace celeritas