From e1f8faca75ea58747e9f5d21a8ad2be3b912b11a Mon Sep 17 00:00:00 2001 From: Nghia Truong Date: Thu, 20 Apr 2023 09:19:45 -0700 Subject: [PATCH 1/4] Fix `subspan` and docs --- cpp/src/io/utilities/hostdevice_vector.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpp/src/io/utilities/hostdevice_vector.hpp b/cpp/src/io/utilities/hostdevice_vector.hpp index 1591abe4064..ed4adccad16 100644 --- a/cpp/src/io/utilities/hostdevice_vector.hpp +++ b/cpp/src/io/utilities/hostdevice_vector.hpp @@ -154,7 +154,7 @@ class hostdevice_vector { /** * @brief Converts a hostdevice_vector into a hostdevice_span. * - * @return A typed hostdevice_span of the hostdevice_vector's data. + * @return A typed hostdevice_span of the hostdevice_vector's data */ [[nodiscard]] operator hostdevice_span() { @@ -164,13 +164,15 @@ class hostdevice_vector { /** * @brief Converts a part of a hostdevice_vector into a hostdevice_span. * - * @return A typed hostdevice_span of the hostdevice_vector's data. + * @param offset The offset of the first element in the subspan + * @param count The number of elements in the subspan + * @return A typed hostdevice_span of the hostdevice_vector's data */ [[nodiscard]] hostdevice_span subspan(size_t offset, size_t count) { CUDF_EXPECTS(count >= offset, "End index cannot be smaller than the starting index."); CUDF_EXPECTS(count <= d_data.size(), "Slice range out of bounds."); - return hostdevice_span{host_data + offset, d_data.data() + offset, count - offset}; + return hostdevice_span{host_data + offset, d_data.data() + offset, count}; } private: From d3d06358386a8e3aaadadf2aebf7dafa07a5a7b9 Mon Sep 17 00:00:00 2001 From: Nghia Truong Date: Thu, 20 Apr 2023 09:43:44 -0700 Subject: [PATCH 2/4] Update tests --- cpp/tests/utilities_tests/span_tests.cu | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpp/tests/utilities_tests/span_tests.cu b/cpp/tests/utilities_tests/span_tests.cu index 7bcbd7a799f..c150bb2070c 100644 --- a/cpp/tests/utilities_tests/span_tests.cu +++ b/cpp/tests/utilities_tests/span_tests.cu @@ -356,6 +356,7 @@ TEST(HostDeviceSpanTest, CanTakeSubspanFull) auto const message_span = hostdevice_span(message.host_ptr(), message.device_ptr(), message.size()); + expect_match("hello world", message.subspan(0, 11)); expect_match("hello world", message_span.subspan(0, 11)); } @@ -365,6 +366,7 @@ TEST(HostDeviceSpanTest, CanTakeSubspanPartial) auto const message_span = hostdevice_span(message.host_ptr(), message.device_ptr(), message.size()); + expect_match("lo w", message.subspan(3, 4)); expect_match("lo w", message_span.subspan(3, 4)); } From 2b0220e7e7f70a14bc575dd4bef1d4bfb7bc73ef Mon Sep 17 00:00:00 2001 From: Nghia Truong Date: Thu, 20 Apr 2023 10:35:38 -0700 Subject: [PATCH 3/4] Fix assert --- cpp/src/io/utilities/hostdevice_vector.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/io/utilities/hostdevice_vector.hpp b/cpp/src/io/utilities/hostdevice_vector.hpp index ed4adccad16..980f94e455b 100644 --- a/cpp/src/io/utilities/hostdevice_vector.hpp +++ b/cpp/src/io/utilities/hostdevice_vector.hpp @@ -170,8 +170,8 @@ class hostdevice_vector { */ [[nodiscard]] hostdevice_span subspan(size_t offset, size_t count) { - CUDF_EXPECTS(count >= offset, "End index cannot be smaller than the starting index."); - CUDF_EXPECTS(count <= d_data.size(), "Slice range out of bounds."); + CUDF_EXPECTS(count <= d_data.size() - offset, + "The span with given offset and count is out of bounds."); return hostdevice_span{host_data + offset, d_data.data() + offset, count}; } From 5fe6eadc00e0ee1713166afe6aa2784344bbdcd9 Mon Sep 17 00:00:00 2001 From: Nghia Truong Date: Thu, 20 Apr 2023 10:37:21 -0700 Subject: [PATCH 4/4] Add one more assert --- cpp/src/io/utilities/hostdevice_vector.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/src/io/utilities/hostdevice_vector.hpp b/cpp/src/io/utilities/hostdevice_vector.hpp index 980f94e455b..ff8502b1dcd 100644 --- a/cpp/src/io/utilities/hostdevice_vector.hpp +++ b/cpp/src/io/utilities/hostdevice_vector.hpp @@ -170,6 +170,7 @@ class hostdevice_vector { */ [[nodiscard]] hostdevice_span subspan(size_t offset, size_t count) { + CUDF_EXPECTS(offset < d_data.size(), "Offset is out of bounds."); CUDF_EXPECTS(count <= d_data.size() - offset, "The span with given offset and count is out of bounds."); return hostdevice_span{host_data + offset, d_data.data() + offset, count};