da4ml 0.3.2__tar.gz → 0.3.3__tar.gz

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.

Potentially problematic release.


This version of da4ml might be problematic. Click here for more details.

Files changed (93) hide show
  1. {da4ml-0.3.2/src/da4ml.egg-info → da4ml-0.3.3}/PKG-INFO +1 -1
  2. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/_version.py +3 -3
  3. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/cpp_codegen.py +1 -1
  4. da4ml-0.3.3/src/da4ml/codegen/cpp/source/binder_util.hh +50 -0
  5. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/vitis_bitshift.hh +5 -3
  6. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/converter/hgq2/parser.py +4 -2
  7. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/fixed_variable.py +4 -0
  8. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/fixed_variable_array.py +4 -0
  9. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/ops/reduce_utils.py +3 -3
  10. {da4ml-0.3.2 → da4ml-0.3.3/src/da4ml.egg-info}/PKG-INFO +1 -1
  11. da4ml-0.3.2/src/da4ml/codegen/cpp/source/binder_util.hh +0 -56
  12. {da4ml-0.3.2 → da4ml-0.3.3}/.clang-format +0 -0
  13. {da4ml-0.3.2 → da4ml-0.3.3}/.github/workflows/python-publish.yml +0 -0
  14. {da4ml-0.3.2 → da4ml-0.3.3}/.github/workflows/sphinx-build.yml +0 -0
  15. {da4ml-0.3.2 → da4ml-0.3.3}/.gitignore +0 -0
  16. {da4ml-0.3.2 → da4ml-0.3.3}/.pre-commit-config.yaml +0 -0
  17. {da4ml-0.3.2 → da4ml-0.3.3}/LICENSE +0 -0
  18. {da4ml-0.3.2 → da4ml-0.3.3}/README.md +0 -0
  19. {da4ml-0.3.2 → da4ml-0.3.3}/docs/Makefile +0 -0
  20. {da4ml-0.3.2 → da4ml-0.3.3}/docs/_static/example.svg +0 -0
  21. {da4ml-0.3.2 → da4ml-0.3.3}/docs/_static/icon.svg +0 -0
  22. {da4ml-0.3.2 → da4ml-0.3.3}/docs/_static/stage1.svg +0 -0
  23. {da4ml-0.3.2 → da4ml-0.3.3}/docs/_static/stage2.svg +0 -0
  24. {da4ml-0.3.2 → da4ml-0.3.3}/docs/_static/workflow.svg +0 -0
  25. {da4ml-0.3.2 → da4ml-0.3.3}/docs/cmvm.md +0 -0
  26. {da4ml-0.3.2 → da4ml-0.3.3}/docs/conf.py +0 -0
  27. {da4ml-0.3.2 → da4ml-0.3.3}/docs/dais.md +0 -0
  28. {da4ml-0.3.2 → da4ml-0.3.3}/docs/faq.md +0 -0
  29. {da4ml-0.3.2 → da4ml-0.3.3}/docs/getting_started.md +0 -0
  30. {da4ml-0.3.2 → da4ml-0.3.3}/docs/index.rst +0 -0
  31. {da4ml-0.3.2 → da4ml-0.3.3}/docs/install.md +0 -0
  32. {da4ml-0.3.2 → da4ml-0.3.3}/docs/status.md +0 -0
  33. {da4ml-0.3.2 → da4ml-0.3.3}/interperter/DAISInterpreter.cc +0 -0
  34. {da4ml-0.3.2 → da4ml-0.3.3}/interperter/DAISInterpreter.hh +0 -0
  35. {da4ml-0.3.2 → da4ml-0.3.3}/pyproject.toml +0 -0
  36. {da4ml-0.3.2 → da4ml-0.3.3}/setup.cfg +0 -0
  37. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/__init__.py +0 -0
  38. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/__init__.py +0 -0
  39. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/api.py +0 -0
  40. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/core/__init__.py +0 -0
  41. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/core/indexers.py +0 -0
  42. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/core/state_opr.py +0 -0
  43. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/types.py +0 -0
  44. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/util/__init__.py +0 -0
  45. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/util/bit_decompose.py +0 -0
  46. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/cmvm/util/mat_decompose.py +0 -0
  47. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/__init__.py +0 -0
  48. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/__init__.py +0 -0
  49. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/hls_model.py +0 -0
  50. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_binary.h +0 -0
  51. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_common.h +0 -0
  52. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_decl.h +0 -0
  53. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_fixed.h +0 -0
  54. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_fixed_base.h +0 -0
  55. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_fixed_ref.h +0 -0
  56. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_fixed_special.h +0 -0
  57. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_int.h +0 -0
  58. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_int_base.h +0 -0
  59. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_int_ref.h +0 -0
  60. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_int_special.h +0 -0
  61. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/ap_shift_reg.h +0 -0
  62. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/etc/ap_private.h +0 -0
  63. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/hls_math.h +0 -0
  64. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/hls_stream.h +0 -0
  65. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/ap_types/utils/x_hls_utils.h +0 -0
  66. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/cpp/source/build_binder.mk +0 -0
  67. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/__init__.py +0 -0
  68. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/comb.py +0 -0
  69. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/io_wrapper.py +0 -0
  70. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/pipeline.py +0 -0
  71. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/binder_util.hh +0 -0
  72. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/build_binder.mk +0 -0
  73. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/build_prj.tcl +0 -0
  74. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/ioutil.hh +0 -0
  75. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/multiplier.v +0 -0
  76. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/mux.v +0 -0
  77. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/negative.v +0 -0
  78. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/shift_adder.v +0 -0
  79. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/source/template.xdc +0 -0
  80. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/codegen/verilog/verilog_model.py +0 -0
  81. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/converter/__init__.py +0 -0
  82. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/converter/hgq2/__init__.py +0 -0
  83. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/converter/hgq2/replica.py +0 -0
  84. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/__init__.py +0 -0
  85. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/ops/__init__.py +0 -0
  86. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/ops/conv_utils.py +0 -0
  87. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/ops/einsum_utils.py +0 -0
  88. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/pipeline.py +0 -0
  89. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml/trace/tracer.py +0 -0
  90. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml.egg-info/SOURCES.txt +0 -0
  91. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml.egg-info/dependency_links.txt +0 -0
  92. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml.egg-info/requires.txt +0 -0
  93. {da4ml-0.3.2 → da4ml-0.3.3}/src/da4ml.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: da4ml
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Digital Arithmetic for Machine Learning
5
5
  Author-email: Chang Sun <chsun@cern.ch>
