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 // We can return the input array, wrapped as an unmanaged View.
47 // Ignore the label, since unmanaged Views don't have labels.
48 return output_view_type(x_raw, x_len);
49 }
50};
51
52template <class ST, class DT>
53struct Get1DConstViewOfUnmanagedHostArray<ST, DT, false> {
54 typedef Kokkos::View<const ST*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged> input_view_type;
55 typedef Kokkos::View<const ST*, DT> output_view_type;
56
57 static output_view_type
58 getView(const char label[], const ST* x_raw, const size_t x_len) {
59 input_view_type x_in(x_raw, x_len);
60 // The memory spaces are different, so we have to create a new
61 // View which is a deep copy of the input array.
62 //
63 // FIXME (mfh 28 Apr 2016) This needs to be converted to
64 // std::string, else the compiler can't figure out what
65 // constructor we're calling.
66 Kokkos::View<ST*, DT> x_out(std::string(label), x_len);
67 // DEEP_COPY REVIEW - NOT TESTED
68 Kokkos::deep_copy(x_out, x_in);
69 return x_out;
70 }
71};
72
73template <class ST, class DT>
74typename Get1DConstViewOfUnmanagedHostArray<ST, DT>::output_view_type
75get1DConstViewOfUnmanagedHostArray(const char label[], const ST* x_raw, const size_t x_len) {
76 return Get1DConstViewOfUnmanagedHostArray<ST, DT>::getView(label, x_raw, x_len);
77}
78
79} // namespace Details
80} // namespace Tpetra
81
82#endif // TPETRA_DETAILS_GET1DCONSTVIEW_HPP
Stand-alone utility functions and macros.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.