44 #if !defined(__CUDACC__) 53 template <
class View1,
class View2>
54 Kokkos::View< typename Kokkos::ViewFactory<View1,View2>::value_type*,
55 typename View1::device_type >
59 typedef typename ViewFac::value_type value_type;
60 typedef typename View1::device_type device_type;
61 typedef typename View1::size_type size_type;
62 typedef Kokkos::View<value_type*,device_type> ViewTmp;
64 static_assert(
unsigned(View1::rank) == 2,
"" );
65 static_assert(
unsigned(View2::rank) == 1,
"" );
67 const size_type m = v1.extent(0);
68 const size_type
n = v1.extent(1);
69 ViewTmp vtmp = ViewFac::template create_view<ViewTmp>(v1,v2,
"tmp",m);
71 Kokkos::parallel_for(m, KOKKOS_LAMBDA (
const size_type i) {
73 for (size_type j=0; j<
n; ++j)
81 #if defined(HAVE_SACADO_KOKKOSCONTAINERS) 84 template <
class View1,
class View2>
85 Kokkos::DynRankView< typename Kokkos::ViewFactory<View1,View2>::value_type,
86 typename View1::device_type >
87 my_func_dynamic(
const View1& v1,
const View2& v2)
90 typedef typename ViewFac::value_type value_type;
91 typedef typename View1::device_type device_type;
92 typedef typename View1::size_type size_type;
93 typedef Kokkos::DynRankView<value_type,device_type> ViewTmp;
98 const size_type m = v1.extent(0);
99 const size_type
n = v1.extent(1);
100 ViewTmp vtmp = ViewFac::template create_view<ViewTmp>(v1,v2,
"tmp",m);
102 Kokkos::parallel_for(m, KOKKOS_LAMBDA (
const size_type i) {
104 for (size_type j=0; j<
n; ++j)
115 int main(
int argc,
char* argv[]) {
117 #if !defined(__CUDACC__) 119 typedef Kokkos::DefaultExecutionSpace execution_space;
121 Kokkos::initialize(argc, argv);
125 const size_t deriv_dim = 1;
131 Kokkos::View<double**,execution_space> v1(
"v1",m,
n);
132 Kokkos::View<double* ,execution_space> v2(
"v2",
n);
134 Kokkos::deep_copy(v1, 2.0);
135 Kokkos::deep_copy(v2, 3.0);
139 std::cout <<
"v3 = " << std::endl;
140 for (
size_t i=0; i<m; ++i) {
141 std::cout <<
"\t" << v3(i) << std::endl;
146 Kokkos::View<FadType*,execution_space> v2_fad(
"v2_fad",
n,deriv_dim+1);
147 Kokkos::deep_copy(v2_fad,
FadType(deriv_dim, 0, 3.0));
149 auto v3_fad =
my_func(v1,v2_fad);
151 std::cout <<
"v3_fad = " << std::endl;
152 for (
size_t i=0; i<m; ++i) {
153 std::cout <<
"\t" << v3_fad(i) << std::endl;
158 #if defined(HAVE_SACADO_KOKKOSCONTAINERS) 163 Kokkos::DynRankView<double,execution_space> v1(
"v1",m,
n);
164 Kokkos::DynRankView<double,execution_space> v2(
"v2",
n);
166 Kokkos::deep_copy(v1, 2.0);
167 Kokkos::deep_copy(v2, 3.0);
169 auto v3 = my_func_dynamic(v1,v2);
171 std::cout <<
"v3 = " << std::endl;
172 for (
size_t i=0; i<m; ++i) {
173 std::cout <<
"\t" << v3(i) << std::endl;
178 Kokkos::DynRankView<FadType,execution_space> v2_fad(
"v2_fad",
n,deriv_dim+1);
179 Kokkos::deep_copy(v2_fad,
FadType(deriv_dim, 0, 3.0));
181 auto v3_fad = my_func_dynamic(v1,v2_fad);
183 std::cout <<
"v3_fad = " << std::endl;
184 for (
size_t i=0; i<m; ++i) {
185 std::cout <<
"\t" << v3_fad(i) << std::endl;
Kokkos::View< typename Kokkos::ViewFactory< View1, View2 >::value_type *, typename View1::device_type > my_func(const View1 &v1, const View2 &v2)
Sacado::Fad::DFad< double > FadType
int main(int argc, char *argv[])
#define TEUCHOS_ASSERT(assertion_test)