94#if defined(NEKTAR_ENABLE_CUDA) || defined(SYCL_ENABLE_CUDA)
96#elif defined(NEKTAR_ENABLE_HIP) || defined(SYCL_ENABLE_HIP)
98#elif defined(SYCL_ENABLE_INTEL)
111 static inline const std::string
name =
"StdMat";
124 static inline const std::string
name =
"SumFac";
139 static inline const std::string
name =
"SumFacTOP";
150 static inline const std::string
name =
"Generic";
194template <FieldState TFieldIn, FieldState TFieldOut,
typename TData>
240 template <
template <
typename>
typename TOperator>
241 static std::shared_ptr<TOperator<TData>>
Create(
242 const unsigned int block_idx,
245 const std::string &execStr,
const std::string &implStr)
247 std::string requestedKey = TOperator<TData>::name + execStr + implStr;
255 auto requestedKey0 = requestedKey;
256 requestedKey = TOperator<TData>::name + execStr +
"Generic";
260 std::stringstream msg;
261 msg <<
"No such operator: " << requestedKey0 << std::endl;
267 return std::static_pointer_cast<TOperator<TData>>(
290 this->
v_Apply(inblock, outblock);
297 this->
v_Apply(inblock, outblock);
338 template <
typename TFunc>
345 func(std::integral_constant<ShapeType, LibUtilities::Seg>{});
348 func(std::integral_constant<ShapeType, LibUtilities::Quad>{});
351 func(std::integral_constant<ShapeType, LibUtilities::Tri>{});
358 func(std::integral_constant<ShapeType, LibUtilities::Hex>{});
361 func(std::integral_constant<ShapeType, LibUtilities::Tet>{});
368 func(std::integral_constant<ShapeType, LibUtilities::Pyr>{});
375 func(std::integral_constant<ShapeType, LibUtilities::Prism>{});
396 template <
typename TFunc>
401 func(std::true_type{});
405 func(std::false_type{});
419 template <
typename TFunc>
424 func(std::false_type{});
428 func(std::true_type{});
442 template <
typename TFunc>
447 func(std::true_type{});
451 func(std::false_type{});
481#if defined(NEKTAR_ENABLE_DEVICE)
486struct DeviceKernelParameters
489 unsigned int blockSize = 0u;
491 unsigned int gridSize = 0u;
493 unsigned int shmemSize = 0u;
495 unsigned int elmtsPerBlock = 0u;
499constexpr unsigned int defaultPackingThreads = 128u;
519template <
typename Implementation,
520 unsigned int PACKING_THREADS = defaultPackingThreads>
522 [[maybe_unused]]
const unsigned int dofsPerElmt)
524 static_assert(std::is_same_v<Implementation, MultiRegions::SumFac> ||
525 std::is_same_v<Implementation, MultiRegions::SumFacTOP>,
526 "Only SumFac and SumFacTOP kernels use GetElmtsPerBlock().");
530 "PACKING_THREADS exceeds the default block size of the "
533 if constexpr (std::is_same_v<Implementation, MultiRegions::SumFac>)
542 unsigned int elmtThreads = 1u;
543 while (elmtThreads < dofsPerElmt)
549 return std::max(1u, PACKING_THREADS / elmtThreads);
562template <
typename Implementation,
563 unsigned int PACKING_THREADS = defaultPackingThreads,
566 std::integral_constant<unsigned int, DOFS>)
568 return std::integral_constant<
570 GetElmtsPerBlock<Implementation, PACKING_THREADS>(DOFS)>{};
607template <
typename Implementation>
609 [[maybe_unused]]
const unsigned int dofsPerElmt,
const size_t nelmt,
610 const unsigned int shmemSize = 0u,
const unsigned int elmtsPerBlock = 0u,
611 const unsigned int passesPerBlock = 0u,
612 [[maybe_unused]]
const unsigned int maxBlockSize =
615 static_assert(std::is_same_v<Implementation, MultiRegions::SumFac> ||
616 std::is_same_v<Implementation, MultiRegions::SumFacTOP>,
617 "Only SumFac and SumFacTOP kernels launch through "
618 "GetDeviceKernelParameters().");
619 constexpr size_t maxGridSize = 2147483647;
620 constexpr unsigned int persistentQueueFactor = 2u;
625 DeviceKernelParameters kernelParams;
627 if constexpr (std::is_same_v<Implementation, MultiRegions::SumFac>)
631 kernelParams.elmtsPerBlock =
634 "SumFac kernels take one warp of elements per block.");
637 const size_t ngroups = (
nelmt + kernelParams.elmtsPerBlock - 1u) /
638 kernelParams.elmtsPerBlock;
641 const unsigned int passes = passesPerBlock ? passesPerBlock : 1u;
644 kernelParams.blockSize = kernelParams.elmtsPerBlock;
645 kernelParams.gridSize =
static_cast<unsigned int>(
646 std::min((ngroups + passes - 1u) / passes, maxGridSize));
647 kernelParams.shmemSize = shmemSize;
649 else if constexpr (std::is_same_v<Implementation, MultiRegions::SumFacTOP>)
656 const size_t ngroups = (
nelmt + kernelParams.elmtsPerBlock - 1u) /
657 kernelParams.elmtsPerBlock;
660 const unsigned int passes =
665 unsigned int threadsPerBlock;
666 if (kernelParams.elmtsPerBlock == 1u)
668 threadsPerBlock = dofsPerElmt;
675 unsigned int elmtThreads = 1u;
676 while (elmtThreads < dofsPerElmt)
680 threadsPerBlock = kernelParams.elmtsPerBlock * elmtThreads;
684 kernelParams.blockSize =
685 std::min((threadsPerBlock + warpsize - 1u) / warpsize * warpsize,
688 GetDeviceProperties::CheckSharedMemoryUsage(shmemSize);
691 static_cast<size_t>(GetDeviceProperties::NumMultiProcessors());
693 const size_t blocksByThreads =
694 GetDeviceProperties::MaxThreadsPerMultiprocessor() /
695 kernelParams.blockSize;
697 const size_t blocksByShared =
700 : GetDeviceProperties::SharedMemoryPerMultiprocessor() /
702 const size_t residentBlocks = std::min(blocksByThreads, blocksByShared);
705 const size_t launchBlocks =
706 smCount * residentBlocks * persistentQueueFactor;
707 const size_t cappedLaunchBlocks =
708 std::max<size_t>(1u, std::min(launchBlocks, maxGridSize));
716 kernelParams.gridSize =
static_cast<unsigned int>(
717 std::min(ngroups, std::max((ngroups + passes - 1u) / passes,
718 cappedLaunchBlocks)));
719 kernelParams.shmemSize = shmemSize;
748template <
typename Implementation>
750 const size_t shmemsize)
752 constexpr size_t minOccupancyDivisor = 4u;
755 DeviceArchProperties device = arch;
756 if constexpr (!arch.known)
758 device.sharedMemoryPerBlock =
759 GetDeviceProperties::SharedMemoryPerBlock();
760 device.sharedMemoryPerMultiprocessor =
761 GetDeviceProperties::SharedMemoryPerMultiprocessor();
762 device.maxThreadsPerMultiprocessor =
static_cast<size_t>(
763 GetDeviceProperties::MaxThreadsPerMultiprocessor());
766 if constexpr (std::is_same_v<Implementation, MultiRegions::SumFac>)
768 if (shmemsize == 0 || shmemsize > device.sharedMemoryPerBlock)
776 const size_t threadsByShared =
777 device.sharedMemoryPerMultiprocessor / shmemsize *
warpsize;
779 return threadsByShared * minOccupancyDivisor >=
780 device.maxThreadsPerMultiprocessor;
783 else if constexpr (std::is_same_v<Implementation, MultiRegions::SumFacTOP>)
785 return shmemsize <= device.sharedMemoryPerBlock;
810template <
typename Implementation>
812 const size_t nelmt,
const unsigned int gridsize,
813 [[maybe_unused]]
const unsigned int elmtsPerBlock)
815 if constexpr (std::is_same_v<Implementation, MultiRegions::SumFac>)
819 else if constexpr (std::is_same_v<Implementation, MultiRegions::SumFacTOP>)
Block-level operator base class and factory machinery shared by every operator family in the MultiReg...
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Get the BlockAttributes for a given field state from an ExpList. This method basically captures ident...
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
tBasePtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
Common base class of the block-operator family interfaces: holds the block index, representative expa...
Base class of the per-family block operators: applies one element operation to every element of one b...
void operator()(LibUtilities::BlockAccessor< TData, TFieldIn > &inblock, LibUtilities::BlockAccessor< TData, TFieldOut > &outblock)
Call operator; equivalent to Apply().
static void DispatchAppendFlag(const bool append, TFunc &&func)
Call func with std::true_type if append and std::false_type otherwise.
static void ShapeSwitch(const LibUtilities::ShapeType shape, TFunc &&func)
Call func with the runtime shape as a compile-time constant, std::integral_constant<LibUtilities::Sha...
bool m_warnOnceTemplate
Set once the generated ShapeBlock switch code has warned that an element size outside the templated s...
ElmtBlockOp(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse)
Construct the interface part of a concrete block operator; called by the factory-registered creator f...
~ElmtBlockOp() override=default
static void DispatchDeformedFlag(const bool deformed, TFunc &&func)
Call func with std::true_type if deformed and std::false_type otherwise.
virtual void v_Apply(LibUtilities::BlockAccessor< TData, TFieldIn > &inblock, LibUtilities::BlockAccessor< TData, TFieldOut > &outblock)=0
Implementation hook for Apply().
static std::shared_ptr< TOperator< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create one block operator through the block-operator factory.
void Apply(LibUtilities::BlockAccessor< TData, TFieldIn > &inblock, LibUtilities::BlockAccessor< TData, TFieldOut > &outblock)
Apply the element operation to every element of the block.
static void DispatchScaleFlag(const TData scale, TFunc &&func)
Call func with std::false_type if scale is one and std::true_type otherwise.
std::shared_ptr< NekDataWarehouse > NekDataWarehouseSharedPtr
std::shared_ptr< Expansion > ExpansionSharedPtr
constexpr unsigned int warpsize
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int elmtsPerBlock
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt
static constexpr unsigned int defaultPassesPerBlock
Passes over its element groups each device thread block is assumed to make in the SumFacTOP grid-size...
constexpr DeviceArchProperties GetDeviceArchProperties()
Limits of the build's target architecture, known at compile time.
static void CheckDeviceArchProperties()
Check, once, that the device has the limits GetDeviceArchProperties() lists for the build's target ar...
Implementation tag: strategy-agnostic implementation, used by families with a single implementation (...
static const std::string name
Implementation tag: apply the operator as one dense standard-region matrix multiplied across all elem...
static const std::string name
Implementation tag: sum-factorised tensor-product evaluation with one element per vector lane.
static const std::string name
Implementation tag: sum-factorised evaluation in which the threads of one device block cooperate on a...
static const std::string name
static constexpr unsigned int defaultBlockSize
static constexpr unsigned int warpSize