pitrou commented on code in PR #36489:
URL: https://github.com/apache/arrow/pull/36489#discussion_r1260751781
##########
cpp/src/arrow/c/bridge.h:
##########
@@ -166,6 +166,140 @@ Result<std::shared_ptr<RecordBatch>>
ImportRecordBatch(struct ArrowArray* array,
/// @}
+/// \defgroup c-data-device-interface Functions for working with the C data
device
+/// interface.
+///
+/// @{
+
+/// \brief EXPERIMENTAL: Type for freeing a sync event
+///
+/// If synchronization is necessary for accessing the data on a device,
+/// a pointer to an event needs to be passed when exporting the device
+/// array. It's the responsibility of the release function for the array
+/// to release the event.
+using ReleaseEventFunc = void (*)(void*);
+
+/// \brief EXPERIMENTAL: Export C++ Array as an ArrowDeviceArray.
+///
+/// The resulting ArrowDeviceArray struct keeps the array data and buffers
alive
+/// until its release callback is called by the consumer. All buffers in
+/// the provided array MUST have the same device_type, otherwise an error
+/// will be returned.
+///
+/// If a non-null sync_event is provided, then the sync_release func must also
be
+/// non-null. If the sync_event is null, then the sync_release parameter is
not called.
+///
+/// \param[in] array Array object to export
+/// \param[in] sync_event A pointer to an event-like object if necessary for
+/// synchronization, otherwise null.
+/// \param[in] sync_release Function pointer to release the sync event
+/// \param[out] out C struct to export the array to
+/// \param[out] out_schema optional C struct to export the array type to
+ARROW_EXPORT
+Status ExportDeviceArray(const Array& array, void* sync_event,
+ ReleaseEventFunc sync_release, struct
ArrowDeviceArray* out,
+ struct ArrowSchema* out_schema = NULLPTR);
+
+/// \brief EXPERIMENTAL: Export C++ RecordBatch as an ArrowDeviceArray.
+///
+/// The record batch is exported as if it were a struct array.
+/// The resulting ArrowDeviceArray struct keeps the record batch data and
buffers alive
+/// until its release callback is called by the consumer.
+///
+/// All buffers of all columns in the record batch must have the same
device_type
+/// otherwise an error will be returned. If columns are on different devices,
+/// they should be exported using different ArrowDeviceArray instances.
+///
+/// If a non-null sync_event is provided, then the sync_release func must also
be
+/// non-null. If the sync_event is null, then the sync_release parameter is
ignored.
+///
+/// \param[in] batch Record batch to export
+/// \param[in] sync_event A pointer to an event-like object if necessary for
+/// synchronization, otherwise null. \param[in] sync_release Function pointer
to release
+/// the sync event \param[out] out C struct where to export the record batch
\param[out]
+/// out_schema optional C struct where to export the record batch schema
+ARROW_EXPORT
+Status ExportDeviceRecordBatch(const RecordBatch& batch, void* sync_event,
+ ReleaseEventFunc sync_release,
+ struct ArrowDeviceArray* out,
+ struct ArrowSchema* out_schema = NULLPTR);
+
+class ARROW_EXPORT DeviceMemoryMgr {
+ public:
+ virtual ~DeviceMemoryMgr() = default;
+
+ virtual Result<std::shared_ptr<MemoryManager>> get_manager(ArrowDeviceType
device_type,
+ int64_t
device_id) const = 0;
+};
Review Comment:
If there's only a single virtual method, just use a `std::function`? Though,
again, I'm not sure having the user implement this makes a very usable API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]