@@ -6,34 +6,29 @@ import {
6
6
getPassingModels ,
7
7
} from "lib/benchmark/compilerUtils" ;
8
8
import { queryClickhouseSaved } from "lib/clickhouse" ;
9
- import {
10
- BenchmarkTimeSeriesResponse ,
11
- CommitRow ,
12
- groupByBenchmarkData ,
13
- toCommitRowMap ,
14
- } from "../utils" ;
15
-
16
- const BENCNMARK_TABLE_NAME = "compilers_benchmark_performance" ;
17
- const BENCNMARK_COMMIT_NAME = "compilers_benchmark_performance_branches" ;
9
+ import { CompilerPerformanceData } from "lib/types" ;
10
+ import { BenchmarkTimeSeriesResponse , groupByBenchmarkData } from "../utils" ;
11
+ //["x86_64","NVIDIA A10G","NVIDIA H100 80GB HBM3"]
12
+ const COMPILER_BENCHMARK_TABLE_NAME = "compilers_benchmark_api_query" ;
18
13
19
14
// TODO(elainewy): improve the fetch performance
20
- export async function getCompilerBenchmarkData ( inputparams : any ) {
15
+ export async function getCompilerBenchmarkData (
16
+ inputparams : any ,
17
+ query_table : string = ""
18
+ ) {
19
+ let table = COMPILER_BENCHMARK_TABLE_NAME ;
20
+ if ( query_table . length > 0 ) {
21
+ table = query_table ;
22
+ }
23
+
21
24
const start = Date . now ( ) ;
22
- const rows = await queryClickhouseSaved ( BENCNMARK_TABLE_NAME , inputparams ) ;
25
+ let rows = await queryClickhouseSaved ( table , inputparams ) ;
23
26
const end = Date . now ( ) ;
24
- console . log ( "time to get data" , end - start ) ;
25
-
26
- const startc = Date . now ( ) ;
27
- const commits = await queryClickhouseSaved (
28
- BENCNMARK_COMMIT_NAME ,
29
- inputparams
30
- ) ;
31
- const endc = Date . now ( ) ;
32
- console . log ( "time to get commit data" , endc - startc ) ;
33
- const commitMap = toCommitRowMap ( commits ) ;
27
+ console . log ( "time to get compiler timeseris data" , end - start ) ;
34
28
35
29
if ( rows . length === 0 ) {
36
30
const response : BenchmarkTimeSeriesResponse = {
31
+ total_rows : 0 ,
37
32
time_series : [ ] ,
38
33
time_range : {
39
34
start : "" ,
@@ -43,11 +38,26 @@ export async function getCompilerBenchmarkData(inputparams: any) {
43
38
return response ;
44
39
}
45
40
41
+ // extract backend from output in runtime instead of doing it in the query. since it's expensive for regex matching.
42
+ // TODO(elainewy): we should add this as a column in the database for less runtime logics.
43
+ rows . map ( ( row ) => {
44
+ const backend =
45
+ row . backend && row . backend !== ""
46
+ ? row . backend
47
+ : extractBackendSqlStyle (
48
+ row . output ,
49
+ row . suite ,
50
+ inputparams . dtype ,
51
+ inputparams . mode ,
52
+ inputparams . device
53
+ ) ;
54
+ row [ "backend" ] = backend ;
55
+ } ) ;
56
+
46
57
// TODO(elainewy): add logics to handle the case to return raw data
47
58
const benchmark_time_series_response = toPrecomputeCompiler (
48
59
rows ,
49
60
inputparams ,
50
- commitMap ,
51
61
"time_series"
52
62
) ;
53
63
return benchmark_time_series_response ;
@@ -56,18 +66,16 @@ export async function getCompilerBenchmarkData(inputparams: any) {
56
66
function toPrecomputeCompiler (
57
67
rawData : any [ ] ,
58
68
inputparams : any ,
59
- commitMap : Record < string , CommitRow > ,
60
69
type : string = "time_series"
61
70
) {
62
71
const data = convertToCompilerPerformanceData ( rawData ) ;
72
+ const commit_map = toWorkflowIdMap ( data ) ;
63
73
const models = getPassingModels ( data ) ;
64
-
65
74
const passrate = computePassrate ( data , models ) ;
66
75
const geomean = computeGeomean ( data , models ) ;
67
76
const peakMemory = computeMemoryCompressionRatio ( data , models ) ;
68
77
69
78
const all_data = [ passrate , geomean , peakMemory ] . flat ( ) ;
70
-
71
79
const earliest_timestamp = Math . min (
72
80
...all_data . map ( ( row ) => new Date ( row . granularity_bucket ) . getTime ( ) )
73
81
) ;
@@ -81,9 +89,8 @@ function toPrecomputeCompiler(
81
89
row [ "arch" ] = inputparams [ "arch" ] ;
82
90
row [ "device" ] = inputparams [ "device" ] ;
83
91
row [ "mode" ] = inputparams [ "mode" ] ;
84
- // always keep this:
85
- row [ "commit" ] = commitMap [ row [ "workflow_id" ] ] ?. head_sha ;
86
- row [ "branch" ] = commitMap [ row [ "workflow_id" ] ] ?. head_branch ;
92
+ row [ "commit" ] = commit_map . get ( row . workflow_id ) ?. commit ;
93
+ row [ "branch" ] = commit_map . get ( row . workflow_id ) ?. branch ;
87
94
} ) ;
88
95
89
96
let res : any [ ] = [ ] ;
@@ -163,11 +170,44 @@ function toPrecomputeCompiler(
163
170
}
164
171
165
172
const response : BenchmarkTimeSeriesResponse = {
166
- time_series : res ,
173
+ total_rows : res . length ,
174
+ total_raw_rows : rawData . length ,
167
175
time_range : {
168
176
start : new Date ( earliest_timestamp ) . toISOString ( ) ,
169
177
end : new Date ( latest_timestamp ) . toISOString ( ) ,
170
178
} ,
179
+ time_series : res ,
171
180
} ;
172
181
return response ;
173
182
}
183
+
184
+ export function extractBackendSqlStyle (
185
+ output : string ,
186
+ suite : string ,
187
+ dtype : string ,
188
+ mode : string ,
189
+ device : string
190
+ ) : string | null {
191
+ const esc = ( s : string ) => s . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
192
+ const tail = `_${ esc ( suite ) } _${ esc ( dtype ) } _${ esc ( mode ) } _${ esc ( device ) } _` ;
193
+
194
+ const temp = output . replace ( new RegExp ( `${ tail } .*$` ) , "" ) ;
195
+
196
+ const m = temp . match ( / .* [ \/ \\ ] ( [ ^ \/ \\ ] + ) $ / ) ;
197
+ return m ? m [ 1 ] : null ;
198
+ }
199
+
200
+ export function toWorkflowIdMap ( data : CompilerPerformanceData [ ] ) {
201
+ const commit_map = new Map < string , any > ( ) ;
202
+ data . forEach ( ( row ) => {
203
+ const commit = row ?. commit ;
204
+ const branch = row ?. branch ;
205
+ const workflow_id = `${ row . workflow_id } ` ;
206
+ commit_map . set ( workflow_id , {
207
+ commit,
208
+ branch,
209
+ workflow_id,
210
+ } ) ;
211
+ } ) ;
212
+ return commit_map ;
213
+ }
0 commit comments