-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-40078: [C++] Import/Export ArrowDeviceArrayStream #40807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c80315d
ce18e5d
efff4fd
49190c9
858e8d5
5c36bee
e4d1699
469ac85
fda7737
9586883
ee531cf
889193c
d80464f
6dcc07d
ba58477
79b3600
f8c2b59
fcd8dc9
dca4503
3211ef3
ff521ab
aeff09f
35ef670
8443150
406ecf1
c22768a
bca54e2
d5a6332
71e152c
c9e63fd
df40625
9284893
915b723
46f436e
0a07bee
7b89fbf
4915884
3dc2d78
331ce10
9b14645
381bc7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,6 +224,42 @@ int64_t ArrayData::ComputeLogicalNullCount() const { | |
| return ArraySpan(*this).ComputeLogicalNullCount(); | ||
| } | ||
|
|
||
| DeviceAllocationType ArrayData::device_type() const { | ||
| // we're using 0 as a sentinel value for NOT YET ASSIGNED | ||
| // there is explicitly no constant DeviceAllocationType to represent | ||
| // the "UNASSIGNED" case as it is invalid for data to not have an | ||
| // assigned device type. If it's still 0 at the end, then we return | ||
| // CPU as the allocation device type | ||
| int type = 0; | ||
zeroshade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for (const auto& buf : buffers) { | ||
| if (!buf) continue; | ||
| if (type == 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition implies that, conversely, in non-debug mode we could immediately return when we encounter a buffer? Instead of continue looping on all buffers and children... |
||
| type = static_cast<int>(buf->device_type()); | ||
zeroshade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| DCHECK_EQ(type, static_cast<int>(buf->device_type())); | ||
|
||
| } | ||
| } | ||
|
|
||
| for (const auto& child : child_data) { | ||
| if (!child) continue; | ||
| if (type == 0) { | ||
| type = static_cast<int>(child->device_type()); | ||
| } else { | ||
| DCHECK_EQ(type, static_cast<int>(child->device_type())); | ||
| } | ||
| } | ||
|
|
||
| if (dictionary) { | ||
| if (type == 0) { | ||
| type = static_cast<int>(dictionary->device_type()); | ||
| } else { | ||
| DCHECK_EQ(type, static_cast<int>(dictionary->device_type())); | ||
| } | ||
| } | ||
|
|
||
| return type == 0 ? DeviceAllocationType::kCPU : static_cast<DeviceAllocationType>(type); | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Methods for ArraySpan | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,11 @@ struct ARROW_EXPORT ArrayData { | |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0) | ||
| : ArrayData(std::move(type), length, null_count, offset) { | ||
| this->buffers = std::move(buffers); | ||
| #ifndef NDEBUG | ||
| // in debug mode, call the `device_type` function to trigger | ||
| // the DCHECKs that validate all the buffers are on the same device | ||
| ARROW_UNUSED(this->device_type()); | ||
| #endif | ||
| } | ||
|
|
||
| ArrayData(std::shared_ptr<DataType> type, int64_t length, | ||
|
|
@@ -110,6 +115,12 @@ struct ARROW_EXPORT ArrayData { | |
| : ArrayData(std::move(type), length, null_count, offset) { | ||
| this->buffers = std::move(buffers); | ||
| this->child_data = std::move(child_data); | ||
| #ifndef NDEBUG | ||
| // in debug mode, call the `device_type` function to trigger | ||
| // the DCHECKs that validate all the buffers (including children) | ||
| // are on the same device | ||
| ARROW_UNUSED(this->device_type()); | ||
| #endif | ||
| } | ||
|
|
||
| static std::shared_ptr<ArrayData> Make(std::shared_ptr<DataType> type, int64_t length, | ||
|
|
@@ -358,6 +369,16 @@ struct ARROW_EXPORT ArrayData { | |
| /// \see GetNullCount | ||
| int64_t ComputeLogicalNullCount() const; | ||
|
|
||
| /// \brief Returns the device_type of the underlying buffers and children | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, but we tend to use infinitives in docstring ("return", not "returns") |
||
| /// | ||
| /// If there are no buffers in this ArrayData object, it just returns | ||
| /// DeviceAllocationType::kCPU as a default. We also assume that all buffers | ||
| /// should be allocated on the same device type and perform DCHECKs to confirm | ||
| /// this in debug mode. | ||
| /// | ||
| /// \return DeviceAllocationType | ||
| DeviceAllocationType device_type() const; | ||
|
|
||
| std::shared_ptr<DataType> type; | ||
| int64_t length = 0; | ||
| mutable std::atomic<int64_t> null_count{0}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.