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-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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
948195e4abb198ba87d483ddf706039aaa1699860dd646f6eeb1a0d8da36961a1c4a44610750bFile 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 |
|---|---|---|
| @@ -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: | ||
Comment on lines
439
to
440
| ||
| 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_; | ||
Uh oh!
There was an error while loading. Please reload this page.
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.