Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
HCSRMatrix.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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#include <alien/kernels/sycl/SYCLPrecomp.h>
10
11
12#include <alien/kernels/sycl/data/HCSRMatrix.h>
13#include <alien/kernels/sycl/data/HCSRMatrixInternal.h>
14
15namespace Alien {
16
17template <typename ValueT>
19allocateDevicePointers(std::size_t nrows,
20 std::size_t nnz,
21 int** ncols,
22 int** rows,
23 int** cols,
24 ValueT** values) const
25{
26 auto& hypre_profile = m_internal->getHypreProfile(m_local_offset) ;
27 auto env = SYCLEnv::instance() ;
28 auto max_num_treads = env->maxNumThreads() ;
29 auto& queue = env->internal()->queue() ;
30 auto ncols_ptr = malloc_device<IndexType>(nrows, queue);
31 auto rows_ptr = malloc_device<IndexType>(nrows, queue);
32 auto cols_ptr = malloc_device<IndexType>(nnz, queue);
33 auto values_ptr = malloc_device<ValueT>(nnz, queue);
34
35 *values = values_ptr ;
36 *cols = cols_ptr ;
37 *ncols = ncols_ptr ;
38 *rows = rows_ptr ;
39}
40
41template <typename ValueT>
43initDevicePointers(int** ncols, int** rows, int** cols, ValueT** values) const
44{
45 auto& hypre_profile = m_internal->getHypreProfile(m_local_offset) ;
46 auto env = SYCLEnv::instance() ;
47 auto max_num_treads = env->maxNumThreads() ;
48 auto nnz = m_profile->getNnz() ;
49 auto& queue = env->internal()->queue() ;
50 auto ncols_ptr = malloc_device<IndexType>(m_local_size, queue);
51 auto rows_ptr = malloc_device<IndexType>(m_local_size, queue);
52 auto cols_ptr = malloc_device<IndexType>(nnz, queue);
53 auto values_ptr = malloc_device<ValueT>(nnz, queue);
54
55 queue.submit( [&](sycl::handler& cgh)
56 {
57 auto access_x = m_internal->m_values.template get_access<sycl::access::mode::read>(cgh);
58 auto access_cols = m_internal->m_cols.template get_access<sycl::access::mode::read>(cgh);
59 auto y_length = nnz ;
60 cgh.parallel_for<class init_ptr>(sycl::range<1>{max_num_treads}, [=] (sycl::item<1> itemId)
61 {
62 auto id = itemId.get_id(0);
63 for (auto i = id; i < y_length; i += itemId.get_range()[0])
64 {
65 values_ptr[i] = access_x[i];
66 cols_ptr[i] = access_cols[i];
67 }
68 });
69 });
70 queue.wait() ;
71
72
73 queue.submit( [&](sycl::handler& cgh)
74 {
75 auto access_ncols = hypre_profile.m_ncols.template get_access<sycl::access::mode::read>(cgh);
76 auto access_rows = hypre_profile.m_rows.template get_access<sycl::access::mode::read>(cgh);
77 auto y_length = m_local_size ;
78 cgh.parallel_for<class init_ptr2>(sycl::range<1>{max_num_treads}, [=] (sycl::item<1> itemId)
79 {
80 auto id = itemId.get_id(0);
81 for (auto i = id; i < y_length; i += itemId.get_range()[0])
82 {
83 ncols_ptr[i] = access_ncols[i];
84 rows_ptr[i] = access_rows[i];
85 }
86 });
87 }) ;
88 queue.wait() ;
89
90 *values = values_ptr ;
91 *cols = cols_ptr ;
92 *ncols = ncols_ptr ;
93 *rows = rows_ptr ;
94}
95
96template <typename ValueT>
98copyDevicePointers(std::size_t nrows,
99 std::size_t nnz,
100 int* rows,
101 int* ncols,
102 int* cols,
103 ValueT* values) const
104{
105 auto& hypre_profile = m_internal->getHypreProfile(m_local_offset) ;
106 auto env = SYCLEnv::instance() ;
107 auto max_num_treads = env->maxNumThreads() ;
108 auto& queue = env->internal()->queue() ;
109
110 //std::cout<<"HCSRMatrix::copyDevicePointers"<<nrows<<" "<<nnz<<std::endl ;
111 queue.submit( [&](sycl::handler& cgh)
112 {
113 auto access_x = m_internal->m_values.template get_access<sycl::access::mode::read>(cgh);
114 auto access_cols = m_internal->m_cols.template get_access<sycl::access::mode::read>(cgh);
115 auto y_length = nnz ;
116 cgh.parallel_for<class init_ptr>(sycl::range<1>{max_num_treads}, [=] (sycl::item<1> itemId)
117 {
118 auto id = itemId.get_id(0);
119 for (auto i = id; i < y_length; i += itemId.get_range()[0])
120 {
121 values[i] = access_x[i];
122 cols[i] = access_cols[i];
123 }
124 });
125 });
126 queue.wait() ;
127
128
129 queue.submit( [&](sycl::handler& cgh)
130 {
131 auto access_ncols = hypre_profile.m_ncols.template get_access<sycl::access::mode::read>(cgh);
132 auto access_rows = hypre_profile.m_rows.template get_access<sycl::access::mode::read>(cgh);
133 auto y_length = nrows ;
134 cgh.parallel_for<class init_ptr2>(sycl::range<1>{max_num_treads}, [=] (sycl::item<1> itemId)
135 {
136 auto id = itemId.get_id(0);
137 for (auto i = id; i < y_length; i += itemId.get_range()[0])
138 {
139 ncols[i] = access_ncols[i];
140 rows[i] = access_rows[i];
141 }
142 });
143 }) ;
144 queue.wait() ;
145 //std::cout<<"HCSRMatrix::copyDevicePointers OK"<<std::endl ;
146}
147
148
149
150template <typename ValueT>
151HCSRMatrix<ValueT>::HCSRView
152HCSRMatrix<ValueT>::hcsrView(BackEnd::Memory::eType memory, int nrows, int nnz) const
153{
154 return HCSRView(this,memory, nrows, nnz) ;
155}
156
157
158
159template <typename ValueT>
161initCOODevicePointers(int** dof_uids, int** rows, int** cols, ValueT** values) const
162{
163
164 const int* h_ghost_uids_ptr = nullptr ;
165 if(m_is_parallel)
166 h_ghost_uids_ptr = m_matrix_dist_info.m_recv_info.m_uids.data() ;
167
168 alien_debug([&] {
169 cout() << "initCOODevicePointers "<<m_local_offset<<" "<<m_ghost_size<<" "<< h_ghost_uids_ptr;
170 });
171 auto& coo_profile = m_internal->getCOOProfile(m_local_offset,m_ghost_size,h_ghost_uids_ptr) ;
172 alien_debug([&] {
173 cout() << "getCOOprofile OK " ;
174 });
175 auto env = SYCLEnv::instance() ;
176 auto max_num_treads = env->maxNumThreads() ;
177 auto nnz = m_profile->getNnz() ;
178 auto& queue = env->internal()->queue() ;
179 auto dof_uids_ptr = malloc_device<IndexType>(m_local_size+m_ghost_size, queue);
180 auto rows_ptr = malloc_device<IndexType>(nnz, queue);
181 auto cols_ptr = malloc_device<IndexType>(nnz, queue);
182 auto values_ptr = malloc_device<ValueT>(nnz, queue);
183
184 queue.submit( [&](sycl::handler& cgh)
185 {
186 auto access_x = m_internal->m_values.template get_access<sycl::access::mode::read>(cgh);
187 auto access_rows = coo_profile.m_rows.template get_access<sycl::access::mode::read>(cgh);
188 auto access_cols = m_internal->m_cols.template get_access<sycl::access::mode::read>(cgh);
189 auto y_length = nnz ;
190 cgh.parallel_for<class init_ptr>(sycl::range<1>{max_num_treads}, [=] (sycl::item<1> itemId)
191 {
192 auto id = itemId.get_id(0);
193 for (auto i = id; i < y_length; i += itemId.get_range()[0])
194 {
195 values_ptr[i] = access_x[i];
196 rows_ptr[i] = access_rows[i];
197 cols_ptr[i] = access_cols[i];
198 }
199 });
200 });
201 queue.wait() ;
202 alien_debug([&] {
203 cout() << "queue Submit OK " ;
204 });
205 /*
206 if(m_is_parallel)
207 {
208 queue.submit( [&](sycl::handler& cgh)
209 {
210 auto y_length = m_local_size + m_ghost_size;
211 auto access_ghost_uids = coo_profile.m_ghost_uids.template get_access<sycl::access::mode::read>(cgh);
212 cgh.parallel_for<class init_ptr2>(sycl::range<1>{max_num_treads},
213 [=] (sycl::item<1> itemId)
214 {
215 auto id = itemId.get_id(0);
216 for (auto i = id; i < y_length; i += itemId.get_range()[0])
217 {
218 if(i<m_local_size)
219 dof_uids_ptr[i] = m_local_offset + i;
220 else
221 dof_uids_ptr[i] = access_ghost_uids[i-m_local_size] ;
222 }
223 });
224 }) ;
225 queue.wait() ;
226 }*/
227
228
229 *values = values_ptr ;
230 *cols = cols_ptr ;
231 *rows = rows_ptr ;
232 *dof_uids = dof_uids_ptr ;
233 alien_debug([&] {
234 cout() << "initCOODevicePointers OK " ;
235 });
236
237}
238
239template <typename ValueT>
240void HCSRMatrix<ValueT>::freeDevicePointers(int* ncols, int* rows, int* cols, ValueT* values) const
241{
242 auto env = SYCLEnv::instance() ;
243 auto& queue = env->internal()->queue() ;
244 sycl::free(values,queue) ;
245 sycl::free(ncols,queue) ;
246 sycl::free(rows,queue) ;
247 sycl::free(cols,queue) ;
248}
249
250template <typename ValueT>
251void HCSRMatrix<ValueT>::freeCOODevicePointers(int* dof_uids, int* rows, int* cols, ValueT* values) const
252{
253 auto env = SYCLEnv::instance() ;
254 auto& queue = env->internal()->queue() ;
255 sycl::free(values,queue) ;
256 sycl::free(dof_uids,queue) ;
257 sycl::free(rows,queue) ;
258 sycl::free(cols,queue) ;
259}
260
261
262template class HCSRMatrix<Real>;
263
264} // namespace Alien
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17