onnx2versal
Loading...
Searching...
No Matches
graph_qlinearmac.h
1#ifndef __QLINEARMAC_GRAPH_H__
2#define __QLINEARMAC_GRAPH_H__
3
4#include <assert.h>
5#include <adf.h>
6#include "qlinearmac.h"
7#include "graph_utils.h"
8
9
37template <
38 template<typename, typename, int, int, int> class QLINEARMAC,
39 typename TT, typename TTPARAM, int B, int W, int IS_RELU>
40class QlinearMacGraph : public adf::graph {
41
42 private:
43 adf::kernel k[1];
44 std::string id;
45
46 public:
47 adf::port<input> pin[1];
48 adf::port<output> pout[1];
49
51 std::vector<TTPARAM> weights,
52 std::vector<TTPARAM> bias,
53 float x_scale,
54 float w_scale,
55 float b_scale,
56 float z_scale,
57 float y_scale,
58 TT x_zero,
59 TTPARAM w_zero,
60 TTPARAM b_zero,
61 TT z_zero,
62 TT y_zero,
63 int repeat_cnt = 1
64 ) {
65 static_assert(2*W < MAX_PARAM_BYTES);
66 k[0] = adf::kernel::create_object<QLINEARMAC<TT, TTPARAM, B, W, IS_RELU>>(
67 weights, bias, x_scale, w_scale, b_scale, z_scale, y_scale, x_zero, w_zero, b_zero, z_zero, y_zero);
68 adf::source(k[0]) = "qlinearmac.cc";
69 adf::headers(k[0]) = {"qlinearmac.h"};
70 adf::runtime<ratio>(k[0]) = 0.6;
71 adf::repetition_count(k[0]) = repeat_cnt;
72 adf::heap_size(k[0]) = 3*W*4 + 1024;
73
74 adf::connect<adf::window<B*W>> (pin[0], k[0].in[0]);
75 adf::connect<adf::window<B*W>> (k[0].out[0], pout[0]);
76
77 adf::location_constraint tilePos = adf::location<adf::kernel>(k[0]);
78 adf::location<adf::parameter>(k[0].param[0]) = tilePos;
79 adf::location<adf::parameter>(k[0].param[0]) = adf::offset(0);
80 adf::location<adf::parameter>(k[0].param[1]) = tilePos;
81 adf::location<adf::parameter>(k[0].param[1]) = adf::offset((W+31)/32*32);
82 }
83
84};
85
86
95template <
96 template<typename, typename, int, int, int> class QLINEARMAC,
97 typename TT, typename TTPARAM, int B, int W, int IS_RELU>
98class QlinearMacStreamGraph : public adf::graph {
99
100 private:
101 adf::kernel k[1];
102 std::string id;
103
104 public:
105 adf::port<input> pin[1];
106 adf::port<output> pout[1];
107
109 std::vector<TTPARAM> weights,
110 std::vector<TTPARAM> bias,
111 float x_scale,
112 float w_scale,
113 float b_scale,
114 float z_scale,
115 float y_scale,
116 TT x_zero,
117 TTPARAM w_zero,
118 TTPARAM b_zero,
119 TT z_zero,
120 TT y_zero
121 ) {
122 static_assert(2*W < MAX_PARAM_BYTES);
123 k[0] = adf::kernel::create_object<QLINEARMAC<TT, TTPARAM, B, W, IS_RELU>>(
124 weights, bias, x_scale, w_scale, b_scale, z_scale, y_scale, x_zero, w_zero, b_zero, z_zero, y_zero);
125 adf::source(k[0]) = "qlinearmac.cc";
126 adf::headers(k[0]) = {"qlinearmac.h"};
127 adf::runtime<ratio>(k[0]) = 0.6;
128 adf::heap_size(k[0]) = 3*W*4 + 1024;
129
130 adf::connect<adf::stream> (pin[0], k[0].in[0]);
131 adf::connect<adf::stream> (k[0].out[0], pout[0]);
132
133 adf::samples_per_iteration(k[0].in[0]) = B*W;
134 adf::samples_per_iteration(k[0].out[0]) = B*W;
135
136 adf::location_constraint tilePos = adf::location<adf::kernel>(k[0]);
137 adf::location<adf::parameter>(k[0].param[0]) = tilePos;
138 adf::location<adf::parameter>(k[0].param[0]) = adf::offset(0);
139 adf::location<adf::parameter>(k[0].param[1]) = tilePos;
140 adf::location<adf::parameter>(k[0].param[1]) = adf::offset((W+31)/32*32);
141 }
142
143};
147#endif // __QLINEARMAC_GRAPH_H__
Single instance graph.
Definition graph_qlinearmac.h:40
Single instance stream graph.
Definition graph_qlinearmac.h:98