1 |
2 |
qaztronic |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// Copyright (C) 2019 Authors and OPENCORES.ORG ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This source file may be used and distributed without ////
|
6 |
|
|
//// restriction provided that this copyright statement is not ////
|
7 |
|
|
//// removed from the file and that any derivative work contains ////
|
8 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// This source file is free software; you can redistribute it ////
|
11 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
12 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
13 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
14 |
|
|
//// later version. ////
|
15 |
|
|
//// ////
|
16 |
|
|
//// This source is distributed in the hope that it will be ////
|
17 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
18 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
19 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
20 |
|
|
//// details. ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
23 |
|
|
//// Public License along with this source; if not, download it ////
|
24 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
25 |
|
|
//// ////
|
26 |
|
|
//////////////////////////////////////////////////////////////////////
|
27 |
|
|
|
28 |
|
|
module
|
29 |
|
|
axis_dense_neuron
|
30 |
|
|
#(
|
31 |
|
|
int N,
|
32 |
|
|
int A,
|
33 |
|
|
string FILE_NAME,
|
34 |
|
|
int START,
|
35 |
|
|
int STOP,
|
36 |
|
|
string ACTIVATION
|
37 |
|
|
)
|
38 |
|
|
(
|
39 |
|
|
axis_if axis_in,
|
40 |
|
|
axis_if axis_out,
|
41 |
|
|
output error,
|
42 |
|
|
input aclk,
|
43 |
|
|
input aresetn
|
44 |
|
|
);
|
45 |
|
|
|
46 |
|
|
// --------------------------------------------------------------------
|
47 |
|
|
axis_if #(4) axis_bias(.*);
|
48 |
|
|
assign axis_bias.tdata = $shortrealtobits(1.0);
|
49 |
|
|
assign axis_bias.tvalid = 1;
|
50 |
|
|
assign axis_bias.tlast = 1;
|
51 |
|
|
|
52 |
|
|
// --------------------------------------------------------------------
|
53 |
|
|
axis_if #(4) axis_az(.*);
|
54 |
|
|
axis_if #(4) axis_cat[2](.*);
|
55 |
|
|
axis_alias axis_alias_bias(axis_bias, axis_cat[0]);
|
56 |
|
|
axis_alias axis_alias_in(axis_in, axis_cat[1]);
|
57 |
|
|
|
58 |
|
|
axis_catenate #(N)
|
59 |
|
|
axis_catenate_i(.axis_in(axis_cat), .axis_out(axis_az), .*);
|
60 |
|
|
|
61 |
|
|
// --------------------------------------------------------------------
|
62 |
|
|
axis_if #(.N(N)) axis_rom(.*);
|
63 |
|
|
|
64 |
|
|
axis_rom #(N, A, FILE_NAME, START, STOP)
|
65 |
|
|
axis_rom_i(.axis_out(axis_rom), .*);
|
66 |
|
|
|
67 |
|
|
// --------------------------------------------------------------------
|
68 |
|
|
wire [31:0] result;
|
69 |
|
|
wire valid;
|
70 |
|
|
|
71 |
|
|
axis_mac axis_mac_i(.axis_ay(axis_rom), .*);
|
72 |
|
|
|
73 |
|
|
// --------------------------------------------------------------------
|
74 |
|
|
// ReLU activation function
|
75 |
|
|
// wire [31:0] activation = result[31] ? 0 : result;
|
76 |
|
|
wire [31:0] activation;
|
77 |
|
|
|
78 |
|
|
generate
|
79 |
|
|
begin: activation_gen
|
80 |
|
|
if(ACTIVATION == "ReLU")
|
81 |
|
|
relu relu_i(.*);
|
82 |
|
|
else if(ACTIVATION == "Linear")
|
83 |
|
|
linear linear_i(.*);
|
84 |
|
|
else
|
85 |
|
|
initial $stop;
|
86 |
|
|
end
|
87 |
|
|
endgenerate
|
88 |
|
|
|
89 |
|
|
// --------------------------------------------------------------------
|
90 |
|
|
wire wr_full;
|
91 |
|
|
wire [(N*8)-1:0] wr_data = activation;
|
92 |
|
|
wire wr_en = valid;
|
93 |
|
|
wire rd_empty;
|
94 |
|
|
wire [(N*8)-1:0] rd_data;
|
95 |
|
|
wire rd_en = axis_out.tvalid & axis_out.tready;
|
96 |
|
|
|
97 |
|
|
// tiny_sync_fifo #(N*8) fifo_i(.clk(aclk), .reset(~aresetn), .*);
|
98 |
|
|
wire [$clog2(64):0] count; // fixme
|
99 |
|
|
sync_fifo #(N*8, 64) fifo_i(.clk(aclk), .reset(~aresetn), .*); // fix me
|
100 |
|
|
|
101 |
|
|
// --------------------------------------------------------------------
|
102 |
|
|
assign axis_out.tvalid = ~rd_empty;
|
103 |
|
|
assign axis_out.tdata = rd_data;
|
104 |
|
|
assign axis_out.tlast = 1;
|
105 |
|
|
assign error = wr_full & valid;
|
106 |
|
|
|
107 |
|
|
// --------------------------------------------------------------------
|
108 |
|
|
endmodule
|