diff --git a/cpp/src/io/utilities/hostdevice_vector.hpp b/cpp/src/io/utilities/hostdevice_vector.hpp index a1e8af51858..0883ac3609f 100644 --- a/cpp/src/io/utilities/hostdevice_vector.hpp +++ b/cpp/src/io/utilities/hostdevice_vector.hpp @@ -26,13 +26,9 @@ #include #include -#include +#include #include -#include - -#include - namespace cudf::detail { /** @@ -57,26 +53,23 @@ class hostdevice_vector { } explicit hostdevice_vector(size_t initial_size, size_t max_size, rmm::cuda_stream_view stream) - : h_data({cudf::io::get_host_memory_resource(), stream}), d_data(0, stream) + : h_data({cudf::io::get_host_memory_resource(), stream}), d_data(max_size, stream) { CUDF_EXPECTS(initial_size <= max_size, "initial_size cannot be larger than max_size"); h_data.reserve(max_size); h_data.resize(initial_size); - - current_size = initial_size; - d_data.resize(max_size, stream); } void push_back(T const& data) { CUDF_EXPECTS(size() < capacity(), "Cannot insert data into hostdevice_vector because capacity has been exceeded."); - h_data[current_size++] = data; + h_data.push_back(data); } [[nodiscard]] size_t capacity() const noexcept { return d_data.size(); } - [[nodiscard]] size_t size() const noexcept { return current_size; } + [[nodiscard]] size_t size() const noexcept { return h_data.size(); } [[nodiscard]] size_t size_bytes() const noexcept { return sizeof(T) * size(); } [[nodiscard]] bool empty() const noexcept { return size() == 0; } @@ -92,6 +85,12 @@ class hostdevice_vector { [[nodiscard]] T* end() { return host_ptr(size()); } [[nodiscard]] T const* end() const { return host_ptr(size()); } + [[nodiscard]] T& front() { return h_data.front(); } + [[nodiscard]] T const& front() const { return front(); } + + [[nodiscard]] T& back() { return h_data.back(); } + [[nodiscard]] T const& back() const { return back(); } + [[nodiscard]] T* device_ptr(size_t offset = 0) { return d_data.data() + offset; } [[nodiscard]] T const* device_ptr(size_t offset = 0) const { return d_data.data() + offset; } @@ -175,7 +174,6 @@ class hostdevice_vector { private: cudf::detail::rmm_host_vector h_data; - size_t current_size = 0; rmm::device_uvector d_data; };