File indexing completed on 2025-08-27 08:47:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <bitset>
0021 #include <string>
0022
0023 #include "arrow/type_fwd.h"
0024 #include "arrow/util/visibility.h"
0025
0026 namespace arrow {
0027
0028 ARROW_EXPORT
0029 const char* DeviceAllocationTypeToCStr(DeviceAllocationType type);
0030
0031 class ARROW_EXPORT DeviceAllocationTypeSet {
0032 private:
0033 std::bitset<kDeviceAllocationTypeMax + 1> device_type_bitset_;
0034
0035 public:
0036
0037 DeviceAllocationTypeSet() = default;
0038
0039
0040 DeviceAllocationTypeSet(
0041 DeviceAllocationType accepted_device_type) {
0042 add(accepted_device_type);
0043 }
0044
0045
0046 static DeviceAllocationTypeSet CpuOnly() {
0047 return DeviceAllocationTypeSet{DeviceAllocationType::kCPU};
0048 }
0049
0050
0051 static DeviceAllocationTypeSet All() {
0052 DeviceAllocationTypeSet all;
0053 all.device_type_bitset_.set();
0054
0055 all.device_type_bitset_.reset(0);
0056 all.device_type_bitset_.reset(5);
0057 all.device_type_bitset_.reset(6);
0058 return all;
0059 }
0060
0061
0062 void add(DeviceAllocationType device_type) {
0063 device_type_bitset_.set(static_cast<int>(device_type));
0064 }
0065
0066
0067 void remove(DeviceAllocationType device_type) {
0068 device_type_bitset_.reset(static_cast<int>(device_type));
0069 }
0070
0071
0072 bool is_cpu_only() const {
0073 return device_type_bitset_ == CpuOnly().device_type_bitset_;
0074 }
0075
0076
0077
0078 bool contains(DeviceAllocationType device_type) const {
0079 return device_type_bitset_.test(static_cast<int>(device_type));
0080 }
0081
0082
0083 void Add(DeviceAllocationTypeSet other) {
0084 device_type_bitset_ |= other.device_type_bitset_;
0085 }
0086
0087
0088
0089 bool Contains(DeviceAllocationTypeSet other) const {
0090
0091 return (other.device_type_bitset_ & device_type_bitset_) == other.device_type_bitset_;
0092 }
0093
0094 std::string ToString() const;
0095 };
0096
0097 }