Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c80315dce18e5defff4fd49190c9858e8d55c36beee4d1699469ac85fda77379586883ee531cf889193cd80464f6dcc07dba5847779b3600f8c2b59fcd8dc9dca45033211ef3ff521abaeff09f35ef6708443150406ecf1c22768abca54e2d5a633271e152cc9e63fddf406259284893915b72346f436e0a07bee7b89fbf49158843dc2d78331ce109b14645381bc7dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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
Uh oh!There was an error while loading. Please reload this page. | ||
| 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
Uh oh!There was an error while loading. Please reload this page. | ||
| } else { | ||
| DCHECK_EQ(type, static_cast<int>(buf->device_type())); | ||
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. Should this only be a debug check? You can create an array with buffers from a different device, or do we disallow that upon creation? MemberAuthor 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. We don't currently disallow it on creation. We don't do any checking of the buffer device types on ArrayData or Array creation currently. It feels wrong to do so in a non-debug context but it might make sense to add debug checks to confirm the device types of all the buffers match in the constructor. Thoughts? 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.
I think that would make sense yes, if we don't want to support that (I don't know if there would actually be use cases for allowing it, in which case I would rather expect a normal error here when trying to export it, saying it requires a single device type) MemberAuthor 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. Added the debug checks in the ArrayData constructors | ||
| } | ||
| } | ||
| 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.
Uh oh!
There was an error while loading. Please reload this page.