Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:42

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-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/PinnedAllocator.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <cstdlib>
0011 
0012 namespace celeritas
0013 {
0014 //---------------------------------------------------------------------------//
0015 /*!
0016  * Allocate pinned host memory when using a device.
0017  *
0018  * Satisfies the Allocator named requirement.
0019  *
0020  * If Celeritas is built without device support, or if the device is disabled
0021  * at runtime (including if this is called before the device is initialized!),
0022  * the allocator will fall back to global \code ::operator new() or \c
0023  * ::operator delete() \endcode. Only use this when necessary (i.e.
0024  * asynchronous H<->D memory transfer is needed) as pinned memory reduces the
0025  * memory available to the systems.
0026  */
0027 template<class T>
0028 struct PinnedAllocator
0029 {
0030     using value_type = T;
0031 
0032     [[nodiscard]] T* allocate(std::size_t);
0033 
0034     void deallocate(T*, std::size_t) noexcept;
0035 };
0036 
0037 template<class T, class U>
0038 bool operator==(PinnedAllocator<T> const&, PinnedAllocator<U> const&)
0039 {
0040     return true;
0041 }
0042 
0043 template<class T, class U>
0044 bool operator!=(PinnedAllocator<T> const&, PinnedAllocator<U> const&)
0045 {
0046     return false;
0047 }
0048 
0049 //---------------------------------------------------------------------------//
0050 }  // namespace celeritas