-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gpu_simple.py
More file actions
140 lines (108 loc) · 4.17 KB
/
test_gpu_simple.py
File metadata and controls
140 lines (108 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
"""
Simple GPU acceleration test without relative imports.
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
def test_gpu_basic():
"""Test basic GPU functionality."""
print("=== Basic GPU Test ===")
try:
from gpu_acceleration import get_gpu_status, GPUFramework, create_gpu_matcher
# Test framework detection
framework = GPUFramework()
print(f"GPU Available: {framework.has_gpu}")
print(f"Preferred Framework: {framework.preferred_framework}")
print(f"Device Count: {framework.gpu_device_count}")
# Test status
status = get_gpu_status()
print(f"GPU Status: {status['available']}")
print(f"Configuration: {status['config']}")
# Test matcher creation
matcher = create_gpu_matcher(enable_gpu=True)
print(f"GPU Matcher Created: {matcher is not None}")
print(f"GPU Enabled: {matcher.enable_gpu}")
return True
except Exception as e:
print(f"GPU test failed: {e}")
return False
def test_similarity_calculation():
"""Test similarity calculation with fallback."""
print("\n=== Similarity Calculation Test ===")
try:
from gpu_acceleration import create_gpu_matcher
# Create matcher (will use CPU fallback if no GPU)
matcher = create_gpu_matcher(enable_gpu=True)
# Test data
names1 = ['Juan dela Cruz', 'Maria Santos', 'Jose Rizal']
names2 = ['Juan de la Cruz', 'Maria Santos-Garcia', 'Dr. Jose Rizal']
# Calculate similarity matrix
similarity_matrix = matcher.batch_similarity_matrix(
names1, names2, algorithm='jaro_winkler'
)
print(f"Similarity matrix shape: {similarity_matrix.shape}")
print(f"Sample similarities:")
for i, name1 in enumerate(names1):
for j, name2 in enumerate(names2):
score = similarity_matrix[i, j]
print(f" '{name1}' vs '{name2}': {score:.4f}")
return True
except Exception as e:
print(f"Similarity calculation test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_configuration():
"""Test GPU configuration."""
print("\n=== Configuration Test ===")
try:
from gpu_acceleration import configure_gpu, get_gpu_status
# Test configuration
test_config = {
'enabled': True,
'framework': 'auto',
'batch_size': 500,
'memory_limit_gb': 2.0
}
configure_gpu(test_config)
# Verify configuration
status = get_gpu_status()
config = status['config']
print(f"Configuration applied successfully:")
for key, value in config.items():
print(f" {key}: {value}")
return True
except Exception as e:
print(f"Configuration test failed: {e}")
return False
def main():
"""Run all GPU tests."""
print("GPU Acceleration Simple Test Suite")
print("==================================")
tests = [
("Basic GPU Detection", test_gpu_basic),
("Similarity Calculation", test_similarity_calculation),
("Configuration Management", test_configuration)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n🧪 Running: {test_name}")
try:
if test_func():
print(f"✅ {test_name}: PASSED")
passed += 1
else:
print(f"❌ {test_name}: FAILED")
except Exception as e:
print(f"❌ {test_name}: ERROR - {e}")
print(f"\n📊 Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! GPU acceleration is working correctly.")
else:
print("⚠️ Some tests failed. Check the output above for details.")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)