Skip to content

Commit

Permalink
Fix host_span constructor to correctly copy is_device_accessible (#…
Browse files Browse the repository at this point in the history
…17020)

One of the `host_span` constructors was not updated when we added `is_device_accessible`, so the value was not assigned. 
This PR fixes this simple error and adds tests that checks that this property is correctly set when creating `host_span`s.

Authors:
  - Vukasin Milovanovic (https://github.com/vuule)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Muhammad Haseeb (https://github.com/mhaseeb123)

URL: #17020
  • Loading branch information
vuule authored Oct 9, 2024
1 parent bd51a25 commit c7b5119
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/include/cudf/utilities/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ struct host_span : public cudf::detail::span_base<T, Extent, host_span<T, Extent
std::is_convertible_v<OtherT (*)[], T (*)[]>, // NOLINT
void>* = nullptr>
constexpr host_span(host_span<OtherT, OtherExtent> const& other) noexcept
: base(other.data(), other.size())
: base(other.data(), other.size()), _is_device_accessible{other.is_device_accessible()}
{
}

Expand Down
20 changes: 20 additions & 0 deletions cpp/tests/utilities_tests/pinned_memory_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cudf/io/parquet.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/pinned_memory.hpp>
#include <cudf/utilities/span.hpp>

#include <rmm/mr/device/pool_memory_resource.hpp>
#include <rmm/mr/pinned_host_memory_resource.hpp>
Expand Down Expand Up @@ -125,3 +126,22 @@ TEST_F(PinnedMemoryTest, MakeHostVector)
EXPECT_FALSE(vec.get_allocator().is_device_accessible());
}
}

TEST_F(PinnedMemoryTest, HostSpan)
{
auto test_ctors = [](auto&& vec) {
auto const is_vec_device_accessible = vec.get_allocator().is_device_accessible();
// Test conversion from a vector
auto const span = cudf::host_span<int16_t>{vec};
EXPECT_EQ(span.is_device_accessible(), is_vec_device_accessible);
// Test conversion from host_span with different type
auto const span_converted = cudf::host_span<int16_t const>{span};
EXPECT_EQ(span_converted.is_device_accessible(), is_vec_device_accessible);
};

cudf::set_allocate_host_as_pinned_threshold(7);
for (int i = 1; i < 10; i++) {
// some iterations will use pinned memory, some will not
test_ctors(cudf::detail::make_host_vector<int16_t>(i, cudf::get_default_stream()));
}
}

0 comments on commit c7b5119

Please sign in to comment.