@@ -6,34 +6,29 @@ import {
66 getPassingModels ,
77} from "lib/benchmark/compilerUtils" ;
88import { 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" ;
1813
1914// 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+
2124 const start = Date . now ( ) ;
22- const rows = await queryClickhouseSaved ( BENCNMARK_TABLE_NAME , inputparams ) ;
25+ let rows = await queryClickhouseSaved ( table , inputparams ) ;
2326 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 ) ;
3428
3529 if ( rows . length === 0 ) {
3630 const response : BenchmarkTimeSeriesResponse = {
31+ total_rows : 0 ,
3732 time_series : [ ] ,
3833 time_range : {
3934 start : "" ,
@@ -43,11 +38,26 @@ export async function getCompilerBenchmarkData(inputparams: any) {
4338 return response ;
4439 }
4540
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+
4657 // TODO(elainewy): add logics to handle the case to return raw data
4758 const benchmark_time_series_response = toPrecomputeCompiler (
4859 rows ,
4960 inputparams ,
50- commitMap ,
5161 "time_series"
5262 ) ;
5363 return benchmark_time_series_response ;
@@ -56,18 +66,16 @@ export async function getCompilerBenchmarkData(inputparams: any) {
5666function toPrecomputeCompiler (
5767 rawData : any [ ] ,
5868 inputparams : any ,
59- commitMap : Record < string , CommitRow > ,
6069 type : string = "time_series"
6170) {
6271 const data = convertToCompilerPerformanceData ( rawData ) ;
72+ const commit_map = toWorkflowIdMap ( data ) ;
6373 const models = getPassingModels ( data ) ;
64-
6574 const passrate = computePassrate ( data , models ) ;
6675 const geomean = computeGeomean ( data , models ) ;
6776 const peakMemory = computeMemoryCompressionRatio ( data , models ) ;
6877
6978 const all_data = [ passrate , geomean , peakMemory ] . flat ( ) ;
70-
7179 const earliest_timestamp = Math . min (
7280 ...all_data . map ( ( row ) => new Date ( row . granularity_bucket ) . getTime ( ) )
7381 ) ;
@@ -81,9 +89,8 @@ function toPrecomputeCompiler(
8189 row [ "arch" ] = inputparams [ "arch" ] ;
8290 row [ "device" ] = inputparams [ "device" ] ;
8391 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 ;
8794 } ) ;
8895
8996 let res : any [ ] = [ ] ;
@@ -163,11 +170,44 @@ function toPrecomputeCompiler(
163170 }
164171
165172 const response : BenchmarkTimeSeriesResponse = {
166- time_series : res ,
173+ total_rows : res . length ,
174+ total_raw_rows : rawData . length ,
167175 time_range : {
168176 start : new Date ( earliest_timestamp ) . toISOString ( ) ,
169177 end : new Date ( latest_timestamp ) . toISOString ( ) ,
170178 } ,
179+ time_series : res ,
171180 } ;
172181 return response ;
173182}
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