-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweights_ram.sv
More file actions
37 lines (32 loc) · 1021 Bytes
/
weights_ram.sv
File metadata and controls
37 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
`timescale 1ns / 1ps
`define LEARNING_RATE 8'h04
module weights_ram #(
parameter integer IMG_SIZE = 256,
parameter integer CLASSES = 10
) (
input logic clk,
input logic en_update,
input logic [7:0] bram_addr,
input logic [CLASSES-1:0][7:0] weight_deltas,
output logic [CLASSES-1:0][7:0] weights
);
logic [79:0] new_weights;
logic [CLASSES-1:0][7:0] parsed_weights;
logic [79:0] curr_weights;
weight_ram_1 wram ( // block mem instantiation
.addra(bram_addr),
.clka(clk),
.dina(new_weights),
.wea(en_update),
.douta(curr_weights)
);
always_comb begin
for(integer j = 0; j < CLASSES; j++) begin
parsed_weights[j][7:0] = curr_weights[8*j+:8];
end
weights = parsed_weights;
for(integer i = 0; i < CLASSES; i++) begin
new_weights[8*i+:8] = curr_weights[8*i+:8] + ((`LEARNING_RATE * weight_deltas[i]) >> 5);
end
end
endmodule