da4ml 0.5.0__cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. da4ml/__init__.py +4 -0
  2. da4ml/_binary/__init__.py +15 -0
  3. da4ml/_binary/dais_bin.cpython-312-x86_64-linux-gnu.so +0 -0
  4. da4ml/_binary/dais_bin.pyi +5 -0
  5. da4ml/_cli/__init__.py +30 -0
  6. da4ml/_cli/convert.py +194 -0
  7. da4ml/_cli/report.py +295 -0
  8. da4ml/_version.py +32 -0
  9. da4ml/cmvm/__init__.py +4 -0
  10. da4ml/cmvm/api.py +264 -0
  11. da4ml/cmvm/core/__init__.py +221 -0
  12. da4ml/cmvm/core/indexers.py +83 -0
  13. da4ml/cmvm/core/state_opr.py +284 -0
  14. da4ml/cmvm/types.py +739 -0
  15. da4ml/cmvm/util/__init__.py +7 -0
  16. da4ml/cmvm/util/bit_decompose.py +86 -0
  17. da4ml/cmvm/util/mat_decompose.py +121 -0
  18. da4ml/codegen/__init__.py +9 -0
  19. da4ml/codegen/hls/__init__.py +4 -0
  20. da4ml/codegen/hls/hls_codegen.py +196 -0
  21. da4ml/codegen/hls/hls_model.py +255 -0
  22. da4ml/codegen/hls/source/ap_types/ap_binary.h +78 -0
  23. da4ml/codegen/hls/source/ap_types/ap_common.h +376 -0
  24. da4ml/codegen/hls/source/ap_types/ap_decl.h +212 -0
  25. da4ml/codegen/hls/source/ap_types/ap_fixed.h +360 -0
  26. da4ml/codegen/hls/source/ap_types/ap_fixed_base.h +2354 -0
  27. da4ml/codegen/hls/source/ap_types/ap_fixed_ref.h +718 -0
  28. da4ml/codegen/hls/source/ap_types/ap_fixed_special.h +230 -0
  29. da4ml/codegen/hls/source/ap_types/ap_int.h +330 -0
  30. da4ml/codegen/hls/source/ap_types/ap_int_base.h +1885 -0
  31. da4ml/codegen/hls/source/ap_types/ap_int_ref.h +1346 -0
  32. da4ml/codegen/hls/source/ap_types/ap_int_special.h +223 -0
  33. da4ml/codegen/hls/source/ap_types/ap_shift_reg.h +138 -0
  34. da4ml/codegen/hls/source/ap_types/etc/ap_private.h +7199 -0
  35. da4ml/codegen/hls/source/ap_types/hls_math.h +27 -0
  36. da4ml/codegen/hls/source/ap_types/hls_stream.h +263 -0
  37. da4ml/codegen/hls/source/ap_types/utils/x_hls_utils.h +80 -0
  38. da4ml/codegen/hls/source/binder_util.hh +71 -0
  39. da4ml/codegen/hls/source/build_binder.mk +22 -0
  40. da4ml/codegen/hls/source/vitis_bitshift.hh +32 -0
  41. da4ml/codegen/rtl/__init__.py +15 -0
  42. da4ml/codegen/rtl/common_source/binder_util.hh +99 -0
  43. da4ml/codegen/rtl/common_source/build_binder.mk +34 -0
  44. da4ml/codegen/rtl/common_source/build_quartus_prj.tcl +104 -0
  45. da4ml/codegen/rtl/common_source/build_vivado_prj.tcl +111 -0
  46. da4ml/codegen/rtl/common_source/ioutil.hh +124 -0
  47. da4ml/codegen/rtl/common_source/template.sdc +27 -0
  48. da4ml/codegen/rtl/common_source/template.xdc +30 -0
  49. da4ml/codegen/rtl/rtl_model.py +486 -0
  50. da4ml/codegen/rtl/verilog/__init__.py +10 -0
  51. da4ml/codegen/rtl/verilog/comb.py +239 -0
  52. da4ml/codegen/rtl/verilog/io_wrapper.py +113 -0
  53. da4ml/codegen/rtl/verilog/pipeline.py +67 -0
  54. da4ml/codegen/rtl/verilog/source/lookup_table.v +27 -0
  55. da4ml/codegen/rtl/verilog/source/multiplier.v +37 -0
  56. da4ml/codegen/rtl/verilog/source/mux.v +58 -0
  57. da4ml/codegen/rtl/verilog/source/negative.v +31 -0
  58. da4ml/codegen/rtl/verilog/source/shift_adder.v +59 -0
  59. da4ml/codegen/rtl/vhdl/__init__.py +9 -0
  60. da4ml/codegen/rtl/vhdl/comb.py +206 -0
  61. da4ml/codegen/rtl/vhdl/io_wrapper.py +120 -0
  62. da4ml/codegen/rtl/vhdl/pipeline.py +71 -0
  63. da4ml/codegen/rtl/vhdl/source/lookup_table.vhd +52 -0
  64. da4ml/codegen/rtl/vhdl/source/multiplier.vhd +40 -0
  65. da4ml/codegen/rtl/vhdl/source/mux.vhd +102 -0
  66. da4ml/codegen/rtl/vhdl/source/negative.vhd +35 -0
  67. da4ml/codegen/rtl/vhdl/source/shift_adder.vhd +101 -0
  68. da4ml/converter/__init__.py +63 -0
  69. da4ml/converter/hgq2/__init__.py +3 -0
  70. da4ml/converter/hgq2/layers/__init__.py +11 -0
  71. da4ml/converter/hgq2/layers/_base.py +132 -0
  72. da4ml/converter/hgq2/layers/activation.py +81 -0
  73. da4ml/converter/hgq2/layers/attn.py +148 -0
  74. da4ml/converter/hgq2/layers/batchnorm.py +15 -0
  75. da4ml/converter/hgq2/layers/conv.py +149 -0
  76. da4ml/converter/hgq2/layers/dense.py +39 -0
  77. da4ml/converter/hgq2/layers/ops.py +240 -0
  78. da4ml/converter/hgq2/layers/pool.py +107 -0
  79. da4ml/converter/hgq2/layers/table.py +176 -0
  80. da4ml/converter/hgq2/parser.py +161 -0
  81. da4ml/trace/__init__.py +6 -0
  82. da4ml/trace/fixed_variable.py +965 -0
  83. da4ml/trace/fixed_variable_array.py +600 -0
  84. da4ml/trace/ops/__init__.py +13 -0
  85. da4ml/trace/ops/einsum_utils.py +305 -0
  86. da4ml/trace/ops/quantization.py +74 -0
  87. da4ml/trace/ops/reduce_utils.py +105 -0
  88. da4ml/trace/pipeline.py +181 -0
  89. da4ml/trace/tracer.py +186 -0
  90. da4ml/typing/__init__.py +3 -0
  91. da4ml-0.5.0.dist-info/METADATA +85 -0
  92. da4ml-0.5.0.dist-info/RECORD +96 -0
  93. da4ml-0.5.0.dist-info/WHEEL +6 -0
  94. da4ml-0.5.0.dist-info/entry_points.txt +3 -0
  95. da4ml-0.5.0.dist-info/sboms/auditwheel.cdx.json +1 -0
  96. da4ml.libs/libgomp-e985bcbb.so.1.0.0 +0 -0
