Skip to content

Commit 449f46b

Browse files
vloncarjmduarte
andauthored
Fix version extraction in Sphinx config (#669)
* Fix version extraction in Sphinx config * format * Use get_version from setuptools_scm * minor fixes; try with reqs * add test sphinx * try installing git * update reqs * try installing git again * apt-get * try different action * updated image * custom docker image * update tests * Ensure the project name is propagated in Quartus writer Co-authored-by: Javier Duarte <[email protected]>
1 parent 32ee8dc commit 449f46b

File tree

8 files changed

+71
-44
lines changed

8 files changed

+71
-44
lines changed

.github/workflows/build-sphinx.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v1
14-
- uses: ammaraskar/sphinx-action@master
14+
- uses: jmduarte/sphinx-action@main
1515
with:
1616
docs-folder: "docs/"
17-
pre-build-command: "pip install sphinx-rtd-theme numpy six pyyaml h5py 'onnx>=1.4.0' pandas seaborn matplotlib"
1817
- name: Commit Documentation Changes
1918
run: |
2019
git clone https://github.com/fastmachinelearning/hls4ml.git --branch gh-pages --single-branch gh-pages

.github/workflows/test-sphinx.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: test-sphinx
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v1
14+
- uses: jmduarte/sphinx-action@main
15+
with:
16+
docs-folder: "docs/"

docs/conf.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
sys.path.insert(0, os.path.abspath('../'))
1616

1717
import datetime
18-
def get_version(rel_path):
19-
for line in open(rel_path):
20-
if line.startswith('__version__'):
21-
delim = '"' if '"' in line else "'"
22-
return line.split(delim)[1]
23-
else:
24-
raise RuntimeError("Unable to find version string.")
18+
from setuptools_scm import get_version
2519

2620
# -- Project information -----------------------------------------------------
2721

@@ -30,7 +24,7 @@ def get_version(rel_path):
3024
author = 'Fast Machine Learning Lab'
3125

3226
# The full version, including alpha/beta/rc tags
33-
release = get_version("../hls4ml/__init__.py")
27+
release = get_version(root='..', relative_to=__file__)
3428

3529
# -- General configuration ---------------------------------------------------
3630

docs/release_notes.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ See `here <https://github.com/fastmachinelearning/hls4ml/releases>`__ for offici
88

99
**v0.6.0 / coris**
1010

11-
## What's Changed
12-
* `VivadoAccelerator` backend: target `pynq-z2` and `zcu102` boards directly from hls4ml by @nicologhielmetti
13-
* Updated `PyTorch` and `ONNX` converters by @Duchstf
14-
* `line_buffer` Conv2D implementation for `io_stream`: reduced resource usage and latency by @Keb-L, @violatingcp, @vloncar
15-
* Support `QConv2DBatchnorm` layer from `QKeras` by @nicologhielmetti
16-
* Improved profiling plots - easier to compare original vs `hls4ml` converted models by @maksgraczyk
17-
* Better derivation of data types for `QKeras` models by @jmduarte, @thesps
11+
What's changed:
12+
13+
* ``VivadoAccelerator`` backend: target ``pynq-z2`` and ``zcu102`` boards directly from hls4ml by @nicologhielmetti
14+
* Updated ``PyTorch`` and ``ONNX`` converters by @Duchstf
15+
* ``line_buffer`` Conv2D implementation for ``io_stream``: reduced resource usage and latency by @Keb-L, @violatingcp, @vloncar
16+
* Support ``QConv2DBatchnorm`` layer from ``QKeras`` by @nicologhielmetti
17+
* Improved profiling plots - easier to compare original vs ``hls4ml`` converted models by @maksgraczyk
18+
* Better derivation of data types for ``QKeras`` models by @jmduarte, @thesps
1819
* Improved CI by @thesps
19-
* More support for models with branches, skip connections, `Merge` and `Concatenate` layers by @jmduarte, @vloncar
20-
* Support for `Dense` layers over multi-dimensional tensors by @vloncar
20+
* More support for models with branches, skip connections, ``Merge`` and ``Concatenate`` layers by @jmduarte, @vloncar
21+
* Support for ``Dense`` layers over multi-dimensional tensors by @vloncar
2122
* Overall improvements by @vloncar, @jmduarte, @thesps, @jmitrevs & others
2223

23-
## New Contributors
24+
New contributors:
25+
2426
* @siorpaes made their first contribution in https://github.com/fastmachinelearning/hls4ml/pull/424
2527
* @jmitrevs made their first contribution in https://github.com/fastmachinelearning/hls4ml/pull/403
2628
* @anders-wind made their first contribution in https://github.com/fastmachinelearning/hls4ml/pull/302

docs/requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sphinx>=3.2.1
2+
sphinx_rtd_theme
3+
toposort>=1.5.0
4+
numpy
5+
six
6+
pyyaml
7+
h5py
8+
onnx>=1.4.0
9+
pandas
10+
seaborn
11+
matplotlib
12+
setuptools_scm[toml]>=5

hls4ml/writer/quartus_writer.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ def write_project_cpp(self, model):
114114
## myproject.cpp
115115
###################
116116

117+
project_name = model.config.get_project_name()
118+
117119
filedir = os.path.dirname(os.path.abspath(__file__))
118120
f = open(os.path.join(filedir, '../templates/quartus/firmware/myproject.cpp'), 'r')
119-
fout = open('{}/firmware/{}.cpp'.format(model.config.get_output_dir(), model.config.get_project_name()), 'w')
121+
fout = open('{}/firmware/{}.cpp'.format(model.config.get_output_dir(), project_name), 'w')
120122

121123
model_inputs = model.get_input_variables()
122124
model_outputs = model.get_output_variables()
@@ -127,7 +129,7 @@ def write_project_cpp(self, model):
127129
for line in f.readlines():
128130
# Add headers to weights and biases
129131
if 'myproject' in line:
130-
newline = line.replace('myproject', model.config.get_project_name())
132+
newline = line.replace('myproject', project_name)
131133

132134
# Intel HLS 'streams' need to be passed by reference to top-level entity or declared as global variables
133135
# Streams cannot be declared inside a function
@@ -146,29 +148,29 @@ def write_project_cpp(self, model):
146148
elif '//hls-fpga-machine-learning instantiate GCC top-level' in line:
147149
newline = line
148150
if io_type == 'io_stream':
149-
newline += 'void myproject(\n'
151+
newline += f'void {project_name}(\n'
150152
for inp in model_inputs:
151153
newline += indent+'stream_in<{}> &{}_stream,\n'.format(inp.type.name, inp.name)
152154
for out in model_outputs:
153155
newline += indent+'stream_out<{}> &{}_stream\n'.format(out.type.name, out.name)
154156
newline += ') {\n'
155157
if io_type == 'io_parallel':
156-
newline = 'output_data myproject(\n'
158+
newline = f'output_data {project_name}(\n'
157159
newline+=indent+'input_data inputs\n'
158160
newline+=') {\n'
159161

160162
# Instantiate HLS top-level function, to be used during HLS synthesis
161163
elif '//hls-fpga-machine-learning instantiate HLS top-level' in line:
162164
newline = line
163165
if io_type == 'io_stream':
164-
newline += 'component void myproject(\n'
166+
newline += f'component void {project_name}(\n'
165167
for inp in model_inputs:
166168
newline += indent+'stream_in<{}> &{}_stream,\n'.format(inp.type.name, inp.name)
167169
for out in model_outputs:
168170
newline += indent+'stream_out<{}> &{}_stream\n'.format(out.type.name, out.name)
169171
newline += ') {\n'
170172
if io_type == 'io_parallel':
171-
newline += 'component output_data myproject(\n'
173+
newline += f'component output_data {project_name}(\n'
172174
newline += indent+'input_data inputs\n'
173175
newline += ') {\n'
174176

@@ -263,9 +265,11 @@ def write_project_header(self, model):
263265
## myproject.h
264266
#######################
265267

268+
project_name = model.config.get_project_name()
269+
266270
filedir = os.path.dirname(os.path.abspath(__file__))
267271
f = open(os.path.join(filedir, '../templates/quartus/firmware/myproject.h'), 'r')
268-
fout = open('{}/firmware/{}.h'.format(model.config.get_output_dir(), model.config.get_project_name()), 'w')
272+
fout = open('{}/firmware/{}.h'.format(model.config.get_output_dir(), project_name), 'w')
269273

270274
model_inputs = model.get_input_variables()
271275
model_outputs = model.get_output_variables()
@@ -276,39 +280,40 @@ def write_project_header(self, model):
276280

277281
for line in f.readlines():
278282
if 'MYPROJECT' in line:
279-
newline = line.replace('MYPROJECT', format(model.config.get_project_name().upper()))
283+
newline = line.replace('MYPROJECT', format(project_name.upper()))
280284

281285
elif 'myproject' in line:
282-
newline = line.replace('myproject', model.config.get_project_name())
286+
newline = line.replace('myproject', project_name)
283287

284288
elif '//hls-fpga-machine-learning instantiate GCC top-level' in line:
285289
newline = line
286290
# For io_stream, input and output are passed by reference; see myproject.h & myproject.cpp for more details
291+
287292
if io_type == 'io_stream':
288-
newline += 'void myproject(\n'
293+
newline += f'void {project_name}(\n'
289294
for inp in model_inputs:
290295
newline += indent+'stream_in<{}> &{}_stream,\n'.format(inp.type.name, inp.name)
291296
for out in model_outputs:
292297
newline += indent+'stream_out<{}> &{}_stream\n'.format(out.type.name, out.name)
293298
newline += ');\n'
294299
# In io_parallel, a struct is returned; see myproject.h & myproject.cpp for more details
295300
else:
296-
newline += 'output_data myproject(\n'
301+
newline += f'output_data {project_name}(\n'
297302
newline += indent+'input_data inputs\n'
298303
newline += ');\n'
299304

300305
# Similar to GCC instantiation, but with the keyword 'component'
301306
elif '//hls-fpga-machine-learning instantiate HLS top-level' in line:
302307
newline = line
303308
if io_type == 'io_stream':
304-
newline += 'component void myproject(\n'
309+
newline += f'component void {project_name}(\n'
305310
for inp in model_inputs:
306311
newline += indent+'stream_in<{}> &{}_stream,\n'.format(inp.type.name, inp.name)
307312
for out in model_outputs:
308313
newline += indent+'stream_out<{}> &{}_stream\n'.format(out.type.name, out.name)
309314
newline += ');\n'
310315
else:
311-
newline += 'component output_data myproject(\n'
316+
newline += f'component output_data {project_name}(\n'
312317
newline += indent+'input_data inputs\n'
313318
newline += ');\n'
314319

test/pytest/test_keras_h5_loader.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
test_root_path = Path(__file__).parent
99

10-
test_root_path = Path('/tmp')
11-
1210

1311
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
1412
def test_keras_h5_loader(backend):
@@ -20,14 +18,15 @@ def test_keras_h5_loader(backend):
2018

2119
hls_config = hls4ml.utils.config_from_keras_model(model, granularity='name')
2220

23-
config = {'OutputDir': 'KerasH5_loader_test',
24-
'ProjectName': 'KerasH5_loader_test',
25-
'Backend': backend,
26-
'ClockPeriod': 25.0,
27-
'IOType': 'io_parallel',
28-
'HLSConfig': hls_config,
29-
'KerasH5': str(test_root_path / 'KerasH5_loader_test.h5'),
30-
'output_dir': str(test_root_path / 'KerasH5_loader_test')}
21+
config = {
22+
'OutputDir': str(test_root_path / f'hls4mlprj_KerasH5_loader_test_{backend}'),
23+
'ProjectName': f'KerasH5_loader_test_{backend}',
24+
'Backend': backend,
25+
'ClockPeriod': 25.0,
26+
'IOType': 'io_parallel',
27+
'HLSConfig': hls_config,
28+
'KerasH5': str(test_root_path / f'hls4mlprj_KerasH5_loader_test_{backend}/model.h5'),
29+
}
3130

3231
model.save(config['KerasH5'])
3332
hls_model = hls4ml.converters.keras_to_hls(config)

test/pytest/test_softsign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def test_softsign(backend, input_shape, io_type):
3030
acc_hls4ml = accuracy_score(np.argmax(y_keras, axis=-1).ravel(), np.argmax(y_hls4ml, axis=-1).ravel())
3131

3232
print('Accuracy hls4ml relative to keras: {}'.format(acc_hls4ml))
33-
assert acc_hls4ml >= 0.97
33+
assert acc_hls4ml >= 0.96

0 commit comments

Comments
 (0)