data_sink.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/types.hpp>
10 
11 #include <rmm/cuda_stream_view.hpp>
12 
13 #include <algorithm>
14 #include <future>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
24 namespace CUDF_EXPORT cudf {
26 namespace io {
27 
36 class data_sink {
37  public:
44  static std::unique_ptr<data_sink> create(std::string const& filepath);
45 
52  static std::unique_ptr<data_sink> create(std::vector<char>* buffer);
53 
62  static std::unique_ptr<data_sink> create();
63 
75  static std::unique_ptr<data_sink> create(cudf::io::data_sink* const user_sink);
76 
83  template <typename T>
84  static std::vector<std::unique_ptr<data_sink>> create(std::vector<T> const& args)
85  {
86  std::vector<std::unique_ptr<data_sink>> sinks;
87  sinks.reserve(args.size());
88  std::transform(args.cbegin(), args.cend(), std::back_inserter(sinks), [](auto const& arg) {
89  return data_sink::create(arg);
90  });
91  return sinks;
92  }
93 
97  virtual ~data_sink() {};
98 
105  virtual void host_write(void const* data, size_t size) = 0;
106 
129  [[nodiscard]] virtual bool supports_device_write() const { return false; }
130 
137  [[nodiscard]] virtual bool is_device_write_preferred(size_t size) const
138  {
139  return supports_device_write();
140  }
141 
156  virtual void device_write(void const* gpu_data, size_t size, rmm::cuda_stream_view stream)
157  {
158  CUDF_FAIL("data_sink classes that support device_write must override it.");
159  }
160 
183  virtual std::future<void> device_write_async(void const* gpu_data,
184  size_t size,
185  rmm::cuda_stream_view stream)
186  {
187  CUDF_FAIL("data_sink classes that support device_write_async must override it.");
188  }
189 
193  virtual void flush() = 0;
194 
200  virtual size_t bytes_written() = 0;
201 };
202  // end of group
204 } // namespace io
205 } // namespace CUDF_EXPORT cudf
Interface class for storing the output data from the writers.
Definition: data_sink.hpp:36
virtual void flush()=0
Flush the data written into the sink.
static std::vector< std::unique_ptr< data_sink > > create(std::vector< T > const &args)
Creates a vector of data sinks, one per element in the input vector.
Definition: data_sink.hpp:84
virtual void device_write(void const *gpu_data, size_t size, rmm::cuda_stream_view stream)
Append the buffer content to the sink from a gpu address.
Definition: data_sink.hpp:156
virtual bool supports_device_write() const
Whether or not this sink supports writing from gpu memory addresses.
Definition: data_sink.hpp:129
static std::unique_ptr< data_sink > create(cudf::io::data_sink *const user_sink)
Create a wrapped custom user data sink.
virtual bool is_device_write_preferred(size_t size) const
Estimates whether a direct device write would be more optimal for the given size.
Definition: data_sink.hpp:137
static std::unique_ptr< data_sink > create()
Create a void sink (one that does no actual io)
static std::unique_ptr< data_sink > create(std::string const &filepath)
Create a sink from a file path.
virtual ~data_sink()
Base class destructor.
Definition: data_sink.hpp:97
virtual size_t bytes_written()=0
Returns the total number of bytes written into this sink.
virtual void host_write(void const *data, size_t size)=0
Append the buffer content to the sink.
virtual std::future< void > device_write_async(void const *gpu_data, size_t size, rmm::cuda_stream_view stream)
Asynchronously append the buffer content to the sink from a gpu address.
Definition: data_sink.hpp:183
static std::unique_ptr< data_sink > create(std::vector< char > *buffer)
Create a sink from a std::vector.
Exception types and error-checking macros used throughout libcudf.
std::unique_ptr< column > transform(std::vector< column_view > const &inputs, std::string const &transform_udf, data_type output_type, bool is_ptx, std::optional< void * > user_data=std::nullopt, null_aware is_null_aware=null_aware::NO, output_nullability null_policy=output_nullability::PRESERVE, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new column by applying a transform function against every element of the input columns.
#define CUDF_FAIL(...)
Indicates that an erroneous code path has been taken.
Definition: error.hpp:223
cuDF interfaces
Definition: host_udf.hpp:26
Type declarations for libcudf.