-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_build.py
More file actions
executable file
·166 lines (140 loc) · 5.39 KB
/
test_build.py
File metadata and controls
executable file
·166 lines (140 loc) · 5.39 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
"""
Test script to verify the GPU Roofline benchmark toolkit build and basic functionality.
"""
import subprocess
import sys
import os
from pathlib import Path
def run_command(cmd, description):
"""Run a command and report success/failure."""
print(f"\n=== {description} ===")
print(f"Running: {' '.join(cmd)}")
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
print(f"✓ SUCCESS: {description}")
if result.stdout:
print(f"Output: {result.stdout.strip()}")
return True
except subprocess.CalledProcessError as e:
print(f"✗ FAILED: {description}")
print(f"Error: {e.stderr.strip()}")
return False
except FileNotFoundError:
print(f"✗ COMMAND NOT FOUND: {cmd[0]}")
return False
def check_file_exists(filepath, description):
"""Check if a file exists."""
if Path(filepath).exists():
print(f"✓ Found: {description} ({filepath})")
return True
else:
print(f"✗ Missing: {description} ({filepath})")
return False
def main():
print("GPU Roofline Benchmark - Build Test")
print("=" * 50)
# Check prerequisites
print("\n=== Checking Prerequisites ===")
has_cmake = run_command(['cmake', '--version'], "CMake availability")
has_python = run_command(['python3', '--version'], "Python 3 availability")
has_git = run_command(['git', '--version'], "Git availability")
# Check optional dependencies
print("\n=== Checking Optional Dependencies ===")
has_nvcc = run_command(['nvcc', '--version'], "CUDA toolkit (nvcc)")
has_metal = False
if sys.platform == 'darwin':
has_metal = run_command(['xcrun', '-find', 'metal'], "Metal compiler")
# Check project structure
print("\n=== Checking Project Structure ===")
structure_checks = [
("CMakeLists.txt", "Main CMake file"),
("bench.yaml", "Benchmark configuration"),
("run.py", "Main orchestration script"),
("collect.py", "Data collection script"),
("plot_roofline.py", "Plotting script"),
("src/kernels/saxpy.cu", "SAXPY CUDA kernel"),
("src/kernels/saxpy.metal", "SAXPY Metal kernel"),
("backends/cuda/cuda_runner.cpp", "CUDA backend"),
("backends/metal/metal_runner.mm", "Metal backend"),
("backends/cpu/cpu_runner.cpp", "CPU backend"),
("include/kernel_launcher.hpp", "Kernel launcher interface"),
]
structure_ok = all(check_file_exists(filepath, desc) for filepath, desc in structure_checks)
# Test Python dependencies
print("\n=== Testing Python Dependencies ===")
python_deps = ['yaml', 'pandas', 'numpy', 'matplotlib']
deps_ok = True
for dep in python_deps:
try:
result = subprocess.run([sys.executable, '-c', f'import {dep}'],
capture_output=True, check=True)
print(f"✓ Python module: {dep}")
except subprocess.CalledProcessError:
print(f"✗ Missing Python module: {dep}")
deps_ok = False
if not deps_ok:
print("\nTo install missing dependencies:")
print(f" pip install {' '.join(python_deps)}")
# Test basic CMake configuration
print("\n=== Testing CMake Configuration ===")
cmake_ok = True
if has_cmake:
# Test CPU-only build
os.makedirs("build/test", exist_ok=True)
cmake_ok = run_command([
'cmake', '-B', 'build/test', '-S', '.',
'-DENABLE_CPU=ON', '-DENABLE_CUDA=OFF', '-DENABLE_METAL=OFF'
], "CMake configuration (CPU only)")
# Test run.py basic functionality
print("\n=== Testing Run Script ===")
run_test = run_command([sys.executable, 'run.py', '--help'],
"Run script help")
# Summary
print("\n" + "=" * 50)
print("BUILD TEST SUMMARY")
print("=" * 50)
all_good = True
if has_cmake and has_python and has_git:
print("✓ Core prerequisites available")
else:
print("✗ Missing core prerequisites")
all_good = False
if structure_ok:
print("✓ Project structure complete")
else:
print("✗ Project structure incomplete")
all_good = False
if deps_ok:
print("✓ Python dependencies available")
else:
print("✗ Missing Python dependencies")
all_good = False
if cmake_ok:
print("✓ CMake configuration works")
else:
print("✗ CMake configuration failed")
all_good = False
print(f"\nAvailable backends:")
if has_nvcc:
print(" ✓ CUDA (GPU)")
else:
print(" ✗ CUDA (install CUDA toolkit)")
if has_metal:
print(" ✓ Metal (GPU)")
elif sys.platform == 'darwin':
print(" ✗ Metal (install Xcode)")
else:
print(" - Metal (macOS only)")
print(" ✓ CPU (OpenMP)")
if all_good:
print(f"\n🎉 PROJECT READY! Next steps:")
print(f" 1. python run.py --device auto --kernels saxpy")
print(f" 2. python collect.py results/*.json")
print(f" 3. python plot_roofline.py results/*.csv")
else:
print(f"\n❌ PROJECT NEEDS ATTENTION")
print(f" Fix the issues above before proceeding")
return 0 if all_good else 1
if __name__ == "__main__":
sys.exit(main())