File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -225,23 +225,22 @@ XPUVersion get_xpu_version(int dev_id) {
225
225
if (dev_id == -1 ) {
226
226
dev_id = GetXPUCurrentDeviceId ();
227
227
}
228
- static std::once_flag xpu_version_init_flag;
229
- static XPUVersion xpu_version;
230
- std::call_once (xpu_version_init_flag, [&] {
228
+ thread_local std::unordered_map<int , XPUVersion> xpu_version_map;
229
+ if (xpu_version_map.count (dev_id) == 0 ) {
231
230
uint64_t v = 0 ;
232
231
PADDLE_ENFORCE_XPU_SUCCESS (xpu_device_get_attr (&v, XPUATTR_MODEL, dev_id));
233
232
if (v == K100 || v == K200) {
234
233
VLOG (1 ) << " KUNLUN device " << dev_id << " is XPU1\n " ;
235
- xpu_version = XPU1;
234
+ xpu_version_map[dev_id] = XPU1;
236
235
} else if (v < KL3_BEGIN) {
237
236
VLOG (1 ) << " KUNLUN device " << dev_id << " is XPU2\n " ;
238
- xpu_version = XPU2;
237
+ xpu_version_map[dev_id] = XPU2;
239
238
} else {
240
239
VLOG (1 ) << " KUNLUN device " << dev_id << " is XPU3\n " ;
241
- xpu_version = XPU3;
240
+ xpu_version_map[dev_id] = XPU3;
242
241
}
243
- });
244
- return xpu_version ;
242
+ }
243
+ return xpu_version_map[dev_id] ;
245
244
}
246
245
247
246
void set_xpu_debug_level (int level) {
You can’t perform that action at this time.
0 commit comments