-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-43541: [C++] Check accepted device allocation types before executing kernel #43542
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
Open
felipecrv
wants to merge
11
commits into
apache:main
Choose a base branch
from
felipecrv:check_device_type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
948195e
cpp: Constrain InputTypes by a set of accepted allocation device types
felipecrv 4abb198
cpp: Expose AdjustNonNullable on internal to use it in data.h
felipecrv ba87d48
cpp: Make DropNull[Chunked]Array CUDA-safe
felipecrv 3ddf706
array.pxi: Remove _assert_cpu() from __array__
felipecrv 039aaa1
array.pxi: Remove _assert_cpu() from to_pylist()
felipecrv 699860d
test_array.py: Add another test to __getitem__
felipecrv d646f6e
array.pxi: Let C++ check device type for 4 functions
felipecrv eb1a0d8
array.pxi: Let C++ check device type for take/filter
felipecrv da36961
array.pxi: Let C++ check device type for cast/is_null/is_nan/is_valid…
felipecrv a1c4a44
array.pxi: Let C++ check device type for drop_null
felipecrv 610750b
test_array.py: Add another invocation for drop_null
felipecrv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| #include <string> | ||
|
|
||
| #include "arrow/buffer.h" | ||
| #include "arrow/chunked_array.h" | ||
| #include "arrow/compute/exec.h" | ||
| #include "arrow/device_allocation_type_set.h" | ||
| #include "arrow/result.h" | ||
|
|
@@ -431,6 +432,25 @@ bool InputType::Matches(const Datum& value) const { | |
| return Matches(*value.type()); | ||
| } | ||
|
|
||
| bool InputType::MatchesDeviceAllocationType(const Datum& value) const { | ||
| DCHECK(Matches(value)); | ||
| switch (value.kind()) { | ||
| case Datum::NONE: | ||
| case Datum::RECORD_BATCH: | ||
| case Datum::TABLE: | ||
|
||
| break; | ||
| case Datum::ARRAY: | ||
| return accepted_device_types_.contains(value.array()->device_type()); | ||
| case Datum::CHUNKED_ARRAY: | ||
| return accepted_device_types_.Contains(value.chunked_array()->device_types()); | ||
| case Datum::SCALAR: | ||
| // Scalars are asssumed as always residing in CPU memory for now. | ||
| return accepted_device_types_.contains(DeviceAllocationType::kCPU); | ||
| } | ||
| DCHECK(false) << "MatchesDeviceAllocationType expects ARRAY, CHUNKED_ARRAY or SCALAR"; | ||
| return false; | ||
| } | ||
|
|
||
| const std::shared_ptr<DataType>& InputType::type() const { | ||
| DCHECK_EQ(InputType::EXACT_TYPE, kind_); | ||
| return type_; | ||
|
|
@@ -529,6 +549,50 @@ bool KernelSignature::MatchesInputs(const std::vector<TypeHolder>& types) const | |
| return true; | ||
| } | ||
|
|
||
| bool KernelSignature::MatchesDeviceAllocationTypes( | ||
| const std::vector<Datum>& args, DeviceAllocationTypeSet* out_expected_device_types, | ||
| int* out_offending_arg_index) const { | ||
| DeviceAllocationTypeSet expected_device_types; | ||
| int offending_arg_index = 0; | ||
| bool matches = true; | ||
| if (is_varargs_) { | ||
| for (size_t i = 0; i < args.size(); ++i) { | ||
| auto& param_type = in_types_[std::min(i, in_types_.size() - 1)]; | ||
| DCHECK(param_type.Matches(*args[i].type())); | ||
| if (!param_type.MatchesDeviceAllocationType(args[i])) { | ||
| matches = false; | ||
| expected_device_types = param_type.accepted_device_types(); | ||
| offending_arg_index = static_cast<int>(i); | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| DCHECK(args.size() == in_types_.size()); | ||
| if (args.size() != in_types_.size()) { | ||
| matches = false; | ||
| } else { | ||
| for (size_t i = 0; i < in_types_.size(); ++i) { | ||
| auto& param_type = in_types_[i]; | ||
| DCHECK(param_type.Matches(*args[i].type())); | ||
| if (!param_type.MatchesDeviceAllocationType(args[i])) { | ||
| matches = false; | ||
| offending_arg_index = static_cast<int>(i); | ||
| expected_device_types = param_type.accepted_device_types(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (out_expected_device_types) { | ||
| *out_expected_device_types = expected_device_types; | ||
| } | ||
| if (out_offending_arg_index) { | ||
| *out_offending_arg_index = offending_arg_index; | ||
| } | ||
| return matches; | ||
| } | ||
|
|
||
| size_t KernelSignature::Hash() const { | ||
| if (hash_code_ != 0) { | ||
| return hash_code_; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will probably remove this
DCHECKand keep the ones inKernelSignature::MatchesDeviceAllocationTypes.