felipecrv commented on code in PR #36489:
URL: https://github.com/apache/arrow/pull/36489#discussion_r1254877854
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -663,6 +672,115 @@ Status ExportRecordBatch(const RecordBatch& batch, struct
ArrowArray* out,
return Status::OK();
}
+//////////////////////////////////////////////////////////////////////////
+// C device arrays
+
+Result<std::pair<DeviceType, int64_t>> validate_device_info(const ArrayData&
data) {
+ DeviceType device_type = DeviceType::UNKNOWN;
+ int64_t device_id = -1;
+
+ for (const auto& buf : data.buffers) {
+ if (!buf) {
+ // some buffers might be null
+ // for example, the null bitmap is optional if there's no nulls
+ continue;
+ }
+
+ if (device_type == DeviceType::UNKNOWN) {
+ device_type = buf->device_type();
+ device_id = buf->device()->device_id();
+ continue;
+ }
+
+ if (buf->device_type() != device_type) {
+ return Status::Invalid(
+ "exporting device array with buffers on more than one device.");
+ }
+
+ if (buf->device()->device_id() != device_id) {
+ return Status::Invalid(
+ "exporting device array with buffers on multiple device ids.");
+ }
+ }
+
+ // recursively check the children
+ auto info = std::make_pair(device_type, device_id);
Review Comment:
You won't have to do any comparisons in the second for loop. Just
recursively call the auxiliary function passing the accumulators.
--
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]