44 #if !defined(__CUDACC__)
54 template <
class View1,
class View2>
55 Kokkos::View< typename Kokkos::ViewFactory<View1,View2>::value_type*,
56 typename View1::device_type >
60 typedef typename ViewFac::value_type value_type;
61 typedef typename View1::device_type device_type;
62 typedef typename View1::size_type size_type;
63 typedef Kokkos::View<value_type*,device_type> ViewTmp;
65 static_assert(
unsigned(View1::rank) == 2,
"" );
66 static_assert(
unsigned(View2::rank) == 1,
"" );
68 const size_type m = v1.extent(0);
69 const size_type
n = v1.extent(1);
70 ViewTmp vtmp = ViewFac::template create_view<ViewTmp>(v1,v2,
"tmp",m);
72 Kokkos::parallel_for(m, KOKKOS_LAMBDA (
const size_type i) {
74 for (size_type j=0; j<n; ++j)
82 #if defined(HAVE_SACADO_KOKKOSCONTAINERS)
85 template <
class View1,
class View2>
86 Kokkos::DynRankView< typename Kokkos::ViewFactory<View1,View2>::value_type,
87 typename View1::device_type >
88 my_func_dynamic(
const View1& v1,
const View2& v2)
91 typedef typename ViewFac::value_type value_type;
92 typedef typename View1::device_type device_type;
93 typedef typename View1::size_type size_type;
94 typedef Kokkos::DynRankView<value_type,device_type> ViewTmp;
99 const size_type m = v1.extent(0);
100 const size_type
n = v1.extent(1);
101 ViewTmp vtmp = ViewFac::template create_view<ViewTmp>(v1,v2,
"tmp",m);
103 Kokkos::parallel_for(m, KOKKOS_LAMBDA (
const size_type i) {
105 for (size_type j=0; j<n; ++j)
116 int main(
int argc,
char* argv[]) {
118 #if !defined(__CUDACC__)
120 typedef Kokkos::DefaultExecutionSpace execution_space;
122 Kokkos::initialize(argc, argv);
126 const size_t deriv_dim = 1;
132 Kokkos::View<double**,execution_space> v1(
"v1",m,n);
133 Kokkos::View<double* ,execution_space> v2(
"v2",n);
135 Kokkos::deep_copy(v1, 2.0);
136 Kokkos::deep_copy(v2, 3.0);
140 std::cout <<
"v3 = " << std::endl;
141 for (
size_t i=0; i<m; ++i) {
142 std::cout <<
"\t" << v3(i) << std::endl;
147 Kokkos::View<FadType*,execution_space> v2_fad(
"v2_fad",n,deriv_dim+1);
148 Kokkos::deep_copy(v2_fad,
FadType(deriv_dim, 0, 3.0));
150 auto v3_fad =
my_func(v1,v2_fad);
152 std::cout <<
"v3_fad = " << std::endl;
153 for (
size_t i=0; i<m; ++i) {
154 std::cout <<
"\t" << v3_fad(i) << std::endl;
159 #if defined(HAVE_SACADO_KOKKOSCONTAINERS)
164 Kokkos::DynRankView<double,execution_space> v1(
"v1",m,n);
165 Kokkos::DynRankView<double,execution_space> v2(
"v2",n);
167 Kokkos::deep_copy(v1, 2.0);
168 Kokkos::deep_copy(v2, 3.0);
170 auto v3 = my_func_dynamic(v1,v2);
172 std::cout <<
"v3 = " << std::endl;
173 for (
size_t i=0; i<m; ++i) {
174 std::cout <<
"\t" << v3(i) << std::endl;
179 Kokkos::DynRankView<FadType,execution_space> v2_fad(
"v2_fad",n,deriv_dim+1);
180 Kokkos::deep_copy(v2_fad,
FadType(deriv_dim, 0, 3.0));
182 auto v3_fad = my_func_dynamic(v1,v2_fad);
184 std::cout <<
"v3_fad = " << std::endl;
185 for (
size_t i=0; i<m; ++i) {
186 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
#define TEUCHOS_ASSERT(assertion_test)