@@ -0,0 +1,223 @@
1
+ /*
2
+ * Copyright 2011-2019 Xilinx, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef __AP_INT_SPECIAL_H__
18
+ #define __AP_INT_SPECIAL_H__
19
+
20
+ #ifndef __AP_INT_H__
21
+ #error "Only ap_fixed.h and ap_int.h can be included directly in user code."
22
+ #endif
23
+
24
+ #ifndef __SYNTHESIS__
25
+ #include <cstdio>
26
+ #include <cstdlib>
27
+ #endif
28
+ // FIXME AP_AUTOCC cannot handle many standard headers, so declare instead of
29
+ // include.
30
+ // #include <complex>
31
+ namespace std {
32
+ template<typename _Tp> class complex;
33
+ }
34
+
35
+ /*
36
+ TODO: Modernize the code using C++11/C++14
37
+ 1. constexpr http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0415r0.html
38
+ 2. move constructor
39
+ */
40
+
41
+ namespace std {
42
+ /*
43
+ Specialize std::complex<ap_int> to zero initialization ap_int.
44
+
45
+ To reduce the area cost, ap_int is not zero initialized, just like basic
46
+ types float or double. However, libstdc++ provides specialization for float,
47
+ double and long double, initializing image part to 0 when not specified.
48
+
49
+ This has become a difficulty in switching legacy code from these C types to
50
+ ap_int. To ease the tranform of legacy code, we have to implement
51
+ specialization of std::complex<> for our type.
52
+
53
+ As ap_int is a template, it is impossible to specialize only the methods
54
+ that causes default initialization of value type in std::complex<>. An
55
+ explicit full specialization of the template class has to be done, covering
56
+ all the member functions and operators of std::complex<> as specified
57
+ in standard 26.2.4 and 26.2.5.
58
+ */
59
+ template <int _AP_W>
60
+ class complex<ap_int<_AP_W> > {
61
+ public:
62
+ typedef ap_int<_AP_W> _Tp;
63
+ typedef _Tp value_type;
64
+
65
+ // 26.2.4/1
66
+ // Constructor without argument
67
+ // Default initialize, so that in dataflow, the variable is only written once.
68
+ complex() : _M_real(_Tp()), _M_imag(_Tp()) {}
69
+ // Constructor with ap_int.
70
+ // Zero initialize image part when not specified, so that `C(1) == C(1,0)`
71
+ complex(const _Tp &__r, const _Tp &__i = _Tp(0))
72
+ : _M_real(__r), _M_imag(__i) {}
73
+
74
+ // Constructor with another complex number
75
+ template <typename _Up>
76
+ complex(const complex<_Up> &__z) : _M_real(__z.real()), _M_imag(__z.imag()) {}
77
+
78
+ #if __cplusplus >= 201103L
79
+ const _Tp& real() const { return _M_real; }
80
+ const _Tp& imag() const { return _M_imag; }
81
+ #else
82
+ _Tp& real() { return _M_real; }
83
+ const _Tp& real() const { return _M_real; }
84
+ _Tp& imag() { return _M_imag; }
85
+ const _Tp& imag() const { return _M_imag; }
86
+ #endif
87
+
88
+ void real(_Tp __val) { _M_real = __val; }
89
+
90
+ void imag(_Tp __val) { _M_imag = __val; }
91
+
92
+ // Assign this complex number with ap_int.
93
+ // Zero initialize image poarrt, so that `C c; c = 1; c == C(1,0);`
94
+ complex<_Tp> &operator=(const _Tp __t) {
95
+ _M_real = __t;
96
+ _M_imag = _Tp(0);
97
+ return *this;
98
+ }
99
+
100
+ // 26.2.5/1
101
+ // Add ap_int to this complex number.
102
+ complex<_Tp> &operator+=(const _Tp &__t) {
103
+ _M_real += __t;
104
+ return *this;
105
+ }
106
+
107
+ // 26.2.5/3
108
+ // Subtract ap_int from this complex number.
109
+ complex<_Tp> &operator-=(const _Tp &__t) {
110
+ _M_real -= __t;
111
+ return *this;
112
+ }
113
+
114
+ // 26.2.5/5
115
+ // Multiply this complex number by ap_int.
116
+ complex<_Tp> &operator*=(const _Tp &__t) {
117
+ _M_real *= __t;
118
+ _M_imag *= __t;
119
+ return *this;
120
+ }
121
+
122
+ // 26.2.5/7
123
+ // Divide this complex number by ap_int.
124
+ complex<_Tp> &operator/=(const _Tp &__t) {
125
+ _M_real /= __t;
126
+ _M_imag /= __t;
127
+ return *this;
128
+ }
129
+
130
+ // Assign complex number to this complex number.
131
+ template <typename _Up>
132
+ complex<_Tp> &operator=(const complex<_Up> &__z) {
133
+ _M_real = __z.real();
134
+ _M_imag = __z.imag();
135
+ return *this;
136
+ }
137
+
138
+ // 26.2.5/9
139
+ // Add complex number to this.
140
+ template <typename _Up>
141
+ complex<_Tp> &operator+=(const complex<_Up> &__z) {
142
+ _M_real += __z.real();
143
+ _M_imag += __z.imag();
144
+ return *this;
145
+ }
146
+
147
+ // 26.2.5/11
148
+ // Subtract complex number from this.
149
+ template <typename _Up>
150
+ complex<_Tp> &operator-=(const complex<_Up> &__z) {
151
+ _M_real -= __z.real();
152
+ _M_imag -= __z.imag();
153
+ return *this;
154
+ }
155
+
156
+ // 26.2.5/13
157
+ // Multiply this by complex number.
158
+ template <typename _Up>
159
+ complex<_Tp> &operator*=(const complex<_Up> &__z) {
160
+ const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
161
+ _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
162
+ _M_real = __r;
163
+ return *this;
164
+ }
165
+
166
+ // 26.2.5/15
167
+ // Divide this by complex number.
168
+ template <typename _Up>
169
+ complex<_Tp> &operator/=(const complex<_Up> &__z) {
170
+ complex<_Tp> cj (__z.real(), -__z.imag());
171
+ complex<_Tp> a = (*this) * cj;
172
+ complex<_Tp> b = cj * __z;
173
+ _M_real = a.real() / b.real();
174
+ _M_imag = a.imag() / b.real();
175
+ return *this;
176
+ }
177
+
178
+ private:
179
+ _Tp _M_real;
180
+ _Tp _M_imag;
181
+
182
+ }; // class complex<ap_int<_AP_W> >
183
+
184
+
185
+ /*
186
+ Non-member operations
187
+ These operations are not required by standard in 26.2.6, but libstdc++
188
+ defines them for
189
+ float, double or long double's specialization.
190
+ */
191
+ // Compare complex number with ap_int.
192
+ template <int _AP_W>
193
+ inline bool operator==(const complex<ap_int<_AP_W> > &__x, const ap_int<_AP_W> &__y) {
194
+ return __x.real() == __y &&
195
+ __x.imag() == 0;
196
+ }
197
+
198
+ // Compare ap_int with complex number.
199
+ template <int _AP_W>
200
+ inline bool operator==(const ap_int<_AP_W> &__x, const complex<ap_int<_AP_W> > &__y) {
201
+ return __x == __y.real() &&
202
+ 0 == __y.imag();
203
+ }
204
+
205
+ // Compare complex number with ap_int.
206
+ template <int _AP_W>
207
+ inline bool operator!=(const complex<ap_int<_AP_W> > &__x, const ap_int<_AP_W> &__y) {
208
+ return __x.real() != __y ||
209
+ __x.imag() != 0;
210
+ }
211
+
212
+ // Compare ap_int with complex number.
213
+ template <int _AP_W>
214
+ inline bool operator!=(const ap_int<_AP_W> &__x, const complex<ap_int<_AP_W> > &__y) {
215
+ return __x != __y.real() ||
216
+ 0 != __y.imag();
217
+ }
218
+
219
+ } // namespace std
220
+
221
+ #endif // ifndef __AP_INT_SPECIAL_H__
222
+
223
+ // -*- cpp -*-
@@ -0,0 +1,138 @@
1
+ /*
2
+ #- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
3
+ #-
4
+ #- This file contains confidential and proprietary information
5
+ #- of Xilinx, Inc. and is protected under U.S. and
6
+ #- international copyright and other intellectual property
7
+ #- laws.
8
+ #-
9
+ #- DISCLAIMER
10
+ #- This disclaimer is not a license and does not grant any
11
+ #- rights to the materials distributed herewith. Except as
12
+ #- otherwise provided in a valid license issued to you by
13
+ #- Xilinx, and to the maximum extent permitted by applicable
14
+ #- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
15
+ #- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
16
+ #- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
17
+ #- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
18
+ #- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
19
+ #- (2) Xilinx shall not be liable (whether in contract or tort,
20
+ #- including negligence, or under any other theory of
21
+ #- liability) for any loss or damage of any kind or nature
22
+ #- related to, arising under or in connection with these
23
+ #- materials, including for any direct, or any indirect,
24
+ #- special, incidental, or consequential loss or damage
25
+ #- (including loss of data, profits, goodwill, or any type of
26
+ #- loss or damage suffered as a result of any action brought
27
+ #- by a third party) even if such damage or loss was
28
+ #- reasonably foreseeable or Xilinx had been advised of the
29
+ #- possibility of the same.
30
+ #-
31
+ #- CRITICAL APPLICATIONS
32
+ #- Xilinx products are not designed or intended to be fail-
33
+ #- safe, or for use in any application requiring fail-safe
34
+ #- performance, such as life-support or safety devices or
35
+ #- systems, Class III medical devices, nuclear facilities,
36
+ #- applications related to the deployment of airbags, or any
37
+ #- other applications that could lead to death, personal
38
+ #- injury, or severe property or environmental damage
39
+ #- (individually and collectively, "Critical
40
+ #- Applications"). Customer assumes the sole risk and
41
+ #- liability of any use of Xilinx products in Critical
42
+ #- Applications, subject only to applicable laws and
43
+ #- regulations governing limitations on product liability.
44
+ #-
45
+ #- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
46
+ #- PART OF THIS FILE AT ALL TIMES.
47
+ #- ************************************************************************
48
+
49
+
50
+ Licensed under the Apache License, Version 2.0 (the "License");
51
+ you may not use this file except in compliance with the License.
52
+ You may obtain a copy of the License at
53
+
54
+ http://www.apache.org/licenses/LICENSE-2.0
55
+
56
+ Unless required by applicable law or agreed to in writing, software
57
+ distributed under the License is distributed on an "AS IS" BASIS,
58
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
+ See the License for the specific language governing permissions and
60
+ limitations under the License.
61
+ */
62
+
63
+ #ifndef __SIM_AP_SHIFT_REG_H__
64
+ #define __SIM_AP_SHIFT_REG_H__
65
+
66
+
67
+ /*
68
+ * This file contains a C++ model of shift register.
69
+ * It defines C level simulation model.
70
+ */
71
+ #ifndef __cplusplus
72
+ #error C++ is required to include this header file
73
+ #else
74
+
75
+ #include <cassert>
76
+
77
+ //////////////////////////////////////////////
78
+ // C level simulation model for ap_shift_reg
79
+ //////////////////////////////////////////////
80
+ template<typename __SHIFT_T__, unsigned int __SHIFT_DEPTH__ = 32>
81
+ class ap_shift_reg
82
+ {
83
+ public:
84
+ /// Constructors
85
+ ap_shift_reg() { }
86
+ ap_shift_reg(const char* name) { }
87
+ /// Destructor
88
+ virtual ~ap_shift_reg() { }
89
+
90
+ private:
91
+ /// Make copy constructor and assignment operator private
92
+ ap_shift_reg(const ap_shift_reg< __SHIFT_T__, __SHIFT_DEPTH__ >& shreg)
93
+ {
94
+ for (unsigned i = 0; i < __SHIFT_DEPTH__; ++i)
95
+ Array[i] = shreg.Array[i];
96
+ }
97
+
98
+ ap_shift_reg& operator = (const ap_shift_reg< __SHIFT_T__,
99
+ __SHIFT_DEPTH__ >& shreg)
100
+ {
101
+ for (unsigned i = 0; i < __SHIFT_DEPTH__; ++i)
102
+ Array[i] = shreg.Array[i];
103
+ return *this;
104
+ }
105
+
106
+ public:
107
+ // Shift the queue, push to back and read from a given address.
108
+ __SHIFT_T__ shift(__SHIFT_T__ DataIn,
109
+ unsigned int Addr = __SHIFT_DEPTH__ - 1, bool Enable = true)
110
+ {
111
+ assert(Addr < __SHIFT_DEPTH__ &&
112
+ "Out-of-bound shift is found in ap_shift_reg.");
113
+ __SHIFT_T__ ret = Array[Addr];
114
+ if (Enable) {
115
+ for (unsigned int i = __SHIFT_DEPTH__ - 1; i > 0; --i)
116
+ Array[i] = Array[i-1];
117
+ Array[0] = DataIn;
118
+ }
119
+ return ret;
120
+ }
121
+
122
+ // Read from a given address.
123
+ __SHIFT_T__ read(unsigned int Addr = __SHIFT_DEPTH__ - 1) const
124
+ {
125
+ assert(Addr < __SHIFT_DEPTH__ &&
126
+ "Out-of-bound read is found in ap_shift_reg.");
127
+ return Array[Addr];
128
+ }
129
+
130
+ protected:
131
+ __SHIFT_T__ Array[__SHIFT_DEPTH__];
132
+ };
133
+
134
+ #endif //__cplusplus
135
+
136
+ #endif //__SIM_AP_SHIFT_REG_H__
137
+
138
+