Skip to content

Commit 766d52e

Browse files
authored
Merge pull request #27 from t81dev/phase-18-semantic-optimization-2052748221906594406
Phase 18 — Ternary Workload Maturation & Measurement Plane
2 parents 2ae2701 + 2a72659 commit 766d52e

25 files changed

Lines changed: 645 additions & 250 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# --- Compiled Binaries & Objects ---
22
bin/*
3+
benchmarks/synthetic/saturation
4+
benchmarks/synthetic/density
5+
benchmarks/gemm/gemm_bench
6+
benchmarks/lstm/lstm_bench
7+
benchmarks/temporal/lstm_persistent
38
obj_dir/*
49
*.o
510
*.a

benchmarks/Makefile

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,34 @@ CC=gcc
22
CFLAGS=-O3 -I../include -I../src
33
LDFLAGS=-L../bin -ltfmbs_device -lpthread
44

5-
TARGETS=layer1_synthetic layer2_kernels
5+
# Reorganized Phase 18 Structure
6+
SYNTHETIC_BINS=synthetic/saturation synthetic/density
7+
GEMM_BINS=gemm/gemm_bench
8+
LSTM_BINS=lstm/lstm_bench
9+
TEMPORAL_BINS=temporal/lstm_persistent
610

7-
all: $(TARGETS)
11+
ALL_BINS=$(SYNTHETIC_BINS) $(GEMM_BINS) $(LSTM_BINS) $(TEMPORAL_BINS)
812

9-
layer1_synthetic: layer1_synthetic.c
13+
all: $(ALL_BINS)
14+
15+
synthetic/%: synthetic/%.c
16+
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
17+
18+
gemm/%: gemm/%.c
1019
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
1120

12-
layer2_kernels: layer2_kernels.c
21+
lstm/%: lstm/%.c
1322
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
1423

24+
temporal/%: temporal/%.c
25+
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
26+
27+
bench: all
28+
@echo "Running Phase 18 Benchmarks..."
29+
@for bin in $(ALL_BINS); do \
30+
echo "Running $$bin..."; \
31+
LD_LIBRARY_PATH=../bin ./$$bin; \
32+
done
33+
1534
clean:
16-
rm -f $(TARGETS)
35+
rm -f $(ALL_BINS)

benchmarks/density_metrics.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zero_skips,total_ops,active_ops,mem_reads,mem_writes,broadcasts,residency_hits,residency_misses,cycles,fabric_cost,semantic_efficiency
2+
524288,524288,0,105061,2048,6,18,0,8738,541701.00,0.0000
3+
524288,524288,0,105061,2048,6,18,0,18,8738,541701.00,0.0000

benchmarks/gemm/gemm_bench.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <time.h>
5+
#include "tfmbs_api.h"
6+
7+
void benchmark_gemm_kernel() {
8+
printf("\n--- [GEMM] Kernel Benchmark ---\n");
9+
int rows = 1024, cols = 1024;
10+
11+
int8_t* host_w = malloc(rows * cols);
12+
for(int j=0; j<rows*cols; j++) host_w[j] = (rand()%3)-1;
13+
14+
tfmbs_tensor_t w = tfmbs_tensor_bind(host_w, rows * cols, 1);
15+
tfmbs_tensor_t i = tfmbs_tensor_bind(NULL, cols, 1);
16+
tfmbs_tensor_t o = tfmbs_tensor_bind(NULL, rows * sizeof(int32_t), 0);
17+
18+
for(int n=0; n<5; n++) {
19+
fabric_handle_t h = tfmbs_gemm(&w, &i, &o, rows, cols);
20+
tfmbs_sync(h);
21+
22+
fabric_metrics_t m;
23+
fabric_get_metrics(&m);
24+
printf("Run %d: Cost: %.2f, Efficiency: %.4f, Residency Hits: %lu\n",
25+
n, m.fabric_cost, m.semantic_efficiency, m.residency_hits);
26+
tfmbs_dump_metrics_csv("gemm_metrics.csv");
27+
}
28+
29+
tfmbs_tensor_release(&w); tfmbs_tensor_release(&i); tfmbs_tensor_release(&o);
30+
free(host_w);
31+
}
32+
33+
int main() {
34+
benchmark_gemm_kernel();
35+
return 0;
36+
}

benchmarks/gemm_metrics.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zero_skips,total_ops,active_ops,mem_reads,mem_writes,broadcasts,residency_hits,residency_misses,cycles,fabric_cost,semantic_efficiency
2+
349272,1048576,699304,209919,4096,5,15,0,17476,1781677.00,0.3925
3+
349272,1048576,699304,209919,4096,5,15,0,15,17476,1781677.00,0.3925

benchmarks/layer1_synthetic.c

Lines changed: 0 additions & 84 deletions
This file was deleted.

benchmarks/layer2_kernels.c

Lines changed: 0 additions & 75 deletions
This file was deleted.

benchmarks/lstm/lstm_bench.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <time.h>
5+
#include "tfmbs_api.h"
6+
7+
void benchmark_lstm_kernel() {
8+
printf("\n--- [LSTM] Kernel Benchmark ---\n");
9+
int h_size = 512;
10+
int i_size = 512;
11+
int rows = 4 * h_size;
12+
int cols = i_size + h_size;
13+
14+
int8_t* host_w = malloc(rows * cols);
15+
for(int j=0; j<rows*cols; j++) host_w[j] = (rand()%3)-1;
16+
17+
tfmbs_tensor_t w = tfmbs_tensor_bind(host_w, rows * cols, 1);
18+
tfmbs_tensor_t i = tfmbs_tensor_bind(NULL, cols, 1);
19+
tfmbs_tensor_t o = tfmbs_tensor_bind(NULL, rows * sizeof(int32_t), 0);
20+
21+
for(int n=0; n<5; n++) {
22+
fabric_handle_t h = tfmbs_lstm_step(&w, &i, &o, h_size, i_size);
23+
tfmbs_sync(h);
24+
25+
fabric_metrics_t m;
26+
fabric_get_metrics(&m);
27+
printf("Run %d: Cost: %.2f, Efficiency: %.4f, Residency Hits: %lu\n",
28+
n, m.fabric_cost, m.semantic_efficiency, m.residency_hits);
29+
}
30+
31+
tfmbs_tensor_release(&w); tfmbs_tensor_release(&i); tfmbs_tensor_release(&o);
32+
free(host_w);
33+
}
34+
35+
int main() {
36+
benchmark_lstm_kernel();
37+
tfmbs_dump_metrics_csv("lstm_metrics.csv");
38+
return 0;
39+
}

benchmarks/lstm_metrics.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zero_skips,total_ops,active_ops,mem_reads,mem_writes,broadcasts,residency_hits,residency_misses,cycles,fabric_cost,semantic_efficiency
2+
699703,2097152,1397449,419634,8192,0,15,0,3072,3561155.00,0.3924
3+
699703,2097152,1397449,419634,8192,0,15,0,0,3072,3561155.00,0.3924

benchmarks/saturation_metrics.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zero_skips,total_ops,active_ops,mem_reads,mem_writes,broadcasts,residency_hits,residency_misses,cycles,fabric_cost,semantic_efficiency
2+
0,1048576,1048576,209919,4096,3,12,0,17476,2130945.00,0.4921
3+
0,1048576,1048576,209919,4096,3,12,0,6,17476,2130945.00,0.4921

0 commit comments

Comments
 (0)