Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:46

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2021-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file corecel/data/detail/Filler.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <algorithm>
0011 
0012 #include "corecel/Assert.hh"
0013 #include "corecel/Macros.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/cont/Span.hh"
0016 #include "corecel/sys/ThreadId.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 
0024 //! Assign on host or mapped / managed memory
0025 template<class T, MemSpace M>
0026 struct Filler
0027 {
0028     T const& value;
0029 
0030     void operator()(Span<T> data) const
0031     {
0032         std::fill(data.begin(), data.end(), value);
0033     }
0034 };
0035 
0036 //! Assign on device
0037 template<class T>
0038 struct Filler<T, MemSpace::device>
0039 {
0040   public:
0041     explicit Filler(T const& value) : value_{value} {};
0042     Filler(T const& value, StreamId stream)
0043         : value_{value}, stream_{stream} {};
0044 
0045     void operator()(Span<T>) const;
0046 
0047   private:
0048     T const& value_;
0049     StreamId stream_;
0050 };
0051 
0052 #if !CELER_USE_DEVICE
0053 template<class T>
0054 void Filler<T, MemSpace::device>::operator()(Span<T>) const
0055 {
0056     CELER_NOT_CONFIGURED("CUDA or HIP");
0057 }
0058 #else
0059 extern template struct Filler<real_type, MemSpace::device>;
0060 extern template struct Filler<size_type, MemSpace::device>;
0061 extern template struct Filler<int, MemSpace::device>;
0062 extern template struct Filler<TrackSlotId, MemSpace::device>;
0063 #endif
0064 
0065 //---------------------------------------------------------------------------//
0066 }  // namespace detail
0067 }  // namespace celeritas