zeroshade commented on code in PR #39770:
URL: https://github.com/apache/arrow/pull/39770#discussion_r1470153660
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -1851,10 +1853,25 @@ struct ArrayImporter {
template <typename OffsetType>
Status ImportStringValuesBuffer(int32_t offsets_buffer_id, int32_t buffer_id,
int64_t byte_width = 1) {
- auto offsets = data_->GetValues<OffsetType>(offsets_buffer_id);
+ if (device_type_ == DeviceAllocationType::kCPU) {
+ auto offsets = data_->GetValues<OffsetType>(offsets_buffer_id);
+ // Compute visible size of buffer
+ int64_t buffer_size =
+ (c_struct_->length > 0) ? byte_width * offsets[c_struct_->length] :
0;
+ return ImportBuffer(buffer_id, buffer_size);
+ }
+
+ // we only need the value of the last offset so let's just copy that
+ // one value from device to host.
+ auto single_value_buf =
+ SliceBuffer(data_->buffers[offsets_buffer_id],
+ c_struct_->length * sizeof(OffsetType),
sizeof(OffsetType));
+ ARROW_ASSIGN_OR_RAISE(
+ auto cpubuf, Buffer::ViewOrCopy(single_value_buf,
default_cpu_memory_manager()));
+ auto offsets = cpubuf->data_as<OffsetType>();
Review Comment:
Possibly, I didn't necessarily want to make this that large by adding to the
`MemoryManager` interface, but it's definitely a good idea to do in the future.
--
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]