Nektar++
Loading...
Searching...
No Matches
Backends.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Backends.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
39
40#include <algorithm>
41#include <type_traits>
42
43#include <float.h>
44#include <iostream>
45#include <limits.h>
46#include <string>
47#include <unordered_map>
48#include <utility>
49
50#if defined(_MSC_VER)
51#undef max
52#undef min
53#endif
54
55#if defined(NEKTAR_ENABLE_CUDA)
57#elif defined(NEKTAR_ENABLE_HIP)
59#elif defined(NEKTAR_ENABLE_SYCL)
61#endif
62
63namespace Nektar
64{
65
66// Largest number of values one parallel_reduce of several values combines.
67constexpr unsigned int internalReductionMaxValues = 12;
68
69#if defined(NEKTAR_ENABLE_DEVICE)
70extern std::unordered_map<unsigned int, void *> internalMemoryBufferMap;
71extern void *internalDeviceBuffer;
72extern void *internalHostBuffer;
73extern unsigned int internalMaxDataSizeByte;
74// Bytes of each stream's reduction scratch in internalMemoryBufferMap:
75// internalReductionMaxValues partial results of double per thread block of the
76// largest reduction grid.
77extern unsigned int internalReductionBufferSize;
78#endif
79
80namespace NektarSpaces
81{
82
83// Memory space.
84// Used to refer to any data in host memory.
86{
87};
88#if defined(NEKTAR_ENABLE_DEVICE)
89// Used to refer to any data in device memory.
90struct DeviceSpace
91{
92};
93#else
94// No specific GPU so the device is the host.
96#endif
97
98// Execution space.
99struct Serial
100{
101 static inline const std::string name = "Serial";
103};
104
105struct AVX
106{
107 static inline const std::string name = "AVX";
109};
110
111struct Device
112{
113 static inline const std::string name = "Device";
115#if defined(NEKTAR_ENABLE_CUDA) || defined(SYCL_ENABLE_CUDA)
116 static constexpr unsigned int defaultBlockSize = 256u;
117 static constexpr unsigned int maximumBlockSize = 1024u;
118 static constexpr unsigned int warpSize = 32u;
119#elif defined(NEKTAR_ENABLE_HIP) || defined(SYCL_ENABLE_HIP)
120 static constexpr unsigned int defaultBlockSize = 256u;
121 static constexpr unsigned int maximumBlockSize = 1024u;
122 static constexpr unsigned int warpSize = 64u;
123#elif defined(SYCL_ENABLE_INTEL)
124 static constexpr unsigned int defaultBlockSize = 128u;
125 static constexpr unsigned int maximumBlockSize = 1024u;
126 static constexpr unsigned int warpSize = 32u;
127#elif defined(SYCL_ENABLE_CPU)
128 static constexpr unsigned int defaultBlockSize = 256u;
129 static constexpr unsigned int maximumBlockSize = 256u;
130#if defined(__ADAPTIVECPP__) || defined(__DPCPP_COMPILER_NATIVE_CPU)
131 static constexpr unsigned int warpSize = 1u;
132#elif defined(__DPCPP_COMPILER)
133 static constexpr unsigned int warpSize = 8u;
134#elif defined(NEKTAR_USE_SIMSYCL)
135 // SimSYCL simulates a sub-group of 32 by default.
136 static constexpr unsigned int warpSize = 32u;
137#else
138 static constexpr unsigned int warpSize = 1u;
139#endif
140#else
141 static constexpr unsigned int defaultBlockSize = 1u;
142 static constexpr unsigned int maximumBlockSize = 1u;
143 static constexpr unsigned int warpSize = 1u;
144#endif
145
146 // Threads per block of a reduction.
147 static constexpr unsigned int reductionBlockSize()
148 {
149 return defaultBlockSize;
150 }
151
152 // Thread blocks of reductionBlockSize() threads for the first stage of a
153 // reduction over n values: one value per thread, at least one block and at
154 // most maximumBlockSize, the partial sums internalReductionBufferSize
155 // holds.
156 static constexpr unsigned int reductionGridSize(const size_t n)
157 {
158 constexpr unsigned int blockSize = reductionBlockSize();
159 return static_cast<unsigned int>(std::min<size_t>(
160 std::max<size_t>((n + blockSize - 1u) / blockSize, 1u),
162 }
163};
164
165#if defined(__ADAPTIVECPP__)
166#define SYCL_SUBGROUP_SIZE(x)
167#elif defined(__DPCPP_COMPILER)
168#define SYCL_SUBGROUP_SIZE(x) [[sycl::reqd_sub_group_size(x)]]
169#else
170#define SYCL_SUBGROUP_SIZE(x)
171#endif
172
173// Host memory alignment
174#if defined(NEKTAR_ENABLE_SIMD)
175static constexpr size_t host_memory_alignment =
177#else
178static constexpr size_t host_memory_alignment =
179 __STDCPP_DEFAULT_NEW_ALIGNMENT__;
180#endif
181
182// Vector width
183template <typename ExecSpace, typename TData> struct vector_width
184{
185};
186
187template <typename TData> struct vector_width<Serial, TData>
188{
189 static constexpr unsigned int value = 1u;
190};
191
192template <typename TData> struct vector_width<AVX, TData>
193{
194 static constexpr unsigned int value = tinysimd::simd<TData>::width;
195};
196
197template <typename TData> struct vector_width<Device, TData>
198{
199#if defined(NEKTAR_ENABLE_CUDA) || defined(SYCL_ENABLE_CUDA) || \
200 defined(NEKTAR_ENABLE_HIP) || defined(SYCL_ENABLE_HIP) || \
201 defined(SYCL_ENABLE_INTEL)
202 static_assert(
204 "AVX/Device back-ends interoperability requires device vector width "
205 "(warpsize) to be integer multiple of SIMD vector width");
206#endif
207 static constexpr unsigned int value = Device::warpSize;
208};
209
210template <typename TData> struct max_vector_width
211{
212 // Use maximum vector width for back-ends interoperability.
213 static constexpr unsigned int value = std::max(
215};
216
217template <typename TData>
218static unsigned int GetVectorWidth(const std::string &execName)
219{
220 if (execName == "Serial")
221 {
223 }
224 else if (execName == "AVX")
225 {
227 }
228 else if (execName == "Device")
229 {
231 }
232 else
233 {
234 return 0;
235 }
236}
237
238} // namespace NektarSpaces
239
240#if defined(__CUDACC__) || defined(__NEK_HIPCC__) || defined(NEKTAR_ENABLE_SYCL)
241#define DEVICE_COMPILE_ONLY
242#endif
243
244// NEK_RESTRICT
245#if defined(NEKTAR_ENABLE_CUDA) && defined(DEVICE_COMPILE_ONLY)
246#define NEK_RESTRICT __restrict__
247#elif defined(NEKTAR_ENABLE_HIP) && defined(DEVICE_COMPILE_ONLY)
248#define NEK_RESTRICT __restrict__
249#elif defined(NEKTAR_ENABLE_SYCL)
250#define NEK_RESTRICT __restrict__
251#elif defined(_MSC_VER)
252#define NEK_RESTRICT __restrict
253#else
254#define NEK_RESTRICT __restrict__
255#endif
256
257// NEK_HOSTDEVICE_INLINE
258// Used to define a generic function that can be used on both the
259// host or the dvice . All generic functions must be prefixed by the
260// NEK_HOSTDEVICE_INLINE decorator.
261#if defined(NEKTAR_ENABLE_CUDA) && defined(DEVICE_COMPILE_ONLY)
262#define NEK_HOSTDEVICE_INLINE __host__ __device__ __forceinline__
263#elif defined(NEKTAR_ENABLE_HIP) && defined(DEVICE_COMPILE_ONLY)
264#define NEK_HOSTDEVICE_INLINE __host__ __device__ __forceinline__
265#elif defined(NEKTAR_ENABLE_SYCL)
266#define NEK_HOSTDEVICE_INLINE NEK_FORCE_INLINE
267#else
268#define NEK_HOSTDEVICE_INLINE NEK_FORCE_INLINE
269#endif
270
271// NEK_DEVICE_INLINE
272// Used to define a device function (e.g. a function launched
273// from a kernel function and executing on the device). All
274// device functions must be prefixed by the NEK_DEVICE_INLINE
275// decorator.
276#if defined(NEKTAR_ENABLE_CUDA) && defined(DEVICE_COMPILE_ONLY)
277#define NEK_DEVICE_INLINE __device__ __forceinline__
278#elif defined(NEKTAR_ENABLE_HIP) && defined(DEVICE_COMPILE_ONLY)
279#define NEK_DEVICE_INLINE __device__ __forceinline__
280#elif defined(NEKTAR_ENABLE_SYCL)
281#define NEK_DEVICE_INLINE NEK_FORCE_INLINE
282#else
283#define NEK_DEVICE_INLINE NEK_FORCE_INLINE
284#endif
285
286// NEK_DEVICE_KERNEL
287// Used to define a kernel function (e.g. a function launched
288// from the host and executing on the device). All kernel
289// functions must be prefixed by the NEK_DEVICE_KERNEL decorator.
290#if defined(NEKTAR_ENABLE_CUDA) && defined(DEVICE_COMPILE_ONLY)
291#define NEK_DEVICE_KERNEL __global__
292#elif defined(NEKTAR_ENABLE_HIP) && defined(DEVICE_COMPILE_ONLY)
293#define NEK_DEVICE_KERNEL __global__
294#elif defined(NEKTAR_ENABLE_SYCL)
295#define NEK_DEVICE_KERNEL NEK_FORCE_INLINE
296#else
297#define NEK_DEVICE_KERNEL NEK_FORCE_INLINE
298#endif
299
300template <typename TData> std::string DataTypeToString(void)
301{
302 if constexpr (std::is_same_v<TData, float>)
303 {
304 return "float";
305 }
306 else if constexpr (std::is_same_v<TData, double>)
307 {
308 return "double";
309 }
310}
311
312// const_if metafunction return "const T" type if B = true and "T" type
313// otherwise.
314template <bool B, typename TData = void> struct const_if
315{
316 typedef TData type;
317};
318
319template <class TData> struct const_if<true, TData>
320{
321 typedef const TData type;
322};
323
324template <bool B, typename TData> struct data_type_if
325{
326 typedef TData type;
327};
328
329template <typename TData> struct data_type_if<true, TData>
330{
332};
333
334template <bool B, typename TData> struct simd_type_if
335{
337};
338
339template <typename TData> struct simd_type_if<true, TData>
340{
342};
343
344/**
345 * @brief @p a where @p m holds, and @p b elsewhere.
346 *
347 * For a scalar type @p m is the bool of a comparison and this is the ternary;
348 * for a SIMD type it is the mask of a comparison, and each lane is chosen on
349 * its own (tinysimd::select). Both @p a and @p b are evaluated either way, so
350 * code that needs only one on a scalar type branches instead.
351 */
352template <typename TMask, typename TData>
353NEK_HOSTDEVICE_INLINE TData Select(const TMask &m, const TData &a,
354 const TData &b)
355{
356 if constexpr (std::is_arithmetic_v<TData>)
357 {
358 return m ? a : b;
359 }
360 else
361 {
362 return select(m, a, b);
363 }
364}
365
366[[maybe_unused]] static inline void nekSetDevice(
367 [[maybe_unused]] unsigned int device_rank)
368{
369#if defined(NEKTAR_ENABLE_CUDA)
370 CHECK_HIPCUDA_ERROR(cudaSetDevice(device_rank));
371#elif defined(NEKTAR_ENABLE_HIP)
372 CHECK_HIPCUDA_ERROR(hipSetDevice(device_rank));
373#elif defined(NEKTAR_ENABLE_SYCL)
374 internalSYCLDeviceId = device_rank;
375#else
376 // Do nothing
377#endif
378}
379
380[[maybe_unused]] static inline unsigned int nekGetDevice()
381{
382#if defined(NEKTAR_ENABLE_CUDA)
383 int device_rank = 0;
384 CHECK_HIPCUDA_ERROR(cudaGetDevice(&device_rank));
385 return device_rank;
386#elif defined(NEKTAR_ENABLE_HIP)
387 int device_rank = 0;
388 CHECK_HIPCUDA_ERROR(hipGetDevice(&device_rank));
389 return device_rank;
390#elif defined(NEKTAR_ENABLE_SYCL)
392#else
393 return 0;
394#endif
395}
396
397[[maybe_unused]] static inline unsigned int nekGetNumDevice()
398{
399 int num_device = 0;
400#if defined(NEKTAR_ENABLE_CUDA)
401 CHECK_HIPCUDA_ERROR(cudaGetDeviceCount(&num_device));
402#elif defined(NEKTAR_ENABLE_HIP)
403 CHECK_HIPCUDA_ERROR(hipGetDeviceCount(&num_device));
404#elif defined(SYCL_ENABLE_CUDA) || defined(SYCL_ENABLE_HIP) || \
405 defined(SYCL_ENABLE_INTEL)
406 num_device = sycl::device::get_devices(sycl::info::device_type::gpu).size();
407#elif defined(NEKTAR_USE_SIMSYCL)
408 num_device = 1;
409#endif
410 return num_device;
411}
412
413[[maybe_unused]] static inline void nekDeviceSynchronize(void)
414{
415#if defined(NEKTAR_ENABLE_CUDA)
416 CHECK_HIPCUDA_ERROR(cudaDeviceSynchronize());
417#elif defined(NEKTAR_ENABLE_HIP)
418 CHECK_HIPCUDA_ERROR(hipDeviceSynchronize());
419#elif defined(NEKTAR_ENABLE_SYCL)
420 auto &Queues = SYCLQueue::GetAllInstances();
421 for (auto &item : Queues)
422 {
423 item.second->wait();
424 }
425#endif
426}
427
428[[maybe_unused]] static inline void nekStreamSynchronize(
429 [[maybe_unused]] const unsigned int streamID)
430{
431#if defined(NEKTAR_ENABLE_CUDA)
432 auto stream = CUDAStream::GetInstance(streamID);
433 CHECK_HIPCUDA_ERROR(cudaStreamSynchronize(stream));
434#elif defined(NEKTAR_ENABLE_HIP)
435 auto stream = HIPStream::GetInstance(streamID);
436 CHECK_HIPCUDA_ERROR(hipStreamSynchronize(stream));
437#elif defined(NEKTAR_ENABLE_SYCL)
438 SYCLQueue::GetInstance(streamID).wait();
439#endif
440}
441
442template <
443 typename ExecSpace,
444 std::enable_if_t<!std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
445 Enable = true>
446static void SetStreamDependencies([[maybe_unused]] unsigned int streamID,
447 [[maybe_unused]] unsigned int eventID)
448{
449}
450
451template <
452 typename ExecSpace,
453 std::enable_if_t<!std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
454 Enable = true>
456 [[maybe_unused]] unsigned int streamID,
457 [[maybe_unused]] std::vector<unsigned int> &eventIDs)
458{
459}
460
461template <
462 typename ExecSpace,
463 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
464 Enable = true>
465static void SetStreamDependencies([[maybe_unused]] unsigned int streamID,
466 [[maybe_unused]] unsigned int eventID)
467{
468#if defined(NEKTAR_ENABLE_CUDA)
469 if (streamID != eventID)
470 {
471 auto stream = CUDAStream::GetInstance(streamID);
472 auto e = CUDAStream::GetEvent(eventID);
473 if (e != nullptr)
474 {
475 CHECK_HIPCUDA_ERROR(cudaStreamWaitEvent(stream, e));
476 }
477 }
478#elif defined(NEKTAR_ENABLE_HIP)
479 if (streamID != eventID)
480 {
481 auto stream = HIPStream::GetInstance(streamID);
482 auto e = HIPStream::GetEvent(eventID);
483 if (e != nullptr)
484 {
485 CHECK_HIPCUDA_ERROR(hipStreamWaitEvent(stream, e));
486 }
487 }
488#elif defined(NEKTAR_ENABLE_SYCL)
489 if (streamID != eventID)
490 {
491 [[maybe_unused]] sycl::event event = SYCLQueue::GetEvent(eventID);
492#if defined(__ADAPTIVECPP__)
493 sycl::event e =
494 SYCLQueue::GetInstance(streamID).submit([&](sycl::handler &cgh) {
495 cgh.depends_on(event);
496 cgh.AdaptiveCpp_enqueue_custom_operation(
497 [=]([[maybe_unused]] sycl::interop_handle ih) {});
498 });
499 SYCLQueue::SetEvent(streamID, e);
500#elif defined(__DPCPP_COMPILER)
501 sycl::event e = SYCLQueue::GetInstance(streamID).submit(
502 [&](sycl::handler &cgh) { cgh.ext_oneapi_barrier({event}); });
503 SYCLQueue::SetEvent(streamID, e);
504#endif
505 }
506#endif
507}
508
509template <
510 typename ExecSpace,
511 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
512 Enable = true>
513static void SetStreamDependencies(
514 [[maybe_unused]] unsigned int streamID,
515 [[maybe_unused]] std::vector<unsigned int> &eventIDs)
516{
517#if defined(NEKTAR_ENABLE_CUDA)
518 auto stream = CUDAStream::GetInstance(streamID);
519 for (auto eventID : eventIDs)
520 {
521 if (streamID != eventID)
522 {
523 auto e = CUDAStream::GetEvent(eventID);
524 if (e != nullptr)
525 {
526 CHECK_HIPCUDA_ERROR(cudaStreamWaitEvent(stream, e));
527 }
528 }
529 }
530#elif defined(NEKTAR_ENABLE_HIP)
531 auto stream = HIPStream::GetInstance(streamID);
532 for (auto eventID : eventIDs)
533 {
534 if (streamID != eventID)
535 {
536 auto e = HIPStream::GetEvent(eventID);
537 if (e != nullptr)
538 {
539 CHECK_HIPCUDA_ERROR(hipStreamWaitEvent(stream, e));
540 }
541 }
542 }
543#elif defined(NEKTAR_ENABLE_SYCL)
544 std::vector<sycl::event> events;
545 for (auto eventID : eventIDs)
546 {
547 if (streamID != eventID)
548 {
549 events.push_back(SYCLQueue::GetEvent(eventID));
550 }
551 }
552#if defined(__ADAPTIVECPP__)
553 sycl::event e =
554 SYCLQueue::GetInstance(streamID).submit([&](sycl::handler &cgh) {
555 cgh.depends_on(events);
556 cgh.AdaptiveCpp_enqueue_custom_operation(
557 [=]([[maybe_unused]] sycl::interop_handle ih) {});
558 });
559 SYCLQueue::SetEvent(streamID, e);
560#elif defined(__DPCPP_COMPILER)
561 sycl::event e = SYCLQueue::GetInstance(streamID).submit(
562 [&](sycl::handler &cgh) { cgh.ext_oneapi_barrier(events); });
563 SYCLQueue::SetEvent(streamID, e);
564#endif
565#endif
566}
567
568/// Record the current point of stream @p streamID for SetStreamDependencies.
569/// SYCL queues record their last submission themselves.
570template <typename ExecSpace>
571static void RecordStreamEvent([[maybe_unused]] const unsigned int streamID)
572{
573 if constexpr (std::is_same_v<ExecSpace, NektarSpaces::Device>)
574 {
575#if defined(NEKTAR_ENABLE_CUDA)
576 CUDAStream::RecordEvent(streamID);
577#elif defined(NEKTAR_ENABLE_HIP)
578 HIPStream::RecordEvent(streamID);
579#endif
580 }
581}
582
583/// Whether stream @p streamID has been created, and so may hold work.
584template <typename ExecSpace>
585static bool StreamExists([[maybe_unused]] const unsigned int streamID)
586{
587 if constexpr (std::is_same_v<ExecSpace, NektarSpaces::Device>)
588 {
589#if defined(NEKTAR_ENABLE_CUDA)
590 return CUDAStream::GetAllInstances().count(streamID) > 0;
591#elif defined(NEKTAR_ENABLE_HIP)
592 return HIPStream::GetAllInstances().count(streamID) > 0;
593#elif defined(NEKTAR_ENABLE_SYCL)
594 return SYCLQueue::GetAllInstances().count(streamID) > 0;
595#endif
596 }
597 return false;
598}
599
600/**
601 * @brief Order the work queued next on stream @p streamID after the work
602 * already queued on each of @p streamIDs.
603 *
604 * A stream never created holds no work and is skipped, as is, on CUDA and
605 * HIP, a join onto the default stream, which already orders against the
606 * numbered streams, created blocking. SYCL on the CPU maps every id to one
607 * in-order queue, and the host runs in submission order: neither has
608 * anything to order.
609 */
610template <typename ExecSpace>
611static void JoinStreams(
612 [[maybe_unused]] const unsigned int streamID,
613 [[maybe_unused]] const std::vector<unsigned int> &streamIDs)
614{
615 if constexpr (std::is_same_v<ExecSpace, NektarSpaces::Device>)
616 {
617#if defined(NEKTAR_ENABLE_CUDA) || defined(NEKTAR_ENABLE_HIP)
618 if (streamID == 0)
619 {
620 return;
621 }
622
623 for (const auto id : streamIDs)
624 {
625 if (id != streamID && StreamExists<ExecSpace>(id))
626 {
627 RecordStreamEvent<ExecSpace>(id);
628 SetStreamDependencies<ExecSpace>(streamID, id);
629 }
630 }
631#elif defined(NEKTAR_ENABLE_SYCL) && !defined(SYCL_ENABLE_CPU)
632 // One barrier on the last submission of every queue holding work.
633 std::vector<unsigned int> waitOn;
634 for (const auto id : streamIDs)
635 {
636 if (id != streamID && StreamExists<ExecSpace>(id))
637 {
638 waitOn.push_back(id);
639 }
640 }
641
642 if (!waitOn.empty())
643 {
644 SetStreamDependencies<ExecSpace>(streamID, waitOn);
645 }
646#endif
647 }
648}
649
650/// Order the work queued next on stream @p streamID after the work already
651/// queued on stream @p producerID; JoinStreams() with one stream.
652template <typename ExecSpace>
653static void JoinStreams(const unsigned int streamID,
654 const unsigned int producerID)
655{
656 JoinStreams<ExecSpace>(streamID, std::vector<unsigned int>{producerID});
657}
658
659/**
660 * @brief Order the work queued next on each of @p streamIDs after the work
661 * already queued on stream @p streamID.
662 *
663 * Skipped under the same conditions as JoinStreams(): nothing is ordered
664 * after a stream never created, or, on CUDA and HIP, after the default
665 * stream.
666 */
667template <typename ExecSpace>
668static void ReleaseStreams(
669 [[maybe_unused]] const unsigned int streamID,
670 [[maybe_unused]] const std::vector<unsigned int> &streamIDs)
671{
672 if constexpr (std::is_same_v<ExecSpace, NektarSpaces::Device>)
673 {
674#if defined(NEKTAR_ENABLE_CUDA) || defined(NEKTAR_ENABLE_HIP)
675 if (streamID == 0 || !StreamExists<ExecSpace>(streamID))
676 {
677 return;
678 }
679
680 bool recorded = false;
681 for (const auto id : streamIDs)
682 {
683 if (id == streamID)
684 {
685 continue;
686 }
687
688 if (!recorded)
689 {
690 RecordStreamEvent<ExecSpace>(streamID);
691 recorded = true;
692 }
693
694 SetStreamDependencies<ExecSpace>(id, streamID);
695 }
696#elif defined(NEKTAR_ENABLE_SYCL) && !defined(SYCL_ENABLE_CPU)
697 if (!StreamExists<ExecSpace>(streamID))
698 {
699 return;
700 }
701
702 for (const auto id : streamIDs)
703 {
704 if (id != streamID)
705 {
706 SetStreamDependencies<ExecSpace>(id, streamID);
707 }
708 }
709#endif
710 }
711}
712
713} // namespace Nektar
#define NEK_HOSTDEVICE_INLINE
Definition Backends.hpp:268
#define CHECK_HIPCUDA_ERROR(err)
static std::unordered_map< unsigned int, cudaStream_t > & GetAllInstances(void)
static void RecordEvent(unsigned int id)
static cudaEvent_t GetEvent(unsigned int id)
static cudaStream_t & GetInstance(unsigned int id)
static hipStream_t & GetInstance(unsigned int id)
Definition HIPStream.hpp:85
static void RecordEvent(unsigned int id)
static hipEvent_t GetEvent(unsigned int id)
static std::unordered_map< unsigned int, hipStream_t > & GetAllInstances(void)
static std::unordered_map< unsigned int, sycl::queue * > & GetAllInstances(void)
static sycl::queue & GetInstance(unsigned int id)
Definition SYCLQueue.hpp:55
static void SetEvent(unsigned int id, sycl::event &e)
static sycl::event & GetEvent(unsigned int id)
HostSpace DeviceSpace
Definition Backends.hpp:95
static unsigned int GetVectorWidth(const std::string &execName)
Definition Backends.hpp:218
static constexpr size_t host_memory_alignment
Definition Backends.hpp:178
static unsigned int nekGetNumDevice()
Definition Backends.hpp:397
static unsigned int nekGetDevice()
Definition Backends.hpp:380
static void SetStreamDependencies(unsigned int streamID, unsigned int eventID)
Definition Backends.hpp:446
static void nekDeviceSynchronize(void)
Definition Backends.hpp:413
static void nekStreamSynchronize(const unsigned int streamID)
Definition Backends.hpp:428
unsigned int internalSYCLDeviceId
Definition SYCLQueue.cpp:40
NEK_HOSTDEVICE_INLINE TData Select(const TMask &m, const TData &a, const TData &b)
a where m holds, and b elsewhere.
Definition Backends.hpp:353
static void nekSetDevice(unsigned int device_rank)
Definition Backends.hpp:366
static bool StreamExists(const unsigned int streamID)
Whether stream streamID has been created, and so may hold work.
Definition Backends.hpp:585
static void ReleaseStreams(const unsigned int streamID, const std::vector< unsigned int > &streamIDs)
Order the work queued next on each of streamIDs after the work already queued on stream streamID.
Definition Backends.hpp:668
static void RecordStreamEvent(const unsigned int streamID)
Record the current point of stream streamID for SetStreamDependencies. SYCL queues record their last ...
Definition Backends.hpp:571
std::string DataTypeToString(void)
Definition Backends.hpp:300
static void JoinStreams(const unsigned int streamID, const std::vector< unsigned int > &streamIDs)
Order the work queued next on stream streamID after the work already queued on each of streamIDs.
Definition Backends.hpp:611
constexpr unsigned int internalReductionMaxValues
Definition Backends.hpp:67
typename abi< ScalarType, width >::type simd
Definition tinysimd.hpp:138
scalarT< double > select(scalarMask m, scalarT< double > a, scalarT< double > b)
Definition scalar.hpp:462
static const std::string name
Definition Backends.hpp:107
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
static const std::string name
Definition Backends.hpp:113
static const std::string name
Definition Backends.hpp:101
static constexpr unsigned int value
Definition Backends.hpp:213
tinysimd::simd< TData > type
Definition Backends.hpp:331
tinysimd::simd< TData > type
Definition Backends.hpp:341
tinysimd::scalarT< TData > type
Definition Backends.hpp:336