OpenCores
URL https://opencores.org/ocsvn/keras_to_fpga/keras_to_fpga/trunk

Subversion Repositories keras_to_fpga

[/] [keras_to_fpga/] [trunk/] [src/] [nn/] [axis_dense.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
30
  #(
31
    int N,
32
    int SHAPE[],
33
    string LAYER,
34
    string DIR,
35
    string ACTIVATION
36
  )
37
  (
38
    axis_if axis_in,
39
    axis_if axis_out,
40
    wire    error,
41
    input   aclk,
42
    input   aresetn
43
  );
44
 
45
  // --------------------------------------------------------------------
46
  initial
47
    $display("### layer: %s SHAPE = (%0.d, %0.d) | (inputs, neurons) | %s", LAYER, SHAPE[0], SHAPE[1], ACTIVATION);
48
 
49
  // --------------------------------------------------------------------
50
  localparam A = $clog2(SHAPE[0]+1);
51
  localparam ROM_SIZE = 2**A;
52
  localparam START = 0;
53
  localparam STOP = SHAPE[0]+1;
54
  localparam MA = $clog2(SHAPE[1]); // fixme
55
 
56
  // --------------------------------------------------------------------
57
  axis_if #(N) axis_neuron[(2**MA)-1:0](.*);
58
  wire [SHAPE[1]-1:0] neuron_error;
59
 
60
  generate
61
    for(genvar j = 0; j < 2**MA; j++)
62
      if(j < SHAPE[1])
63
      begin: neuron_gen
64
        localparam FILE_NAME = $sformatf("%s/%s_%0.d.txt", DIR, LAYER, j);
65
        axis_dense_neuron #(N, A, FILE_NAME, START, STOP, ACTIVATION)
66
          neuron_i(.axis_out(axis_neuron[j]), .error(neuron_error[j]),  .*);
67
      end
68
      else
69
      begin: dummy_gen
70
        assign axis_neuron[j].tvalid = 1;
71
        assign axis_neuron[j].tdata = 0;
72
        assign axis_neuron[j].tlast = 1;
73
      end
74
  endgenerate
75
 
76
  // --------------------------------------------------------------------
77
  generate
78
  begin: catenate_gen
79
    if(SHAPE[1] > 1)
80
        recursive_axis_catenate #(.N(N), .MA(MA))
81
          recursive_axis_catenate_i(.axis_in(axis_neuron), .*);
82
    else
83
      axis_alias axis_alias_in(axis_neuron[0], axis_out);
84
  end
85
  endgenerate
86
 
87
  // --------------------------------------------------------------------
88
  assign error = |neuron_error;
89
 
90
// --------------------------------------------------------------------
91
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.