Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:38

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/data/ParamsDataInterface.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 
0013 #include "Ref.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Interface class for accessing parameter data.
0020  */
0021 template<template<Ownership, MemSpace> class P>
0022 class ParamsDataInterface
0023 {
0024   public:
0025     //!@{
0026     //! \name Type aliases
0027     using HostRef = HostCRef<P>;
0028     using DeviceRef = DeviceCRef<P>;
0029     //!@}
0030 
0031     //! Reference CPU geometry data
0032     virtual HostRef const& host_ref() const = 0;
0033 
0034     //! Reference managed GPU geometry data
0035     virtual DeviceRef const& device_ref() const = 0;
0036 
0037     // Dispatch a "ref" call to host or device data
0038     template<MemSpace M>
0039     inline P<Ownership::const_reference, M> const& ref() const;
0040 
0041   protected:
0042     // Protected destructor prevents deletion of pointer-to-interface
0043     ~ParamsDataInterface() = default;
0044 
0045     // Prohibit copy/move beween interface classes
0046     ParamsDataInterface() = default;
0047     CELER_DEFAULT_COPY_MOVE(ParamsDataInterface);
0048 };
0049 
0050 //---------------------------------------------------------------------------//
0051 // INLINE DEFINITIONS
0052 //---------------------------------------------------------------------------//
0053 /*!
0054  * Dispatch a "ref" call to host or device data.
0055  */
0056 template<template<Ownership, MemSpace> class P>
0057 template<MemSpace M>
0058 P<Ownership::const_reference, M> const& ParamsDataInterface<P>::ref() const
0059 {
0060     // Note: CUDA 11.4.2 + GCC 11.2.0 doesn't support 'if constexpr'
0061     return get_ref<M>(*this);
0062 }
0063 
0064 //---------------------------------------------------------------------------//
0065 }  // namespace celeritas