Nalu
Nalu: a generalized unstructured massively parallel low Mach flow code designed to support a variety of energy applications of interest (most notably Wind ECP) built on the Sierra Toolkit and Trilinos solver Tpetra/Epetra stack. The open source BSD, clause 3 license model has been chosen for the code base. See LICENSE for more information. http://NaluCFD.org
KokkosInterface.h
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2014 Sandia Corporation. */
3 /* This software is released under the license detailed */
4 /* in the file, LICENSE, which is located in the top-level Nalu */
5 /* directory structure */
6 /*------------------------------------------------------------------------*/
7 
8 #ifndef INCLUDE_KOKKOSINTERFACE_H_
9 #define INCLUDE_KOKKOSINTERFACE_H_
10 
11 #include <stk_mesh/base/Entity.hpp>
12 #include <Kokkos_Core.hpp>
13 
14 namespace sierra {
15 namespace nalu {
16 
18 using DeviceSpace = Kokkos::DefaultExecutionSpace;
19 
20 using DeviceShmem = DeviceSpace::scratch_memory_space;
21 using DynamicScheduleType = Kokkos::Schedule<Kokkos::Dynamic>;
22 using TeamHandleType = Kokkos::TeamPolicy<DeviceSpace, DynamicScheduleType>::member_type;
23 
24 template <typename T>
25 using SharedMemView = Kokkos::View<T, Kokkos::LayoutRight, DeviceShmem, Kokkos::MemoryUnmanaged>;
26 
27 using DeviceTeamPolicy = Kokkos::TeamPolicy<DeviceSpace>;
28 using DeviceTeam = DeviceTeamPolicy::member_type;
29 
30 inline DeviceTeamPolicy get_team_policy(const size_t sz, const size_t bytes_per_team,
31  const size_t bytes_per_thread)
32 {
33  DeviceTeamPolicy policy(sz, Kokkos::AUTO);
34  return policy.set_scratch_size(0, Kokkos::PerTeam(bytes_per_team), Kokkos::PerThread(bytes_per_thread));
35 }
36 
37 inline
39 {
40  return Kokkos::subview(SharedMemView<int**>(team.team_shmem(), team.team_size(), len), team.team_rank(), Kokkos::ALL());
41 }
42 
43 inline
45 {
46  return Kokkos::subview(SharedMemView<stk::mesh::Entity**>(team.team_shmem(), team.team_size(), len), team.team_rank(), Kokkos::ALL());
47 }
48 
49 template<typename T>
51 {
52  return Kokkos::subview(SharedMemView<T**>(team.team_shmem(), team.team_size(), len), team.team_rank(), Kokkos::ALL());
53 }
54 
55 template<typename T>
56 SharedMemView<T**> get_shmem_view_2D(const TeamHandleType& team, size_t len1, size_t len2)
57 {
58  return Kokkos::subview(SharedMemView<T***>(team.team_shmem(), team.team_size(), len1, len2), team.team_rank(), Kokkos::ALL(), Kokkos::ALL());
59 }
60 
61 template<typename T>
62 SharedMemView<T***> get_shmem_view_3D(const TeamHandleType& team, size_t len1, size_t len2, size_t len3)
63 {
64  return Kokkos::subview(SharedMemView<T****>(team.team_shmem(), team.team_size(), len1, len2, len3), team.team_rank(), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL());
65 }
66 
67 template<typename SizeType, class Function>
68 void kokkos_parallel_for(const std::string& debuggingName, SizeType n, Function loop_body)
69 {
70  Kokkos::parallel_for(debuggingName, Kokkos::RangePolicy<Kokkos::Serial>(0, n), loop_body);
71 }
72 
73 template<typename SizeType, class Function, typename ReduceType>
74 void kokkos_parallel_reduce(SizeType n, Function loop_body, ReduceType& reduce, const std::string& debuggingName)
75 {
76  Kokkos::parallel_reduce(debuggingName, Kokkos::RangePolicy<Kokkos::Serial>(0, n), loop_body, reduce);
77 }
78 
79 }
80 }
81 
82 #endif /* INCLUDE_KOKKOSINTERFACE_H_ */
SharedMemView< stk::mesh::Entity * > get_entity_shmem_view_1D(const TeamHandleType &team, size_t len)
Definition: KokkosInterface.h:44
Kokkos::HostSpace HostSpace
Definition: KokkosInterface.h:17
DeviceTeamPolicy::member_type DeviceTeam
Definition: KokkosInterface.h:28
Definition: ABLForcingAlgorithm.C:26
Kokkos::DefaultExecutionSpace DeviceSpace
Definition: KokkosInterface.h:18
SharedMemView< int * > get_int_shmem_view_1D(const TeamHandleType &team, size_t len)
Definition: KokkosInterface.h:38
void kokkos_parallel_for(const std::string &debuggingName, SizeType n, Function loop_body)
Definition: KokkosInterface.h:68
Kokkos::Schedule< Kokkos::Dynamic > DynamicScheduleType
Definition: KokkosInterface.h:21
SharedMemView< T * > get_shmem_view_1D(const TeamHandleType &team, size_t len)
Definition: KokkosInterface.h:50
Kokkos::TeamPolicy< DeviceSpace > DeviceTeamPolicy
Definition: KokkosInterface.h:27
void kokkos_parallel_reduce(SizeType n, Function loop_body, ReduceType &reduce, const std::string &debuggingName)
Definition: KokkosInterface.h:74
DeviceTeamPolicy get_team_policy(const size_t sz, const size_t bytes_per_team, const size_t bytes_per_thread)
Definition: KokkosInterface.h:30
Kokkos::View< T, Kokkos::LayoutRight, DeviceShmem, Kokkos::MemoryUnmanaged > SharedMemView
Definition: KokkosInterface.h:25
SharedMemView< T ** > get_shmem_view_2D(const TeamHandleType &team, size_t len1, size_t len2)
Definition: KokkosInterface.h:56
Kokkos::TeamPolicy< DeviceSpace, DynamicScheduleType >::member_type TeamHandleType
Definition: KokkosInterface.h:22
DeviceSpace::scratch_memory_space DeviceShmem
Definition: KokkosInterface.h:20
SharedMemView< T *** > get_shmem_view_3D(const TeamHandleType &team, size_t len1, size_t len2, size_t len3)
Definition: KokkosInterface.h:62