|
|
|||
File indexing completed on 2026-12-03 10:41:05
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/PinnedAllocator.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <cstdlib> 0010 0011 #include "corecel/Macros.hh" 0012 0013 #include "detail/PinnedAllocatorImpl.hh" 0014 0015 namespace celeritas 0016 { 0017 //---------------------------------------------------------------------------// 0018 /*! 0019 * Allocate pinned host memory when using a device. 0020 * 0021 * Satisfies the Allocator named requirement. 0022 * 0023 * If Celeritas is built without device support, or if the device is disabled 0024 * at runtime (including if this is called before the device is initialized!), 0025 * the allocator will fall back to global \code ::operator new() or \c 0026 * ::operator delete() \endcode. Only use this when necessary (i.e. 0027 * asynchronous H<->D memory transfer is needed) as pinned memory reduces the 0028 * memory available to the systems. 0029 */ 0030 template<class T> 0031 struct PinnedAllocator 0032 { 0033 using value_type = T; 0034 0035 [[nodiscard]] CELER_FORCEINLINE T* allocate(std::size_t count) 0036 { 0037 return static_cast<T*>(detail::malloc_pinned(count, sizeof(T))); 0038 } 0039 0040 CELER_FORCEINLINE void deallocate(T* ptr, std::size_t) noexcept 0041 { 0042 return detail::free_pinned(ptr); 0043 } 0044 0045 template<class U> 0046 friend bool operator==(PinnedAllocator const&, PinnedAllocator<U> const&) 0047 { 0048 return true; 0049 } 0050 template<class U> 0051 friend bool operator!=(PinnedAllocator const&, PinnedAllocator<U> const&) 0052 { 0053 return false; 0054 } 0055 }; 0056 0057 //---------------------------------------------------------------------------// 0058 } // namespace celeritas
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|