Nektar++
Loading...
Searching...
No Matches
MathSYCLKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MathSYCLKernels.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
37#if defined(NEKTAR_ENABLE_SYCL)
38
41
42#include <cmath>
43#include <cstddef>
44#include <cstdint>
45#include <limits>
46#include <type_traits>
47
48namespace Nektar::Math
49{
50
51// The 16 / sizeof(TData) entries of x from 16 / sizeof(TData) * tid in one
52// load, for float or double.
53template <typename TData>
54static inline sycl::vec<TData, 16 / sizeof(TData)> vecLoad(const TData *x,
55 const size_t tid)
56{
57 return reinterpret_cast<const sycl::vec<TData, 16 / sizeof(TData)> *>(
58 x)[tid];
59}
60
61// The vecSize mask entries matching a vecLoad of TData.
62template <typename TData>
63using VecMask = sycl::vec<uint8_t, 16 / sizeof(TData)>;
64
65// The vecSize entries of mask matching vecLoad of TData at tid, in one load.
66template <typename TData>
67static inline VecMask<TData> vecLoadMask(const uint8_t *mask, const size_t tid)
68{
69 return reinterpret_cast<const VecMask<TData> *>(mask)[tid];
70}
71
72template <
73 typename ExecSpace, typename TData,
74 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
75 Enable = true>
76inline void zeroKernel(const size_t nsize, TData *x,
77 const unsigned int streamID = 0)
78{
79 deviceMemset(x, 0, nsize * sizeof(TData), streamID);
80}
81
82template <
83 typename ExecSpace, typename TData,
84 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
85 Enable = true>
86inline void fillKernel(const size_t nsize, const TData &val, TData *x,
87 const unsigned int streamID = 0)
88{
89 deviceFill(x, val, nsize, streamID);
90}
91
92template <
93 typename ExecSpace, typename TData,
94 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
95 Enable = true>
96inline void copyKernel(const size_t nsize, const TData *x, TData *y,
97 const unsigned int streamID = 0)
98{
99 deviceMemcpy<eDeviceToDevice>(y, x, nsize * sizeof(TData), streamID);
100}
101
102template <
103 typename ExecSpace, typename TData,
104 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
105 Enable = true>
106inline void absKernel(const size_t nsize, const TData *x, TData *y,
107 const unsigned int streamID = 0)
108{
109 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
110 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
111
112 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
113 sycl::event e = Q.submit([=](sycl::handler &cgh) {
114 setSYCLDefaultExecutionDependency(streamID, cgh);
115 cgh.parallel_for(sycl::nd_range<1>(gridSize * blockSize, blockSize),
116 [=](sycl::nd_item<1> indx) SYCL_SUBGROUP_SIZE(
118 size_t idx0 = indx.get_global_id(0);
119 size_t stride = indx.get_global_range(0);
120
121 for (size_t idx = idx0; idx < nsize; idx += stride)
122 {
123 y[idx] = sycl::fabs(x[idx]);
124 }
125 });
126 });
127 SYCLQueue::SetEvent(streamID, e);
128}
129
130template <
131 typename ExecSpace, typename TData,
132 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
133 Enable = true>
134inline void negKernel(const size_t nsize, const TData *x, TData *y,
135 const unsigned int streamID = 0)
136{
137 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
138 sycl::event e = Q.submit([=](sycl::handler &cgh) {
139 setSYCLDefaultExecutionDependency(streamID, cgh);
140 cgh.parallel_for(sycl::range<1>(nsize),
141 [=](sycl::id<1> indx) { y[indx] = -x[indx]; });
142 });
143 SYCLQueue::SetEvent(streamID, e);
144}
145
146template <
147 typename ExecSpace, typename TData,
148 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
149 Enable = true>
150inline void sqrtKernel(const size_t nsize, const TData *x, TData *y,
151 const unsigned int streamID = 0)
152{
153 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
154 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
155
156 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
157 sycl::event e = Q.submit([=](sycl::handler &cgh) {
158 setSYCLDefaultExecutionDependency(streamID, cgh);
159 cgh.parallel_for(sycl::nd_range<1>(gridSize * blockSize, blockSize),
160 [=](sycl::nd_item<1> indx) SYCL_SUBGROUP_SIZE(
162 size_t idx0 = indx.get_global_id(0);
163 size_t stride = indx.get_global_range(0);
164
165 for (size_t idx = idx0; idx < nsize; idx += stride)
166 {
167 // sycl::sqrt selects the device overload
168 // (float/double)
169 y[idx] = sycl::sqrt(x[idx]);
170 }
171 });
172 });
173 SYCLQueue::SetEvent(streamID, e);
174}
175
176template <
177 typename ExecSpace, typename TData,
178 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
179 Enable = true>
180inline void addKernel(const size_t nsize, const TData *x, const TData *y,
181 TData *z, const unsigned int streamID = 0)
182{
183 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
184 sycl::event e = Q.submit([=](sycl::handler &cgh) {
185 setSYCLDefaultExecutionDependency(streamID, cgh);
186 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
187 z[indx] = x[indx] + y[indx];
188 });
189 });
190 SYCLQueue::SetEvent(streamID, e);
191}
192
193template <
194 typename ExecSpace, typename TData,
195 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
196 Enable = true>
197inline void addScalarKernel(const size_t nsize, const TData alpha,
198 const TData *x, TData *y,
199 const unsigned int streamID = 0)
200{
201 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
202 sycl::event e = Q.submit([=](sycl::handler &cgh) {
203 setSYCLDefaultExecutionDependency(streamID, cgh);
204 cgh.parallel_for(sycl::range<1>(nsize),
205 [=](sycl::id<1> indx) { y[indx] = x[indx] + alpha; });
206 });
207 SYCLQueue::SetEvent(streamID, e);
208}
209
210// addScalarKernel over the ncomp components of compSize values of a block,
211// stored as element groups of width lanes by ndata points of which the first
212// nelmt elements are not padding: y = x + alpha, and zero in the padding.
213template <
214 typename ExecSpace, typename TData,
215 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
216 Enable = true>
217inline void addScalarKernel(const unsigned int ncomp, const size_t compSize,
218 const size_t nelmt, const unsigned int ndata,
219 const unsigned int width, const TData alpha,
220 const TData *x, TData *y,
221 const unsigned int streamID = 0)
222{
223 const size_t prefix = (nelmt / width) * width * ndata;
224
225 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
226 sycl::event e = Q.submit([=](sycl::handler &cgh) {
227 setSYCLDefaultExecutionDependency(streamID, cgh);
228 cgh.parallel_for(
229 sycl::range<2>(ncomp, compSize), [=](sycl::id<2> indx) {
230 const size_t i = indx[1];
231 const size_t idx = indx[0] * compSize + i;
232 const bool padding =
233 i >= prefix &&
234 (i / (ndata * width)) * width + i % width >= nelmt;
235 y[idx] = padding ? TData(0) : x[idx] + alpha;
236 });
237 });
238 SYCLQueue::SetEvent(streamID, e);
239}
240
241template <
242 typename ExecSpace, typename TData,
243 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
244 Enable = true>
245inline void subKernel(const size_t nsize, const TData *x, const TData *y,
246 TData *z, const unsigned int streamID = 0)
247{
248 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
249 sycl::event e = Q.submit([=](sycl::handler &cgh) {
250 setSYCLDefaultExecutionDependency(streamID, cgh);
251 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
252 z[indx] = x[indx] - y[indx];
253 });
254 });
255 SYCLQueue::SetEvent(streamID, e);
256}
257
258template <
259 typename ExecSpace, typename TData,
260 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
261 Enable = true>
262inline void mulKernel(const size_t nsize, const TData alpha, const TData *x,
263 TData *y, const unsigned int streamID = 0)
264{
265 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
266 sycl::event e = Q.submit([=](sycl::handler &cgh) {
267 setSYCLDefaultExecutionDependency(streamID, cgh);
268 cgh.parallel_for(sycl::range<1>(nsize),
269 [=](sycl::id<1> indx) { y[indx] = alpha * x[indx]; });
270 });
271 SYCLQueue::SetEvent(streamID, e);
272}
273
274template <
275 typename ExecSpace, typename TData,
276 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
277 Enable = true>
278inline void mulKernel(const size_t nsize, const TData *x, const TData *y,
279 TData *z, const unsigned int streamID = 0)
280{
281 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
282 sycl::event e = Q.submit([=](sycl::handler &cgh) {
283 setSYCLDefaultExecutionDependency(streamID, cgh);
284 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
285 z[indx] = x[indx] * y[indx];
286 });
287 });
288 SYCLQueue::SetEvent(streamID, e);
289}
290
291template <
292 typename ExecSpace, typename TData,
293 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
294 Enable = true>
295inline void divKernel(const size_t nsize, const TData alpha, const TData *x,
296 TData *y, const unsigned int streamID = 0)
297{
298 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
299 sycl::event e = Q.submit([=](sycl::handler &cgh) {
300 setSYCLDefaultExecutionDependency(streamID, cgh);
301 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
302 y[indx] = (x[indx] == TData(0)) ? TData(0) : alpha / x[indx];
303 });
304 });
305 SYCLQueue::SetEvent(streamID, e);
306}
307
308template <
309 typename ExecSpace, typename TData,
310 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
311 Enable = true>
312inline void divKernel(const size_t nsize, const TData *x, const TData *y,
313 TData *z, const unsigned int streamID = 0)
314{
315 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
316 sycl::event e = Q.submit([=](sycl::handler &cgh) {
317 setSYCLDefaultExecutionDependency(streamID, cgh);
318 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
319 z[indx] = (y[indx] == TData(0)) ? TData(0) : x[indx] / y[indx];
320 });
321 });
322 SYCLQueue::SetEvent(streamID, e);
323}
324
325template <
326 typename ExecSpace, typename TData,
327 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
328 Enable = true>
329inline void daxpyKernel(const size_t nsize, const TData alpha, const TData *x,
330 const TData *y, TData *z,
331 const unsigned int streamID = 0)
332{
333 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
334 sycl::event e = Q.submit([=](sycl::handler &cgh) {
335 setSYCLDefaultExecutionDependency(streamID, cgh);
336 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
337 z[indx] = alpha * x[indx] + y[indx];
338 });
339 });
340 SYCLQueue::SetEvent(streamID, e);
341}
342
343template <
344 typename ExecSpace, typename TData,
345 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
346 Enable = true>
347inline void daxpbyKernel(const size_t nsize, const TData alpha, const TData *x,
348 const TData beta, const TData *y, TData *z,
349 const unsigned int streamID = 0)
350{
351 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
352 sycl::event e = Q.submit([=](sycl::handler &cgh) {
353 setSYCLDefaultExecutionDependency(streamID, cgh);
354 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
355 z[indx] = alpha * x[indx] + beta * y[indx];
356 });
357 });
358 SYCLQueue::SetEvent(streamID, e);
359}
360
361template <
362 typename ExecSpace, typename TData,
363 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
364 Enable = true>
365inline void daxpbypzKernel(const size_t nsize, const TData alpha,
366 const TData *x, const TData beta, const TData *y,
367 const TData *z, TData *w,
368 const unsigned int streamID = 0)
369{
370 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
371 sycl::event e = Q.submit([=](sycl::handler &cgh) {
372 setSYCLDefaultExecutionDependency(streamID, cgh);
373 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
374 w[indx] = alpha * x[indx] + beta * y[indx] + z[indx];
375 });
376 });
377 SYCLQueue::SetEvent(streamID, e);
378}
379
380template <
381 typename ExecSpace, typename TData,
382 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
383 Enable = true>
384inline void daxpbypczKernel(const size_t nsize, const TData alpha,
385 const TData *x, const TData beta, const TData *y,
386 const TData gamma, const TData *z, TData *w,
387 const unsigned int streamID = 0)
388{
389 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
390 sycl::event e = Q.submit([=](sycl::handler &cgh) {
391 setSYCLDefaultExecutionDependency(streamID, cgh);
392 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
393 w[indx] = alpha * x[indx] + beta * y[indx] + gamma * z[indx];
394 });
395 });
396 SYCLQueue::SetEvent(streamID, e);
397}
398
399// z = sum_j alpha_j x_j over the terms, plus z itself if APPEND, in one pass
400// over z.
401template <
402 typename ExecSpace, bool APPEND, typename TData,
403 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
404 Enable = true>
405inline void linearCombinationKernel(const size_t nsize,
406 const LinearCombinationTerms<TData> &terms,
407 TData *z, const unsigned int streamID = 0)
408{
409 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
410 sycl::event e = Q.submit([=](sycl::handler &cgh) {
411 setSYCLDefaultExecutionDependency(streamID, cgh);
412 cgh.parallel_for(sycl::range<1>(nsize), [=](sycl::id<1> indx) {
413 TData acc = APPEND ? z[indx] : TData(0);
414 for (unsigned int j = 0; j < terms.n; ++j)
415 {
416 acc += terms.alpha[j] * terms.x[j][indx];
417 }
418 z[indx] = acc;
419 });
420 });
421 SYCLQueue::SetEvent(streamID, e);
422}
423
424// Reductions of reduceKernel.
425enum class ReduceOp
426{
427 Sum,
428 Max,
429 Min,
430 AbsMax
431};
432
433// Identity of a reduction.
434template <ReduceOp op, typename TData> inline constexpr TData reduceIdentity()
435{
436 if constexpr (op == ReduceOp::Sum)
437 {
438 return 0;
439 }
440 else if constexpr (op == ReduceOp::Max)
441 {
442 return std::numeric_limits<TData>::lowest();
443 }
444 else if constexpr (op == ReduceOp::Min)
445 {
446 return std::numeric_limits<TData>::max();
447 }
448 else if constexpr (op == ReduceOp::AbsMax)
449 {
450 return 0;
451 }
452}
453
454// Sets *dest to val if init, and otherwise combines val into it by reduction
455// op. Set, it has a single writer. Combined into, it may be shared with the
456// reductions of other blocks of a Field on other queues, so takes one
457// device-scope atomic.
458template <bool init, ReduceOp op, typename TData>
459static inline void reduceStore(TData *const dest, const TData val)
460{
461 if constexpr (init)
462 {
463 *dest = val;
464 }
465 else if constexpr (op == ReduceOp::Sum)
466 {
467 atomic_add<NektarSpaces::GlobalScope>(dest, val);
468 }
469 else if constexpr (op == ReduceOp::Max || op == ReduceOp::AbsMax)
470 {
471 // An AbsMax partial result is not negative.
472 atomic_max<NektarSpaces::GlobalScope>(dest, val);
473 }
474 else if constexpr (op == ReduceOp::Min)
475 {
476 atomic_min<NektarSpaces::GlobalScope>(dest, val);
477 }
478}
479
480// Transforms of the entries reduceKernel reduces.
481template <typename TData> struct IdentityOp
482{
483 inline TData operator()(const TData x)
484 {
485 return x;
486 }
487};
488
489template <typename TData> struct AbsOp
490{
491 inline TData operator()(const TData x)
492 {
493 return sycl::fabs(x);
494 }
495};
496
497template <typename TData> struct SquareOp
498{
499 inline TData operator()(const TData x)
500 {
501 return x * x;
502 }
503};
504
505template <typename TData> struct MultiplyOp
506{
507 inline TData operator()(const TData x, const TData y)
508 {
509 return x * y;
510 }
511};
512
513// Transforms of the entries reduceNKernel reduces, writing value s of an entry
514// to vals[s].
515template <typename TData> struct IdentityEachOp
516{
517 template <typename... TIn>
518 inline void operator()(TData *vals, const TIn... x)
519 {
520 unsigned int s = 0;
521 ((vals[s++] = x), ...);
522 }
523};
524
525template <typename TData> struct MultiplyFirstOp
526{
527 template <typename... TIn>
528 inline void operator()(TData *vals, const TData x, const TIn... y)
529 {
530 unsigned int s = 0;
531 ((vals[s++] = x * y), ...);
532 }
533};
534
535// Combination of two values by a reduction.
536template <ReduceOp op, typename TData>
537static inline TData reduceJoin(const TData a, const TData b)
538{
539 if constexpr (op == ReduceOp::Sum)
540 {
541 return a + b;
542 }
543 else if constexpr (op == ReduceOp::Max)
544 {
545 return sycl::fmax(a, b);
546 }
547 else if constexpr (op == ReduceOp::Min)
548 {
549 return sycl::fmin(a, b);
550 }
551 else if constexpr (op == ReduceOp::AbsMax)
552 {
553 return sycl::fmax(sycl::fabs(a), sycl::fabs(b));
554 }
555}
556
557// Combination of v by reduction op with TransformOp<TData>() of each lane of
558// the vecLoad results xv.
559template <ReduceOp op, template <typename> typename TransformOp, typename TData,
560 typename... TVec>
561static inline TData vecReduceJoin(const TData v, const TVec... xv)
562{
563 if constexpr (std::is_same_v<TData, float>)
564 {
565 return reduceJoin<op>(
566 v, reduceJoin<op>(reduceJoin<op>(TransformOp<TData>()(xv[0]...),
567 TransformOp<TData>()(xv[1]...)),
568 reduceJoin<op>(TransformOp<TData>()(xv[2]...),
569 TransformOp<TData>()(xv[3]...))));
570 }
571 else if constexpr (std::is_same_v<TData, double>)
572 {
573 return reduceJoin<op>(v,
574 reduceJoin<op>(TransformOp<TData>()(xv[0]...),
575 TransformOp<TData>()(xv[1]...)));
576 }
577}
578
579// Combination of v[0, nred) by reduction op with the values
580// TransformOp<TData>()(vals, x...) writes to vals[0, nred).
581template <ReduceOp op, unsigned int nred,
582 template <typename> typename TransformOp, typename TData,
583 typename... TIn>
584static inline void reduceNJoin(TData *v, const TIn... x)
585{
586 TData vals[nred];
587 TransformOp<TData>()(vals, x...);
588 for (unsigned int s = 0; s < nred; ++s)
589 {
590 v[s] = reduceJoin<op>(v[s], vals[s]);
591 }
592}
593
594// As reduceNJoin, with each lane of the vecLoad results xv.
595template <ReduceOp op, unsigned int nred,
596 template <typename> typename TransformOp, typename TData,
597 typename... TVec>
598static inline void vecReduceNJoin(TData *v, const TVec... xv)
599{
600 if constexpr (std::is_same_v<TData, float>)
601 {
602 TData a[nred], b[nred], c[nred], d[nred];
603 TransformOp<TData>()(a, xv[0]...);
604 TransformOp<TData>()(b, xv[1]...);
605 TransformOp<TData>()(c, xv[2]...);
606 TransformOp<TData>()(d, xv[3]...);
607 for (unsigned int s = 0; s < nred; ++s)
608 {
609 v[s] = reduceJoin<op>(v[s],
610 reduceJoin<op>(reduceJoin<op>(a[s], b[s]),
611 reduceJoin<op>(c[s], d[s])));
612 }
613 }
614 else if constexpr (std::is_same_v<TData, double>)
615 {
616 TData a[nred], b[nred];
617 TransformOp<TData>()(a, xv[0]...);
618 TransformOp<TData>()(b, xv[1]...);
619 for (unsigned int s = 0; s < nred; ++s)
620 {
621 v[s] = reduceJoin<op>(v[s], reduceJoin<op>(a[s], b[s]));
622 }
623 }
624}
625
626// As vecReduceJoin, over the lanes the vecLoadMask result m selects.
627template <ReduceOp op, template <typename> typename TransformOp, typename TData,
628 typename... TVec>
629static inline TData vecReduceJoinMasked(const TData v, const VecMask<TData> m,
630 const TVec... xv)
631{
632 constexpr TData identity = reduceIdentity<op, TData>();
633
634 if constexpr (std::is_same_v<TData, float>)
635 {
636 return reduceJoin<op>(
637 v, reduceJoin<op>(
638 reduceJoin<op>(
639 m[0] ? TransformOp<TData>()(xv[0]...) : identity,
640 m[1] ? TransformOp<TData>()(xv[1]...) : identity),
641 reduceJoin<op>(
642 m[2] ? TransformOp<TData>()(xv[2]...) : identity,
643 m[3] ? TransformOp<TData>()(xv[3]...) : identity)));
644 }
645 else if constexpr (std::is_same_v<TData, double>)
646 {
647 return reduceJoin<op>(
648 v,
649 reduceJoin<op>(m[0] ? TransformOp<TData>()(xv[0]...) : identity,
650 m[1] ? TransformOp<TData>()(xv[1]...) : identity));
651 }
652}
653
654// TransformOp<TData>()(vals, x...) if m, otherwise the identity of op, in
655// vals[0, nred).
656template <ReduceOp op, unsigned int nred,
657 template <typename> typename TransformOp, typename TData,
658 typename... TIn>
659static inline void maskTransformN(TData *vals, const uint8_t m, const TIn... x)
660{
661 TransformOp<TData>()(vals, x...);
662 for (unsigned int s = 0; s < nred; ++s)
663 {
664 vals[s] = m ? vals[s] : reduceIdentity<op, TData>();
665 }
666}
667
668// As vecReduceNJoin, over the lanes the vecLoadMask result m selects.
669template <ReduceOp op, unsigned int nred,
670 template <typename> typename TransformOp, typename TData,
671 typename... TVec>
672static inline void vecReduceNJoinMasked(TData *v, const VecMask<TData> m,
673 const TVec... xv)
674{
675 if constexpr (std::is_same_v<TData, float>)
676 {
677 TData a[nred], b[nred], c[nred], d[nred];
678 maskTransformN<op, nred, TransformOp>(a, m[0], xv[0]...);
679 maskTransformN<op, nred, TransformOp>(b, m[1], xv[1]...);
680 maskTransformN<op, nred, TransformOp>(c, m[2], xv[2]...);
681 maskTransformN<op, nred, TransformOp>(d, m[3], xv[3]...);
682 for (unsigned int s = 0; s < nred; ++s)
683 {
684 v[s] = reduceJoin<op>(v[s],
685 reduceJoin<op>(reduceJoin<op>(a[s], b[s]),
686 reduceJoin<op>(c[s], d[s])));
687 }
688 }
689 else if constexpr (std::is_same_v<TData, double>)
690 {
691 TData a[nred], b[nred];
692 maskTransformN<op, nred, TransformOp>(a, m[0], xv[0]...);
693 maskTransformN<op, nred, TransformOp>(b, m[1], xv[1]...);
694 for (unsigned int s = 0; s < nred; ++s)
695 {
696 v[s] = reduceJoin<op>(v[s], reduceJoin<op>(a[s], b[s]));
697 }
698 }
699}
700
701// Partial result of reduction op over TransformOp<TData>()(x[i]...) per
702// work-group, in out[g] for work-group g, which it is set to if init and is
703// otherwise combined into.
704template <bool init, ReduceOp op, template <typename> typename TransformOp,
705 typename TData, typename... TIn>
706void reduceKernel(const unsigned int gridSize, const unsigned int blockSize,
707 const unsigned int streamID, const size_t nsize, TData *out,
708 const TIn *...x)
709{
710 static_assert((std::is_same_v<TIn, TData> && ...),
711 "reduceKernel: inputs of the output type.");
712
713 constexpr TData identity = reduceIdentity<op, TData>();
714 constexpr unsigned int vecSize =
715 std::is_same_v<TData, float> || std::is_same_v<TData, double>
716 ? (16u / sizeof(TData))
717 : 1u;
718
719 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
720 sycl::event e = Q.submit([=](sycl::handler &cgh) {
721 setSYCLDefaultExecutionDependency(streamID, cgh);
722 sycl::local_accessor<TData, 1> scratchpad(sycl::range<1>(blockSize),
723 cgh);
724 cgh.parallel_for(
725 sycl::nd_range<1>(gridSize * blockSize, blockSize),
726 [=](sycl::nd_item<1> indx) SYCL_SUBGROUP_SIZE(
728 auto scratch =
729 scratchpad
730 .template get_multi_ptr<sycl::access::decorated::yes>()
731 .get();
732 const size_t lid = indx.get_local_id(0);
733 const size_t gid = indx.get_global_id(0);
734
735 TData tmp = identity;
736 if constexpr (vecSize > 1u)
737 {
738 for (size_t tid = gid; tid < nsize / vecSize;
739 tid += indx.get_global_range(0))
740 {
741 tmp = vecReduceJoin<op, TransformOp>(
742 tmp, vecLoad(x, tid)...);
743 }
744 }
745 else
746 {
747 for (size_t tid = gid; tid < nsize;
748 tid += indx.get_global_range(0))
749 {
750 tmp = reduceJoin<op>(tmp,
751 TransformOp<TData>()(x[tid]...));
752 }
753 }
754
755 // process final elements (if there are any)
756 if (gid < nsize % vecSize)
757 {
758 const size_t tid = nsize - 1u - gid;
759 tmp = reduceJoin<op>(tmp, TransformOp<TData>()(x[tid]...));
760 }
761 scratch[lid] = tmp;
762
763 indx.barrier(sycl::access::fence_space::local_space);
764
765 unsigned int n = NektarSpaces::Device::maximumBlockSize / 2;
766 while (n > 0)
767 {
768 if (blockSize > n && lid < n && lid + n < blockSize)
769 {
770 scratch[lid] =
771 reduceJoin<op>(scratch[lid], scratch[lid + n]);
772 }
773 indx.barrier(sycl::access::fence_space::local_space);
774 n /= 2;
775 }
776
777 if (lid == 0)
778 {
779 reduceStore<init, op>(out + indx.get_group(0), scratch[0]);
780 }
781 });
782 });
783 SYCLQueue::SetEvent(streamID, e);
784}
785
786// As reduceKernel, over the entries mask selects.
787template <bool init, ReduceOp op, template <typename> typename TransformOp,
788 typename TData, typename... TIn>
789void reduceKernel(const unsigned int gridSize, const unsigned int blockSize,
790 const unsigned int streamID, const size_t nsize,
791 const uint8_t *mask, TData *out, const TIn *...x)
792{
793 static_assert((std::is_same_v<TIn, TData> && ...),
794 "reduceKernel: inputs of the output type.");
795
796 constexpr TData identity = reduceIdentity<op, TData>();
797 constexpr unsigned int vecSize =
798 std::is_same_v<TData, float> || std::is_same_v<TData, double>
799 ? (16u / sizeof(TData))
800 : 1u;
801
802 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
803 sycl::event e = Q.submit([=](sycl::handler &cgh) {
804 setSYCLDefaultExecutionDependency(streamID, cgh);
805 sycl::local_accessor<TData, 1> scratchpad(sycl::range<1>(blockSize),
806 cgh);
807 cgh.parallel_for(
808 sycl::nd_range<1>(gridSize * blockSize, blockSize),
809 [=](sycl::nd_item<1> indx) SYCL_SUBGROUP_SIZE(
811 auto scratch =
812 scratchpad
813 .template get_multi_ptr<sycl::access::decorated::yes>()
814 .get();
815 const size_t lid = indx.get_local_id(0);
816 const size_t gid = indx.get_global_id(0);
817
818 TData tmp = identity;
819 if constexpr (vecSize > 1u)
820 {
821 for (size_t tid = gid; tid < nsize / vecSize;
822 tid += indx.get_global_range(0))
823 {
824 tmp = vecReduceJoinMasked<op, TransformOp>(
825 tmp, vecLoadMask<TData>(mask, tid),
826 vecLoad(x, tid)...);
827 }
828 }
829 else
830 {
831 for (size_t tid = gid; tid < nsize;
832 tid += indx.get_global_range(0))
833 {
834 tmp = mask[tid]
835 ? reduceJoin<op>(
836 tmp, TransformOp<TData>()(x[tid]...))
837 : tmp;
838 }
839 }
840
841 // process final elements (if there are any)
842 if (gid < nsize % vecSize)
843 {
844 const size_t tid = nsize - 1u - gid;
845 tmp = mask[tid] ? reduceJoin<op>(
846 tmp, TransformOp<TData>()(x[tid]...))
847 : tmp;
848 }
849 scratch[lid] = tmp;
850
851 indx.barrier(sycl::access::fence_space::local_space);
852
853 unsigned int n = NektarSpaces::Device::maximumBlockSize / 2;
854 while (n > 0)
855 {
856 if (blockSize > n && lid < n && lid + n < blockSize)
857 {
858 scratch[lid] =
859 reduceJoin<op>(scratch[lid], scratch[lid + n]);
860 }
861 indx.barrier(sycl::access::fence_space::local_space);
862 n /= 2;
863 }
864
865 if (lid == 0)
866 {
867 reduceStore<init, op>(out + indx.get_group(0), scratch[0]);
868 }
869 });
870 });
871 SYCLQueue::SetEvent(streamID, e);
872}
873
874// Partial results of nred reductions op per work-group, of the values
875// TransformOp<TData>()(vals, x[i]...) writes to vals[0, nred) for each
876// entry i: result s of work-group g is in out[s * gridSize + g], which it is
877// set to if init and is otherwise combined into.
878template <bool init, ReduceOp op, unsigned int nred,
879 template <typename> typename TransformOp, typename TData,
880 typename... TIn>
881void reduceNKernel(const unsigned int gridSize, const unsigned int blockSize,
882 const unsigned int streamID, const size_t nsize, TData *out,
883 const TIn *...x)
884{
885 static_assert((std::is_same_v<TIn, TData> && ...),
886 "reduceNKernel: inputs of the output type.");
887
888 constexpr TData identity = reduceIdentity<op, TData>();
889 constexpr unsigned int vecSize =
890 std::is_same_v<TData, float> || std::is_same_v<TData, double>
891 ? (16u / sizeof(TData))
892 : 1u;
893
894 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
895 sycl::event e = Q.submit([=](sycl::handler &cgh) {
896 setSYCLDefaultExecutionDependency(streamID, cgh);
897 sycl::local_accessor<TData, 1> scratchpad(
898 sycl::range<1>(nred * blockSize), cgh);
899 cgh.parallel_for(
900 sycl::nd_range<1>(gridSize * blockSize, blockSize),
901 [=](sycl::nd_item<1> indx) SYCL_SUBGROUP_SIZE(
903 auto scratch =
904 scratchpad
905 .template get_multi_ptr<sycl::access::decorated::yes>()
906 .get();
907 const size_t lid = indx.get_local_id(0);
908 const size_t gid = indx.get_global_id(0);
909
910 TData tmp[nred];
911 for (unsigned int s = 0; s < nred; ++s)
912 {
913 tmp[s] = identity;
914 }
915
916 // Vector loads need every input 16-byte aligned, which the
917 // final stage's partial results past the first sum need not
918 // be.
919 size_t nvec = 0;
920 if constexpr (vecSize > 1u)
921 {
922 if (((reinterpret_cast<uintptr_t>(x) % 16u == 0u) && ...))
923 {
924 nvec = nsize / vecSize;
925 }
926
927 for (size_t tid = gid; tid < nvec;
928 tid += indx.get_global_range(0))
929 {
930 vecReduceNJoin<op, nred, TransformOp>(
931 tmp, vecLoad(x, tid)...);
932 }
933 }
934
935 // process the remaining entries
936 for (size_t tid = nvec * vecSize + gid; tid < nsize;
937 tid += indx.get_global_range(0))
938 {
939 reduceNJoin<op, nred, TransformOp>(tmp, x[tid]...);
940 }
941 for (unsigned int s = 0; s < nred; ++s)
942 {
943 scratch[s * blockSize + lid] = tmp[s];
944 }
945
946 indx.barrier(sycl::access::fence_space::local_space);
947
948 unsigned int n = NektarSpaces::Device::maximumBlockSize / 2;
949 while (n > 0)
950 {
951 if (blockSize > n && lid < n && lid + n < blockSize)
952 {
953 for (unsigned int s = 0; s < nred; ++s)
954 {
955 scratch[s * blockSize + lid] = reduceJoin<op>(
956 scratch[s * blockSize + lid],
957 scratch[s * blockSize + lid + n]);
958 }
959 }
960 indx.barrier(sycl::access::fence_space::local_space);
961 n /= 2;
962 }
963
964 if (lid == 0)
965 {
966 for (unsigned int s = 0; s < nred; ++s)
967 {
968 reduceStore<init, op>(out + s * gridSize +
969 indx.get_group(0),
970 scratch[s * blockSize]);
971 }
972 }
973 });
974 });
975 SYCLQueue::SetEvent(streamID, e);
976}
977
978// As reduceNKernel, over the entries mask selects.
979template <bool init, ReduceOp op, unsigned int nred,
980 template <typename> typename TransformOp, typename TData,
981 typename... TIn>
982void reduceNKernel(const unsigned int gridSize, const unsigned int blockSize,
983 const unsigned int streamID, const size_t nsize,
984 const uint8_t *mask, TData *out, const TIn *...x)
985{
986 static_assert((std::is_same_v<TIn, TData> && ...),
987 "reduceNKernel: inputs of the output type.");
988
989 constexpr TData identity = reduceIdentity<op, TData>();
990 constexpr unsigned int vecSize =
991 std::is_same_v<TData, float> || std::is_same_v<TData, double>
992 ? (16u / sizeof(TData))
993 : 1u;
994
995 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
996 sycl::event e = Q.submit([=](sycl::handler &cgh) {
997 setSYCLDefaultExecutionDependency(streamID, cgh);
998 sycl::local_accessor<TData, 1> scratchpad(
999 sycl::range<1>(nred * blockSize), cgh);
1000 cgh.parallel_for(
1001 sycl::nd_range<1>(gridSize * blockSize, blockSize),
1002 [=](sycl::nd_item<1> indx) SYCL_SUBGROUP_SIZE(
1004 auto scratch =
1005 scratchpad
1006 .template get_multi_ptr<sycl::access::decorated::yes>()
1007 .get();
1008 const size_t lid = indx.get_local_id(0);
1009 const size_t gid = indx.get_global_id(0);
1010
1011 TData tmp[nred];
1012 for (unsigned int s = 0; s < nred; ++s)
1013 {
1014 tmp[s] = identity;
1015 }
1016
1017 size_t nvec = 0;
1018 if constexpr (vecSize > 1u)
1019 {
1020 nvec = nsize / vecSize;
1021
1022 for (size_t tid = gid; tid < nvec;
1023 tid += indx.get_global_range(0))
1024 {
1025 vecReduceNJoinMasked<op, nred, TransformOp>(
1026 tmp, vecLoadMask<TData>(mask, tid),
1027 vecLoad(x, tid)...);
1028 }
1029 }
1030
1031 // process the remaining entries
1032 for (size_t tid = nvec * vecSize + gid; tid < nsize;
1033 tid += indx.get_global_range(0))
1034 {
1035 if (mask[tid])
1036 {
1037 reduceNJoin<op, nred, TransformOp>(tmp, x[tid]...);
1038 }
1039 }
1040 for (unsigned int s = 0; s < nred; ++s)
1041 {
1042 scratch[s * blockSize + lid] = tmp[s];
1043 }
1044
1045 indx.barrier(sycl::access::fence_space::local_space);
1046
1047 unsigned int n = NektarSpaces::Device::maximumBlockSize / 2;
1048 while (n > 0)
1049 {
1050 if (blockSize > n && lid < n && lid + n < blockSize)
1051 {
1052 for (unsigned int s = 0; s < nred; ++s)
1053 {
1054 scratch[s * blockSize + lid] = reduceJoin<op>(
1055 scratch[s * blockSize + lid],
1056 scratch[s * blockSize + lid + n]);
1057 }
1058 }
1059 indx.barrier(sycl::access::fence_space::local_space);
1060 n /= 2;
1061 }
1062
1063 if (lid == 0)
1064 {
1065 for (unsigned int s = 0; s < nred; ++s)
1066 {
1067 reduceStore<init, op>(out + s * gridSize +
1068 indx.get_group(0),
1069 scratch[s * blockSize]);
1070 }
1071 }
1072 });
1073 });
1074 SYCLQueue::SetEvent(streamID, e);
1075}
1076
1077template <
1078 typename ExecSpace, bool init, typename TData,
1079 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1080 Enable = true>
1081inline void reduceSumKernel(const size_t nsize, const TData *x, TData *out,
1082 const unsigned int streamID = 0)
1083{
1084#if defined(SYCL_ENABLE_CPU)
1085 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1086
1087 sycl::property_list initializer =
1088 init ? sycl::property_list{sycl::property::reduction::
1089 initialize_to_identity{}}
1090 : sycl::property_list{};
1091 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1092 setSYCLDefaultExecutionDependency(streamID, cgh);
1093 cgh.parallel_for(
1094 sycl::range<1>(nsize),
1095 sycl::reduction(out, sycl::plus<>(), initializer),
1096 [=](sycl::id<1> indx, auto &reducer) { reducer += x[indx]; });
1097 });
1098 SYCLQueue::SetEvent(streamID, e);
1099#else
1100 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1101 const unsigned int gridSize =
1103
1104 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1105 {
1106 deviceMalloc(&internalMemoryBufferMap[streamID],
1107 internalReductionBufferSize, streamID);
1108 }
1109
1110 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1111 reduceKernel<true, ReduceOp::Sum, IdentityOp>(gridSize, blockSize, streamID,
1112 nsize, buffer, x);
1113 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1114 gridSize, out, buffer);
1115#endif
1116}
1117
1118template <
1119 typename ExecSpace, bool init, typename TData,
1120 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1121 Enable = true>
1122inline void reduceSumKernel(const size_t nsize, const uint8_t *mask,
1123 const TData *x, TData *out,
1124 const unsigned int streamID = 0)
1125{
1126#if defined(SYCL_ENABLE_CPU)
1127 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1128
1129 sycl::property_list initializer =
1130 init ? sycl::property_list{sycl::property::reduction::
1131 initialize_to_identity{}}
1132 : sycl::property_list{};
1133 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1134 setSYCLDefaultExecutionDependency(streamID, cgh);
1135 cgh.parallel_for(sycl::range<1>(nsize),
1136 sycl::reduction(out, sycl::plus<>(), initializer),
1137 [=](sycl::id<1> indx, auto &reducer) {
1138 reducer += mask[indx] * x[indx];
1139 });
1140 });
1141 SYCLQueue::SetEvent(streamID, e);
1142#else
1143 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1144 const unsigned int gridSize =
1146
1147 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1148 {
1149 deviceMalloc(&internalMemoryBufferMap[streamID],
1150 internalReductionBufferSize, streamID);
1151 }
1152
1153 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1154 reduceKernel<true, ReduceOp::Sum, IdentityOp>(gridSize, blockSize, streamID,
1155 nsize, mask, buffer, x);
1156 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1157 gridSize, out, buffer);
1158#endif
1159}
1160
1161template <
1162 typename ExecSpace, bool init, typename TData,
1163 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1164 Enable = true>
1165inline void reduceMaxKernel(const size_t nsize, const TData *x, TData *out,
1166 const unsigned int streamID = 0)
1167{
1168#if defined(SYCL_ENABLE_CPU)
1169 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1170
1171 sycl::property_list initializer =
1172 init ? sycl::property_list{sycl::property::reduction::
1173 initialize_to_identity{}}
1174 : sycl::property_list{};
1175 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1176 setSYCLDefaultExecutionDependency(streamID, cgh);
1177 cgh.parallel_for(
1178 sycl::range<1>(nsize),
1179 sycl::reduction(out, sycl::maximum<>(), initializer),
1180 [=](sycl::id<1> indx, auto &reducer) { reducer.combine(x[indx]); });
1181 });
1182 SYCLQueue::SetEvent(streamID, e);
1183#else
1184 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1185 const unsigned int gridSize =
1187
1188 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1189 {
1190 deviceMalloc(&internalMemoryBufferMap[streamID],
1191 internalReductionBufferSize, streamID);
1192 }
1193
1194 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1195 reduceKernel<true, ReduceOp::Max, IdentityOp>(gridSize, blockSize, streamID,
1196 nsize, buffer, x);
1197 reduceKernel<init, ReduceOp::Max, IdentityOp>(1, gridSize, streamID,
1198 gridSize, out, buffer);
1199#endif
1200}
1201
1202template <
1203 typename ExecSpace, bool init, typename TData,
1204 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1205 Enable = true>
1206inline void reduceMaxKernel(const size_t nsize, const uint8_t *mask,
1207 const TData *x, TData *out,
1208 const unsigned int streamID = 0)
1209{
1210#if defined(SYCL_ENABLE_CPU)
1211 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1212
1213 sycl::property_list initializer =
1214 init ? sycl::property_list{sycl::property::reduction::
1215 initialize_to_identity{}}
1216 : sycl::property_list{};
1217 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1218 setSYCLDefaultExecutionDependency(streamID, cgh);
1219 cgh.parallel_for(sycl::range<1>(nsize),
1220 sycl::reduction(out, sycl::maximum<>(), initializer),
1221 [=](sycl::id<1> indx, auto &reducer) {
1222 if (mask[indx])
1223 {
1224 reducer.combine(x[indx]);
1225 }
1226 });
1227 });
1228 SYCLQueue::SetEvent(streamID, e);
1229#else
1230 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1231 const unsigned int gridSize =
1233
1234 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1235 {
1236 deviceMalloc(&internalMemoryBufferMap[streamID],
1237 internalReductionBufferSize, streamID);
1238 }
1239
1240 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1241 reduceKernel<true, ReduceOp::Max, IdentityOp>(gridSize, blockSize, streamID,
1242 nsize, mask, buffer, x);
1243 reduceKernel<init, ReduceOp::Max, IdentityOp>(1, gridSize, streamID,
1244 gridSize, out, buffer);
1245#endif
1246}
1247
1248template <
1249 typename ExecSpace, bool init, typename TData,
1250 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1251 Enable = true>
1252inline void reduceMinKernel(const size_t nsize, const TData *x, TData *out,
1253 const unsigned int streamID = 0)
1254{
1255#if defined(SYCL_ENABLE_CPU)
1256 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1257
1258 sycl::property_list initializer =
1259 init ? sycl::property_list{sycl::property::reduction::
1260 initialize_to_identity{}}
1261 : sycl::property_list{};
1262 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1263 setSYCLDefaultExecutionDependency(streamID, cgh);
1264 cgh.parallel_for(
1265 sycl::range<1>(nsize),
1266 sycl::reduction(out, sycl::minimum<>(), initializer),
1267 [=](sycl::id<1> indx, auto &reducer) { reducer.combine(x[indx]); });
1268 });
1269 SYCLQueue::SetEvent(streamID, e);
1270#else
1271 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1272 const unsigned int gridSize =
1274
1275 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1276 {
1277 deviceMalloc(&internalMemoryBufferMap[streamID],
1278 internalReductionBufferSize, streamID);
1279 }
1280
1281 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1282 reduceKernel<true, ReduceOp::Min, IdentityOp>(gridSize, blockSize, streamID,
1283 nsize, buffer, x);
1284 reduceKernel<init, ReduceOp::Min, IdentityOp>(1, gridSize, streamID,
1285 gridSize, out, buffer);
1286#endif
1287}
1288
1289template <
1290 typename ExecSpace, bool init, typename TData,
1291 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1292 Enable = true>
1293inline void reduceMinKernel(const size_t nsize, const uint8_t *mask,
1294 const TData *x, TData *out,
1295 const unsigned int streamID = 0)
1296{
1297#if defined(SYCL_ENABLE_CPU)
1298 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1299
1300 sycl::property_list initializer =
1301 init ? sycl::property_list{sycl::property::reduction::
1302 initialize_to_identity{}}
1303 : sycl::property_list{};
1304 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1305 setSYCLDefaultExecutionDependency(streamID, cgh);
1306 cgh.parallel_for(sycl::range<1>(nsize),
1307 sycl::reduction(out, sycl::minimum<>(), initializer),
1308 [=](sycl::id<1> indx, auto &reducer) {
1309 if (mask[indx])
1310 {
1311 reducer.combine(x[indx]);
1312 }
1313 });
1314 });
1315 SYCLQueue::SetEvent(streamID, e);
1316#else
1317 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1318 const unsigned int gridSize =
1320
1321 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1322 {
1323 deviceMalloc(&internalMemoryBufferMap[streamID],
1324 internalReductionBufferSize, streamID);
1325 }
1326
1327 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1328 reduceKernel<true, ReduceOp::Min, IdentityOp>(gridSize, blockSize, streamID,
1329 nsize, mask, buffer, x);
1330 reduceKernel<init, ReduceOp::Min, IdentityOp>(1, gridSize, streamID,
1331 gridSize, out, buffer);
1332#endif
1333}
1334
1335template <
1336 typename ExecSpace, bool init, typename TData,
1337 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1338 Enable = true>
1339inline void ddotKernel(const size_t nsize, const TData *x, const TData *y,
1340 TData *out, const unsigned int streamID = 0)
1341{
1342#if defined(SYCL_ENABLE_CPU)
1343 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1344
1345 sycl::property_list initializer =
1346 init ? sycl::property_list{sycl::property::reduction::
1347 initialize_to_identity{}}
1348 : sycl::property_list{};
1349 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1350 setSYCLDefaultExecutionDependency(streamID, cgh);
1351 cgh.parallel_for(sycl::range<1>(nsize),
1352 sycl::reduction(out, sycl::plus<>(), initializer),
1353 [=](sycl::id<1> indx, auto &reducer) {
1354 reducer += x[indx] * y[indx];
1355 });
1356 });
1357 SYCLQueue::SetEvent(streamID, e);
1358#else
1359 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1360 const unsigned int gridSize =
1362
1363 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1364 {
1365 deviceMalloc(&internalMemoryBufferMap[streamID],
1366 internalReductionBufferSize, streamID);
1367 }
1368
1369 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1370 reduceKernel<true, ReduceOp::Sum, MultiplyOp>(gridSize, blockSize, streamID,
1371 nsize, buffer, x, y);
1372 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1373 gridSize, out, buffer);
1374#endif
1375}
1376
1377template <
1378 typename ExecSpace, bool init, typename TData,
1379 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1380 Enable = true>
1381inline void ddotKernel(const size_t nsize, const uint8_t *mask, const TData *x,
1382 const TData *y, TData *out,
1383 const unsigned int streamID = 0)
1384{
1385#if defined(SYCL_ENABLE_CPU)
1386 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1387
1388 sycl::property_list initializer =
1389 init ? sycl::property_list{sycl::property::reduction::
1390 initialize_to_identity{}}
1391 : sycl::property_list{};
1392 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1393 setSYCLDefaultExecutionDependency(streamID, cgh);
1394 cgh.parallel_for(sycl::range<1>(nsize),
1395 sycl::reduction(out, sycl::plus<>(), initializer),
1396 [=](sycl::id<1> indx, auto &reducer) {
1397 reducer += mask[indx] * x[indx] * y[indx];
1398 });
1399 });
1400 SYCLQueue::SetEvent(streamID, e);
1401#else
1402 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1403 const unsigned int gridSize =
1405
1406 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1407 {
1408 deviceMalloc(&internalMemoryBufferMap[streamID],
1409 internalReductionBufferSize, streamID);
1410 }
1411
1412 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1413 reduceKernel<true, ReduceOp::Sum, MultiplyOp>(gridSize, blockSize, streamID,
1414 nsize, mask, buffer, x, y);
1415 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1416 gridSize, out, buffer);
1417#endif
1418}
1419
1420// ddot2Kernel computes, in one pass over x, out[0] (+)= (x, y) and out[1] (+)=
1421// (x, z): two dot products sharing x, over the entries mask selects unless it
1422// is null.
1423template <
1424 typename ExecSpace, bool init, typename TData,
1425 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1426 Enable = true>
1427inline void ddot2Kernel(const size_t nsize, const uint8_t *mask, const TData *x,
1428 const TData *y, const TData *z, TData *out,
1429 const unsigned int streamID = 0)
1430{
1431#if defined(SYCL_ENABLE_CPU)
1432 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1433
1434 sycl::property_list initializer =
1435 init ? sycl::property_list{sycl::property::reduction::
1436 initialize_to_identity{}}
1437 : sycl::property_list{};
1438 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1439 setSYCLDefaultExecutionDependency(streamID, cgh);
1440 cgh.parallel_for(sycl::range<1>(nsize),
1441 sycl::reduction(out, sycl::plus<>(), initializer),
1442 sycl::reduction(out + 1, sycl::plus<>(), initializer),
1443 [=](sycl::id<1> indx, auto &xy, auto &xz) {
1444 const TData xi =
1445 mask ? mask[indx] * x[indx] : x[indx];
1446 xy += xi * y[indx];
1447 xz += xi * z[indx];
1448 });
1449 });
1450 SYCLQueue::SetEvent(streamID, e);
1451#else
1452 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1453 const unsigned int gridSize =
1455
1456 // Two partial sums per work-group, which internalReductionBufferSize
1457 // holds.
1458 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1459 {
1460 deviceMalloc(&internalMemoryBufferMap[streamID],
1461 internalReductionBufferSize, streamID);
1462 }
1463
1464 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1465 if (mask)
1466 {
1467 reduceNKernel<true, ReduceOp::Sum, 2, MultiplyFirstOp>(
1468 gridSize, blockSize, streamID, nsize, mask, buffer, x, y, z);
1469 }
1470 else
1471 {
1472 reduceNKernel<true, ReduceOp::Sum, 2, MultiplyFirstOp>(
1473 gridSize, blockSize, streamID, nsize, buffer, x, y, z);
1474 }
1475 reduceNKernel<init, ReduceOp::Sum, 2, IdentityEachOp>(
1476 1, blockSize, streamID, gridSize, out, buffer, buffer + gridSize);
1477#endif
1478}
1479
1480template <
1481 typename ExecSpace, bool init, typename TData,
1482 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1483 Enable = true>
1484inline void l1normKernel(const size_t nsize, const TData *x, TData *out,
1485 const unsigned int streamID = 0)
1486{
1487#if defined(SYCL_ENABLE_CPU)
1488 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1489
1490 sycl::property_list initializer =
1491 init ? sycl::property_list{sycl::property::reduction::
1492 initialize_to_identity{}}
1493 : sycl::property_list{};
1494 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1495 setSYCLDefaultExecutionDependency(streamID, cgh);
1496 cgh.parallel_for(sycl::range<1>(nsize),
1497 sycl::reduction(out, sycl::plus<>(), initializer),
1498 [=](sycl::id<1> indx, auto &reducer) {
1499 reducer += sycl::fabs(x[indx]);
1500 });
1501 });
1502 SYCLQueue::SetEvent(streamID, e);
1503#else
1504 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1505 const unsigned int gridSize =
1507
1508 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1509 {
1510 deviceMalloc(&internalMemoryBufferMap[streamID],
1511 internalReductionBufferSize, streamID);
1512 }
1513
1514 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1515 reduceKernel<true, ReduceOp::Sum, AbsOp>(gridSize, blockSize, streamID,
1516 nsize, buffer, x);
1517 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1518 gridSize, out, buffer);
1519#endif
1520}
1521
1522template <
1523 typename ExecSpace, bool init, typename TData,
1524 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1525 Enable = true>
1526inline void l1normKernel(const size_t nsize, const uint8_t *mask,
1527 const TData *x, TData *out,
1528 const unsigned int streamID = 0)
1529{
1530#if defined(SYCL_ENABLE_CPU)
1531 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1532
1533 sycl::property_list initializer =
1534 init ? sycl::property_list{sycl::property::reduction::
1535 initialize_to_identity{}}
1536 : sycl::property_list{};
1537 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1538 setSYCLDefaultExecutionDependency(streamID, cgh);
1539 cgh.parallel_for(sycl::range<1>(nsize),
1540 sycl::reduction(out, sycl::plus<>(), initializer),
1541 [=](sycl::id<1> indx, auto &reducer) {
1542 reducer += mask[indx] * sycl::fabs(x[indx]);
1543 });
1544 });
1545 SYCLQueue::SetEvent(streamID, e);
1546#else
1547 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1548 const unsigned int gridSize =
1550
1551 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1552 {
1553 deviceMalloc(&internalMemoryBufferMap[streamID],
1554 internalReductionBufferSize, streamID);
1555 }
1556
1557 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1558 reduceKernel<true, ReduceOp::Sum, AbsOp>(gridSize, blockSize, streamID,
1559 nsize, mask, buffer, x);
1560 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1561 gridSize, out, buffer);
1562#endif
1563}
1564
1565template <
1566 typename ExecSpace, bool init, typename TData,
1567 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1568 Enable = true>
1569inline void l2normKernel(const size_t nsize, const TData *x, TData *out,
1570 const unsigned int streamID = 0)
1571{
1572#if defined(SYCL_ENABLE_CPU)
1573 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1574
1575 sycl::property_list initializer =
1576 init ? sycl::property_list{sycl::property::reduction::
1577 initialize_to_identity{}}
1578 : sycl::property_list{};
1579 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1580 setSYCLDefaultExecutionDependency(streamID, cgh);
1581 cgh.parallel_for(sycl::range<1>(nsize),
1582 sycl::reduction(out, sycl::plus<>(), initializer),
1583 [=](sycl::id<1> indx, auto &reducer) {
1584 reducer += x[indx] * x[indx];
1585 });
1586 });
1587 SYCLQueue::SetEvent(streamID, e);
1588#else
1589 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1590 const unsigned int gridSize =
1592
1593 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1594 {
1595 deviceMalloc(&internalMemoryBufferMap[streamID],
1596 internalReductionBufferSize, streamID);
1597 }
1598
1599 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1600 reduceKernel<true, ReduceOp::Sum, SquareOp>(gridSize, blockSize, streamID,
1601 nsize, buffer, x);
1602 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1603 gridSize, out, buffer);
1604#endif
1605}
1606
1607template <
1608 typename ExecSpace, bool init, typename TData,
1609 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1610 Enable = true>
1611inline void l2normKernel(const size_t nsize, const uint8_t *mask,
1612 const TData *x, TData *out,
1613 const unsigned int streamID = 0)
1614{
1615#if defined(SYCL_ENABLE_CPU)
1616 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1617
1618 sycl::property_list initializer =
1619 init ? sycl::property_list{sycl::property::reduction::
1620 initialize_to_identity{}}
1621 : sycl::property_list{};
1622 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1623 setSYCLDefaultExecutionDependency(streamID, cgh);
1624 cgh.parallel_for(sycl::range<1>(nsize),
1625 sycl::reduction(out, sycl::plus<>(), initializer),
1626 [=](sycl::id<1> indx, auto &reducer) {
1627 reducer += mask[indx] * x[indx] * x[indx];
1628 });
1629 });
1630 SYCLQueue::SetEvent(streamID, e);
1631#else
1632 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1633 const unsigned int gridSize =
1635
1636 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1637 {
1638 deviceMalloc(&internalMemoryBufferMap[streamID],
1639 internalReductionBufferSize, streamID);
1640 }
1641
1642 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1643 reduceKernel<true, ReduceOp::Sum, SquareOp>(gridSize, blockSize, streamID,
1644 nsize, mask, buffer, x);
1645 reduceKernel<init, ReduceOp::Sum, IdentityOp>(1, gridSize, streamID,
1646 gridSize, out, buffer);
1647#endif
1648}
1649
1650template <
1651 typename ExecSpace, bool init, typename TData,
1652 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1653 Enable = true>
1654inline void linfnormKernel(const size_t nsize, const TData *x, TData *out,
1655 const unsigned int streamID = 0)
1656{
1657#if defined(SYCL_ENABLE_CPU)
1658 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1659
1660 sycl::property_list initializer =
1661 init ? sycl::property_list{sycl::property::reduction::
1662 initialize_to_identity{}}
1663 : sycl::property_list{};
1664 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1665 setSYCLDefaultExecutionDependency(streamID, cgh);
1666 cgh.parallel_for(sycl::range<1>(nsize),
1667 sycl::reduction(out, sycl::maximum<>(), initializer),
1668 [=](sycl::id<1> indx, auto &reducer) {
1669 reducer.combine(sycl::fabs(x[indx]));
1670 });
1671 });
1672 SYCLQueue::SetEvent(streamID, e);
1673#else
1674 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1675 const unsigned int gridSize =
1677
1678 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1679 {
1680 deviceMalloc(&internalMemoryBufferMap[streamID],
1681 internalReductionBufferSize, streamID);
1682 }
1683
1684 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1685 reduceKernel<true, ReduceOp::AbsMax, IdentityOp>(
1686 gridSize, blockSize, streamID, nsize, buffer, x);
1687 reduceKernel<init, ReduceOp::AbsMax, IdentityOp>(1, gridSize, streamID,
1688 gridSize, out, buffer);
1689#endif
1690}
1691
1692template <
1693 typename ExecSpace, bool init, typename TData,
1694 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1695 Enable = true>
1696inline void linfnormKernel(const size_t nsize, const uint8_t *mask,
1697 const TData *x, TData *out,
1698 const unsigned int streamID = 0)
1699{
1700#if defined(SYCL_ENABLE_CPU)
1701 sycl::queue &Q = SYCLQueue::GetInstance(streamID);
1702
1703 sycl::property_list initializer =
1704 init ? sycl::property_list{sycl::property::reduction::
1705 initialize_to_identity{}}
1706 : sycl::property_list{};
1707 sycl::event e = Q.submit([=](sycl::handler &cgh) {
1708 setSYCLDefaultExecutionDependency(streamID, cgh);
1709 cgh.parallel_for(sycl::range<1>(nsize),
1710 sycl::reduction(out, sycl::maximum<>(), initializer),
1711 [=](sycl::id<1> indx, auto &reducer) {
1712 if (mask[indx])
1713 {
1714 reducer.combine(sycl::fabs(x[indx]));
1715 }
1716 });
1717 });
1718 SYCLQueue::SetEvent(streamID, e);
1719#else
1720 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1721 const unsigned int gridSize =
1723
1724 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1725 {
1726 deviceMalloc(&internalMemoryBufferMap[streamID],
1727 internalReductionBufferSize, streamID);
1728 }
1729
1730 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1731 reduceKernel<true, ReduceOp::AbsMax, IdentityOp>(
1732 gridSize, blockSize, streamID, nsize, mask, buffer, x);
1733 reduceKernel<init, ReduceOp::AbsMax, IdentityOp>(1, gridSize, streamID,
1734 gridSize, out, buffer);
1735#endif
1736}
1737
1738} // namespace Nektar::Math
1739
1740#endif
#define SYCL_SUBGROUP_SIZE(x)
Definition Backends.hpp:170
static cgsize_t gid(int i, int j, int k)
static sycl::queue & GetInstance(unsigned int id)
Definition SYCLQueue.hpp:55
static void SetEvent(unsigned int id, sycl::event &e)
array buffer
Definition GsLib.hpp:81
@ beta
Gauss Radau pinned at x=-1,.
Definition PointsType.h:59
void l1normKernel(const size_t nsize, const TData *x, TData *out, const unsigned int streamID=0)
void absKernel(const size_t nsize, const TData *x, TData *y, const unsigned int streamID=0)
void ddot2Kernel(const size_t nsize, const uint8_t *mask, const TData *x, const TData *y, const TData *z, TData *out, const unsigned int streamID=0)
void negKernel(const size_t nsize, const TData *x, TData *y, const unsigned int streamID=0)
void copyKernel(const size_t nsize, const TData *x, TData *y, const unsigned int streamID=0)
void daxpbypzKernel(const size_t nsize, const TData alpha, const TData *x, const TData beta, const TData *y, const TData *z, TData *w, const unsigned int streamID=0)
void daxpbyKernel(const size_t nsize, const TData alpha, const TData *x, const TData beta, const TData *y, TData *z, const unsigned int streamID=0)
void addKernel(const size_t nsize, const TData *x, const TData *y, TData *z, const unsigned int streamID=0)
void reduceMinKernel(const size_t nsize, const TData *x, TData *out, const unsigned int streamID=0)
void divKernel(const size_t nsize, const TData alpha, const TData *x, TData *y, const unsigned int streamID=0)
void zeroKernel(const size_t nsize, TData *x, const unsigned int streamID=0)
void daxpyKernel(const size_t nsize, const TData alpha, const TData *x, const TData *y, TData *z, const unsigned int streamID=0)
void addScalarKernel(const size_t nsize, const TData alpha, const TData *x, TData *y, const unsigned int streamID=0)
void daxpbypczKernel(const size_t nsize, const TData alpha, const TData *x, const TData beta, const TData *y, const TData gamma, const TData *z, TData *w, const unsigned int streamID=0)
void sqrtKernel(const size_t nsize, const TData *x, TData *y, const unsigned int streamID=0)
void subKernel(const size_t nsize, const TData *x, const TData *y, TData *z, const unsigned int streamID=0)
void reduceMaxKernel(const size_t nsize, const TData *x, TData *out, const unsigned int streamID=0)
void ddotKernel(const size_t nsize, const TData *x, const TData *y, TData *out, const unsigned int streamID=0)
void reduceSumKernel(const size_t nsize, const TData *x, TData *out, const unsigned int streamID=0)
void linfnormKernel(const size_t nsize, const TData *x, TData *out, const unsigned int streamID=0)
void fillKernel(const size_t nsize, const TData &val, TData *x, const unsigned int streamID=0)
void linearCombinationKernel(const size_t nsize, const LinearCombinationTerms< TData > &terms, TData *z, const unsigned int streamID=0)
void l2normKernel(const size_t nsize, const TData *x, TData *out, const unsigned int streamID=0)
void mulKernel(const size_t nsize, const TData alpha, const TData *x, TData *y, const unsigned int streamID=0)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt
std::vector< double > d(NPUPPER *NPUPPER)
void deviceMemset(TData *dst, const int val, const size_t size, const unsigned int streamID)
void deviceMalloc(TData **src, const size_t size, const unsigned int streamID, const MemAllocType memAllocType=eHostPageable)
void deviceFill(TData *dst, const TData val, const size_t size, const unsigned int streamID)
static constexpr unsigned int defaultBlockSize
Definition Backends.hpp:141
static constexpr unsigned int reductionBlockSize()
Definition Backends.hpp:147
static constexpr unsigned int maximumBlockSize
Definition Backends.hpp:142
static constexpr unsigned int warpSize
Definition Backends.hpp:143
static constexpr unsigned int reductionGridSize(const size_t n)
Definition Backends.hpp:156