6
6
  License: GNU Lesser General Public License v3 (LGPLv3)
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.3.2'
32
- __version_tuple__ = version_tuple = (0, 3, 2)
31
+ __version__ = version = '0.3.3'
32
+ __version_tuple__ = version_tuple = (0, 3, 3)
33
33
 
34
- __commit_id__ = commit_id = 'g01e84ad19'
34
+ __commit_id__ = commit_id = 'g87b111b38'
@@ -46,7 +46,7 @@ def ssa_gen(sol: Solution, print_latency: bool, typestr_fn: Callable[[bool | int
46
46
  match op.opcode:
47
47
  case -1:
48
48
  # Input marker
49
- val = f'inp[{ops[op.id0].id0}]'
49
+ val = f'inp[{op.id0}]'
50
50
  case 0 | 1:
51
51
  # Common a+/-b<<shift op
52
52
  ref1 = f'bit_shift<{op.data}>(v{op.id1})' if op.data != 0 else f'v{op.id1}'
@@ -0,0 +1,50 @@
1
+ #pragma once
2
+ #include <cstddef>
3
+
4
+ #ifdef _OPENMP
5
+ #include <algorithm>
6
+ #include <omp.h>
7
+ constexpr bool _openmp = true;
8
+ #else
9
+ constexpr bool _openmp = false;
10
+ #endif
11
+
12
+ template <typename CONFIG_T, typename T> void _inference(T *c_inp, T *c_out, size_t n_samples) {
13
+ typename CONFIG_T::inp_t in_fixed_buf[CONFIG_T::N_inp];
14
+ typename CONFIG_T::out_t out_fixed_buf[CONFIG_T::N_out];
15
+
16
+ for (size_t i = 0; i < n_samples; ++i) {
17
+ size_t offset_in = i * CONFIG_T::N_inp;
18
+ size_t offset_out = i * CONFIG_T::N_out;
19
+ for (size_t j = 0; j < CONFIG_T::N_inp; ++j) {
20
+ in_fixed_buf[j] = c_inp[offset_in + j];
21
+ }
22
+
23
+ CONFIG_T::f(in_fixed_buf, out_fixed_buf);
24
+
25
+ for (size_t j = 0; j < CONFIG_T::N_out; ++j) {
26
+ c_out[offset_out + j] = out_fixed_buf[j];
27
+ }
28
+ }
29
+ }
30
+
31
+ template <typename CONFIG_T, typename T> void batch_inference(T *c_inp, T *c_out, size_t n_samples) {
32
+ #ifdef _OPENMP
33
+ size_t n_max_threads = omp_get_max_threads();
34
+ size_t n_samples_per_thread = std::max<size_t>(n_samples / n_max_threads, 32);
35
+ size_t n_thread = n_samples / n_samples_per_thread;
36
+ n_thread += (n_samples % n_samples_per_thread) ? 1 : 0;
37
+
38
+ #pragma omp parallel for num_threads(n_thread) schedule(static)
39
+ for (size_t i = 0; i < n_thread; ++i) {
40
+ size_t start = i * n_samples_per_thread;
41
+ size_t end = std::min<size_t>(start + n_samples_per_thread, n_samples);
42
+ size_t n_samples_this_thread = end - start;
43
+ size_t offset_in = start * CONFIG_T::N_inp;
44
+ size_t offset_out = start * CONFIG_T::N_out;
45
+ _inference<CONFIG_T, T>(&c_inp[offset_in], &c_out[offset_out], n_samples_this_thread);
46
+ }
47
+ #else
48
+ _inference<CONFIG_T, T>(c_inp, c_out, n_samples);
49
+ #endif
50
+ }
@@ -1,14 +1,16 @@
1
1
  #pragma once
2
- #include "ap_types/ap_fixed.h"
2
+ #include "ap_fixed.h"
3
3
 
4
- template <int s, int b, int i, ap_q_mode Q, ap_o_mode O, int N> ap_fixed<b, i + s> bit_shift(ap_fixed<b, i, Q, O, N> x) {
4
+ template <int s, int b, int i, ap_q_mode Q, ap_o_mode O, int N>
5
+ ap_fixed<b, i + s> bit_shift(ap_fixed<b, i, Q, O, N> x) {
5
6
  #pragma HLS INLINE
6
7
  ap_fixed<b, i + s> r;
7
8
  r.range() = x.range();
8
9
  return r;
9
10
  };
10
11
 
11
- template <int s, int b, int i, ap_q_mode Q, ap_o_mode O, int N> ap_ufixed<b, i + s> bit_shift(ap_ufixed<b, i, Q, O, N> x) {
12
+ template <int s, int b, int i, ap_q_mode Q, ap_o_mode O, int N>
13
+ ap_ufixed<b, i + s> bit_shift(ap_ufixed<b, i, Q, O, N> x) {
12
14
  #pragma HLS INLINE
13
15
  ap_ufixed<b, i + s> r;
14
16
  r.range() = x.range();
@@ -6,8 +6,8 @@ import keras
6
6
  import numpy as np
7
7
  from keras import KerasTensor, Operation
8
8
 
9
- from ...trace import FixedVariableArray, HWConfig, comb_trace
10
- from ...trace.fixed_variable_array import FixedVariableArrayInput
9
+ from ...trace import FixedVariableArray, FixedVariableArrayInput, HWConfig, comb_trace
10
+ from ...trace.fixed_variable import FixedVariable
11
11
  from .replica import _registry
12
12
 
13
13
 
@@ -55,6 +55,8 @@ def replace_tensors(tensor_map: dict[KerasTensor, FixedVariableArray], obj: Any)
55
55
  def _flatten_arr(args: Any) -> FixedVariableArray:
56
56
  if isinstance(args, FixedVariableArray):
57
57
  return np.ravel(args) # type: ignore
58
+ if isinstance(args, FixedVariable):
59
+ return FixedVariableArray(np.array([args]))
58
60
  if not isinstance(args, Sequence):
59
61
  return None # type: ignore
60
62
  args = [_flatten_arr(a) for a in args]
@@ -265,6 +265,10 @@ class FixedVariable:
265
265
  def __sub__(self, other: 'FixedVariable|int|float|Decimal'):
266
266
  return self + (-other)
267
267
 
268
+ def __truediv__(self, other: 'int|float|Decimal'):
269
+ assert not isinstance(other, FixedVariable), 'Division by variable is not supported'
270
+ return self * (1 / other)
271
+
268
272
  def __mul__(self, other: 'FixedVariable|int|float|Decimal') -> 'FixedVariable':
269
273
  if other == 0:
270
274
  return FixedVariable(0, 0, 1, hwconf=self.hwconf, opr='const')
@@ -164,6 +164,10 @@ class FixedVariableArray:
164
164
  latency: NDArray[np.floating] | float = 0.0,
165
165
  solver_options: dict[str, Any] | None = None,
166
166
  ):
167
+ mask = k + i + f <= 0
168
+ k = np.where(mask, 0, k)
169
+ i = np.where(mask, 0, i)
170
+ f = np.where(mask, 0, f)
167
171
  step = 2.0**-f
168
172
  _high = 2.0**i
169
173
  high, low = _high - step, -_high * k
@@ -99,7 +99,7 @@ def reduce(operator: Callable[[T, T], T], x: TA, axis: int | Sequence[int] | Non
99
99
  r = _arr.reshape(target_shape) # type: ignore
100
100
 
101
101
  if isinstance(x, FixedVariableArray):
102
- ret = FixedVariableArray(r, solver_config)
103
- if ret.size == 1 and not keepdims:
104
- return ret.ravel()[0] # type: ignore
102
+ r = FixedVariableArray(r, solver_config)
103
+ if r.size == 1 and not keepdims:
104
+ return r.ravel()[0] # type: ignore
105
105
  return r if r.size > 1 or keepdims else r.ravel()[0] # type: ignore
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: da4ml
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Digital Arithmetic for Machine Learning
5
5
  Author-email: Chang Sun <chsun@cern.ch>
6
6
  License: GNU Lesser General Public License v3 (LGPLv3)
@@ -1,56 +0,0 @@
1
- #pragma once
2
- #include <cstddef>
3
-
4
- #ifdef _OPENMP
5
- #include <algorithm>
6
- #include <omp.h>
7
- constexpr bool _openmp = true;
8
- #else
9
- constexpr bool _openmp = false;
10
- #endif
11
-
12
- template <typename CONFIG_T, typename T> void _inference(T *c_inp, T *c_out, size_t n_samples)
13
- {
14
- typename CONFIG_T::inp_t in_fixed_buf[CONFIG_T::N_inp];
15
- typename CONFIG_T::out_t out_fixed_buf[CONFIG_T::N_out];
16
-
17
- for(size_t i = 0; i < n_samples; ++i)
18
- {
19
- size_t offset_in = i * CONFIG_T::N_inp;
20
- size_t offset_out = i * CONFIG_T::N_out;
21
- for(size_t j = 0; j < CONFIG_T::N_inp; ++j)
22
- {
23
- in_fixed_buf[j] = c_inp[offset_in + j];
24
- }
25
-
26
- CONFIG_T::f(in_fixed_buf, out_fixed_buf);
27
-
28
- for(size_t j = 0; j < CONFIG_T::N_out; ++j)
29
- {
30
- c_out[offset_out + j] = out_fixed_buf[j];
31
- }
32
- }
33
- }
34
-
35
- template <typename CONFIG_T, typename T> void batch_inference(T *c_inp, T *c_out, size_t n_samples)
36
- {
37
- #ifdef _OPENMP
38
- size_t n_max_threads = omp_get_max_threads();
39
- size_t n_samples_per_thread = std::max<size_t>(n_samples / n_max_threads, 32);
40
- size_t n_thread = n_samples / n_samples_per_thread;
41
- n_thread += (n_samples % n_samples_per_thread) ? 1 : 0;
42
-
43
- #pragma omp parallel for num_threads(n_thread) schedule(static)
44
- for(size_t i = 0; i < n_thread; ++i)
45
- {
46
- size_t start = i * n_samples_per_thread;
47
- size_t end = std::min<size_t>(start + n_samples_per_thread, n_samples);
48
- size_t n_samples_this_thread = end - start;
49
- size_t offset_in = start * CONFIG_T::N_inp;
50
- size_t offset_out = start * CONFIG_T::N_out;
51
- _inference<CONFIG_T, T>(&c_inp[offset_in], &c_out[offset_out], n_samples_this_thread);
52
- }
53
- #else
54
- _inference<CONFIG_T, T>(c_inp, c_out, n_samples);
55
- #endif
56
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes