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::move(data_owner));
94 static std::unique_ptr<datasource>
create(std::string
const& filepath,
138 template <
typename T>
139 static std::vector<std::unique_ptr<datasource>>
create(std::vector<T>
const& args)
141 std::vector<std::unique_ptr<datasource>> sources;
142 sources.reserve(args.size());
143 std::transform(args.cbegin(), args.cend(), std::back_inserter(sources), [](
auto const& arg) {
144 return datasource::create(arg);
162 virtual std::unique_ptr<datasource::buffer>
host_read(
size_t offset,
size_t size) = 0;
173 virtual size_t host_read(
size_t offset,
size_t size, uint8_t* dst) = 0;
197 return supports_device_read();
216 virtual std::unique_ptr<datasource::buffer>
device_read(
size_t offset,
220 CUDF_FAIL(
"datasource classes that support device_read must override it.");
242 CUDF_FAIL(
"datasource classes that support device_read must override it.");
270 CUDF_FAIL(
"datasource classes that support device_read_async must override it.");
278 [[nodiscard]]
virtual size_t size()
const = 0;
285 [[nodiscard]]
virtual bool is_empty()
const {
return size() == 0; }
307 [[nodiscard]]
size_t size()
const override {
return _size; }
314 [[nodiscard]] uint8_t
const*
data()
const override {
return _data; }
317 uint8_t
const* _data{
nullptr};
328 template <
typename Container>
337 : _data(std::move(data_owner)), _data_ptr(_data.data()), _size(_data.size())
350 : _data(std::move(data_owner)), _data_ptr(data_ptr), _size(size)
359 [[nodiscard]]
size_t size()
const override {
return _size; }
366 [[nodiscard]] uint8_t
const*
data()
const override
368 return static_cast<uint8_t const*
>(_data_ptr);
373 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.