fasthardware 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fasthardware/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import gc
|
|
4
|
+
import ctypes
|
|
5
|
+
import multiprocessing
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class HardwareAccelerator:
|
|
9
|
+
def __init__(self):
|
|
10
|
+
self.device_status = "UNKNOWN"
|
|
11
|
+
self.cpu_cores = multiprocessing.cpu_count()
|
|
12
|
+
|
|
13
|
+
def speedup(self, enable_gc_tuning=True, force_device=None):
|
|
14
|
+
"""
|
|
15
|
+
π 보μ€μ λ§λ² μμ€: μ΄λ€ νλ‘κ·Έλ¨μ΄λ νλμ¨μ΄ μ±λ₯μ μ΅λμΉλ‘ λ‘겨μ€λ λ©μλ
|
|
16
|
+
"""
|
|
17
|
+
print("\n" + "=" * 60)
|
|
18
|
+
print("β‘ [HARDWARE SPEEDUP ENGAGED] μμ€ν
κ°μ μμ§ κ°λ μμ...")
|
|
19
|
+
print("=" * 60)
|
|
20
|
+
|
|
21
|
+
# 1. νμ΄μ¬ λ΄μ₯ λ©λͺ¨λ¦¬ κ΄λ¦¬(GC) κ°μ νλ
|
|
22
|
+
if enable_gc_tuning:
|
|
23
|
+
gc.disable() # 무λΆλ³ν GC κ°μ
μΌλ‘ μΈν νλ μ λλ μμ² μ°¨λ¨
|
|
24
|
+
print(f"βοΈ [λ©λͺ¨λ¦¬ μ΅μ ν] νμ΄μ¬ λ΄μ₯ GC λΉνμ±ν μλ£. (μλ κ³ μ μ€μν μ ν)")
|
|
25
|
+
|
|
26
|
+
# 2. νλμ¨μ΄ νκ²½ μλ νμ λ° κ°μ λ°±μλ λ§€ν
|
|
27
|
+
detected_gpu = self._detect_gpu_hardware()
|
|
28
|
+
|
|
29
|
+
if force_device:
|
|
30
|
+
self.device_status = force_device
|
|
31
|
+
print(f"β οΈ [κ°μ μ€μ ] 보μ€μ μμ²μ μν΄ {force_device} λͺ¨λλ‘ κ°μ ꡬλν©λλ€.")
|
|
32
|
+
else:
|
|
33
|
+
self.device_status = detected_gpu
|
|
34
|
+
|
|
35
|
+
# 3. κ°μ§λ νλμ¨μ΄λ³ νΉν μ΅μ ν νκ²½ μ£Όμ
|
|
36
|
+
if self.device_status == "NVIDIA_CUDA":
|
|
37
|
+
self._engage_cuda_acceleration()
|
|
38
|
+
elif self.device_status == "INTEL_IGPU" or self.device_status == "OPENVINO":
|
|
39
|
+
self._engage_intel_acceleration()
|
|
40
|
+
else:
|
|
41
|
+
self._engage_cpu_vector_acceleration()
|
|
42
|
+
|
|
43
|
+
print(f"π₯ [κ°μ μ±κ³΅] νμ¬ μμ€ν
μ '{self.device_status}' ν νμ λͺ¨λλ‘ κ°λ μ€μ
λλ€.")
|
|
44
|
+
print("=" * 60 + "\n")
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def _detect_gpu_hardware(self):
|
|
48
|
+
""" μμ€ν
νλμ¨μ΄λ₯Ό λ€μ΄λ νΈλ‘ μ€μΊνλ λ΄λΆ 맀컀λμ¦ """
|
|
49
|
+
# 1. NVIDIA CUDA κ°λ₯ μ¬λΆ 체ν¬
|
|
50
|
+
try:
|
|
51
|
+
import torch
|
|
52
|
+
if torch.cuda.is_available():
|
|
53
|
+
return "NVIDIA_CUDA"
|
|
54
|
+
except ImportError:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
# 2. Intel OpenVINO κ°μ μ₯μΉ μ²΄ν¬
|
|
58
|
+
try:
|
|
59
|
+
import openvino as ov
|
|
60
|
+
core = ov.Core()
|
|
61
|
+
if "GPU" in core.available_devices:
|
|
62
|
+
return "INTEL_IGPU"
|
|
63
|
+
except ImportError:
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
return "PURE_CPU"
|
|
67
|
+
|
|
68
|
+
def _engage_cuda_acceleration(self):
|
|
69
|
+
""" NVIDIA μΈμ₯ κ·Έλν½ μΉ΄λκ° μμ λ VRAM μ μ‘ μλ λ° μ€λ λ μ΅μ ν """
|
|
70
|
+
print("π [GPU κ°μ] NVIDIA CUDA νλμ¨μ΄ μ½μ΄ κ°μ§! κ³ μ μ°μ° μ€νΈλ¦Όμ κ°λ°©ν©λλ€.")
|
|
71
|
+
# λ΄λΆ νλ μμν¬ νλ νλκ·Έ μ€μ
|
|
72
|
+
os.environ["CUDA_MODULE_LOADING"] = "LAZY"
|
|
73
|
+
# OpenCVκ° λͺ
μμ μΌλ‘ CUDAλ₯Ό μΈ μ μλλ‘ νκ²½ λ§€ν (λΉλ νκ²½μ λ°λΌ μλ)
|
|
74
|
+
os.environ["OPENCV_CUDA_USE_NVTX"] = "1"
|
|
75
|
+
|
|
76
|
+
def _engage_intel_acceleration(self):
|
|
77
|
+
""" μΈν
λ΄μ₯ GPU λλ OpenVINO νμ΄νλΌμΈ μ΅μ ν λ μ΄ν΄μ μ£Όμ
"""
|
|
78
|
+
print("π [GPU κ°μ] Intel iGPU / OpenVINO κ°μ μμ§ κ°μ§! ν°λ³΄ λ μ΄ν΄μ ννΈλ₯Ό μ£Όμ
ν©λλ€.")
|
|
79
|
+
# μΈν
νλμ¨μ΄ μ°λ£¨ν μ΅μ ν νλκ·Έ κ³ μ
|
|
80
|
+
os.environ["OV_FRONTEND_CACHE_ENABLE"] = "1"
|
|
81
|
+
|
|
82
|
+
def _engage_cpu_vector_acceleration(self):
|
|
83
|
+
""" GPUκ° μμ λ, CPUμ λͺ¨λ λ©ν°μ½μ΄λ₯Ό 100% μ₯μ΄μ§λ AVX2/OpenMP κ°μ λ°μΈλ© """
|
|
84
|
+
print(f"π» [CPU μ΅μ ν] μ μ© GPU λ―Έκ°μ§. 물리 μ½μ΄ {self.cpu_cores}κ° μ 체μ κ³ μ λ²‘ν° μ°μ°(SIMD)μ λͺ
λ Ήν©λλ€.")
|
|
85
|
+
|
|
86
|
+
# MKL, OpenBLAS λ± νμ΄μ¬ λ΄λΆ νλ ¬ μ°μ° λΌμ΄λΈλ¬λ¦¬κ° CPU λ©ν°μ½μ΄λ₯Ό νλ‘ μ°λλ‘ κ°μ μΈν
|
|
87
|
+
threads_str = str(self.cpu_cores)
|
|
88
|
+
os.environ["OMP_NUM_THREADS"] = threads_str
|
|
89
|
+
os.environ["MKL_NUM_THREADS"] = threads_str
|
|
90
|
+
os.environ["OPENBLAS_NUM_THREADS"] = threads_str
|
|
91
|
+
os.environ["VECLIB_MAXIMUM_THREADS"] = threads_str
|
|
92
|
+
os.environ["NUMEXPR_NUM_THREADS"] = threads_str
|
|
93
|
+
|
|
94
|
+
def manual_sweep(self):
|
|
95
|
+
""" νλ‘κ·Έλ¨ λ£¨ν μμμ ν
κΉμ λ°©μ§νκΈ° μν΄ λ³΄μ€κ° μν λ μλμΌλ‘ λ©λͺ¨λ¦¬λ₯Ό μ΄κ³ μ μ²μνλ λ©μλ """
|
|
96
|
+
gc.collect()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# μΈλΆμμ κ·Έλ₯ "import hardware" ν λ°λ‘ μΈ μ μλλ‘ μ±κΈν€ μΈμ€ν΄μ€ 미리 μμ±
|
|
100
|
+
_accelerator = HardwareAccelerator()
|
|
101
|
+
speedup = _accelerator.speedup
|
|
102
|
+
manual_sweep = _accelerator.manual_sweep
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fasthardware
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: λ²μ© CPU/GPU νλμ¨μ΄ ν°λ³΄ κ°μ λ° λ©λͺ¨λ¦¬ νλ λΌμ΄λΈλ¬λ¦¬
|
|
5
|
+
Author: WoonGyo Choi & Gemini
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: classifier
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
fasthardware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
fasthardware/fasthardware.py,sha256=XbP7wjTZXH6nxPwG31ZCciElcdmC-2YG5qD6_WaMvSE,4620
|
|
3
|
+
fasthardware-1.0.0.dist-info/METADATA,sha256=wh6DvyEwdIWI_nBcR5zEoa3FBsljC7gZp55dRXYv25g,386
|
|
4
|
+
fasthardware-1.0.0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
5
|
+
fasthardware-1.0.0.dist-info/top_level.txt,sha256=7jKJkbsAhAnNNFbytkFyzYIDuBrC21frSD3Peq7u6q4,13
|
|
6
|
+
fasthardware-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fasthardware
|