21 #include <cudf/utilities/export.hpp>
29 namespace CUDF_EXPORT
cudf {
44 template <
typename Container>
58 [[nodiscard]]
virtual size_t size()
const = 0;
65 [[nodiscard]]
virtual uint8_t
const*
data()
const = 0;
79 template <
typename Container>
80 static std::unique_ptr<buffer>
create(Container&& data_owner)
82 return std::make_unique<owning_buffer<Container>>(std::forward<Container>(data_owner));
101 static std::unique_ptr<datasource>
create(std::string
const& filepath,
103 size_t max_size_estimate = 0);
145 template <
typename T>
146 static std::vector<std::unique_ptr<datasource>>
create(std::vector<T>
const& args)
148 std::vector<std::unique_ptr<datasource>> sources;
149 sources.reserve(args.size());
150 std::transform(args.cbegin(), args.cend(), std::back_inserter(sources), [](
auto const& arg) {
151 return datasource::create(arg);
169 virtual std::unique_ptr<datasource::buffer>
host_read(
size_t offset,
size_t size) = 0;
180 virtual size_t host_read(
size_t offset,
size_t size, uint8_t* dst) = 0;
204 return supports_device_read();
223 virtual std::unique_ptr<datasource::buffer>
device_read(
size_t offset,
227 CUDF_FAIL(
"datasource classes that support device_read must override it.");
249 CUDF_FAIL(
"datasource classes that support device_read must override it.");
277 CUDF_FAIL(
"datasource classes that support device_read_async must override it.");
285 [[nodiscard]]
virtual size_t size()
const = 0;
292 [[nodiscard]]
virtual bool is_empty()
const {
return size() == 0; }
314 [[nodiscard]]
size_t size()
const override {
return _size; }
321 [[nodiscard]] uint8_t
const*
data()
const override {
return _data; }
324 uint8_t
const* _data{
nullptr};
335 template <
typename Container>
340 static_assert(std::is_rvalue_reference_v<Container&&>,
341 "The container argument passed to the constructor must be an rvalue.");
350 : _data(std::move(moved_data_owner)), _data_ptr(_data.data()), _size(_data.size())
363 owning_buffer(Container&& moved_data_owner, uint8_t
const* data_ptr,
size_t size)
364 : _data(std::move(moved_data_owner)), _data_ptr(data_ptr), _size(size)
373 [[nodiscard]]
size_t size()
const override {
return _size; }
380 [[nodiscard]] uint8_t
const*
data()
const override
382 return static_cast<uint8_t const*
>(_data_ptr);
387 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.
owning_buffer(Container &&moved_data_owner)
Moves the input container into the newly created object.
owning_buffer(Container &&moved_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.
size_t size() const override
Returns the size 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::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.
static std::unique_ptr< datasource > create(std::string const &filepath, size_t offset=0, size_t max_size_estimate=0)
Creates a source from a file path.
#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.