| 233 | } |
| 234 | |
| 235 | DeviceAllocationType ArrayData::device_type() const { |
| 236 | // we're using 0 as a sentinel value for NOT YET ASSIGNED |
| 237 | // there is explicitly no constant DeviceAllocationType to represent |
| 238 | // the "UNASSIGNED" case as it is invalid for data to not have an |
| 239 | // assigned device type. If it's still 0 at the end, then we return |
| 240 | // CPU as the allocation device type |
| 241 | int type = 0; |
| 242 | for (const auto& buf : buffers) { |
| 243 | if (!buf) continue; |
| 244 | #ifdef NDEBUG |
| 245 | return buf->device_type(); |
| 246 | #else |
| 247 | if (type == 0) { |
| 248 | type = static_cast<int>(buf->device_type()); |
| 249 | } else { |
| 250 | DCHECK_EQ(type, static_cast<int>(buf->device_type())); |
| 251 | } |
| 252 | #endif |
| 253 | } |
| 254 | |
| 255 | for (const auto& child : child_data) { |
| 256 | if (!child) continue; |
| 257 | #ifdef NDEBUG |
| 258 | return child->device_type(); |
| 259 | #else |
| 260 | if (type == 0) { |
| 261 | type = static_cast<int>(child->device_type()); |
| 262 | } else { |
| 263 | DCHECK_EQ(type, static_cast<int>(child->device_type())); |
| 264 | } |
| 265 | #endif |
| 266 | } |
| 267 | |
| 268 | if (dictionary) { |
| 269 | #ifdef NDEBUG |
| 270 | return dictionary->device_type(); |
| 271 | #else |
| 272 | if (type == 0) { |
| 273 | type = static_cast<int>(dictionary->device_type()); |
| 274 | } else { |
| 275 | DCHECK_EQ(type, static_cast<int>(dictionary->device_type())); |
| 276 | } |
| 277 | #endif |
| 278 | } |
| 279 | |
| 280 | return type == 0 ? DeviceAllocationType::kCPU : static_cast<DeviceAllocationType>(type); |
| 281 | } |
| 282 | |
| 283 | // ---------------------------------------------------------------------- |
| 284 | // Methods for ArraySpan |
no outgoing calls