-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathto_arrow_device.cu
613 lines (507 loc) · 22.8 KB
/
to_arrow_device.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/*
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "arrow_utilities.hpp"
#include <cudf/column/column.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/detail/device_scalar.hpp>
#include <cudf/detail/interop.hpp>
#include <cudf/detail/iterator.cuh>
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/dictionary/dictionary_column_view.hpp>
#include <cudf/interop.hpp>
#include <cudf/lists/lists_column_view.hpp>
#include <cudf/null_mask.hpp>
#include <cudf/strings/strings_column_view.hpp>
#include <cudf/table/table_view.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/memory_resource.hpp>
#include <cudf/utilities/traits.hpp>
#include <cudf/utilities/type_dispatcher.hpp>
#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>
#include <thrust/for_each.h>
#include <thrust/iterator/counting_iterator.h>
#include <nanoarrow/nanoarrow.h>
#include <nanoarrow/nanoarrow.hpp>
#include <nanoarrow/nanoarrow_device.h>
namespace cudf {
namespace detail {
namespace {
template <typename T>
void device_buffer_finalize(ArrowBufferAllocator* allocator, uint8_t*, int64_t)
{
auto* unique_buffer = reinterpret_cast<std::unique_ptr<T>*>(allocator->private_data);
delete unique_buffer;
}
template <typename>
struct is_device_scalar : public std::false_type {};
template <typename T>
struct is_device_scalar<cudf::detail::device_scalar<T>> : public std::true_type {};
template <typename>
struct is_device_uvector : public std::false_type {};
template <typename T>
struct is_device_uvector<rmm::device_uvector<T>> : public std::true_type {};
template <typename T>
int set_buffer(std::unique_ptr<T> device_buf, int64_t i, ArrowArray* out)
{
ArrowBuffer* buf = ArrowArrayBuffer(out, i);
auto ptr = reinterpret_cast<uint8_t*>(device_buf->data());
buf->size_bytes = [&] {
if constexpr (is_device_scalar<T>::value) {
return sizeof(typename T::value_type);
} else if constexpr (is_device_uvector<T>::value) {
return sizeof(typename T::value_type) * device_buf->size();
} else {
return device_buf->size();
}
}();
// we make a new unique_ptr and move to it in case there was a custom deleter
NANOARROW_RETURN_NOT_OK(
ArrowBufferSetAllocator(buf,
ArrowBufferDeallocator(&device_buffer_finalize<T>,
new std::unique_ptr<T>(std::move(device_buf)))));
buf->data = ptr;
return NANOARROW_OK;
}
struct dispatch_to_arrow_device {
template <typename T,
CUDF_ENABLE_IF(not is_rep_layout_compatible<T>() and not is_fixed_point<T>())>
int operator()(cudf::column&&, rmm::cuda_stream_view, rmm::device_async_resource_ref, ArrowArray*)
{
CUDF_FAIL("Unsupported type for to_arrow_device", cudf::data_type_error);
}
// cover rep layout compatible and decimal types
template <typename T, CUDF_ENABLE_IF(is_rep_layout_compatible<T>() or is_fixed_point<T>())>
int operator()(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out)
{
nanoarrow::UniqueArray tmp;
auto const storage_type = id_to_arrow_storage_type(column.type().id());
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), storage_type, column));
auto contents = column.release();
NANOARROW_RETURN_NOT_OK(set_contents(contents, tmp.get()));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
int set_null_mask(column::contents& contents, ArrowArray* out)
{
if (contents.null_mask) {
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.null_mask), validity_buffer_idx, out));
}
return NANOARROW_OK;
}
int set_contents(column::contents& contents, ArrowArray* out)
{
NANOARROW_RETURN_NOT_OK(set_null_mask(contents, out));
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.data), fixed_width_data_buffer_idx, out));
return NANOARROW_OK;
}
};
template <>
int dispatch_to_arrow_device::operator()<bool>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out)
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), NANOARROW_TYPE_BOOL, column));
auto bitmask = detail::bools_to_mask(column.view(), stream, mr);
auto contents = column.release();
NANOARROW_RETURN_NOT_OK(set_null_mask(contents, tmp.get()));
NANOARROW_RETURN_NOT_OK(
set_buffer(std::move(bitmask.first), fixed_width_data_buffer_idx, tmp.get()));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device::operator()<cudf::string_view>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out)
{
ArrowType nanoarrow_type = NANOARROW_TYPE_STRING;
if (column.num_children() > 0 &&
column.child(cudf::strings_column_view::offsets_column_index).type().id() ==
cudf::type_id::INT64) {
nanoarrow_type = NANOARROW_TYPE_LARGE_STRING;
}
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), nanoarrow_type, column));
if (column.size() == 0) {
// the scalar zero here is necessary because the spec for string arrays states
// that the offsets buffer should contain "length + 1" signed integers. So in
// the case of a 0 length string array, there should be exactly 1 value, zero,
// in the offsets buffer. While some arrow implementations may accept a zero-sized
// offsets buffer, best practices would be to allocate the buffer with the single value.
if (nanoarrow_type == NANOARROW_TYPE_STRING) {
auto zero = std::make_unique<cudf::detail::device_scalar<int32_t>>(0, stream, mr);
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(zero), fixed_width_data_buffer_idx, tmp.get()));
} else {
auto zero = std::make_unique<cudf::detail::device_scalar<int64_t>>(0, stream, mr);
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(zero), fixed_width_data_buffer_idx, tmp.get()));
}
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
auto contents = column.release();
NANOARROW_RETURN_NOT_OK(set_null_mask(contents, tmp.get()));
auto offsets_contents =
contents.children[cudf::strings_column_view::offsets_column_index]->release();
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(offsets_contents.data), 1, tmp.get()));
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(contents.data), 2, tmp.get()));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device::operator()<cudf::list_view>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out);
template <>
int dispatch_to_arrow_device::operator()<cudf::dictionary32>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out);
template <>
int dispatch_to_arrow_device::operator()<cudf::struct_view>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out)
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), NANOARROW_TYPE_STRUCT, column));
NANOARROW_RETURN_NOT_OK(ArrowArrayAllocateChildren(tmp.get(), column.num_children()));
auto contents = column.release();
NANOARROW_RETURN_NOT_OK(set_null_mask(contents, tmp.get()));
for (size_t i = 0; i < size_t(tmp->n_children); ++i) {
ArrowArray* child_ptr = tmp->children[i];
auto& child = contents.children[i];
NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher(
child->type(), dispatch_to_arrow_device{}, std::move(*child), stream, mr, child_ptr));
}
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device::operator()<cudf::list_view>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out)
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), NANOARROW_TYPE_LIST, column));
NANOARROW_RETURN_NOT_OK(ArrowArrayAllocateChildren(tmp.get(), 1));
auto contents = column.release();
NANOARROW_RETURN_NOT_OK(set_null_mask(contents, tmp.get()));
auto offsets_contents =
contents.children[cudf::lists_column_view::offsets_column_index]->release();
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(offsets_contents.data), 1, tmp.get()));
auto& child = contents.children[cudf::lists_column_view::child_column_index];
NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher(
child->type(), dispatch_to_arrow_device{}, std::move(*child), stream, mr, tmp->children[0]));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device::operator()<cudf::dictionary32>(cudf::column&& column,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr,
ArrowArray* out)
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(
tmp.get(),
id_to_arrow_type(column.child(cudf::dictionary_column_view::indices_column_index).type().id()),
column));
NANOARROW_RETURN_NOT_OK(ArrowArrayAllocateDictionary(tmp.get()));
auto contents = column.release();
NANOARROW_RETURN_NOT_OK(set_null_mask(contents, tmp.get()));
auto indices_contents =
contents.children[cudf::dictionary_column_view::indices_column_index]->release();
NANOARROW_RETURN_NOT_OK(
set_buffer(std::move(indices_contents.data), fixed_width_data_buffer_idx, tmp.get()));
auto& keys = contents.children[cudf::dictionary_column_view::keys_column_index];
NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher(
keys->type(), dispatch_to_arrow_device{}, std::move(*keys), stream, mr, tmp->dictionary));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
struct dispatch_to_arrow_device_view {
cudf::column_view column;
rmm::cuda_stream_view stream;
rmm::device_async_resource_ref mr;
template <typename T,
CUDF_ENABLE_IF(not is_rep_layout_compatible<T>() and not is_fixed_point<T>())>
int operator()(ArrowArray*) const
{
CUDF_FAIL("Unsupported type for to_arrow_device", cudf::data_type_error);
}
template <typename T, CUDF_ENABLE_IF(is_rep_layout_compatible<T>() or is_fixed_point<T>())>
int operator()(ArrowArray* out) const
{
nanoarrow::UniqueArray tmp;
auto const storage_type = id_to_arrow_storage_type(column.type().id());
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), storage_type, column));
NANOARROW_RETURN_NOT_OK(set_null_mask(column, tmp.get()));
NANOARROW_RETURN_NOT_OK(set_view_to_buffer(column, tmp.get()));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
int set_buffer_view(void const* in_ptr, size_t size, int64_t i, ArrowArray* out) const
{
ArrowBuffer* buf = ArrowArrayBuffer(out, i);
buf->size_bytes = size;
// reset the deallocator to do nothing since this is a non-owning view
NANOARROW_RETURN_NOT_OK(ArrowBufferSetAllocator(
buf, ArrowBufferDeallocator([](ArrowBufferAllocator*, uint8_t*, int64_t) {}, nullptr)));
buf->data = const_cast<uint8_t*>(reinterpret_cast<uint8_t const*>(in_ptr));
return NANOARROW_OK;
}
int set_null_mask(column_view column, ArrowArray* out) const
{
if (column.nullable()) {
NANOARROW_RETURN_NOT_OK(set_buffer_view(column.null_mask(),
bitmask_allocation_size_bytes(column.size()),
validity_buffer_idx,
out));
}
return NANOARROW_OK;
}
int set_view_to_buffer(column_view column, ArrowArray* out) const
{
auto const type_size = cudf::size_of(column.type());
return set_buffer_view(column.head<uint8_t>() + (type_size * column.offset()),
column.size() * type_size,
fixed_width_data_buffer_idx,
out);
}
};
template <>
int dispatch_to_arrow_device_view::operator()<bool>(ArrowArray* out) const
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), NANOARROW_TYPE_BOOL, column));
auto bitmask = detail::bools_to_mask(column, stream, mr);
NANOARROW_RETURN_NOT_OK(
set_buffer(std::move(bitmask.first), fixed_width_data_buffer_idx, tmp.get()));
NANOARROW_RETURN_NOT_OK(set_null_mask(column, tmp.get()));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device_view::operator()<cudf::string_view>(ArrowArray* out) const
{
ArrowType nanoarrow_type = NANOARROW_TYPE_STRING;
if (column.num_children() > 0 &&
column.child(cudf::strings_column_view::offsets_column_index).type().id() ==
cudf::type_id::INT64) {
nanoarrow_type = NANOARROW_TYPE_LARGE_STRING;
}
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), nanoarrow_type, column));
if (column.size() == 0) {
// https://github.com/rapidsai/cudf/pull/15047#discussion_r1546528552
if (nanoarrow_type == NANOARROW_TYPE_LARGE_STRING) {
auto zero = std::make_unique<cudf::detail::device_scalar<int64_t>>(0, stream, mr);
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(zero), fixed_width_data_buffer_idx, tmp.get()));
} else {
auto zero = std::make_unique<cudf::detail::device_scalar<int32_t>>(0, stream, mr);
NANOARROW_RETURN_NOT_OK(set_buffer(std::move(zero), fixed_width_data_buffer_idx, tmp.get()));
}
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
NANOARROW_RETURN_NOT_OK(set_null_mask(column, tmp.get()));
auto const scv = cudf::strings_column_view(column);
NANOARROW_RETURN_NOT_OK(set_view_to_buffer(scv.offsets(), tmp.get()));
NANOARROW_RETURN_NOT_OK(
set_buffer_view(scv.chars_begin(stream), scv.chars_size(stream), 2, tmp.get()));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device_view::operator()<cudf::list_view>(ArrowArray* out) const;
template <>
int dispatch_to_arrow_device_view::operator()<cudf::dictionary32>(ArrowArray* out) const;
template <>
int dispatch_to_arrow_device_view::operator()<cudf::struct_view>(ArrowArray* out) const
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), NANOARROW_TYPE_STRUCT, column));
NANOARROW_RETURN_NOT_OK(ArrowArrayAllocateChildren(tmp.get(), column.num_children()));
NANOARROW_RETURN_NOT_OK(set_null_mask(column, tmp.get()));
for (size_t i = 0; i < size_t(tmp->n_children); ++i) {
ArrowArray* child_ptr = tmp->children[i];
auto const child = column.child(i);
NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher(
child.type(), dispatch_to_arrow_device_view{child, stream, mr}, child_ptr));
}
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device_view::operator()<cudf::list_view>(ArrowArray* out) const
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(tmp.get(), NANOARROW_TYPE_LIST, column));
NANOARROW_RETURN_NOT_OK(ArrowArrayAllocateChildren(tmp.get(), 1));
NANOARROW_RETURN_NOT_OK(set_null_mask(column, tmp.get()));
auto const lcv = cudf::lists_column_view(column);
NANOARROW_RETURN_NOT_OK(set_view_to_buffer(lcv.offsets(), tmp.get()));
auto child = lcv.child();
NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher(
child.type(), dispatch_to_arrow_device_view{child, stream, mr}, tmp->children[0]));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
template <>
int dispatch_to_arrow_device_view::operator()<cudf::dictionary32>(ArrowArray* out) const
{
nanoarrow::UniqueArray tmp;
NANOARROW_RETURN_NOT_OK(initialize_array(
tmp.get(),
id_to_arrow_type(column.child(cudf::dictionary_column_view::indices_column_index).type().id()),
column));
NANOARROW_RETURN_NOT_OK(ArrowArrayAllocateDictionary(tmp.get()));
NANOARROW_RETURN_NOT_OK(set_null_mask(column, tmp.get()));
auto const dcv = cudf::dictionary_column_view(column);
NANOARROW_RETURN_NOT_OK(set_view_to_buffer(dcv.indices(), tmp.get()));
auto keys = dcv.keys();
NANOARROW_RETURN_NOT_OK(cudf::type_dispatcher(
keys.type(), dispatch_to_arrow_device_view{keys, stream, mr}, tmp->dictionary));
ArrowArrayMove(tmp.get(), out);
return NANOARROW_OK;
}
struct ArrowDeviceArrayPrivateData {
ArrowArray parent;
cudaEvent_t sync_event;
};
void ArrowDeviceArrayRelease(ArrowArray* array)
{
auto private_data = reinterpret_cast<ArrowDeviceArrayPrivateData*>(array->private_data);
RMM_ASSERT_CUDA_SUCCESS(cudaEventDestroy(private_data->sync_event));
ArrowArrayRelease(&private_data->parent);
delete private_data;
array->release = nullptr;
}
unique_device_array_t create_device_array(nanoarrow::UniqueArray&& out,
rmm::cuda_stream_view stream)
{
NANOARROW_THROW_NOT_OK(
ArrowArrayFinishBuilding(out.get(), NANOARROW_VALIDATION_LEVEL_MINIMAL, nullptr));
auto private_data = std::make_unique<detail::ArrowDeviceArrayPrivateData>();
CUDF_CUDA_TRY(cudaEventCreate(&private_data->sync_event));
CUDF_CUDA_TRY(cudaEventRecord(private_data->sync_event, stream.value()));
ArrowArrayMove(out.get(), &private_data->parent);
unique_device_array_t result(new ArrowDeviceArray, [](ArrowDeviceArray* arr) {
if (arr->array.release != nullptr) { ArrowArrayRelease(&arr->array); }
delete arr;
});
result->device_id = rmm::get_current_cuda_device().value();
result->device_type = ARROW_DEVICE_CUDA;
result->sync_event = &private_data->sync_event;
result->array = private_data->parent; // makes a shallow copy
result->array.private_data = private_data.release();
result->array.release = &detail::ArrowDeviceArrayRelease;
return result;
}
} // namespace
unique_device_array_t to_arrow_device(cudf::table&& table,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
nanoarrow::UniqueArray tmp;
NANOARROW_THROW_NOT_OK(ArrowArrayInitFromType(tmp.get(), NANOARROW_TYPE_STRUCT));
NANOARROW_THROW_NOT_OK(ArrowArrayAllocateChildren(tmp.get(), table.num_columns()));
tmp->length = table.num_rows();
tmp->null_count = 0;
auto cols = table.release();
for (size_t i = 0; i < cols.size(); ++i) {
auto child = tmp->children[i];
auto col = cols[i].get();
NANOARROW_THROW_NOT_OK(cudf::type_dispatcher(
col->type(), detail::dispatch_to_arrow_device{}, std::move(*col), stream, mr, child));
}
return create_device_array(std::move(tmp), stream);
}
unique_device_array_t to_arrow_device(cudf::column&& col,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
nanoarrow::UniqueArray tmp;
NANOARROW_THROW_NOT_OK(cudf::type_dispatcher(
col.type(), detail::dispatch_to_arrow_device{}, std::move(col), stream, mr, tmp.get()));
return create_device_array(std::move(tmp), stream);
}
unique_device_array_t to_arrow_device(cudf::table_view const& table,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
nanoarrow::UniqueArray tmp;
NANOARROW_THROW_NOT_OK(ArrowArrayInitFromType(tmp.get(), NANOARROW_TYPE_STRUCT));
NANOARROW_THROW_NOT_OK(ArrowArrayAllocateChildren(tmp.get(), table.num_columns()));
tmp->length = table.num_rows();
tmp->null_count = 0;
for (cudf::size_type i = 0; i < table.num_columns(); ++i) {
auto child = tmp->children[i];
auto col = table.column(i);
NANOARROW_THROW_NOT_OK(cudf::type_dispatcher(
col.type(), detail::dispatch_to_arrow_device_view{col, stream, mr}, child));
}
return create_device_array(std::move(tmp), stream);
}
unique_device_array_t to_arrow_device(cudf::column_view const& col,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
nanoarrow::UniqueArray tmp;
NANOARROW_THROW_NOT_OK(cudf::type_dispatcher(
col.type(), detail::dispatch_to_arrow_device_view{col, stream, mr}, tmp.get()));
return create_device_array(std::move(tmp), stream);
}
} // namespace detail
unique_device_array_t to_arrow_device(cudf::table&& table,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::to_arrow_device(std::move(table), stream, mr);
}
unique_device_array_t to_arrow_device(cudf::column&& col,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::to_arrow_device(std::move(col), stream, mr);
}
unique_device_array_t to_arrow_device(cudf::table_view const& table,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::to_arrow_device(table, stream, mr);
}
unique_device_array_t to_arrow_device(cudf::column_view const& col,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::to_arrow_device(col, stream, mr);
}
} // namespace cudf