interop.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 // We disable warning 611 because the `arrow::TableBatchReader` only partially
20 // override the `ReadNext` method of `arrow::RecordBatchReader::ReadNext`
21 // triggering warning 611-D from nvcc.
22 #ifdef __CUDACC__
23 #pragma nv_diag_suppress 611
24 #pragma nv_diag_suppress 2810
25 #endif
26 #include <rmm/resource_ref.hpp>
27 
28 #include <arrow/api.h>
29 #ifdef __CUDACC__
30 #pragma nv_diag_default 611
31 #pragma nv_diag_default 2810
32 #endif
33 
34 #include <cudf/column/column.hpp>
35 #include <cudf/detail/transform.hpp>
36 #include <cudf/table/table.hpp>
38 #include <cudf/types.hpp>
39 #include <cudf/utilities/export.hpp>
40 #include <cudf/utilities/span.hpp>
41 
43 #include <rmm/resource_ref.hpp>
44 
45 #include <utility>
46 
47 struct DLManagedTensor;
48 
49 struct ArrowDeviceArray;
50 
51 struct ArrowSchema;
52 
53 struct ArrowArray;
54 
55 struct ArrowArrayStream;
56 
57 namespace CUDF_EXPORT cudf {
81 std::unique_ptr<table> from_dlpack(
82  DLManagedTensor const* managed_tensor,
84 
103 DLManagedTensor* to_dlpack(
104  table_view const& input,
106  // end of group
108 
122  std::string name;
123  std::vector<column_metadata> children_meta;
124 
130  column_metadata(std::string _name) : name(std::move(_name)) {}
131  column_metadata() = default;
132 };
133 
156 [[deprecated("Use cudf::to_arrow_host")]] std::shared_ptr<arrow::Table> to_arrow(
157  table_view input,
158  std::vector<column_metadata> const& metadata = {},
160  arrow::MemoryPool* ar_mr = arrow::default_memory_pool());
161 
181 [[deprecated("Use cudf::to_arrow_host")]] std::shared_ptr<arrow::Scalar> to_arrow(
182  cudf::scalar const& input,
183  column_metadata const& metadata = {},
185  arrow::MemoryPool* ar_mr = arrow::default_memory_pool());
186 
191 using unique_schema_t = std::unique_ptr<ArrowSchema, void (*)(ArrowSchema*)>;
192 
197 using unique_device_array_t = std::unique_ptr<ArrowDeviceArray, void (*)(ArrowDeviceArray*)>;
198 
216 
242  cudf::table&& table,
245 
271  cudf::column&& col,
274 
303  cudf::table_view const& table,
306 
335  cudf::column_view const& col,
338 
360  cudf::table_view const& table,
363 
385  cudf::column_view const& col,
388 
399 [[deprecated("Use cudf::from_arrow_host")]] std::unique_ptr<table> from_arrow(
400  arrow::Table const& input,
403 
417 [[deprecated("See docstring for migration strategies")]] std::unique_ptr<cudf::scalar> from_arrow(
418  arrow::Scalar const& input,
421 
437 std::unique_ptr<cudf::table> from_arrow(
438  ArrowSchema const* schema,
439  ArrowArray const* input,
442 
456 std::unique_ptr<cudf::column> from_arrow_column(
457  ArrowSchema const* schema,
458  ArrowArray const* input,
461 
480 std::unique_ptr<table> from_arrow_host(
481  ArrowSchema const* schema,
482  ArrowDeviceArray const* input,
485 
499 std::unique_ptr<table> from_arrow_stream(
500  ArrowArrayStream* input,
503 
521 std::unique_ptr<column> from_arrow_host_column(
522  ArrowSchema const* schema,
523  ArrowDeviceArray const* input,
526 
531 using owned_columns_t = std::vector<std::unique_ptr<cudf::column>>;
532 
541 template <typename ViewType>
548  explicit custom_view_deleter(owned_columns_t&& owned) : owned_mem_{std::move(owned)} {}
549 
555  void operator()(ViewType* ptr) const { delete ptr; }
556 
558 };
559 
565  std::unique_ptr<cudf::table_view, custom_view_deleter<cudf::table_view>>;
566 
603  ArrowSchema const* schema,
604  ArrowDeviceArray const* input,
607 
613  std::unique_ptr<cudf::column_view, custom_view_deleter<cudf::column_view>>;
614 
646  ArrowSchema const* schema,
647  ArrowDeviceArray const* input,
650  // end of group
652 } // namespace CUDF_EXPORT cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
A container of nullable device data as a column of elements.
Definition: column.hpp:48
An owning class to represent a singular value.
Definition: scalar.hpp:49
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:200
A set of cudf::column's of the same size.
Definition: table.hpp:41
Class definition for cudf::column.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
std::unique_ptr< cudf::table_view, custom_view_deleter< cudf::table_view > > unique_table_view_t
typedef for a unique_ptr to a cudf::table_view with custom deleter
Definition: interop.hpp:565
std::vector< std::unique_ptr< cudf::column > > owned_columns_t
typedef for a vector of owning columns, used for conversion from ArrowDeviceArray
Definition: interop.hpp:531
unique_device_array_t to_arrow_device(cudf::column_view const &col, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create ArrowDeviceArray from a column view.
std::shared_ptr< arrow::Scalar > to_arrow(cudf::scalar const &input, column_metadata const &metadata={}, rmm::cuda_stream_view stream=cudf::get_default_stream(), arrow::MemoryPool *ar_mr=arrow::default_memory_pool())
Create arrow::Scalar from cudf scalar input
unique_schema_t to_arrow_schema(cudf::table_view const &input, cudf::host_span< column_metadata const > metadata)
Create ArrowSchema from cudf table and metadata.
std::unique_ptr< column > from_arrow_host_column(ArrowSchema const *schema, ArrowDeviceArray const *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::column from given ArrowDeviceArray input.
unique_column_view_t from_arrow_device_column(ArrowSchema const *schema, ArrowDeviceArray const *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::column_view from given ArrowDeviceArray and ArrowSchema
std::unique_ptr< cudf::column_view, custom_view_deleter< cudf::column_view > > unique_column_view_t
typedef for a unique_ptr to a cudf::column_view with custom deleter
Definition: interop.hpp:613
std::unique_ptr< ArrowSchema, void(*)(ArrowSchema *)> unique_schema_t
typedef for a unique_ptr to an ArrowSchema with custom deleter
Definition: interop.hpp:191
std::unique_ptr< ArrowDeviceArray, void(*)(ArrowDeviceArray *)> unique_device_array_t
typedef for a unique_ptr to an ArrowDeviceArray with a custom deleter
Definition: interop.hpp:197
std::unique_ptr< table > from_arrow_host(ArrowSchema const *schema, ArrowDeviceArray const *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::table from given ArrowDeviceArray input.
std::unique_ptr< table > from_arrow_stream(ArrowArrayStream *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::table from given ArrowArrayStream input.
unique_device_array_t to_arrow_host(cudf::column_view const &col, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Copy column view data to host and create ArrowDeviceArray for it.
std::unique_ptr< cudf::column > from_arrow_column(ArrowSchema const *schema, ArrowArray const *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::column from a given ArrowArray and ArrowSchema input.
unique_table_view_t from_arrow_device(ArrowSchema const *schema, ArrowDeviceArray const *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::table_view from given ArrowDeviceArray and ArrowSchema
std::unique_ptr< cudf::table > from_arrow(ArrowSchema const *schema, ArrowArray const *input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Create cudf::table from given ArrowArray and ArrowSchema input.
DLManagedTensor * to_dlpack(table_view const &input, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Convert a cudf table into a DLPack DLTensor.
std::unique_ptr< table > from_dlpack(DLManagedTensor const *managed_tensor, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Convert a DLPack DLTensor into a cudf table.
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
device_memory_resource * get_current_device_resource()
cuDF interfaces
Definition: aggregation.hpp:35
APIs for spans.
Detailed metadata information for arrow array.
Definition: interop.hpp:121
column_metadata(std::string _name)
Construct a new column metadata object.
Definition: interop.hpp:130
std::vector< column_metadata > children_meta
Metadata of children of the column.
Definition: interop.hpp:123
std::string name
Name of the column.
Definition: interop.hpp:122
functor for a custom deleter to a unique_ptr of table_view
Definition: interop.hpp:542
void operator()(ViewType *ptr) const
operator to delete the unique_ptr
Definition: interop.hpp:555
owned_columns_t owned_mem_
Owned columns that must be deleted.
Definition: interop.hpp:557
custom_view_deleter(owned_columns_t &&owned)
Construct a new custom view deleter object.
Definition: interop.hpp:548
C++20 std::span with reduced feature set.
Definition: span.hpp:231
Class definition for cudf::table.
Class definitions for (mutable)_table_view
Type declarations for libcudf.