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

Changing cudf::io::source_info to use cudf::host_span<std::byte> in a non-breaking form #12730

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 10 additions & 0 deletions cpp/include/cudf/io/datasource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,21 @@ class datasource {
/**
* @brief Creates a source from a host memory buffer.
*
# @deprecated Since 23.04
*
* @param[in] buffer Host buffer object
* @return Constructed datasource object
*/
static std::unique_ptr<datasource> create(host_buffer const& buffer);

/**
* @brief Creates a source from a host memory buffer.
*
* @param[in] buffer Host buffer object
* @return Constructed datasource object
*/
static std::unique_ptr<datasource> create(cudf::host_span<std::byte const> buffer);

/**
* @brief Creates a source from a device memory buffer.
*
Expand Down
74 changes: 70 additions & 4 deletions cpp/include/cudf/io/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ struct table_with_metadata {
/**
* @brief Non-owning view of a host memory buffer
*
* @deprecated Since 23.04
*
* Used to describe buffer input in `source_info` objects.
*/
struct host_buffer {
Expand All @@ -166,6 +168,21 @@ struct host_buffer {
host_buffer(const char* data, size_t size) : data(data), size(size) {}
};

/**
* @brief Returns `true` if the type is byte-like, meaning it is reasonable to pass as a pointer to
* bytes.
*
* @tparam T The representation type
* @return `true` if the type is considered a byte-like type
*/
template <typename T>
constexpr inline auto is_byte_like_type()
{
return cuda::std::is_same_v<T, int8_t> || cuda::std::is_same_v<T, char> ||
cuda::std::is_same_v<T, uint8_t> || cuda::std::is_same_v<T, unsigned char> ||
cuda::std::is_same_v<T, std::byte>;
hyperbolic2346 marked this conversation as resolved.
Show resolved Hide resolved
}
vuule marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Source information for read interfaces
*/
Expand All @@ -191,21 +208,70 @@ struct source_info {
/**
* @brief Construct a new source info object for multiple buffers in host memory
*
* @deprecated Since 23.04
*
* @param host_buffers Input buffers in host memory
*/
explicit source_info(std::vector<host_buffer> const& host_buffers)
: _type(io_type::HOST_BUFFER), _host_buffers(host_buffers)
explicit source_info(std::vector<host_buffer> const& host_buffers) : _type(io_type::HOST_BUFFER)
{
_host_buffers.reserve(host_buffers.size());
vuule marked this conversation as resolved.
Show resolved Hide resolved
std::transform(host_buffers.begin(),
host_buffers.end(),
std::back_inserter(_host_buffers),
[](auto const hb) {
return cudf::host_span<std::byte const>{
reinterpret_cast<std::byte const*>(hb.data), hb.size};
});
}

/**
* @brief Construct a new source info object for a single buffer
*
* @deprecated Since 23.04
*
* @param host_data Input buffer in host memory
* @param size Size of the buffer
*/
explicit source_info(const char* host_data, size_t size)
: _type(io_type::HOST_BUFFER), _host_buffers({{host_data, size}})
: _type(io_type::HOST_BUFFER),
_host_buffers(
{cudf::host_span<std::byte const>(reinterpret_cast<std::byte const*>(host_data), size)})
{
}

/**
* @brief Construct a new source info object for multiple buffers in host memory
*
* @param host_buffers Input buffers in host memory
*/
template <typename T, CUDF_ENABLE_IF(is_byte_like_type<T>())>
explicit source_info(cudf::host_span<cudf::host_span<T const>> const& host_buffers)
hyperbolic2346 marked this conversation as resolved.
Show resolved Hide resolved
: _type(io_type::HOST_BUFFER)
{
if constexpr (not std::is_same_v<std::remove_cv_t<T>, std::byte>) {
vuule marked this conversation as resolved.
Show resolved Hide resolved
_host_buffers.reserve(host_buffers.size());
std::transform(host_buffers.begin(),
host_buffers.end(),
std::back_inserter(_host_buffers),
[](auto const s) {
return cudf::host_span<std::byte const>{
reinterpret_cast<std::byte const*>(s.data()), s.size()};
});
} else {
_host_buffers = host_buffers;
}
}

/**
* @brief Construct a new source info object for a single buffer
*
* @param host_data Input buffer in host memory
*/
template <typename T, CUDF_ENABLE_IF(is_byte_like_type<T>())>
explicit source_info(cudf::host_span<T const> host_data)
hyperbolic2346 marked this conversation as resolved.
Show resolved Hide resolved
: _type(io_type::HOST_BUFFER),
_host_buffers{cudf::host_span<std::byte const>(
reinterpret_cast<std::byte const*>(host_data.data()), host_data.size())}
{
}

Expand Down Expand Up @@ -289,7 +355,7 @@ struct source_info {
private:
io_type _type = io_type::FILEPATH;
std::vector<std::string> _filepaths;
std::vector<host_buffer> _host_buffers;
std::vector<cudf::host_span<std::byte const>> _host_buffers;
std::vector<cudf::device_span<std::byte const>> _device_buffers;
std::vector<cudf::io::datasource*> _user_sources;
};
Expand Down
8 changes: 7 additions & 1 deletion cpp/src/io/utilities/datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,16 @@ std::unique_ptr<datasource> datasource::create(const std::string& filepath,
}

std::unique_ptr<datasource> datasource::create(host_buffer const& buffer)
{
return create(
cudf::host_span<std::byte const>{reinterpret_cast<std::byte const*>(buffer.data), buffer.size});
}

std::unique_ptr<datasource> datasource::create(cudf::host_span<std::byte const> buffer)
hyperbolic2346 marked this conversation as resolved.
Show resolved Hide resolved
{
// Use Arrow IO buffer class for zero-copy reads of host memory
return std::make_unique<arrow_io_source>(std::make_shared<arrow::io::BufferReader>(
reinterpret_cast<const uint8_t*>(buffer.data), buffer.size));
reinterpret_cast<const uint8_t*>(buffer.data()), buffer.size()));
}

std::unique_ptr<datasource> datasource::create(cudf::device_span<std::byte const> buffer)
Expand Down