alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
BufGenericSyclImpl.hpp
Go to the documentation of this file.
1/* Copyright 2024 Jan Stephan, Luca Ferragina, Aurora Perego, Andrea Bocci
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
10#include "alpaka/vec/Vec.hpp"
11
12#include <functional>
13#include <memory>
14#include <type_traits>
15
16#ifdef ALPAKA_ACC_SYCL_ENABLED
17
18namespace alpaka::detail
19{
20 //! The Sycl memory buffer implementation.
21 template<typename TElem, typename TDim, typename TIdx, concepts::Tag TTag>
22 class BufGenericSyclImpl final
23 {
24 static_assert(
25 !std::is_const_v<TElem>,
26 "The elem type of the buffer can not be const because the C++ Standard forbids containers of const "
27 "elements!");
28 static_assert(!std::is_const_v<TIdx>, "The idx type of the buffer can not be const!");
29
30 public:
31 template<typename TExtent>
32 ALPAKA_FN_HOST BufGenericSyclImpl(
33 DevGenericSycl<TTag> dev,
34 TElem* pMem,
35 std::function<void(TElem*)> deleter,
36 TExtent const& extent) noexcept
37 : m_dev(std::move(dev))
38 , m_pMem(pMem)
39 , m_deleter(std::move(deleter))
40 , m_extentElements(getExtentVecEnd<TDim>(extent))
41 {
43
44 static_assert(
45 TDim::value == Dim<TExtent>::value,
46 "The dimensionality of TExtent and the dimensionality of the TDim template parameter have to be "
47 "identical!");
48 static_assert(
49 std::is_same_v<TIdx, Idx<TExtent>>,
50 "The idx type of TExtent and the TIdx template parameter have to be identical!");
51
52# if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
53 std::cout << __func__ << " e: " << m_extentElements << " ptr: " << static_cast<void*>(m_pMem) << std::endl;
54# endif
55 }
56
57 BufGenericSyclImpl(BufGenericSyclImpl&&) = delete;
58 auto operator=(BufGenericSyclImpl&&) -> BufGenericSyclImpl& = delete;
59
60 ALPAKA_FN_HOST ~BufGenericSyclImpl()
61 {
63
64 // NOTE: m_pMem is allowed to be a nullptr here.
65 m_deleter(m_pMem);
66 }
67
68 private:
69 DevGenericSycl<TTag> m_dev;
70 TElem* const m_pMem;
71 std::function<void(TElem*)> m_deleter;
72 Vec<TDim, TIdx> m_extentElements;
73
74 // friend declarations to allow usage of these pointers in the respective trait implementations
75 template<typename TBuf, typename TSfinae>
76 friend struct alpaka::trait::GetDev;
77
78 template<typename TBuf, typename TSfinae>
79 friend struct alpaka::trait::GetExtents;
80
81 template<typename TBuf, typename TSfinae>
82 friend struct alpaka::trait::GetPtrNative;
83
84 template<typename TBuf, typename TDev, typename TSfinae>
85 friend struct alpaka::trait::GetPtrDev;
86 };
87} // namespace alpaka::detail
88
89#endif
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
Definition Debug.hpp:55
#define ALPAKA_FN_HOST
Definition Common.hpp:40
The device get trait.
Definition Traits.hpp:27
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition Traits.hpp:37
The pointer on device get trait.
Definition Traits.hpp:58
The native pointer get trait.
Definition Traits.hpp:54