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
use std::sync::Arc;
use super::{
Column, CudaEvent, DataFrame, InteropError, PreparedColumnExport, PreparedTableExport, Runtime, Series, Table,
dataframe_import_names, prepare_device_table_export_from_columns,
prepare_device_table_export_from_columns_with_readiness, prepare_from_owned_column, prepare_host_from_owned_column,
prepare_host_table_export_from_columns, wrap_imported_dataframe, wrap_imported_series,
};
impl Series {
/// Convenience consumer that imports a shared prepared export root into an
/// unnamed high-level `Series`.
pub fn try_import_from_prepared_column_export_into_runtime(
export: &PreparedColumnExport<'_>,
runtime: &Runtime,
) -> Result<Self, InteropError> {
let operation = "interop::Series::try_import_from_prepared_column_export_into_runtime";
let column = Column::try_import_from_prepared_column_export_into_runtime(export, runtime)?;
wrap_imported_series(column, operation)
}
/// Convenience producer that projects this high-level `Series` into the
/// shared prepared device export profile.
///
/// The returned export is producer-rooted. Consumers activate read access
/// later via [`PreparedColumnExport::try_activate_read_lease`].
///
/// The export describes `self`'s device buffers and holds a shared
/// `Arc<Column>` for its lifetime. The returned type still borrows `self`,
/// so it cannot outlive that borrow. Returns an [`InteropError`] when a
/// column's layout falls outside the prepared device profile, its buffers
/// are not on a CUDA device, or the execution binding or producer readiness
/// of `self`'s runtime domain is unavailable.
pub fn try_prepare_device_column_export(&self) -> Result<PreparedColumnExport<'_>, InteropError> {
prepare_from_owned_column(self.as_column(), "interop::Series::try_prepare_device_column_export")
// SAFETY: the Arc owns the projected storage and readiness domain.
.map(|export| unsafe { export.with_retained_owner(self.arc()) })
}
/// Convenience producer that projects this high-level `Series` into the
/// shared prepared host export profile.
///
/// This materializes the active logical range to owned host-visible bytes
/// and therefore is not zero-copy.
///
/// The `'static` export owns retained host copies and does not borrow `self`.
/// Returns an [`InteropError`] when a column's type or layout is not
/// supported by host export or its data cannot be copied to host memory.
pub fn try_prepare_host_column_export(&self) -> Result<PreparedColumnExport<'static>, InteropError> {
prepare_host_from_owned_column(self.as_column(), "interop::Series::try_prepare_host_column_export")
}
/// Convenience producer that projects this high-level `Series` into the
/// shared prepared device export profile with producer event-ordered
/// readiness.
pub fn try_prepare_device_column_export_with_event<'a>(
&'a self,
event: &'a CudaEvent,
) -> Result<PreparedColumnExport<'a>, InteropError> {
self.as_column()
.try_prepare_device_column_export_with_event(event)
// SAFETY: retain the column storage and the supplied readiness event.
.map(|export| unsafe { export.with_retained_owner(Arc::new((self.arc(), event.clone()))) })
}
}
impl DataFrame {
/// Imports a shared prepared table export root into a high-level
/// `DataFrame`, using `names` when supplied or schema names carried on the
/// shared root otherwise.
pub fn try_import_from_prepared_table_export_into_runtime(
export: &PreparedTableExport<'_>,
names: Option<Vec<String>>,
runtime: &Runtime,
) -> Result<Self, InteropError> {
let operation = "interop::DataFrame::try_import_from_prepared_table_export_into_runtime";
let names = dataframe_import_names(names, export.table().names(), operation)?;
let table = Table::try_import_from_prepared_table_export_into_runtime(export, runtime)?;
wrap_imported_dataframe(table, names, operation)
}
/// Convenience producer that projects this high-level `DataFrame` into the
/// shared prepared device export profile.
///
/// The returned export is producer-rooted. Consumers activate read access
/// later via [`PreparedTableExport::try_activate_read_lease`].
///
/// The export describes `self`'s device buffers and holds a clone of `self`
/// for its lifetime. The returned type still borrows `self`, so it cannot
/// outlive that borrow. Returns an [`InteropError`] when a column's layout
/// falls outside the prepared device profile, its buffers are not on a CUDA
/// device, or the execution binding or producer readiness of `self`'s
/// runtime domain is unavailable.
pub fn try_prepare_device_table_export(&self) -> Result<PreparedTableExport<'_>, InteropError> {
prepare_device_table_export_from_columns(
self.columns_map().values().map(AsRef::as_ref),
self.num_rows(),
Some(self.column_names_owned()),
self.execution_domain(),
"interop::DataFrame::try_prepare_device_table_export",
)
// SAFETY: the clone retains each column and its readiness domain.
.map(|export| unsafe { export.with_retained_owner(Arc::new(self.clone())) })
}
/// Convenience producer that projects this high-level `DataFrame` into the
/// shared prepared host export profile.
///
/// This materializes each supported top-level column to owned host-visible
/// bytes and therefore is not zero-copy.
///
/// The `'static` export owns retained host copies and does not borrow `self`.
/// Returns an [`InteropError`] when a column's type or layout is not
/// supported by host export or its data cannot be copied to host memory.
pub fn try_prepare_host_table_export(&self) -> Result<PreparedTableExport<'static>, InteropError> {
prepare_host_table_export_from_columns(
self.columns_map().values().map(AsRef::as_ref),
self.num_rows(),
Some(self.column_names_owned()),
"interop::DataFrame::try_prepare_host_table_export",
)
}
/// Convenience producer that projects this high-level `DataFrame` into the
/// shared prepared device export profile with producer event-ordered
/// readiness.
pub fn try_prepare_device_table_export_with_event<'a>(
&'a self,
event: &'a CudaEvent,
) -> Result<PreparedTableExport<'a>, InteropError> {
let operation = "interop::DataFrame::try_prepare_device_table_export_with_event";
let context =
super::table_export::DeviceTableExportContext::from_event(operation, self.execution_domain(), event)?;
prepare_device_table_export_from_columns_with_readiness(
self.columns_map().values().map(AsRef::as_ref),
self.num_rows(),
Some(self.column_names_owned()),
context,
)
// SAFETY: retain all frame columns and the supplied readiness event.
.map(|export| unsafe { export.with_retained_owner(Arc::new((self.clone(), event.clone()))) })
}
}