Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
VectorAccessorImplT.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8
9#pragma once
10
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15#include <alien/kernels/sycl/data/HCSRVector.h>
16#include <alien/kernels/sycl/data/HCSRVectorInternal.h>
17
18#include <alien/kernels/sycl/data/SYCLParallelEngine.h>
19#include <alien/kernels/sycl/data/SYCLParallelEngineImplT.h>
20
21#include <alien/handlers/scalar/sycl/VectorAccessorT.h>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Alien
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace SYCL
33{
34
35 /*---------------------------------------------------------------------------*/
36 /*---------------------------------------------------------------------------*/
37 template <typename ValueT>
38 class VectorAccessorT<ValueT>::Impl
39 {
40 public :
41 typedef typename HCSRVector<ValueT>::InternalType VectorInternalType ;
42 typedef typename VectorInternalType::ValueBufferType ValueBufferType ;
43
44 Impl(ValueBufferType& buffer)
45 : m_buffer(buffer)
46 {}
47
48 //std::span<ValueT> m_values ;
49 ValueBufferType& m_buffer ;
50
51 auto accessor(SYCLControlGroupHandler& cgh) {
52 return m_buffer.template get_access<sycl::access::mode::read_write>(cgh.m_internal) ;
53 }
54 };
55
56 template <typename ValueT>
57 VectorAccessorT<ValueT>::VectorAccessorT(IVector& vector, bool update)
58 : m_time_stamp(nullptr)
59 , m_local_offset(0)
60 , m_finalized(false)
61 {
62 auto& v = vector.impl()->get<BackEnd::tag::hcsr>(update);
63 m_local_offset = v.distribution().offset();
64 m_impl.reset(new Impl(v.internal()->values())) ;
65 m_time_stamp = &v;
66 }
67
68 template <typename ValueT>
69 typename VectorAccessorT<ValueT>::Impl* VectorAccessorT<ValueT>::impl() {
70 assert(m_impl.get()) ;
71 return m_impl.get() ;
72 }
73
74 /*---------------------------------------------------------------------------*/
75
76 template <typename ValueT>
77 void VectorAccessorT<ValueT>::end()
78 {
79 if (m_finalized)
80 return;
81 m_finalized = true;
82 }
83
84 template <typename ValueT>
85 class VectorAccessorT<ValueT>::View
86 {
87 sycl::handler* m_h = nullptr ;
88 sycl::buffer<ValueT,1>* m_b = nullptr ;
89 using AccessorType = decltype(m_b->template get_access<sycl::access::mode::read_write>(*m_h));
90
91 public :
92 explicit View(AccessorType accessor)
93 : m_accessor(accessor)
94 {}
95
96 ValueT& operator[](std::size_t index) const {
97 return m_accessor[index] ;
98 }
99
100 private :
101 AccessorType m_accessor ;
102
103 } ;
104
105 template <typename ValueT>
106 class VectorAccessorT<ValueT>::ConstView
107 {
108 sycl::handler* m_h = nullptr ;
109 sycl::buffer<ValueT,1>* m_b = nullptr ;
110 using AccessorType = decltype(m_b->template get_access<sycl::access::mode::read>(*m_h));
111
112 public :
113 explicit ConstView(AccessorType accessor)
114 : m_accessor(accessor)
115 {}
116
117 ValueT operator[](std::size_t index) const {
118 return m_accessor[index] ;
119 }
120
121 private :
122 AccessorType m_accessor ;
123 } ;
124
125
126 template <typename ValueT>
127 class VectorAccessorT<ValueT>::HostView
128 {
129 public :
130 typedef typename HCSRVector<ValueT>::InternalType VectorInternalType ;
131 typedef typename VectorInternalType::ValueBufferType ValueBufferType ;
132
133 sycl::buffer<ValueT,1>* m_b = nullptr ;
134 using AccessorType = decltype(m_b->get_host_access());
135
136 explicit HostView(AccessorType values)
137 : m_values(values)
138 {
139
140 }
141
142 ValueType operator[](std::size_t index) const {
143 return m_values[index] ;
144 }
145
146 private:
147 AccessorType m_values ;
148 };
149
150 /*---------------------------------------------------------------------------*/
151 template <typename ValueT>
152 typename VectorAccessorT<ValueT>::View VectorAccessorT<ValueT>::view(SYCLControlGroupHandler& cgh)
153 {
154 return View(m_impl->m_buffer.template get_access<sycl::access::mode::read_write>(cgh.m_internal)) ;
155 }
156
157 template <typename ValueT>
158 typename VectorAccessorT<ValueT>::ConstView VectorAccessorT<ValueT>::constView(SYCLControlGroupHandler& cgh) const
159 {
160 return VectorAccessorT<ValueT>::ConstView(m_impl->m_buffer.template get_access<sycl::access::mode::read>(cgh.m_internal)) ;
161 }
162
163 template <typename ValueT>
164 typename VectorAccessorT<ValueT>::HostView VectorAccessorT<ValueT>::hostView() const
165 {
166 return HostView(m_impl->m_buffer.get_host_access()) ;
167 }
168
169 /*---------------------------------------------------------------------------*/
170 /*---------------------------------------------------------------------------*/
171
172 /*---------------------------------------------------------------------------*/
173 /*---------------------------------------------------------------------------*/
174
175} // namespace SYCL
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180} // namespace Alien
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
MultiVectorImpl.h.
Interface for all vectors.
Definition IVector.h:51
virtual MultiVectorImpl * impl()=0
Get the multivector implementation.
const VectorDistribution & distribution() const
Get the vector distribution.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17