forked from ORNL/HeCBench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_benchmarks.py
More file actions
136 lines (110 loc) · 4.83 KB
/
convert_benchmarks.py
File metadata and controls
136 lines (110 loc) · 4.83 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
#!/usr/bin/env python3
"""
Script to generate CMakeLists.txt files for HeCBench benchmarks
"""
import os
import sys
from pathlib import Path
def get_source_files(benchmark_dir):
"""Get list of source files (.cu or .cpp) in benchmark directory"""
sources = []
for ext in ['*.cu', '*.cpp']:
sources.extend(Path(benchmark_dir).glob(ext))
# Return just the filenames, not full paths
return [s.name for s in sorted(sources)]
def get_categories(benchmark_name):
"""Infer categories from benchmark name - this is a simplified heuristic"""
# Common patterns
ml_keywords = ['adam', 'adamw', 'attention', 'softmax', 'backprop', 'lstm', 'gru']
crypto_keywords = ['aes', 'md5', 'sha', 'rsa']
math_keywords = ['fft', 'dct', 'gemm', 'blas']
graph_keywords = ['bfs', 'dfs', 'floyd', 'pagerank']
categories = []
if any(kw in benchmark_name.lower() for kw in ml_keywords):
categories.append('ml')
if any(kw in benchmark_name.lower() for kw in crypto_keywords):
categories.append('cryptography')
if any(kw in benchmark_name.lower() for kw in math_keywords):
categories.append('math')
if any(kw in benchmark_name.lower() for kw in graph_keywords):
categories.append('graph')
# Default category if none matched
if not categories:
categories.append('algorithms')
return categories
def create_cmake_file(benchmark_name, model, source_files, categories):
"""Generate CMakeLists.txt content"""
sources_str = ' '.join(source_files)
categories_str = ' '.join(categories)
content = f"""# {benchmark_name}-{model}/CMakeLists.txt
add_hecbench_benchmark(
NAME {benchmark_name}
MODEL {model}
SOURCES {sources_str}
CATEGORIES {categories_str}
)
"""
return content
def main():
src_dir = Path('src')
if not src_dir.exists():
# Try current directory
if Path('.').resolve().name == 'src':
src_dir = Path('.')
else:
print("Error: Must run from HeCBench root or src directory")
sys.exit(1)
benchmarks_to_convert = [
# Final batch: remaining benchmarks with source files (63 benchmarks)
'addBiasQKV', 'addBiasResidualLayerNorm', 'allreduce', 'atomicAggregate',
'atomicCAS', 'atomicSystemWide', 'attentionMultiHead', 'axhelm',
'bh', 'bicgstab', 'bincount', 'bitcracker', 'bitpacking', 'bitpermute',
'blas-dot', 'blas-fp8gemm', 'blas-gemmBatched', 'blas-gemmEx2', 'blas-gemmEx',
'blas-gemmStridedBatched', 'blockAccess', 'blockexchange', 'bm3d', 'bn',
'bonds', 'boxfilter', 'bscan', 'bsearch', 'bspline-vgh', 'bsw', 'b+tree',
'btree', 'car', 'cbsfil', 'cc', 'ccl', 'ccs', 'ccsd-trpdrv', 'ced',
'chacha20', 'channelShuffle', 'che', 'chemv', 'clock', 'cm', 'cmembench',
'cmp', 'collision', 'colorwheel', 'columnarSolver', 'complex', 'concat',
'concurrentKernels', 'contract', 'conversion', 'convolution3D', 'cooling',
'coordinates', 'cross', 'crossEntropy', 'softmax-fused', 'softmax-online',
'tridiagonal'
]
models = ['cuda', 'hip', 'sycl', 'omp']
created_count = 0
for benchmark in benchmarks_to_convert:
categories = get_categories(benchmark)
for model in models:
bench_dir = src_dir / f'{benchmark}-{model}'
if not bench_dir.exists():
print(f" Skipping {benchmark}-{model} (directory not found)")
continue
# Check if CMakeLists.txt already exists
cmake_file = bench_dir / 'CMakeLists.txt'
if cmake_file.exists():
print(f" Skipping {benchmark}-{model} (CMakeLists.txt exists)")
continue
# Get source files
sources = get_source_files(bench_dir)
if not sources:
print(f" WARNING: {benchmark}-{model} has no source files!")
continue
# Create CMakeLists.txt
content = create_cmake_file(benchmark, model, sources, categories)
cmake_file.write_text(content)
created_count += 1
print(f"✓ Created {benchmark}-{model}/CMakeLists.txt ({len(sources)} sources)")
print(f"\nCreated {created_count} CMakeLists.txt files")
# Update src/CMakeLists.txt with new benchmarks
src_cmake = src_dir / 'CMakeLists.txt'
if src_cmake.exists():
content = src_cmake.read_text()
# Find the HECBENCH_POC_BENCHMARKS list
if 'HECBENCH_POC_BENCHMARKS' in content:
# Add new benchmarks
import re
benchmarks_list = '\n '.join(benchmarks_to_convert)
# This is a manual step - tell user to update
print(f"\n⚠ Don't forget to update src/CMakeLists.txt to include:")
print(f" {', '.join(benchmarks_to_convert)}")
if __name__ == '__main__':
main()