21 #include <cudf/utilities/span.hpp>
43 template <
typename Container>
57 [[nodiscard]]
virtual size_t size()
const = 0;
64 [[nodiscard]]
virtual uint8_t
const*
data()
const = 0;
78 template <
typename Container>
79 static std::unique_ptr<buffer>
create(Container&& data_owner)
81 return std::make_unique<owning_buffer<Container>>(std::move(data_owner));
93 static std::unique_ptr<datasource>
create(std::string
const& filepath,
137 template <
typename T>
138 static std::vector<std::unique_ptr<datasource>>
create(std::vector<T>
const& args)
140 std::vector<std::unique_ptr<datasource>> sources;
141 sources.reserve(args.size());
142 std::transform(args.cbegin(), args.cend(), std::back_inserter(sources), [](
auto const& arg) {
143 return datasource::create(arg);
161 virtual std::unique_ptr<datasource::buffer>
host_read(
size_t offset,
size_t size) = 0;
215 virtual std::unique_ptr<datasource::buffer>
device_read(
size_t offset,
219 CUDF_FAIL(
"datasource classes that support device_read must override it.");
241 CUDF_FAIL(
"datasource classes that support device_read must override it.");
269 CUDF_FAIL(
"datasource classes that support device_read_async must override it.");
277 [[nodiscard]]
virtual size_t size()
const = 0;
306 [[nodiscard]]
size_t size()
const override {
return _size; }
313 [[nodiscard]] uint8_t
const*
data()
const override {
return _data; }
316 uint8_t
const* _data{
nullptr};
327 template <
typename Container>
336 : _data(std::move(data_owner)), _data_ptr(_data.
data()), _size(_data.
size())
349 : _data(std::move(data_owner)), _data_ptr(data_ptr), _size(
size)
358 [[nodiscard]]
size_t size()
const override {
return _size; }
365 [[nodiscard]] uint8_t
const*
data()
const override
367 return static_cast<uint8_t const*
>(_data_ptr);
372 void const* _data_ptr;
Interface class for buffers that the datasource returns to the caller.
virtual ~buffer()
Base class destructor.
static std::unique_ptr< buffer > create(Container &&data_owner)
Factory to construct a datasource buffer object from a container.
virtual size_t size() const =0
Returns the buffer size in bytes.
virtual uint8_t const * data() const =0
Returns the address of the data in the buffer.
Implementation for non owning buffer where datasource holds buffer until destruction.
size_t size() const override
Returns the size of the buffer.
uint8_t const * data() const override
Returns the pointer to the buffer.
non_owning_buffer(uint8_t const *data, size_t size)
Construct a new non owning buffer object.
Derived implementation of buffer that owns the data.
size_t size() const override
Returns the size of the buffer.
owning_buffer(Container &&data_owner)
Moves the input container into the newly created object.
owning_buffer(Container &&data_owner, uint8_t const *data_ptr, size_t size)
Moves the input container into the newly created object, and exposes a subspan of the buffer.
uint8_t const * data() const override
Returns the pointer to the data in the buffer.
Interface class for providing input data to the readers.
static std::unique_ptr< datasource > create(std::string const &filepath, size_t offset=0, size_t size=0)
Creates a source from a file path.
static std::vector< std::unique_ptr< datasource > > create(std::vector< T > const &args)
Creates a vector of datasources, one per element in the input vector.
virtual bool supports_device_read() const
Whether or not this source supports reading directly into device memory.
static std::unique_ptr< datasource > create(datasource *source)
Creates a source from an user implemented datasource object.
virtual size_t device_read(size_t offset, size_t size, uint8_t *dst, rmm::cuda_stream_view stream)
Reads a selected range into a preallocated device buffer.
virtual bool is_device_read_preferred(size_t size) const
Estimates whether a direct device read would be more optimal for the given size.
static std::unique_ptr< datasource > create(cudf::device_span< std::byte const > buffer)
Creates a source from a device memory buffer.
virtual std::future< size_t > device_read_async(size_t offset, size_t size, uint8_t *dst, rmm::cuda_stream_view stream)
Asynchronously reads a selected range into a preallocated device buffer.
virtual bool is_empty() const
Returns whether the source contains any data.
virtual size_t host_read(size_t offset, size_t size, uint8_t *dst)=0
Reads a selected range into a preallocated buffer.
static std::unique_ptr< datasource > create(host_buffer const &buffer)
Creates a source from a host memory buffer.
virtual std::unique_ptr< datasource::buffer > device_read(size_t offset, size_t size, rmm::cuda_stream_view stream)
Returns a device buffer with a subset of data from the source.
virtual ~datasource()
Base class destructor.
virtual size_t size() const =0
Returns the size of the data in the source.
virtual std::unique_ptr< datasource::buffer > host_read(size_t offset, size_t size)=0
Returns a buffer with a subset of data from the source.
static std::unique_ptr< datasource > create(cudf::host_span< std::byte const > buffer)
Creates a source from a host memory buffer.
#define CUDF_FAIL(...)
Indicates that an erroneous code path has been taken.
cuDF-IO API type definitions
Device version of C++20 std::span with reduced feature set.
C++20 std::span with reduced feature set.
Non-owning view of a host memory buffer.