| 246 | } |
| 247 | |
| 248 | CompNode::Locator CompNode::Locator::to_physical() const { |
| 249 | mgb_assert(stream >= 0); |
| 250 | DeviceType type_physical; |
| 251 | int device_physical; |
| 252 | int stream_physical; |
| 253 | |
| 254 | type_physical = resolve_device_type(type); |
| 255 | device_physical = device; |
| 256 | stream_physical = stream; |
| 257 | |
| 258 | if ((MGB_HAVE_THREAD) || |
| 259 | CompNode::contain_flag(type_physical, Flag::SUPPORT_NO_THREAD)) { |
| 260 | #if MGB_THREAD_SAFE |
| 261 | MGB_LOCK_GUARD(g_device_map_mtx); |
| 262 | #endif |
| 263 | auto&& cur_dmap = g_device_map[type_physical]; |
| 264 | auto iter = cur_dmap.find(device); |
| 265 | if (iter != cur_dmap.end()) |
| 266 | device_physical = iter->second; |
| 267 | |
| 268 | if (device_physical == -1) |
| 269 | device_physical = 0; |
| 270 | } else { |
| 271 | // we map all logical locators to cpu0:1023 except cpu:default, |
| 272 | // when thread is disabled. |
| 273 | type_physical = DeviceType::CPU; |
| 274 | device_physical = DEVICE_CPU_DEFAULT; |
| 275 | stream_physical = 0; |
| 276 | |
| 277 | if (device != DEVICE_CPU_DEFAULT) { |
| 278 | device_physical = 0; |
| 279 | stream_physical = 1023; |
| 280 | } |
| 281 | } |
| 282 | return {type_physical, device_physical, {stream_physical}}; |
| 283 | } |
| 284 | |
| 285 | std::string CompNode::Locator::to_string() const { |
| 286 | if (device == DEVICE_CPU_DEFAULT) { |