Update utils/hardware/device_manager.py
Browse files
utils/hardware/device_manager.py
CHANGED
|
@@ -7,9 +7,16 @@
|
|
| 7 |
import logging
|
| 8 |
import platform
|
| 9 |
import subprocess
|
|
|
|
| 10 |
from typing import Optional, Dict, Any, List
|
| 11 |
from core.exceptions import DeviceError # Updated import path
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
class DeviceManager:
|
|
@@ -412,4 +419,14 @@ def cleanup_device_memory(self):
|
|
| 412 |
gc.collect()
|
| 413 |
logger.debug("CPU memory cleanup completed")
|
| 414 |
except Exception as e:
|
| 415 |
-
logger.warning(f"CPU memory cleanup failed: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import logging
|
| 8 |
import platform
|
| 9 |
import subprocess
|
| 10 |
+
import os
|
| 11 |
from typing import Optional, Dict, Any, List
|
| 12 |
from core.exceptions import DeviceError # Updated import path
|
| 13 |
|
| 14 |
+
# Fix OpenMP threads early with validation
|
| 15 |
+
if 'OMP_NUM_THREADS' not in os.environ:
|
| 16 |
+
os.environ['OMP_NUM_THREADS'] = '4'
|
| 17 |
+
if 'MKL_NUM_THREADS' not in os.environ:
|
| 18 |
+
os.environ['MKL_NUM_THREADS'] = '4'
|
| 19 |
+
|
| 20 |
logger = logging.getLogger(__name__)
|
| 21 |
|
| 22 |
class DeviceManager:
|
|
|
|
| 419 |
gc.collect()
|
| 420 |
logger.debug("CPU memory cleanup completed")
|
| 421 |
except Exception as e:
|
| 422 |
+
logger.warning(f"CPU memory cleanup failed: {e}")
|
| 423 |
+
|
| 424 |
+
# Global instance for singleton pattern
|
| 425 |
+
_device_manager_instance = None
|
| 426 |
+
|
| 427 |
+
def get_device_manager() -> DeviceManager:
|
| 428 |
+
"""Get or create a singleton DeviceManager instance"""
|
| 429 |
+
global _device_manager_instance
|
| 430 |
+
if _device_manager_instance is None:
|
| 431 |
+
_device_manager_instance = DeviceManager()
|
| 432 |
+
return _device_manager_instance
|