-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-43854: [C++] Expose the set of device types where a ChunkedArray is allocated #43853
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4a60e6
cpp: Add the DeviceAllocationTypeSet class
felipecrv 3480c1b
cpp: Put DeviceAllocationTypeSet in the cheapest possible header
felipecrv 338ca42
cpp: Move DeviceAllocationType to type_fwd.h
felipecrv 7172224
cpp: Add Datum::device_types() definition
felipecrv 46b0400
fixup! cpp: Add the DeviceAllocationTypeSet class
felipecrv 2b1bd82
cpp: Forward-declare DeviceAllocationTypeSet
felipecrv 8cd3da6
cpp: Add ChunkedArray::is_cpu() and tests
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
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
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "arrow/device_allocation_type_set.h" | ||
| #include "arrow/type_fwd.h" | ||
|
|
||
| namespace arrow { | ||
|
|
||
| const char* DeviceAllocationTypeToCStr(DeviceAllocationType type) { | ||
| switch (type) { | ||
| case DeviceAllocationType::kCPU: | ||
| return "CPU"; | ||
| case DeviceAllocationType::kCUDA: | ||
| return "CUDA"; | ||
| case DeviceAllocationType::kCUDA_HOST: | ||
| return "CUDA_HOST"; | ||
| case DeviceAllocationType::kOPENCL: | ||
| return "OPENCL"; | ||
| case DeviceAllocationType::kVULKAN: | ||
| return "VULKAN"; | ||
| case DeviceAllocationType::kMETAL: | ||
| return "METAL"; | ||
| case DeviceAllocationType::kVPI: | ||
| return "VPI"; | ||
| case DeviceAllocationType::kROCM: | ||
| return "ROCM"; | ||
| case DeviceAllocationType::kROCM_HOST: | ||
| return "ROCM_HOST"; | ||
| case DeviceAllocationType::kEXT_DEV: | ||
| return "EXT_DEV"; | ||
| case DeviceAllocationType::kCUDA_MANAGED: | ||
| return "CUDA_MANAGED"; | ||
| case DeviceAllocationType::kONEAPI: | ||
| return "ONEAPI"; | ||
| case DeviceAllocationType::kWEBGPU: | ||
| return "WEBGPU"; | ||
| case DeviceAllocationType::kHEXAGON: | ||
| return "HEXAGON"; | ||
| } | ||
| return "<UNKNOWN>"; | ||
| } | ||
|
|
||
| std::string DeviceAllocationTypeSet::ToString() const { | ||
| std::string result = "{"; | ||
| for (int i = 1; i <= kDeviceAllocationTypeMax; i++) { | ||
| if (device_type_bitset_.test(i)) { | ||
| // Skip all the unused values in the enum. | ||
| switch (i) { | ||
| case 0: | ||
| case 5: | ||
| case 6: | ||
| continue; | ||
| } | ||
| if (result.size() > 1) { | ||
| result += ", "; | ||
| } | ||
| result += DeviceAllocationTypeToCStr(static_cast<DeviceAllocationType>(i)); | ||
| } | ||
| } | ||
| result += "}"; | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace arrow |
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 |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <bitset> | ||
| #include <string> | ||
|
|
||
| #include "arrow/type_fwd.h" | ||
| #include "arrow/util/visibility.h" | ||
|
|
||
| namespace arrow { | ||
|
|
||
| ARROW_EXPORT | ||
| const char* DeviceAllocationTypeToCStr(DeviceAllocationType type); | ||
|
|
||
| class ARROW_EXPORT DeviceAllocationTypeSet { | ||
| private: | ||
| std::bitset<kDeviceAllocationTypeMax + 1> device_type_bitset_; | ||
|
|
||
| public: | ||
| /// \brief Construct an empty set of device types. | ||
| DeviceAllocationTypeSet() = default; | ||
|
|
||
| /// \brief Construct a set of device types with a single device type. | ||
| DeviceAllocationTypeSet( // NOLINT implicit construction | ||
| DeviceAllocationType accepted_device_type) { | ||
| add(accepted_device_type); | ||
| } | ||
|
|
||
| /// \brief Construct a set of device types containing only "kCPU". | ||
| static DeviceAllocationTypeSet CpuOnly() { | ||
| return DeviceAllocationTypeSet{DeviceAllocationType::kCPU}; | ||
| } | ||
|
|
||
| /// \brief Construct a set of device types containing all device types. | ||
| static DeviceAllocationTypeSet All() { | ||
| DeviceAllocationTypeSet all; | ||
| all.device_type_bitset_.set(); | ||
| // Don't set the invalid enum values. | ||
| all.device_type_bitset_.reset(0); | ||
| all.device_type_bitset_.reset(5); | ||
| all.device_type_bitset_.reset(6); | ||
| return all; | ||
| } | ||
|
|
||
| /// \brief Add a device type to the set of device types. | ||
| void add(DeviceAllocationType device_type) { | ||
| device_type_bitset_.set(static_cast<int>(device_type)); | ||
| } | ||
|
|
||
| /// \brief Remove a device type from the set of device types. | ||
| void remove(DeviceAllocationType device_type) { | ||
| device_type_bitset_.reset(static_cast<int>(device_type)); | ||
| } | ||
|
|
||
| /// \brief Return true iff the set only contains the CPU device type. | ||
| bool is_cpu_only() const { | ||
| return device_type_bitset_ == CpuOnly().device_type_bitset_; | ||
| } | ||
|
|
||
| /// \brief Return true if the set of accepted device types includes the | ||
| /// device type. | ||
| bool contains(DeviceAllocationType device_type) const { | ||
| return device_type_bitset_.test(static_cast<int>(device_type)); | ||
| } | ||
|
|
||
| /// \brief Add all device types from another set to this set. | ||
| void Add(DeviceAllocationTypeSet other) { | ||
| device_type_bitset_ |= other.device_type_bitset_; | ||
| } | ||
|
|
||
| /// \brief Return true if the set of accepted device types includes all the | ||
| /// device types in the other set. | ||
| bool Contains(DeviceAllocationTypeSet other) const { | ||
| // other \subseteq this <==> (other \intersect this == other) | ||
| return (other.device_type_bitset_ & device_type_bitset_) == other.device_type_bitset_; | ||
| } | ||
|
|
||
| std::string ToString() const; | ||
| }; | ||
|
|
||
| } // namespace arrow |
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
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.
Uh oh!
There was an error while loading. Please reload this page.