Interface Documentation
Version: invalid
kernel_interface.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #if !defined(__FLECSI_PRIVATE__)
19 #error Do not include this file directly!
20 #endif
21 
22 #if !defined(FLECSI_ENABLE_KOKKOS)
23 #error FLECSI_ENABLE_KOKKOS not defined! This file depends on Kokkos!
24 #endif
25 
26 #include <kokkos.h>
27 
28 #include <string>
29 
30 namespace flecsi {
31 namespace exec {
32 
40 template<typename ITERATOR, typename LAMBDA>
41 parallel_for(ITERATOR const iterator,
42  LAMBDA const lambda,
43  std::string const & name = "") {
44 
45  struct functor_t {
46 
47  functor_t(ITERATOR & iterator, LAMBDA & lambda)
48  : iterator_(iterator), lambda_(lambda) {}
49 
50  KOKKOS_INLINE_FUNCTION void operator()(int i) const {
51  lambda(iterator[i]);
52  } // operator()
53 
54  private:
55  ITERATOR & iterator_;
56  LAMBDA & lambda_;
57 
58  }; // struct functor_t
59 
60  Kokkos::parallel_for(name, iterator.size(), functor_t{iterator, lambda});
61 
62 } // parallel_for
63 
69 // We will need this when/if we begin to customize behavior based on
70 // ITERATOR type.
71 // template<typename ITERATOR> struct forall {};
72 
73 template<typename ITERATOR>
74 struct forall {
75 
83  forall(ITERATOR iterator, std::string const & name = "")
84  : iterator_(iterator), name_(name) {}
85 
92  template<typename LAMBDA>
93  struct functor {
94 
95  functor(ITERATOR iterator, LAMBDA lambda, std::string const & name)
96  : iterator_(iterator), lambda_(lambda), name_(name) {}
97 
98  void operator()(int64_t i) const {
99  lambda_(iterator_[i]);
100  } // operator()
101 
102  private:
103  ITERATOR iterator_;
104  LAMBDA lambda_;
105  std::string & const name_;
106 
107  }; // struct functor_t
108 
116  template<typename CALLABLE>
117  void operator<<(CALLABLE l) {
118  Kokkos::parallel_for(
119  name_, iterator_.size(), functor_t{iterator_, lambda_});
120  } // operator<<
121 
122 private:
123  ITERATOR iterator_;
124  std::string & const name_;
125 
126 }; // struct forall
127 
128 } // namespace exec
129 } // namespace flecsi
Definition: kernel_interface.hh:74
void operator<<(CALLABLE l)
Definition: kernel_interface.hh:117
forall(ITERATOR iterator, std::string const &name="")
Definition: kernel_interface.hh:83
Definition: kernel_interface.hh:93
parallel_for(ITERATOR const iterator, LAMBDA const lambda, std::string const &name="")
Definition: kernel_interface.hh:41
Definition: control.hh:31