Skip to content

Commit cd6c400

Browse files
author
Antigravity Agent
committed
feat(pins): Trinity Pins DSL - Single Source of Truth (#492)
- Lexer with proper token types (keywords, identifiers, strings, punctuation) - Recursive descent parser for board, fabric, and design files - XDC emitter that generates Vivado-compatible constraint files - CLI commands: tri fpga pins {to-xdc|validate|ir|doctor} Files: - src/tri/pins_parser.zig - Full DSL implementation (~1400 LOC) - src/tri/tri_fpga.zig - CLI routing for fpga pins commands - fpga/boards/qmtech_xc7a100t.board.tri - Board definition with connectors - fpga/designs/uart_bridge_fixed.design.tri - Test design binding Generated XDC: uart_bridge_fixed.design.xdc ✓ uart_rx → FPGA L20 (FT232RL RXD) ✓ uart_tx → FPGA K20 (FT232RL TXD) ✓ led → FPGA T23 (Status LED) ✓ clk → FPGA M22 (50MHz oscillator) Билд зелёный!
1 parent cedbd2c commit cd6c400

20 files changed

Lines changed: 1502 additions & 76 deletions

.trinity/dev_agents.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

.trinity/dev_loop_state.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

.trinity/dev_session.json

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

.trinity/doctor_prev.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1775077532 score=100 laws=5/5 dirty=0 healed=18
1+
1775088476 score=100 laws=5/5 dirty=0 healed=18

.trinity/mu/heartbeat.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"agent":"mu","wake":324,"timestamp":1775079011,"errors_scanned":0,"fixes_applied":0,"build_ok":true,"test_ok":true}
1+
{"agent":"mu","wake":384,"timestamp":1775099069,"errors_scanned":0,"fixes_applied":0,"build_ok":true,"test_ok":true}

codegen_impl

247 KB
Binary file not shown.

fpga/boards/qmtech_xc7a100t.board.tri

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ board qmtech_xc7a100t {
2222
}
2323

2424
uart ft232rl {
25-
txd fpga.K20 # FPGA uart_tx → FT232RL RXD (green, J2 pin 6)
26-
rxd fpga.L20 # FT232RL TXD → FPGA uart_rx (white, J2 pin 5)
25+
# FT232RL TXD (белый, J2.5) → FPGA uart_rx (L20)
26+
# FT232RL RXD (зелёный, J2.6) → FPGA uart_tx (K20)
27+
txd fpga.L20
28+
rxd fpga.K20
2729
baud 115200
2830
}
2931

fpga/designs/uart_bridge_fixed.design.xdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ set_property LOC M22 [get_ports clk]
99
set_property IOSTANDARD LVCMOS33 [get_ports clk]
1010

1111
# board.uart.ft232rl.txd
12-
set_property LOC K20 [get_ports uart_rx]
12+
set_property LOC L20 [get_ports uart_rx]
1313
set_property IOSTANDARD LVCMOS33 [get_ports uart_rx]
1414

1515
# board.uart.ft232rl.rxd
16-
set_property LOC L20 [get_ports uart_tx]
16+
set_property LOC K20 [get_ports uart_tx]
1717
set_property IOSTANDARD LVCMOS33 [get_ports uart_tx]
1818

1919
# board.led.status

specs/algo/dense.tri

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,60 @@ functions:
109109
grad_input[i] = sum_j(weights[i][j] * grad_output[j])
110110

111111
behaviors:
112+
- name: forward_dense
113+
description: "Dense layer forward pass implementation"
114+
implementation: |
115+
pub fn forward(input: []const f32, weights: []const f32, bias: []const f32, output: []f32, config: DenseConfig) void {
116+
const input_size = config.input_size;
117+
const output_size = config.output_size;
118+
119+
for (0..output_size) |output_j| {
120+
var sum: f32 = if (config.has_bias) bias[output_j] else 0;
121+
122+
for (0..input_size) |input_i| {
123+
const weight_idx = input_i * output_size + output_j;
124+
sum += input[input_i] * weights[weight_idx];
125+
}
126+
127+
output[output_j] = sum; // Activation applied externally
128+
}
129+
}
130+
131+
- name: backward_dense
132+
description: "Dense layer backward pass implementation"
133+
implementation: |
134+
pub fn backward(grad_output: []const f32, input: []const f32, weights: []const f32,
135+
grad_input: []f32, grad_weights: []f32, grad_bias: []f32,
136+
config: DenseConfig) void {
137+
const input_size = config.input_size;
138+
const output_size = config.output_size;
139+
140+
// Clear gradients
141+
@memset(grad_weights, 0);
142+
143+
// Compute grad_weights and grad_bias
144+
for (0..output_size) |output_j| {
145+
if (config.has_bias) {
146+
grad_bias[output_j] = grad_output[output_j];
147+
}
148+
149+
for (0..input_size) |input_i| {
150+
const weight_idx = input_i * output_size + output_j;
151+
grad_weights[weight_idx] += input[input_i] * grad_output[output_j];
152+
}
153+
}
154+
155+
// Compute grad_input
156+
for (0..input_size) |input_i| {
157+
var sum: f32 = 0;
158+
for (0..output_size) |output_j| {
159+
const weight_idx = input_i * output_size + output_j;
160+
sum += weights[weight_idx] * grad_output[output_j];
161+
}
162+
grad_input[input_i] = sum;
163+
}
164+
}
165+
112166
- name: matrix_multiply
113167
description: "Core operation is matrix-vector multiplication"
114168
implementation: |

specs/algo/mse_loss.tri

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ types:
1111
MSELossConfig:
1212
fields:
1313
- name: reduction
14-
type: string
14+
type: []const u8
1515
description: "mean, sum, or none"
1616

1717
functions:
@@ -27,5 +27,37 @@ functions:
2727
# sum over all elements, divide by count
2828

2929
behaviors:
30+
- name: forward_mse_loss
31+
description: "MSE loss forward implementation"
32+
implementation: |
33+
pub fn forward(predictions: []const f32, targets: []const f32) f32 {
34+
const n = predictions.len;
35+
if (n == 0) return 0;
36+
37+
var sum_loss: f32 = 0;
38+
for (predictions, 0..) |pred, i| {
39+
const diff = pred - targets[i];
40+
sum_loss += diff * diff;
41+
}
42+
43+
return sum_loss / @as(f32, @floatFromInt(n));
44+
}
45+
46+
- name: backward_mse_loss
47+
description: "MSE loss backward implementation"
48+
implementation: |
49+
pub fn backward(predictions: []const f32, targets: []const f32, grad_input: []f32) void {
50+
const n = predictions.len;
51+
if (n == 0) return;
52+
53+
const scale = 2.0 / @as(f32, @floatFromInt(n));
54+
for (predictions, 0..) |pred, i| {
55+
grad_input[i] = scale * (pred - targets[i]);
56+
}
57+
}
58+
3059
- name: squared_error
3160
description: "Penalizes large errors more heavily"
61+
implementation: |
62+
Loss = mean((predictions - targets)^2)
63+
Gradient = 2 * (predictions - targets) / n

0 commit comments

Comments
 (0)