Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix host_span constructor to correctly copy is_device_accessible #17020

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
}
}
Loading