35 alpaka::concepts::Api T_Api,
37 alpaka::concepts::Vector T_Extents,
38 alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
48 T_Extents
const& extents,
49 T_Extents
const& pitches,
50 std::shared_ptr<internal::ManagedDealloc> managedDeleter,
51 T_MemAlignment
const memAlignment)
52 : BaseView{
api,
data, extents, pitches, memAlignment}
53 , m_deleter{std::move(managedDeleter)}
82 T_UserExtents
const& extents,
83 T_UserPitches
const& pitches,
84 std::invocable<>
auto deleter,
85 T_MemAlignment
const memAlignment =
Alignment{})
86 : BaseView{any,
data, extents, pitches, memAlignment}
87 , m_deleter{
std::make_shared<internal::ManagedDealloc>(deleter)}
91 "extent type and pitch type must be lossless convertible");
94 template<
typename T_Type_Other>
95 requires alpaka::internal::concepts::InnerTypeAllowedCast<T_Type, T_Type_Other>
97 : BaseView{static_cast<BaseView>(other)}
98 , m_deleter(other.m_deleter)
110 template<
typename T_Type_Other>
111 requires alpaka::internal::concepts::InnerTypeAllowedCast<T_Type, T_Type_Other>
113 : BaseView{
std::move(static_cast<BaseView>(other))}
114 , m_deleter(
std::move(other.m_deleter))
130 return static_cast<BaseView
>(*this);
136 using ConstValueType = std::add_const_t<typename BaseView::value_type>;
139 static_cast<ConstValueType*
>(this->
data()),
153 Vec extentMd = extents;
166 Vec extentMd = extents;
188 Vec offsetMd = offsets;
189 Vec extentMd = extents;
190 assert((offsetMd + extentMd <= this->
getExtents()).
reduce(std::logical_and{}));
191 auto shiftedPtr = &(*this)[offsetMd];
205 Vec offsetMd = offsets;
206 Vec extentMd = extents;
207 assert((offsetMd + extentMd <= this->
getExtents()).
reduce(std::logical_and{}));
208 auto shiftedPtr = &(*this)[offsetMd];
257 auto del = m_deleter;
258 queue.enqueueHostFnDeferred([_ = std::move(del)] {});
264 return m_deleter.use_count();
268 [[nodiscard]]
constexpr explicit operator bool() const noexcept
270 return static_cast<bool>(m_deleter);
275 template<alpaka::concepts::Po
inter T>
276 using ConstPtr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>;
278 std::shared_ptr<internal::ManagedDealloc> m_deleter;
290 T_UserExtents
const&,
291 T_UserPitches
const&,
292 std::invocable<>
auto,
293 T_MemAlignment
const)
297 typename T_UserPitches::UniVec,
305 SharedBuffer(T_Any
const&, T_Type*, T_UserExtents
const&, T_UserPitches
const&, std::invocable<>
auto)
309 typename T_UserPitches::UniVec,
321 return any.getView();
334 <<
" , alignment=" << T_MemAlignment::template
get<T_Type>() <<
" }";
339namespace alpaka::internal
347 struct GetApi::Op<onHost::SharedBuffer<T_Api, T_Type, T_Extents, T_MemAlignment>>
349 inline constexpr auto operator()(
auto&& buffer)
const
351 alpaka::unused(buffer);
357 alpaka::concepts::Api T_Api,
359 alpaka::concepts::Vector T_Extents,
360 alpaka::concepts::Alignment T_MemAlignment>
361 struct CopyConstructableDataSource<onHost::
SharedBuffer<T_Api, T_Type, T_Extents, T_MemAlignment>> : std::true_type
#define ALPAKA_TYPEOF(...)
Get the type of instance.
#define ALPAKA_FORWARD(instance)
Perfectly forward an instance as argument.
Concept to check for an alignment object.
Concept to check for APIs.
Concept to check if the given type implements the getApi(T x) function returning an alpaka::concepts:...
Concept to check if a type is a vector or scalar variable.
Concept to check if a type is a vector.
Functionality which is usable on the host CPU controller thread.
SharedBuffer(T_Any const &, T_Type *, T_UserExtents const &, T_UserPitches const &, std::invocable<> auto, T_MemAlignment const) -> SharedBuffer< ALPAKA_TYPEOF(getApi(std::declval< T_Any >())), T_Type, typename T_UserPitches::UniVec, T_MemAlignment >
std::ostream & operator<<(std::ostream &s, DeviceProperties const &p)
decltype(auto) data(auto &&any)
pointer to data of an object
std::convertible_to< std::string > auto getName(auto &&any)
Runtime name for a given object.
void wait(alpaka::concepts::HasGet auto &handle)
wait for all work to be finished
void reduce(Queue< T_Device, T_QueueKind > const &queue, alpaka::concepts::Executor auto const exec, DataType const &neutralElement, alpaka::concepts::IMdSpan auto out, auto &&binaryReduceFn, auto &&in)
accumulate the results into a scalar value.
constexpr bool isLosslesslyConvertible_v
constexpr decltype(auto) getApi(auto &&any)
Get the API an object depends on.
constexpr decltype(auto) get(concepts::SpecializationOf< Dict > auto &t) noexcept
Strongly typed and constexpr representation of a byte-alignment of memory.
constexpr auto getExtents() const
constexpr const_pointer data() const
constexpr T_Pitches getPitches() const
constexpr auto getConstView() const
create a read only view
constexpr View(T_Any const &any, T_Type *data, T_UserExtents const &extents, T_UserPitches const &pitches, T_MemAlignment const memAlignment=T_MemAlignment{})
auto operator()(auto &&any) const
Life time managed buffer with contiguous data.
auto getSubSharedBuffer(alpaka::concepts::VectorOrScalar auto const &extents) const
Creates a buffer pointing to a part of the memory.
SharedBuffer(SharedBuffer const &)=default
constexpr long getUseCount() const noexcept
Return the number of SharedBuffers which points to the same memory.
void keepAlive(auto &queue)
Keep the buffer alive until at least the current spot in the queue, even if it runs out of scope.
SharedBuffer(T_Any const &any, T_Type *data, T_UserExtents const &extents, T_UserPitches const &pitches, std::invocable<> auto deleter, T_MemAlignment const memAlignment=Alignment{})
SharedBuffer & operator=(SharedBuffer const &otherSharedBuffer)=default
Assignment operator keeping const-ness.
void addDestructorAction(std::function< void()> &&action)
Adds a destructor action to the shared buffer.
SharedBuffer(SharedBuffer &&)=default
friend std::ostream & operator<<(std::ostream &s, SharedBuffer< T_OtherApi, T_OtherType, T_OtherExtents, T_OtherMemAlignment2 > const &buffer)
SharedBuffer(SharedBuffer< T_Api, T_Type_Other, T_Extents, T_MemAlignment > &&other)
auto getConstSharedBuffer() const
create a read shared buffer view
auto getSubSharedBuffer(alpaka::concepts::VectorOrScalar auto const &offsets, alpaka::concepts::VectorOrScalar auto const &extents)
friend struct SharedBuffer
SharedBuffer & operator=(SharedBuffer &&)=default
void destructorWaitFor(auto const &any)
Add an action to be executed when the shared_ptr is destroyed.
auto getSubSharedBuffer(alpaka::concepts::VectorOrScalar auto const &offsets, alpaka::concepts::VectorOrScalar auto const &extents) const
Creates a shared sub-buffer view to a part of the memory.
auto getSubSharedBuffer(alpaka::concepts::VectorOrScalar auto const &extents)
SharedBuffer(SharedBuffer< T_Api, T_Type_Other, T_Extents, T_MemAlignment > const &other)