TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, MultiplyMixed, FadType, Layout, Device ) { typedef typename ApplyView<FadType*,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; const size_type num_rows = 2; const size_type fad_size = global_fad_size; // Create and fill views -- do everything on the host for this test FadType f0 = generate_fad<FadType>( num_rows, size_type(2), fad_size, size_type(0), size_type(0)); FadType f1 = generate_fad<FadType>( num_rows, size_type(2), fad_size, size_type(1), size_type(0)); host_view_type h_v("view1", num_rows, fad_size+1); h_v(0) = f0; h_v(1) = f1; FadType f2 = f0 * h_v(1); // Check FadType f3 = f0 * f1; success = checkFads(f3, f2, out); }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, ScalarAssign, FadType, Layout, Device ) { typedef typename ApplyView<FadType*,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; typedef typename FadType::value_type value_type; const size_type num_rows = global_num_rows; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", num_rows, fad_size+1); typename ViewType::array_type va = v; Kokkos::deep_copy( va, 1.0 ); // Deep copy a constant scalar value_type a = 2.3456; ScalarAssignKernel<ViewType,value_type>::apply( v, a ); // Copy to host host_view_type hv = Kokkos::create_mirror_view(v); Kokkos::deep_copy(hv, v); // Check success = true; for (size_type i=0; i<num_rows; ++i) { #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) FadType f = FadType(fad_size, a); #else FadType f = a; #endif success = success && checkFads(f, hv(i), out); } }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, DeepCopy_ConstantFadFull, FadType, Layout, Device ) { typedef typename ApplyView<FadType**,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; const size_type num_rows = global_num_rows; const size_type num_cols = global_num_cols; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", num_rows, num_cols, fad_size+1); typename ViewType::array_type va = v; Kokkos::deep_copy( va, 1.0 ); // Deep copy a constant Fad FadType a(fad_size, 2.3456); for (size_type i=0; i<fad_size; ++i) a.fastAccessDx(i) = 7.89 + (i+1); Kokkos::deep_copy( v, a ); // Copy to host host_view_type hv = Kokkos::create_mirror_view(v); Kokkos::deep_copy(hv, v); // Check success = true; for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { success = success && checkFads(a, hv(i,j), out); } } }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, DeepCopy, FadType, Layout, Device ) { typedef typename ApplyView<FadType**,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; const size_type num_rows = global_num_rows; const size_type num_cols = global_num_cols; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", num_rows, num_cols, fad_size+1); host_view_type h_v = Kokkos::create_mirror_view(v); for (size_type i=0; i<num_rows; ++i) for (size_type j=0; j<num_cols; ++j) h_v(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); Kokkos::deep_copy(v, h_v); // Copy back host_view_type h_v2 = Kokkos::create_mirror_view(v); Kokkos::deep_copy(h_v2, v); // Check success = true; for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); success = success && checkFads(f, h_v2(i,j), out); } } }
bool checkNestedFads(const FadType1& x, const FadType2& x2, Teuchos::FancyOStream& out, double tol = 1.0e-15) { bool success = true; // Check sizes match TEUCHOS_TEST_EQUALITY(x.size(), x2.size(), out, success); // Check values match success = success && checkFads(x.val(), x2.val(), out, tol); // Check derivatives match for (int i=0; i<x.size(); ++i) success = success && checkFads(x.dx(i), x2.dx(i), out, tol); return success; }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device ) { typedef typename FadType::value_type scalar_type; typedef typename ApplyView<scalar_type***,Layout,Device>::type ViewType; typedef typename ApplyView<const scalar_type***,Layout,Device>::type ConstViewType; typedef typename ApplyView<FadType**,Layout,Device,Kokkos::MemoryUnmanaged>::type FadViewType; typedef typename ApplyView<const FadType**,Layout,Device,Kokkos::MemoryUnmanaged>::type ConstFadViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; typedef typename FadViewType::HostMirror fad_host_view_type; const size_type num_rows = global_num_rows; const size_type num_cols = global_num_cols; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", num_rows, num_cols, fad_size+1); host_view_type h_v = Kokkos::create_mirror_view(v); for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); for (size_type k=0; k<fad_size; k++) h_v(i,j,k) = f.dx(k); h_v(i,j,fad_size) = f.val(); } } Kokkos::deep_copy(v, h_v); ConstViewType v_const = v; // Create unmanaged view ConstFadViewType v_fad( v_const.ptr_on_device(), num_rows, num_cols, fad_size+1); // Copy back -- can't use create_mirror_view() because v_fad is unmanaged fad_host_view_type h_v_fad("host_view_fad", num_rows, num_cols, fad_size+1); Kokkos::deep_copy(h_v_fad, v_fad); // Check success = true; for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); success = success && checkFads(f, h_v_fad(i,j), out); } } }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, MultiplyConst, FadType, Layout, Device ) { typedef typename ApplyView<const FadType*,Layout,Device,Kokkos::MemoryUnmanaged>::type ConstViewType; typedef typename ApplyView<FadType*,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; const size_type num_rows = global_num_rows; const size_type fad_size = global_fad_size; // Create and fill views ViewType v1("view1", num_rows, fad_size+1); ViewType v2("view2", num_rows, fad_size+1); host_view_type h_v1 = Kokkos::create_mirror_view(v1); host_view_type h_v2 = Kokkos::create_mirror_view(v2); for (size_type i=0; i<num_rows; ++i) { h_v1(i) = generate_fad<FadType>( num_rows, size_type(2), fad_size, i, size_type(0)); h_v2(i) = generate_fad<FadType>( num_rows, size_type(2), fad_size, i, size_type(1)); } Kokkos::deep_copy(v1, h_v1); Kokkos::deep_copy(v2, h_v2); ConstViewType cv1 = v1; // Launch kernel ViewType v3("view3", num_rows, fad_size+1); MultiplyKernel<ConstViewType,ViewType,ViewType>::apply(cv1,v2,v3); // Copy back host_view_type h_v3 = Kokkos::create_mirror_view(v3); Kokkos::deep_copy(h_v3, v3); // Check success = true; for (size_type i=0; i<num_rows; ++i) { FadType f1 = generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0)); FadType f2 = generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1)); FadType f3 = f1*f2; success = success && checkFads(f3, h_v3(i), out); } }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, Subview, FadType, Layout, Device ) { typedef typename ApplyView<FadType**,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; const size_type num_rows = global_num_rows; const size_type num_cols = global_num_cols; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", num_rows, num_cols, fad_size+1); host_view_type h_v = Kokkos::create_mirror_view(v); for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); h_v(i,j) = f; } } Kokkos::deep_copy(v, h_v); // Create subview of first column size_type col = 1; auto s = Kokkos::subview(v, Kokkos::ALL(), col); // Copy back typedef decltype(s) SubviewType; typedef typename SubviewType::HostMirror HostSubviewType; HostSubviewType h_s = Kokkos::create_mirror_view(s); Kokkos::deep_copy(h_s, s); // Check success = true; #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success); TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success); #endif for (size_type i=0; i<num_rows; ++i) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col); success = success && checkFads(f, h_s(i), out); } }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, Rank8, FadType, Layout, Device ) { typedef typename ApplyView<FadType*******,Layout,Device>::type ViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", 100, 1, 2, 3, 4, 5, 6, fad_size+1); host_view_type h_v = Kokkos::create_mirror_view(v); typename host_view_type::array_type h_a = h_v; Kokkos::deep_copy(h_a, 1.0); FadType f1 = FadType(fad_size, 2.0); h_v(99,0,1,2,3,4,5) = f1; FadType f2 = h_v(99,0,1,2,3,4,5); // Check success = checkFads(f1, f2, out); }