Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_get1DConstView.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_DETAILS_GET1DCONSTVIEW_HPP
11#define TPETRA_DETAILS_GET1DCONSTVIEW_HPP
12
17
18#include "Tpetra_ConfigDefs.hpp"
19#include "Tpetra_Util.hpp"
20#include "Kokkos_DualView.hpp"
21#include <Teuchos_Array.hpp>
22#include <utility>
23
24namespace Tpetra {
25namespace Details {
26
27// mfh 28 Apr 2016: Sometimes we have a raw host array, and we need
28// to make a Kokkos::View out of it that lives in a certain memory
29// space. We don't want to make a deep copy of the input array if
30// we don't need to, but if the memory spaces are different, we need
31// to. The following code does that. The struct is an
32// implementation detail, and the "free" function
33// get1DConstViewOfUnmanagedArray is the interface to call.
34
35template<class ST, class DT,
36 const bool outputIsHostMemory =
37 std::is_same<typename DT::memory_space, Kokkos::HostSpace>::value>
38struct Get1DConstViewOfUnmanagedHostArray {};
39
40template<class ST, class DT>
41struct Get1DConstViewOfUnmanagedHostArray<ST, DT, true> {
42 typedef Kokkos::View<const ST*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged> output_view_type;
43
44 static output_view_type
45 getView (const char /* label */ [], const ST* x_raw, const size_t x_len)
46 {
47 // We can return the input array, wrapped as an unmanaged View.
48 // Ignore the label, since unmanaged Views don't have labels.
49 return output_view_type (x_raw, x_len);
50 }
51};
52
53template<class ST, class DT>
54struct Get1DConstViewOfUnmanagedHostArray<ST, DT, false> {
55 typedef Kokkos::View<const ST*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged> input_view_type;
56 typedef Kokkos::View<const ST*, DT> output_view_type;
57
58 static output_view_type
59 getView (const char label[], const ST* x_raw, const size_t x_len)
60 {
61 input_view_type x_in (x_raw, x_len);
62 // The memory spaces are different, so we have to create a new
63 // View which is a deep copy of the input array.
64 //
65 // FIXME (mfh 28 Apr 2016) This needs to be converted to
66 // std::string, else the compiler can't figure out what
67 // constructor we're calling.
68 Kokkos::View<ST*, DT> x_out (std::string (label), x_len);
69 // DEEP_COPY REVIEW - NOT TESTED
70 Kokkos::deep_copy (x_out, x_in);
71 return x_out;
72 }
73};
74
75template<class ST, class DT>
76 typename Get1DConstViewOfUnmanagedHostArray<ST, DT>::output_view_type
77get1DConstViewOfUnmanagedHostArray (const char label[], const ST* x_raw, const size_t x_len)
78{
79 return Get1DConstViewOfUnmanagedHostArray<ST, DT>::getView (label, x_raw, x_len);
80}
81
82} // namespace Details
83} // namespace Tpetra
84
85#endif // TPETRA_DETAILS_GET1DCONSTVIEW_HPP
Stand-alone utility functions and macros.
Nonmember function that computes a residual Computes R = B - A * X.
Namespace Tpetra contains the class and methods constituting the Tpetra library.