Nektar++
Loading...
Searching...
No Matches
MathHIPCUDAKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MathHIPCUDAKernels.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_CUDA) && defined(DEVICE_COMPILE_ONLY)) || \
38 (defined(NEKTAR_ENABLE_HIP) && defined(DEVICE_COMPILE_ONLY))
39
42
43namespace Nektar::Math
44{
45
46// The vecSize entries of x from vecSize * tid in one load, for float or
47// double.
48template <typename TData>
49NEK_DEVICE_INLINE static auto vecLoad(const TData *x, const size_t tid)
50{
51 if constexpr (std::is_same_v<TData, float>)
52 {
53 return reinterpret_cast<const float4 *>(x)[tid];
54 }
55 else if constexpr (std::is_same_v<TData, double>)
56 {
57 return reinterpret_cast<const double2 *>(x)[tid];
58 }
59}
60
61// The vecSize mask entries matching a vecLoad of TData.
62template <typename TData>
63using VecMask =
64 std::conditional_t<std::is_same_v<TData, float>, uchar4, uchar2>;
65
66// The vecSize entries of mask matching vecLoad of TData at tid, in one load.
67template <typename TData>
68NEK_DEVICE_INLINE static VecMask<TData> vecLoadMask(const uint8_t *mask,
69 const size_t tid)
70{
71 return reinterpret_cast<const VecMask<TData> *>(mask)[tid];
72}
73
74__device__ inline float4 &operator+=(float4 &a, const float4 b)
75{
76 a.x += b.x;
77 a.y += b.y;
78 a.z += b.z;
79 a.w += b.w;
80 return a;
81}
82
83__device__ inline double2 &operator+=(double2 &a, const double2 b)
84{
85 a.x += b.x;
86 a.y += b.y;
87 return a;
88}
89
90__device__ inline float4 &operator+=(float4 &a, const float b)
91{
92 a.x += b;
93 a.y += b;
94 a.z += b;
95 a.w += b;
96 return a;
97}
98
99__device__ inline double2 &operator+=(double2 &a, const double b)
100{
101 a.x += b;
102 a.y += b;
103 return a;
104}
105
106__device__ inline float4 &operator-=(float4 &a, const float4 b)
107{
108 a.x -= b.x;
109 a.y -= b.y;
110 a.z -= b.z;
111 a.w -= b.w;
112 return a;
113}
114
115__device__ inline double2 &operator-=(double2 &a, const double2 b)
116{
117 a.x -= b.x;
118 a.y -= b.y;
119 return a;
120}
121
122__device__ inline float4 &operator-=(float4 &a, const float b)
123{
124 a.x -= b;
125 a.y -= b;
126 a.z -= b;
127 a.w -= b;
128 return a;
129}
130
131__device__ inline double2 &operator-=(double2 &a, const double b)
132{
133 a.x -= b;
134 a.y -= b;
135 return a;
136}
137
138__device__ inline float4 &operator*=(float4 &a, const float4 b)
139{
140 a.x *= b.x;
141 a.y *= b.y;
142 a.z *= b.z;
143 a.w *= b.w;
144 return a;
145}
146
147__device__ inline double2 &operator*=(double2 &a, const double2 b)
148{
149 a.x *= b.x;
150 a.y *= b.y;
151 return a;
152}
153
154__device__ inline float4 &operator*=(float4 &a, const float b)
155{
156 a.x *= b;
157 a.y *= b;
158 a.z *= b;
159 a.w *= b;
160 return a;
161}
162
163__device__ inline double2 &operator*=(double2 &a, const double b)
164{
165 a.x *= b;
166 a.y *= b;
167 return a;
168}
169
170__device__ inline float4 operator*(const float4 &a, const float4 &b)
171{
172 return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
173}
174
175__device__ inline double2 operator*(const double2 &a, const double2 &b)
176{
177 return make_double2(a.x * b.x, a.y * b.y);
178}
179
180__device__ inline float4 operator*(const float &a, const float4 &b)
181{
182 return make_float4(a * b.x, a * b.y, a * b.z, a * b.w);
183}
184
185__device__ inline double2 operator*(const double &a, const double2 &b)
186{
187 return make_double2(a * b.x, a * b.y);
188}
189
190__device__ inline float4 operator+(const float4 &a, const float4 &b)
191{
192 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
193}
194
195__device__ inline double2 operator+(const double2 &a, const double2 &b)
196{
197 return make_double2(a.x + b.x, a.y + b.y);
198}
199
200__device__ inline float4 operator+(const float4 &a, const float &b)
201{
202 return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
203}
204
205__device__ inline double2 operator+(const double2 &a, const double &b)
206{
207 return make_double2(a.x + b, a.y + b);
208}
209
210template <typename TData,
211 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
212__global__ __launch_bounds__(blockSize) void absKernel(const size_t nsize,
213 const TData *x, TData *y)
214{
215 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
216 const size_t stride = blockDim.x * gridDim.x;
217
218 for (size_t idx = idx0; idx < nsize; idx += stride)
219 {
220 y[idx] = std::abs(x[idx]);
221 }
222}
223
224template <typename TData,
225 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
226__global__ __launch_bounds__(blockSize) void negKernel(const size_t nsize,
227 const TData *x, TData *y)
228{
229 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
230 const size_t stride = blockDim.x * gridDim.x;
231
232 for (size_t idx = idx0; idx < nsize; idx += stride)
233 {
234 y[idx] = -x[idx];
235 }
236}
237
238template <typename TData,
239 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
240__global__ __launch_bounds__(blockSize) void sqrtKernel(const size_t nsize,
241 const TData *x,
242 TData *y)
243{
244 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
245 const size_t stride = blockDim.x * gridDim.x;
246
247 for (size_t idx = idx0; idx < nsize; idx += stride)
248 {
249 y[idx] = std::sqrt(x[idx]);
250 }
251}
252
253template <typename TData,
254 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
255__global__ __launch_bounds__(blockSize) void addKernel(const size_t nsize,
256 const TData *x,
257 const TData *y, TData *z)
258{
259 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
260 const size_t stride = blockDim.x * gridDim.x;
261
262 for (size_t idx = idx0; idx < nsize; idx += stride)
263 {
264 z[idx] = x[idx] + y[idx];
265 }
266}
267
268template <typename TData,
269 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
270__global__ __launch_bounds__(blockSize) void addScalarKernel(const size_t nsize,
271 const TData alpha,
272 const TData *x,
273 TData *y)
274{
275 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
276 const size_t stride = blockDim.x * gridDim.x;
277
278 for (size_t idx = idx0; idx < nsize; idx += stride)
279 {
280 y[idx] = x[idx] + alpha;
281 }
282}
283
284template <typename TData,
285 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
286__global__ __launch_bounds__(blockSize) void addScalarKernel(
287 const size_t compSize, const size_t prefix, const size_t nelmt,
288 const unsigned int ndata, const unsigned int width, const TData alpha,
289 const TData *x, TData *y)
290{
291 // One component per row of the grid.
292 const size_t offset = blockIdx.y * compSize;
293 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
294 const size_t stride = blockDim.x * gridDim.x;
295
296 for (size_t i = idx0; i < compSize; i += stride)
297 {
298 const bool padding =
299 i >= prefix && (i / (ndata * width)) * width + i % width >= nelmt;
300 y[offset + i] = padding ? TData(0) : x[offset + i] + alpha;
301 }
302}
303
304template <typename TData,
305 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
306__global__ __launch_bounds__(blockSize) void subKernel(const size_t nsize,
307 const TData *x,
308 const TData *y, TData *z)
309{
310 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
311 const size_t stride = blockDim.x * gridDim.x;
312
313 for (size_t idx = idx0; idx < nsize; idx += stride)
314 {
315 z[idx] = x[idx] - y[idx];
316 }
317}
318
319template <typename TData,
320 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
321__global__ __launch_bounds__(blockSize) void mulKernel(const size_t nsize,
322 const TData alpha,
323 const TData *x, TData *y)
324{
325 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
326 const size_t stride = blockDim.x * gridDim.x;
327
328 for (size_t idx = idx0; idx < nsize; idx += stride)
329 {
330 y[idx] = alpha * x[idx];
331 }
332}
333
334template <typename TData,
335 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
336__global__ __launch_bounds__(blockSize) void mulKernel(const size_t nsize,
337 const TData *x,
338 const TData *y, TData *z)
339{
340 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
341 const size_t stride = blockDim.x * gridDim.x;
342
343 for (size_t idx = idx0; idx < nsize; idx += stride)
344 {
345 z[idx] = x[idx] * y[idx];
346 }
347}
348
349template <typename TData,
350 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
351__global__ __launch_bounds__(blockSize) void divKernel(const size_t nsize,
352 const TData alpha,
353 const TData *x, TData *y)
354{
355 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
356 const size_t stride = blockDim.x * gridDim.x;
357
358 for (size_t idx = idx0; idx < nsize; idx += stride)
359 {
360 y[idx] = (x[idx] == TData(0)) ? TData(0) : alpha / x[idx];
361 }
362}
363
364template <typename TData,
365 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
366__global__ __launch_bounds__(blockSize) void divKernel(const size_t nsize,
367 const TData *x,
368 const TData *y, TData *z)
369{
370 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
371 const size_t stride = blockDim.x * gridDim.x;
372
373 for (size_t idx = idx0; idx < nsize; idx += stride)
374 {
375 z[idx] = (y[idx] == TData(0)) ? TData(0) : x[idx] / y[idx];
376 }
377}
378
379template <typename TData,
380 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
381__global__ __launch_bounds__(blockSize) void daxpyKernel(const size_t nsize,
382 const TData alpha,
383 const TData *x,
384 const TData *y,
385 TData *z)
386{
387 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
388 const size_t stride = blockDim.x * gridDim.x;
389
390 for (size_t idx = idx0; idx < nsize; idx += stride)
391 {
392 z[idx] = alpha * x[idx] + y[idx];
393 }
394}
395
396template <typename TData,
397 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
398__global__ __launch_bounds__(blockSize) void daxpbyKernel(
399 const size_t nsize, const TData alpha, const TData *x, const TData beta,
400 const TData *y, TData *z)
401{
402 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
403 const size_t stride = blockDim.x * gridDim.x;
404
405 for (size_t idx = idx0; idx < nsize; idx += stride)
406 {
407 z[idx] = alpha * x[idx] + beta * y[idx];
408 }
409}
410
411template <typename TData,
412 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
413__global__ __launch_bounds__(blockSize) void daxpbypzKernel(
414 const size_t nsize, const TData alpha, const TData *x, const TData beta,
415 const TData *y, const TData *z, TData *w)
416{
417 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
418 const size_t stride = blockDim.x * gridDim.x;
419
420 for (size_t idx = idx0; idx < nsize; idx += stride)
421 {
422 w[idx] = alpha * x[idx] + beta * y[idx] + z[idx];
423 }
424}
425
426template <typename TData,
427 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
428__global__ __launch_bounds__(blockSize) void daxpbypczKernel(
429 const size_t nsize, const TData alpha, const TData *x, const TData beta,
430 const TData *y, const TData gamma, const TData *z, TData *w)
431{
432 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
433 const size_t stride = blockDim.x * gridDim.x;
434
435 for (size_t idx = idx0; idx < nsize; idx += stride)
436 {
437 w[idx] = alpha * x[idx] + beta * y[idx] + gamma * z[idx];
438 }
439}
440
441// z = sum_j alpha_j x_j over the terms, plus z itself if APPEND, in one pass
442// over z.
443template <bool APPEND, typename TData,
444 unsigned int blockSize = NektarSpaces::Device::defaultBlockSize>
445__global__ __launch_bounds__(blockSize) void linearCombinationKernel(
446 const size_t nsize, const LinearCombinationTerms<TData> terms, TData *z)
447{
448 const size_t idx0 = blockDim.x * blockIdx.x + threadIdx.x;
449 const size_t stride = blockDim.x * gridDim.x;
450
451 for (size_t idx = idx0; idx < nsize; idx += stride)
452 {
453 TData acc = APPEND ? z[idx] : TData(0);
454 for (unsigned int j = 0; j < terms.n; ++j)
455 {
456 acc += terms.alpha[j] * terms.x[j][idx];
457 }
458 z[idx] = acc;
459 }
460}
461
462// Reductions of reduceKernel.
463enum class ReduceOp
464{
465 Sum,
466 Max,
467 Min,
468 AbsMax
469};
470
471// Identity of a reduction.
472template <ReduceOp op, typename TData>
473NEK_HOSTDEVICE_INLINE constexpr TData reduceIdentity()
474{
475 if constexpr (op == ReduceOp::Sum)
476 {
477 return 0;
478 }
479 else if constexpr (op == ReduceOp::Max)
480 {
481 return std::numeric_limits<TData>::lowest();
482 }
483 else if constexpr (op == ReduceOp::Min)
484 {
485 return std::numeric_limits<TData>::max();
486 }
487 else if constexpr (op == ReduceOp::AbsMax)
488 {
489 return 0;
490 }
491}
492
493// Transforms of the entries reduceKernel reduces.
494template <typename TData> struct IdentityOp
495{
496 NEK_DEVICE_INLINE TData operator()(const TData x)
497 {
498 return x;
499 }
500};
501
502template <typename TData> struct AbsOp
503{
504 NEK_DEVICE_INLINE TData operator()(const TData x)
505 {
506 return std::abs(x);
507 }
508};
509
510template <typename TData> struct SquareOp
511{
512 NEK_DEVICE_INLINE TData operator()(const TData x)
513 {
514 return x * x;
515 }
516};
517
518template <typename TData> struct MultiplyOp
519{
520 NEK_DEVICE_INLINE TData operator()(const TData x, const TData y)
521 {
522 return x * y;
523 }
524};
525
526// Transforms of the entries reduceNKernel reduces, writing value s of an entry
527// to vals[s].
528template <typename TData> struct IdentityEachOp
529{
530 template <typename... TIn>
531 NEK_DEVICE_INLINE void operator()(TData *vals, const TIn... x)
532 {
533 unsigned int s = 0;
534 ((vals[s++] = x), ...);
535 }
536};
537
538template <typename TData> struct MultiplyFirstOp
539{
540 template <typename... TIn>
541 NEK_DEVICE_INLINE void operator()(TData *vals, const TData x,
542 const TIn... y)
543 {
544 unsigned int s = 0;
545 ((vals[s++] = x * y), ...);
546 }
547};
548
549// Combination of two values by a reduction.
550template <ReduceOp op, typename TData>
551NEK_DEVICE_INLINE static TData reduceJoin(const TData a, const TData b)
552{
553 if constexpr (op == ReduceOp::Sum)
554 {
555 return a + b;
556 }
557 else if constexpr (op == ReduceOp::Max)
558 {
559 return std::max(a, b);
560 }
561 else if constexpr (op == ReduceOp::Min)
562 {
563 return std::min(a, b);
564 }
565 else if constexpr (op == ReduceOp::AbsMax)
566 {
567 return std::max(std::abs(a), std::abs(b));
568 }
569}
570
571// Combination by reduction op of v over the thread block, valid on the block's
572// first thread.
573template <ReduceOp op, typename TData>
574NEK_DEVICE_INLINE static TData blockReduceJoin(const TData v)
575{
576 constexpr unsigned int warpsize = NektarSpaces::Device::warpSize;
577
578 auto warp = cg::tiled_partition<warpsize>(cg::this_thread_block());
579 return blockReduceWarpPartials(
580 v, reduceIdentity<op, TData>(), [&](TData x) {
581#pragma unroll
582 for (unsigned int offset = warpsize / 2; offset > 0; offset /= 2)
583 {
584 x = reduceJoin<op>(x, warp.shfl_down(x, offset));
585 }
586 return x;
587 });
588}
589
590// Sets *dest to val if init, and otherwise combines val into it by reduction
591// op. Set, it has a single writer. Combined into, it may be shared with the
592// reductions of other blocks of a Field on other streams, so takes one
593// global-scope atomic.
594template <bool init, ReduceOp op, typename TData>
595NEK_DEVICE_INLINE static void reduceStore(TData *const dest, const TData val)
596{
597 if constexpr (init)
598 {
599 *dest = val;
600 }
601 else if constexpr (op == ReduceOp::Sum)
602 {
603 atomic_add<NektarSpaces::GlobalScope>(dest, val);
604 }
605 else if constexpr (op == ReduceOp::Max || op == ReduceOp::AbsMax)
606 {
607 // An AbsMax partial result is not negative.
608 atomic_max<NektarSpaces::GlobalScope>(dest, val);
609 }
610 else if constexpr (op == ReduceOp::Min)
611 {
612 atomic_min<NektarSpaces::GlobalScope>(dest, val);
613 }
614}
615
616// Combination of v by reduction op with TransformOp<TData>() of each lane of
617// the vecLoad results xv.
618template <ReduceOp op, template <typename> typename TransformOp, typename TData,
619 typename... TVec>
620NEK_DEVICE_INLINE static TData vecReduceJoin(const TData v, const TVec... xv)
621{
622 if constexpr (std::is_same_v<TData, float>)
623 {
624 return reduceJoin<op>(
625 v, reduceJoin<op>(reduceJoin<op>(TransformOp<TData>()(xv.x...),
626 TransformOp<TData>()(xv.y...)),
627 reduceJoin<op>(TransformOp<TData>()(xv.z...),
628 TransformOp<TData>()(xv.w...))));
629 }
630 else if constexpr (std::is_same_v<TData, double>)
631 {
632 return reduceJoin<op>(v, reduceJoin<op>(TransformOp<TData>()(xv.x...),
633 TransformOp<TData>()(xv.y...)));
634 }
635}
636
637// Combination of v[0, nred) by reduction op with the values
638// TransformOp<TData>()(vals, x...) writes to vals[0, nred).
639template <ReduceOp op, unsigned int nred,
640 template <typename> typename TransformOp, typename TData,
641 typename... TIn>
642NEK_DEVICE_INLINE static void reduceNJoin(TData *v, const TIn... x)
643{
644 TData vals[nred];
645 TransformOp<TData>()(vals, x...);
646 for (unsigned int s = 0; s < nred; ++s)
647 {
648 v[s] = reduceJoin<op>(v[s], vals[s]);
649 }
650}
651
652// As reduceNJoin, with each lane of the vecLoad results xv.
653template <ReduceOp op, unsigned int nred,
654 template <typename> typename TransformOp, typename TData,
655 typename... TVec>
656NEK_DEVICE_INLINE static void vecReduceNJoin(TData *v, const TVec... xv)
657{
658 if constexpr (std::is_same_v<TData, float>)
659 {
660 TData a[nred], b[nred], c[nred], d[nred];
661 TransformOp<TData>()(a, xv.x...);
662 TransformOp<TData>()(b, xv.y...);
663 TransformOp<TData>()(c, xv.z...);
664 TransformOp<TData>()(d, xv.w...);
665 for (unsigned int s = 0; s < nred; ++s)
666 {
667 v[s] = reduceJoin<op>(v[s],
668 reduceJoin<op>(reduceJoin<op>(a[s], b[s]),
669 reduceJoin<op>(c[s], d[s])));
670 }
671 }
672 else if constexpr (std::is_same_v<TData, double>)
673 {
674 TData a[nred], b[nred];
675 TransformOp<TData>()(a, xv.x...);
676 TransformOp<TData>()(b, xv.y...);
677 for (unsigned int s = 0; s < nred; ++s)
678 {
679 v[s] = reduceJoin<op>(v[s], reduceJoin<op>(a[s], b[s]));
680 }
681 }
682}
683
684// As vecReduceJoin, over the lanes the vecLoadMask result m selects.
685template <ReduceOp op, template <typename> typename TransformOp, typename TData,
686 typename... TVec>
687NEK_DEVICE_INLINE static TData vecReduceJoinMasked(const TData v,
688 const VecMask<TData> m,
689 const TVec... xv)
690{
691 constexpr TData identity = reduceIdentity<op, TData>();
692
693 if constexpr (std::is_same_v<TData, float>)
694 {
695 return reduceJoin<op>(
696 v,
697 reduceJoin<op>(
698 reduceJoin<op>(m.x ? TransformOp<TData>()(xv.x...) : identity,
699 m.y ? TransformOp<TData>()(xv.y...) : identity),
700 reduceJoin<op>(m.z ? TransformOp<TData>()(xv.z...) : identity,
701 m.w ? TransformOp<TData>()(xv.w...)
702 : identity)));
703 }
704 else if constexpr (std::is_same_v<TData, double>)
705 {
706 return reduceJoin<op>(
707 v, reduceJoin<op>(m.x ? TransformOp<TData>()(xv.x...) : identity,
708 m.y ? TransformOp<TData>()(xv.y...) : identity));
709 }
710}
711
712// TransformOp<TData>()(vals, x...) if m, otherwise the identity of op, in
713// vals[0, nred).
714template <ReduceOp op, unsigned int nred,
715 template <typename> typename TransformOp, typename TData,
716 typename... TIn>
717NEK_DEVICE_INLINE static void maskTransformN(TData *vals, const uint8_t m,
718 const TIn... x)
719{
720 TransformOp<TData>()(vals, x...);
721 for (unsigned int s = 0; s < nred; ++s)
722 {
723 vals[s] = m ? vals[s] : reduceIdentity<op, TData>();
724 }
725}
726
727// As vecReduceNJoin, over the lanes the vecLoadMask result m selects.
728template <ReduceOp op, unsigned int nred,
729 template <typename> typename TransformOp, typename TData,
730 typename... TVec>
731NEK_DEVICE_INLINE static void vecReduceNJoinMasked(TData *v,
732 const VecMask<TData> m,
733 const TVec... xv)
734{
735 if constexpr (std::is_same_v<TData, float>)
736 {
737 TData a[nred], b[nred], c[nred], d[nred];
738 maskTransformN<op, nred, TransformOp>(a, m.x, xv.x...);
739 maskTransformN<op, nred, TransformOp>(b, m.y, xv.y...);
740 maskTransformN<op, nred, TransformOp>(c, m.z, xv.z...);
741 maskTransformN<op, nred, TransformOp>(d, m.w, xv.w...);
742 for (unsigned int s = 0; s < nred; ++s)
743 {
744 v[s] = reduceJoin<op>(v[s],
745 reduceJoin<op>(reduceJoin<op>(a[s], b[s]),
746 reduceJoin<op>(c[s], d[s])));
747 }
748 }
749 else if constexpr (std::is_same_v<TData, double>)
750 {
751 TData a[nred], b[nred];
752 maskTransformN<op, nred, TransformOp>(a, m.x, xv.x...);
753 maskTransformN<op, nred, TransformOp>(b, m.y, xv.y...);
754 for (unsigned int s = 0; s < nred; ++s)
755 {
756 v[s] = reduceJoin<op>(v[s], reduceJoin<op>(a[s], b[s]));
757 }
758 }
759}
760
761// Partial result of reduction op over TransformOp<TData>()(x[i]...) per
762// thread block, in out[b] for block b, which it is set to if init and is
763// otherwise combined into.
764template <bool init, ReduceOp op, template <typename> typename TransformOp,
765 typename TData,
766 unsigned int blockSize = NektarSpaces::Device::reductionBlockSize(),
767 typename... TIn>
768__global__ __launch_bounds__(blockSize) void reduceKernel(const size_t nsize,
769 TData *out,
770 const TIn *...x)
771{
772 static_assert((std::is_same_v<TIn, TData> && ...),
773 "reduceKernel: inputs of the output type.");
774
775 constexpr TData identity = reduceIdentity<op, TData>();
776 constexpr unsigned int vecSize =
777 std::is_same_v<TData, float> || std::is_same_v<TData, double>
778 ? (16u / sizeof(TData))
779 : 1u;
780
781 auto grid = cg::this_grid();
782 auto block = cg::this_thread_block();
783 TData v = identity;
784
785 if constexpr (vecSize > 1u)
786 {
787 for (size_t tid = grid.thread_rank(); tid < nsize / vecSize;
788 tid += grid.size())
789 {
790 v = vecReduceJoin<op, TransformOp>(v, vecLoad(x, tid)...);
791 }
792 }
793 else
794 {
795 for (size_t tid = grid.thread_rank(); tid < nsize; tid += grid.size())
796 {
797 v = reduceJoin<op>(v, TransformOp<TData>()(x[tid]...));
798 }
799 }
800
801 // process final elements (if there are any)
802 if (grid.thread_rank() < nsize % vecSize)
803 {
804 size_t tid = nsize - 1u - grid.thread_rank();
805 v = reduceJoin<op>(v, TransformOp<TData>()(x[tid]...));
806 }
807
808 v = blockReduceJoin<op>(v);
809 if (block.thread_rank() == 0)
810 {
811 reduceStore<init, op>(&out[block.group_index().x], v);
812 }
813}
814
815// As reduceKernel, over the entries mask selects.
816template <bool init, ReduceOp op, template <typename> typename TransformOp,
817 typename TData,
818 unsigned int blockSize = NektarSpaces::Device::reductionBlockSize(),
819 typename... TIn>
820__global__ __launch_bounds__(blockSize) void reduceKernel(const size_t nsize,
821 const uint8_t *mask,
822 TData *out,
823 const TIn *...x)
824{
825 static_assert((std::is_same_v<TIn, TData> && ...),
826 "reduceKernel: inputs of the output type.");
827
828 constexpr TData identity = reduceIdentity<op, TData>();
829 constexpr unsigned int vecSize =
830 std::is_same_v<TData, float> || std::is_same_v<TData, double>
831 ? (16u / sizeof(TData))
832 : 1u;
833
834 auto grid = cg::this_grid();
835 auto block = cg::this_thread_block();
836 TData v = identity;
837
838 if constexpr (vecSize > 1u)
839 {
840 for (size_t tid = grid.thread_rank(); tid < nsize / vecSize;
841 tid += grid.size())
842 {
843 v = vecReduceJoinMasked<op, TransformOp>(
844 v, vecLoadMask<TData>(mask, tid), vecLoad(x, tid)...);
845 }
846 }
847 else
848 {
849 for (size_t tid = grid.thread_rank(); tid < nsize; tid += grid.size())
850 {
851 v = mask[tid] ? reduceJoin<op>(v, TransformOp<TData>()(x[tid]...))
852 : v;
853 }
854 }
855
856 // process final elements (if there are any)
857 if (grid.thread_rank() < nsize % vecSize)
858 {
859 size_t tid = nsize - 1u - grid.thread_rank();
860 v = mask[tid] ? reduceJoin<op>(v, TransformOp<TData>()(x[tid]...)) : v;
861 }
862
863 v = blockReduceJoin<op>(v);
864 if (block.thread_rank() == 0)
865 {
866 reduceStore<init, op>(&out[block.group_index().x], v);
867 }
868}
869
870// Partial results of nred reductions op per thread block, of the values
871// TransformOp<TData>()(vals, x[i]...) writes to vals[0, nred) for each
872// entry i: result s of block b is in out[s * gridDim.x + b], which it is set
873// to if init and is otherwise combined into.
874template <bool init, ReduceOp op, unsigned int nred,
875 template <typename> typename TransformOp, typename TData,
876 unsigned int blockSize = NektarSpaces::Device::reductionBlockSize(),
877 typename... TIn>
878__global__ __launch_bounds__(blockSize) void reduceNKernel(const size_t nsize,
879 TData *out,
880 const TIn *...x)
881{
882 static_assert((std::is_same_v<TIn, TData> && ...),
883 "reduceNKernel: inputs of the output type.");
884
885 constexpr TData identity = reduceIdentity<op, TData>();
886 constexpr unsigned int vecSize =
887 std::is_same_v<TData, float> || std::is_same_v<TData, double>
888 ? (16u / sizeof(TData))
889 : 1u;
890
891 auto grid = cg::this_grid();
892 auto block = cg::this_thread_block();
893 TData v[nred];
894
895 for (unsigned int s = 0; s < nred; ++s)
896 {
897 v[s] = identity;
898 }
899
900 // Vector loads need every input 16-byte aligned, which the final stage's
901 // partial results past the first sum need not be.
902 size_t nvec = 0;
903 if constexpr (vecSize > 1u)
904 {
905 if (((reinterpret_cast<uintptr_t>(x) % 16u == 0u) && ...))
906 {
907 nvec = nsize / vecSize;
908 }
909
910 for (size_t tid = grid.thread_rank(); tid < nvec; tid += grid.size())
911 {
912 vecReduceNJoin<op, nred, TransformOp>(v, vecLoad(x, tid)...);
913 }
914 }
915
916 // process the remaining entries
917 for (size_t tid = nvec * vecSize + grid.thread_rank(); tid < nsize;
918 tid += grid.size())
919 {
920 reduceNJoin<op, nred, TransformOp>(v, x[tid]...);
921 }
922
923 for (unsigned int s = 0; s < nred; ++s)
924 {
925 v[s] = blockReduceJoin<op>(v[s]);
926 }
927
928 if (block.thread_rank() == 0)
929 {
930 for (unsigned int s = 0; s < nred; ++s)
931 {
932 reduceStore<init, op>(&out[s * gridDim.x + block.group_index().x],
933 v[s]);
934 }
935 }
936}
937
938// As reduceNKernel, over the entries mask selects.
939template <bool init, ReduceOp op, unsigned int nred,
940 template <typename> typename TransformOp, typename TData,
941 unsigned int blockSize = NektarSpaces::Device::reductionBlockSize(),
942 typename... TIn>
943__global__ __launch_bounds__(blockSize) void reduceNKernel(const size_t nsize,
944 const uint8_t *mask,
945 TData *out,
946 const TIn *...x)
947{
948 static_assert((std::is_same_v<TIn, TData> && ...),
949 "reduceNKernel: inputs of the output type.");
950
951 constexpr TData identity = reduceIdentity<op, TData>();
952 constexpr unsigned int vecSize =
953 std::is_same_v<TData, float> || std::is_same_v<TData, double>
954 ? (16u / sizeof(TData))
955 : 1u;
956
957 auto grid = cg::this_grid();
958 auto block = cg::this_thread_block();
959 TData v[nred];
960
961 for (unsigned int s = 0; s < nred; ++s)
962 {
963 v[s] = identity;
964 }
965
966 size_t nvec = 0;
967 if constexpr (vecSize > 1u)
968 {
969 nvec = nsize / vecSize;
970
971 for (size_t tid = grid.thread_rank(); tid < nvec; tid += grid.size())
972 {
973 vecReduceNJoinMasked<op, nred, TransformOp>(
974 v, vecLoadMask<TData>(mask, tid), vecLoad(x, tid)...);
975 }
976 }
977
978 // process the remaining entries
979 for (size_t tid = nvec * vecSize + grid.thread_rank(); tid < nsize;
980 tid += grid.size())
981 {
982 if (mask[tid])
983 {
984 reduceNJoin<op, nred, TransformOp>(v, x[tid]...);
985 }
986 }
987
988 for (unsigned int s = 0; s < nred; ++s)
989 {
990 v[s] = blockReduceJoin<op>(v[s]);
991 }
992
993 if (block.thread_rank() == 0)
994 {
995 for (unsigned int s = 0; s < nred; ++s)
996 {
997 reduceStore<init, op>(&out[s * gridDim.x + block.group_index().x],
998 v[s]);
999 }
1000 }
1001}
1002
1003// Launchers for the kernels
1004
1005template <
1006 typename ExecSpace, typename TData,
1007 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1008 Enable = true>
1009inline void zeroKernel(const size_t nsize, TData *x,
1010 const unsigned int streamID = 0)
1011{
1012 deviceMemset(x, 0, nsize * sizeof(TData), streamID);
1013}
1014
1015template <
1016 typename ExecSpace, typename TData,
1017 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1018 Enable = true>
1019inline void fillKernel(const size_t nsize, const TData &val, TData *x,
1020 const unsigned int streamID = 0)
1021{
1022 deviceFill(x, val, nsize, streamID);
1023}
1024
1025template <
1026 typename ExecSpace, typename TData,
1027 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1028 Enable = true>
1029inline void copyKernel(const size_t nsize, const TData *x, TData *y,
1030 const unsigned int streamID = 0)
1031{
1032 deviceMemcpy<eDeviceToDevice>(y, x, nsize * sizeof(TData), streamID);
1033}
1034
1035template <
1036 typename ExecSpace, typename TData,
1037 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1038 Enable = true>
1039inline void absKernel(const size_t nsize, const TData *x, TData *y,
1040 const unsigned int streamID = 0)
1041{
1042 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1043 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1044
1045#if defined(NEKTAR_ENABLE_CUDA)
1046 auto stream = CUDAStream::GetInstance(streamID);
1047#elif defined(NEKTAR_ENABLE_HIP)
1048 auto stream = HIPStream::GetInstance(streamID);
1049#endif
1050
1051 absKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y);
1053}
1054
1055template <
1056 typename ExecSpace, typename TData,
1057 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1058 Enable = true>
1059inline void negKernel(const size_t nsize, const TData *x, TData *y,
1060 const unsigned int streamID = 0)
1061{
1062 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1063 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1064
1065#if defined(NEKTAR_ENABLE_CUDA)
1066 auto stream = CUDAStream::GetInstance(streamID);
1067#elif defined(NEKTAR_ENABLE_HIP)
1068 auto stream = HIPStream::GetInstance(streamID);
1069#endif
1070
1071 negKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y);
1073}
1074
1075template <
1076 typename ExecSpace, typename TData,
1077 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1078 Enable = true>
1079inline void sqrtKernel(const size_t nsize, const TData *x, TData *y,
1080 const unsigned int streamID = 0)
1081{
1082 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1083 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1084
1085#if defined(NEKTAR_ENABLE_CUDA)
1086 auto stream = CUDAStream::GetInstance(streamID);
1087#elif defined(NEKTAR_ENABLE_HIP)
1088 auto stream = HIPStream::GetInstance(streamID);
1089#endif
1090
1091 sqrtKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y);
1093}
1094
1095template <
1096 typename ExecSpace, typename TData,
1097 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1098 Enable = true>
1099inline void addKernel(const size_t nsize, const TData *x, const TData *y,
1100 TData *z, const unsigned int streamID = 0)
1101{
1102 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1103 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1104
1105#if defined(NEKTAR_ENABLE_CUDA)
1106 auto stream = CUDAStream::GetInstance(streamID);
1107#elif defined(NEKTAR_ENABLE_HIP)
1108 auto stream = HIPStream::GetInstance(streamID);
1109#endif
1110
1111 addKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y, z);
1113}
1114
1115template <
1116 typename ExecSpace, typename TData,
1117 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1118 Enable = true>
1119inline void addScalarKernel(const size_t nsize, const TData alpha,
1120 const TData *x, TData *y,
1121 const unsigned int streamID = 0)
1122{
1123 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1124 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1125
1126#if defined(NEKTAR_ENABLE_CUDA)
1127 auto stream = CUDAStream::GetInstance(streamID);
1128#elif defined(NEKTAR_ENABLE_HIP)
1129 auto stream = HIPStream::GetInstance(streamID);
1130#endif
1131
1132 addScalarKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, y);
1134}
1135
1136// addScalarKernel over the ncomp components of compSize values of a block,
1137// stored as element groups of width lanes by ndata points of which the first
1138// nelmt elements are not padding: y = x + alpha, and zero in the padding.
1139template <
1140 typename ExecSpace, typename TData,
1141 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1142 Enable = true>
1143inline void addScalarKernel(const unsigned int ncomp, const size_t compSize,
1144 const size_t nelmt, const unsigned int ndata,
1145 const unsigned int width, const TData alpha,
1146 const TData *x, TData *y,
1147 const unsigned int streamID = 0)
1148{
1149 const size_t prefix = (nelmt / width) * width * ndata;
1150 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1151 const dim3 gridSize((compSize + blockSize - 1u) / blockSize, ncomp);
1152
1153#if defined(NEKTAR_ENABLE_CUDA)
1154 auto stream = CUDAStream::GetInstance(streamID);
1155#elif defined(NEKTAR_ENABLE_HIP)
1156 auto stream = HIPStream::GetInstance(streamID);
1157#endif
1158
1159 addScalarKernel<<<gridSize, blockSize, 0, stream>>>(
1160 compSize, prefix, nelmt, ndata, width, alpha, x, y);
1162}
1163
1164template <
1165 typename ExecSpace, typename TData,
1166 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1167 Enable = true>
1168inline void subKernel(const size_t nsize, const TData *x, const TData *y,
1169 TData *z, const unsigned int streamID = 0)
1170{
1171 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1172 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1173
1174#if defined(NEKTAR_ENABLE_CUDA)
1175 auto stream = CUDAStream::GetInstance(streamID);
1176#elif defined(NEKTAR_ENABLE_HIP)
1177 auto stream = HIPStream::GetInstance(streamID);
1178#endif
1179
1180 subKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y, z);
1182}
1183
1184template <
1185 typename ExecSpace, typename TData,
1186 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1187 Enable = true>
1188inline void mulKernel(const size_t nsize, const TData alpha, const TData *x,
1189 TData *y, const unsigned int streamID = 0)
1190{
1191 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1192 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1193
1194#if defined(NEKTAR_ENABLE_CUDA)
1195 auto stream = CUDAStream::GetInstance(streamID);
1196#elif defined(NEKTAR_ENABLE_HIP)
1197 auto stream = HIPStream::GetInstance(streamID);
1198#endif
1199
1200 mulKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, y);
1202}
1203
1204template <
1205 typename ExecSpace, typename TData,
1206 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1207 Enable = true>
1208inline void mulKernel(const size_t nsize, const TData *x, const TData *y,
1209 TData *z, const unsigned int streamID = 0)
1210{
1211 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1212 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1213
1214#if defined(NEKTAR_ENABLE_CUDA)
1215 auto stream = CUDAStream::GetInstance(streamID);
1216#elif defined(NEKTAR_ENABLE_HIP)
1217 auto stream = HIPStream::GetInstance(streamID);
1218#endif
1219
1220 mulKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y, z);
1222}
1223
1224template <
1225 typename ExecSpace, typename TData,
1226 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1227 Enable = true>
1228inline void divKernel(const size_t nsize, const TData alpha, const TData *x,
1229 TData *y, const unsigned int streamID = 0)
1230{
1231 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1232 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1233
1234#if defined(NEKTAR_ENABLE_CUDA)
1235 auto stream = CUDAStream::GetInstance(streamID);
1236#elif defined(NEKTAR_ENABLE_HIP)
1237 auto stream = HIPStream::GetInstance(streamID);
1238#endif
1239
1240 divKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, y);
1242}
1243
1244template <
1245 typename ExecSpace, typename TData,
1246 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1247 Enable = true>
1248inline void divKernel(const size_t nsize, const TData *x, const TData *y,
1249 TData *z, const unsigned int streamID = 0)
1250{
1251 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1252 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1253
1254#if defined(NEKTAR_ENABLE_CUDA)
1255 auto stream = CUDAStream::GetInstance(streamID);
1256#elif defined(NEKTAR_ENABLE_HIP)
1257 auto stream = HIPStream::GetInstance(streamID);
1258#endif
1259
1260 divKernel<<<gridSize, blockSize, 0, stream>>>(nsize, x, y, z);
1262}
1263
1264template <
1265 typename ExecSpace, typename TData,
1266 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1267 Enable = true>
1268inline void daxpyKernel(const size_t nsize, const TData alpha, const TData *x,
1269 const TData *y, TData *z,
1270 const unsigned int streamID = 0)
1271{
1272 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1273 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1274
1275#if defined(NEKTAR_ENABLE_CUDA)
1276 auto stream = CUDAStream::GetInstance(streamID);
1277#elif defined(NEKTAR_ENABLE_HIP)
1278 auto stream = HIPStream::GetInstance(streamID);
1279#endif
1280
1281 daxpyKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, y, z);
1283}
1284
1285template <
1286 typename ExecSpace, typename TData,
1287 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1288 Enable = true>
1289inline void daxpbyKernel(const size_t nsize, const TData alpha, const TData *x,
1290 const TData beta, const TData *y, TData *z,
1291 const unsigned int streamID = 0)
1292{
1293 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1294 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1295
1296#if defined(NEKTAR_ENABLE_CUDA)
1297 auto stream = CUDAStream::GetInstance(streamID);
1298#elif defined(NEKTAR_ENABLE_HIP)
1299 auto stream = HIPStream::GetInstance(streamID);
1300#endif
1301
1302 daxpbyKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, beta, y,
1303 z);
1305}
1306
1307template <
1308 typename ExecSpace, typename TData,
1309 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1310 Enable = true>
1311inline void daxpbypzKernel(const size_t nsize, const TData alpha,
1312 const TData *x, const TData beta, const TData *y,
1313 const TData *z, TData *w,
1314 const unsigned int streamID = 0)
1315{
1316 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1317 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1318
1319#if defined(NEKTAR_ENABLE_CUDA)
1320 auto stream = CUDAStream::GetInstance(streamID);
1321#elif defined(NEKTAR_ENABLE_HIP)
1322 auto stream = HIPStream::GetInstance(streamID);
1323#endif
1324
1325 daxpbypzKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, beta, y,
1326 z, w);
1328}
1329
1330template <
1331 typename ExecSpace, typename TData,
1332 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1333 Enable = true>
1334inline void daxpbypczKernel(const size_t nsize, const TData alpha,
1335 const TData *x, const TData beta, const TData *y,
1336 const TData gamma, const TData *z, TData *w,
1337 const unsigned int streamID = 0)
1338{
1339 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1340 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1341
1342#if defined(NEKTAR_ENABLE_CUDA)
1343 auto stream = CUDAStream::GetInstance(streamID);
1344#elif defined(NEKTAR_ENABLE_HIP)
1345 auto stream = HIPStream::GetInstance(streamID);
1346#endif
1347
1348 daxpbypczKernel<<<gridSize, blockSize, 0, stream>>>(nsize, alpha, x, beta,
1349 y, gamma, z, w);
1351}
1352
1353template <
1354 typename ExecSpace, bool APPEND, typename TData,
1355 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1356 Enable = true>
1357inline void linearCombinationKernel(const size_t nsize,
1358 const LinearCombinationTerms<TData> &terms,
1359 TData *z, const unsigned int streamID = 0)
1360{
1361 const unsigned int blockSize = NektarSpaces::Device::defaultBlockSize;
1362 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
1363
1364#if defined(NEKTAR_ENABLE_CUDA)
1365 auto stream = CUDAStream::GetInstance(streamID);
1366#elif defined(NEKTAR_ENABLE_HIP)
1367 auto stream = HIPStream::GetInstance(streamID);
1368#endif
1369
1370 linearCombinationKernel<APPEND>
1371 <<<gridSize, blockSize, 0, stream>>>(nsize, terms, z);
1373}
1374
1375template <
1376 typename ExecSpace, bool init, typename TData,
1377 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1378 Enable = true>
1379inline void reduceSumKernel(const size_t nsize, const TData *x, TData *out,
1380 const unsigned int streamID = 0)
1381{
1382 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1383 const unsigned int gridSize =
1385
1386#if defined(NEKTAR_ENABLE_CUDA)
1387 auto stream = CUDAStream::GetInstance(streamID);
1388#elif defined(NEKTAR_ENABLE_HIP)
1389 auto stream = HIPStream::GetInstance(streamID);
1390#endif
1391
1392 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1393 {
1394 deviceMalloc(&internalMemoryBufferMap[streamID],
1395 internalReductionBufferSize, streamID);
1396 }
1397
1398 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1399 reduceKernel<true, ReduceOp::Sum, IdentityOp>
1400 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x);
1402 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1403 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1405}
1406
1407template <
1408 typename ExecSpace, bool init, typename TData,
1409 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1410 Enable = true>
1411inline void reduceSumKernel(const size_t nsize, const uint8_t *mask,
1412 const TData *x, TData *out,
1413 const unsigned int streamID = 0)
1414{
1415 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1416 const unsigned int gridSize =
1418
1419#if defined(NEKTAR_ENABLE_CUDA)
1420 auto stream = CUDAStream::GetInstance(streamID);
1421#elif defined(NEKTAR_ENABLE_HIP)
1422 auto stream = HIPStream::GetInstance(streamID);
1423#endif
1424
1425 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1426 {
1427 deviceMalloc(&internalMemoryBufferMap[streamID],
1428 internalReductionBufferSize, streamID);
1429 }
1430
1431 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1432 reduceKernel<true, ReduceOp::Sum, IdentityOp>
1433 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x);
1435 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1436 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1438}
1439
1440template <
1441 typename ExecSpace, bool init, typename TData,
1442 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1443 Enable = true>
1444inline void reduceMaxKernel(const size_t nsize, const TData *x, TData *out,
1445 const unsigned int streamID = 0)
1446{
1447 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1448 const unsigned int gridSize =
1450
1451#if defined(NEKTAR_ENABLE_CUDA)
1452 auto stream = CUDAStream::GetInstance(streamID);
1453#elif defined(NEKTAR_ENABLE_HIP)
1454 auto stream = HIPStream::GetInstance(streamID);
1455#endif
1456
1457 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1458 {
1459 deviceMalloc(&internalMemoryBufferMap[streamID],
1460 internalReductionBufferSize, streamID);
1461 }
1462
1463 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1464 reduceKernel<true, ReduceOp::Max, IdentityOp>
1465 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x);
1467 reduceKernel<init, ReduceOp::Max, IdentityOp>
1468 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1470}
1471
1472template <
1473 typename ExecSpace, bool init, typename TData,
1474 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1475 Enable = true>
1476inline void reduceMaxKernel(const size_t nsize, const uint8_t *mask,
1477 const TData *x, TData *out,
1478 const unsigned int streamID = 0)
1479{
1480 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1481 const unsigned int gridSize =
1483
1484#if defined(NEKTAR_ENABLE_CUDA)
1485 auto stream = CUDAStream::GetInstance(streamID);
1486#elif defined(NEKTAR_ENABLE_HIP)
1487 auto stream = HIPStream::GetInstance(streamID);
1488#endif
1489
1490 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1491 {
1492 deviceMalloc(&internalMemoryBufferMap[streamID],
1493 internalReductionBufferSize, streamID);
1494 }
1495
1496 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1497 reduceKernel<true, ReduceOp::Max, IdentityOp>
1498 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x);
1500 reduceKernel<init, ReduceOp::Max, IdentityOp>
1501 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1503}
1504
1505template <
1506 typename ExecSpace, bool init, typename TData,
1507 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1508 Enable = true>
1509inline void reduceMinKernel(const size_t nsize, const TData *x, TData *out,
1510 const unsigned int streamID = 0)
1511{
1512 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1513 const unsigned int gridSize =
1515
1516#if defined(NEKTAR_ENABLE_CUDA)
1517 auto stream = CUDAStream::GetInstance(streamID);
1518#elif defined(NEKTAR_ENABLE_HIP)
1519 auto stream = HIPStream::GetInstance(streamID);
1520#endif
1521
1522 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1523 {
1524 deviceMalloc(&internalMemoryBufferMap[streamID],
1525 internalReductionBufferSize, streamID);
1526 }
1527
1528 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1529 reduceKernel<true, ReduceOp::Min, IdentityOp>
1530 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x);
1532 reduceKernel<init, ReduceOp::Min, IdentityOp>
1533 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1535}
1536
1537template <
1538 typename ExecSpace, bool init, typename TData,
1539 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1540 Enable = true>
1541inline void reduceMinKernel(const size_t nsize, const uint8_t *mask,
1542 const TData *x, TData *out,
1543 const unsigned int streamID = 0)
1544{
1545 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1546 const unsigned int gridSize =
1548
1549#if defined(NEKTAR_ENABLE_CUDA)
1550 auto stream = CUDAStream::GetInstance(streamID);
1551#elif defined(NEKTAR_ENABLE_HIP)
1552 auto stream = HIPStream::GetInstance(streamID);
1553#endif
1554
1555 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1556 {
1557 deviceMalloc(&internalMemoryBufferMap[streamID],
1558 internalReductionBufferSize, streamID);
1559 }
1560
1561 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1562 reduceKernel<true, ReduceOp::Min, IdentityOp>
1563 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x);
1565 reduceKernel<init, ReduceOp::Min, IdentityOp>
1566 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1568}
1569
1570template <
1571 typename ExecSpace, bool init, typename TData,
1572 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1573 Enable = true>
1574inline void ddotKernel(const size_t nsize, const TData *x, const TData *y,
1575 TData *out, const unsigned int streamID = 0)
1576{
1577 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1578 const unsigned int gridSize =
1580
1581#if defined(NEKTAR_ENABLE_CUDA)
1582 auto stream = CUDAStream::GetInstance(streamID);
1583#elif defined(NEKTAR_ENABLE_HIP)
1584 auto stream = HIPStream::GetInstance(streamID);
1585#endif
1586
1587 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1588 {
1589 deviceMalloc(&internalMemoryBufferMap[streamID],
1590 internalReductionBufferSize, streamID);
1591 }
1592
1593 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1594 reduceKernel<true, ReduceOp::Sum, MultiplyOp>
1595 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x, y);
1597 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1598 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1600}
1601
1602template <
1603 typename ExecSpace, bool init, typename TData,
1604 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1605 Enable = true>
1606inline void ddotKernel(const size_t nsize, const uint8_t *mask, const TData *x,
1607 const TData *y, TData *out,
1608 const unsigned int streamID = 0)
1609{
1610 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1611 const unsigned int gridSize =
1613
1614#if defined(NEKTAR_ENABLE_CUDA)
1615 auto stream = CUDAStream::GetInstance(streamID);
1616#elif defined(NEKTAR_ENABLE_HIP)
1617 auto stream = HIPStream::GetInstance(streamID);
1618#endif
1619
1620 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1621 {
1622 deviceMalloc(&internalMemoryBufferMap[streamID],
1623 internalReductionBufferSize, streamID);
1624 }
1625
1626 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1627 reduceKernel<true, ReduceOp::Sum, MultiplyOp>
1628 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x, y);
1630 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1631 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1633}
1634
1635// ddot2Kernel computes, in one pass over x, out[0] (+)= (x, y) and out[1] (+)=
1636// (x, z): two dot products sharing x, over the entries mask selects unless it
1637// is null.
1638template <
1639 typename ExecSpace, bool init, typename TData,
1640 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1641 Enable = true>
1642inline void ddot2Kernel(const size_t nsize, const uint8_t *mask, const TData *x,
1643 const TData *y, const TData *z, TData *out,
1644 const unsigned int streamID = 0)
1645{
1646 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1647 const unsigned int gridSize =
1649
1650#if defined(NEKTAR_ENABLE_CUDA)
1651 auto stream = CUDAStream::GetInstance(streamID);
1652#elif defined(NEKTAR_ENABLE_HIP)
1653 auto stream = HIPStream::GetInstance(streamID);
1654#endif
1655
1656 // Two partial sums per thread block, which internalReductionBufferSize
1657 // holds.
1658 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1659 {
1660 deviceMalloc(&internalMemoryBufferMap[streamID],
1661 internalReductionBufferSize, streamID);
1662 }
1663
1664 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1665 if (mask)
1666 {
1667 reduceNKernel<true, ReduceOp::Sum, 2, MultiplyFirstOp>
1668 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x, y, z);
1669 }
1670 else
1671 {
1672 reduceNKernel<true, ReduceOp::Sum, 2, MultiplyFirstOp>
1673 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x, y, z);
1674 }
1676 reduceNKernel<init, ReduceOp::Sum, 2, IdentityEachOp>
1677 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer, buffer + gridSize);
1679}
1680
1681template <
1682 typename ExecSpace, bool init, typename TData,
1683 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1684 Enable = true>
1685inline void l1normKernel(const size_t nsize, const TData *x, TData *out,
1686 const unsigned int streamID = 0)
1687{
1688 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1689 const unsigned int gridSize =
1691
1692#if defined(NEKTAR_ENABLE_CUDA)
1693 auto stream = CUDAStream::GetInstance(streamID);
1694#elif defined(NEKTAR_ENABLE_HIP)
1695 auto stream = HIPStream::GetInstance(streamID);
1696#endif
1697
1698 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1699 {
1700 deviceMalloc(&internalMemoryBufferMap[streamID],
1701 internalReductionBufferSize, streamID);
1702 }
1703
1704 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1705 reduceKernel<true, ReduceOp::Sum, AbsOp>
1706 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x);
1708 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1709 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1711}
1712
1713template <
1714 typename ExecSpace, bool init, typename TData,
1715 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1716 Enable = true>
1717inline void l1normKernel(const size_t nsize, const uint8_t *mask,
1718 const TData *x, TData *out,
1719 const unsigned int streamID = 0)
1720{
1721 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1722 const unsigned int gridSize =
1724
1725#if defined(NEKTAR_ENABLE_CUDA)
1726 auto stream = CUDAStream::GetInstance(streamID);
1727#elif defined(NEKTAR_ENABLE_HIP)
1728 auto stream = HIPStream::GetInstance(streamID);
1729#endif
1730
1731 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1732 {
1733 deviceMalloc(&internalMemoryBufferMap[streamID],
1734 internalReductionBufferSize, streamID);
1735 }
1736
1737 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1738 reduceKernel<true, ReduceOp::Sum, AbsOp>
1739 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x);
1741 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1742 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1744}
1745
1746template <
1747 typename ExecSpace, bool init, typename TData,
1748 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1749 Enable = true>
1750inline void l2normKernel(const size_t nsize, const TData *x, TData *out,
1751 const unsigned int streamID = 0)
1752{
1753 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1754 const unsigned int gridSize =
1756
1757#if defined(NEKTAR_ENABLE_CUDA)
1758 auto stream = CUDAStream::GetInstance(streamID);
1759#elif defined(NEKTAR_ENABLE_HIP)
1760 auto stream = HIPStream::GetInstance(streamID);
1761#endif
1762
1763 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1764 {
1765 deviceMalloc(&internalMemoryBufferMap[streamID],
1766 internalReductionBufferSize, streamID);
1767 }
1768
1769 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1770 reduceKernel<true, ReduceOp::Sum, SquareOp>
1771 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x);
1773 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1774 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1776}
1777
1778template <
1779 typename ExecSpace, bool init, typename TData,
1780 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1781 Enable = true>
1782inline void l2normKernel(const size_t nsize, const uint8_t *mask,
1783 const TData *x, TData *out,
1784 const unsigned int streamID = 0)
1785{
1786 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1787 const unsigned int gridSize =
1789
1790#if defined(NEKTAR_ENABLE_CUDA)
1791 auto stream = CUDAStream::GetInstance(streamID);
1792#elif defined(NEKTAR_ENABLE_HIP)
1793 auto stream = HIPStream::GetInstance(streamID);
1794#endif
1795
1796 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1797 {
1798 deviceMalloc(&internalMemoryBufferMap[streamID],
1799 internalReductionBufferSize, streamID);
1800 }
1801
1802 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1803 reduceKernel<true, ReduceOp::Sum, SquareOp>
1804 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x);
1806 reduceKernel<init, ReduceOp::Sum, IdentityOp>
1807 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1809}
1810
1811template <
1812 typename ExecSpace, bool init, typename TData,
1813 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1814 Enable = true>
1815inline void linfnormKernel(const size_t nsize, const TData *x, TData *out,
1816 const unsigned int streamID = 0)
1817{
1818 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1819 const unsigned int gridSize =
1821
1822#if defined(NEKTAR_ENABLE_CUDA)
1823 auto stream = CUDAStream::GetInstance(streamID);
1824#elif defined(NEKTAR_ENABLE_HIP)
1825 auto stream = HIPStream::GetInstance(streamID);
1826#endif
1827
1828 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1829 {
1830 deviceMalloc(&internalMemoryBufferMap[streamID],
1831 internalReductionBufferSize, streamID);
1832 }
1833
1834 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1835 reduceKernel<true, ReduceOp::AbsMax, IdentityOp>
1836 <<<gridSize, blockSize, 0, stream>>>(nsize, buffer, x);
1838 reduceKernel<init, ReduceOp::AbsMax, IdentityOp>
1839 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1841}
1842
1843template <
1844 typename ExecSpace, bool init, typename TData,
1845 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
1846 Enable = true>
1847inline void linfnormKernel(const size_t nsize, const uint8_t *mask,
1848 const TData *x, TData *out,
1849 const unsigned int streamID = 0)
1850{
1851 const unsigned int blockSize = NektarSpaces::Device::reductionBlockSize();
1852 const unsigned int gridSize =
1854
1855#if defined(NEKTAR_ENABLE_CUDA)
1856 auto stream = CUDAStream::GetInstance(streamID);
1857#elif defined(NEKTAR_ENABLE_HIP)
1858 auto stream = HIPStream::GetInstance(streamID);
1859#endif
1860
1861 if (internalMemoryBufferMap.find(streamID) == internalMemoryBufferMap.end())
1862 {
1863 deviceMalloc(&internalMemoryBufferMap[streamID],
1864 internalReductionBufferSize, streamID);
1865 }
1866
1867 TData *buffer = (TData *)internalMemoryBufferMap[streamID];
1868 reduceKernel<true, ReduceOp::AbsMax, IdentityOp>
1869 <<<gridSize, blockSize, 0, stream>>>(nsize, mask, buffer, x);
1871 reduceKernel<init, ReduceOp::AbsMax, IdentityOp>
1872 <<<1, blockSize, 0, stream>>>(gridSize, out, buffer);
1874}
1875
1876} // namespace Nektar::Math
1877
1878#endif
#define NEK_DEVICE_INLINE
Definition Backends.hpp:283
#define NEK_HOSTDEVICE_INLINE
Definition Backends.hpp:268
#define CHECK_LAST_HIPCUDA_ERROR()
static cudaStream_t & GetInstance(unsigned int id)
static hipStream_t & GetInstance(unsigned int id)
Definition HIPStream.hpp:85
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
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out
std::vector< double > d(NPUPPER *NPUPPER)
void deviceMemset(TData *dst, const int val, const size_t size, const unsigned int streamID)
Array< OneD, DataType > operator+(const Array< OneD, DataType > &lhs, typename Array< OneD, DataType >::size_type offset)
NekVector< DataType > operator*(const NekMatrix< LhsDataType, MatrixType > &lhs, const NekVector< DataType > &rhs)
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 warpSize
Definition Backends.hpp:143
static constexpr unsigned int reductionGridSize(const size_t n)
Definition Backends.hpp:156