1import {
2 Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography,
3} from '@mui/material'
4import type { MatmulMethod } from '../methods/types'
6export interface CellResult {
7 gflops: number
8 ms: number
9 sample: number
10}
12export type CellState = CellResult | 'pending' | 'unavailable' | 'error' | undefined
14export interface ResultsTableProps {
15 methods: MatmulMethod[]
16 sizes: number[]
17 cell(methodId: string, n: number): CellState
18}
20function CellContent({ state }: { state: CellState }) {
21 if (state === undefined) return <span>—</span>
22 if (state === 'pending') return <span>…</span>
23 if (state === 'unavailable') return <Typography variant="caption" color="text.secondary">n/a</Typography>
24 if (state === 'error') return <Typography variant="caption" color="error">error</Typography>
25 return (
26 <>
27 <div>{state.gflops.toFixed(2)} GFLOP/s</div>
28 <Typography variant="caption" color="text.secondary">{state.ms.toFixed(1)} ms</Typography>
29 </>
30 )
31}
33export function ResultsTable({ methods, sizes, cell }: ResultsTableProps) {
34 return (
35 <TableContainer component={Paper} variant="outlined">
36 <Table size="small">
37 <TableHead>
38 <TableRow>
39 <TableCell>n</TableCell>
40 {methods.map((m) => (
41 <TableCell key={m.id} align="right">
42 {m.label}
43 <Typography variant="caption" color="text.secondary" component="div">
44 {m.precision}
45 </Typography>
46 </TableCell>
47 ))}
48 </TableRow>
49 </TableHead>
50 <TableBody>
51 {sizes.map((n) => (
52 <TableRow key={n}>
53 <TableCell>{n}</TableCell>
54 {methods.map((m) => (
55 <TableCell key={m.id} align="right">
56 <CellContent state={cell(m.id, n)} />
57 </TableCell>
58 ))}
59 </TableRow>
60 ))}
61 </TableBody>
62 </Table>
63 </TableContainer>
64 )
65}