From e685d35e2af951cd4dba5cb01fe215f22d5e7944 Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Tue, 11 Apr 2023 13:56:12 -0700 Subject: [PATCH] Improvements to ArrayView interface --- benchmarks/BenchmarkArrayView.cpp | 2 +- src/care/ArrayView.h | 62 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/benchmarks/BenchmarkArrayView.cpp b/benchmarks/BenchmarkArrayView.cpp index d6f4a1ea..7341d477 100644 --- a/benchmarks/BenchmarkArrayView.cpp +++ b/benchmarks/BenchmarkArrayView.cpp @@ -19,7 +19,7 @@ static void benchmark_array_view_2d(benchmark::State& state) { const int extent2 = state.range(0); care::host_device_ptr data(extent1*extent2, "data"); - // Make sure memory transfers are not considered + // Make sure memory transfers are not considered in the timing auto temp = care::makeArrayView2D(data, extent1, extent2); (void) temp; diff --git a/src/care/ArrayView.h b/src/care/ArrayView.h index 5052f0fb..55587ced 100644 --- a/src/care/ArrayView.h +++ b/src/care/ArrayView.h @@ -6,6 +6,23 @@ #include "RAJA/util/View.hpp" namespace care { + template + using ArrayView1D = RAJA::View>; + + template + using ArrayCView1D = ArrayView1D; + +#if defined(CARE_GPUCC) + template + using ArrayView2D = RAJA::View>; +#else + template + using ArrayView2D = RAJA::View>; +#endif + + template + using ArrayCView2D = ArrayView2D; + /// /// Creates a 1D view on top of a flat allocation (non-owning semantics) /// @@ -21,6 +38,21 @@ namespace care { auto makeArrayView1D(care::host_device_ptr data, int extent); + /// + /// Creates a 1D const view on top of a flat allocation (non-owning semantics) + /// + /// Moves the data to the default execution space (determined at + /// compile time) and wraps it in a RAJA::View. + /// + /// @param[in] data Container for the allocation + /// @param[in] extent Length of the view + /// + /// @return A RAJA::View object + /// + template + auto makeArrayCView1D(care::host_device_ptr data, + int extent); + /// /// Creates a 2D view on top of a flat allocation (non-owning semantics) /// @@ -38,6 +70,24 @@ namespace care { template auto makeArrayView2D(care::host_device_ptr data, int extent1, int extent2); + + /// + /// Creates a 2D const view on top of a flat allocation (non-owning semantics) + /// + /// Moves the data to the default execution space (determined at + /// compile time) and wraps it in a RAJA::View. When using with a + /// RAJA loop, extent2 should correspond to the length of the RAJA + /// loop for optimal performance. + /// + /// @param[in] data Container for the allocation + /// @param[in] extent1 Length of the 1st dimension + /// @param[in] extent2 Length of the 2nd dimension + /// + /// @return A RAJA::View object + /// + template + auto makeArrayCView2D(care::host_device_ptr data, + int extent1, int extent2); template auto makeArrayView1D(care::host_device_ptr data, @@ -49,6 +99,12 @@ namespace care { #endif } + template + auto makeArrayCView1D(care::host_device_ptr data, + int extent) { + return makeArrayView1D(care::host_device_ptr(data), extent); + } + template auto makeArrayView2D(care::host_device_ptr data, int extent1, int extent2) { @@ -62,6 +118,12 @@ namespace care { return RAJA::View>(data.data(chai::CPU), layout); #endif } + + template + auto makeArrayCView2D(care::host_device_ptr data, + int extent1, int extent2) { + return makeArrayView2D(care::host_device_ptr(data), extent1, extent2); + } } // namespace care #endif // CARE_ARRAY_VIEW_H