static */
| 59 | } |
| 60 | |
| 61 | /* static */ Maybe<Symbol<Device>> Device::New(const std::string& type, int64_t device_id, |
| 62 | bool rematable) { |
| 63 | CHECK_GE_OR_RETURN(device_id, 0) |
| 64 | << Error::InvalidValueError() << "Device ID should be non-negative"; |
| 65 | static thread_local HashMap<std::tuple<std::string, int, bool>, Symbol<Device>> map; |
| 66 | auto key = std::make_tuple(type, device_id, rematable); |
| 67 | auto iter = map.find(key); |
| 68 | if (iter == map.end()) { |
| 69 | Device device(type, device_id, rematable); |
| 70 | JUST(device.Init()); |
| 71 | iter = map.emplace(key, SymbolOf(device)).first; |
| 72 | } |
| 73 | return iter->second; |
| 74 | } |
| 75 | |
| 76 | /* static */ Maybe<Symbol<Device>> Device::New(const std::string& type, int64_t device_id) { |
| 77 | return New(type, device_id, false); |