Skip to content

Commit

Permalink
Initial restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
vloncar committed Aug 26, 2019
1 parent 5813394 commit 0cf1344
Show file tree
Hide file tree
Showing 90 changed files with 153 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*.pyc
__pycache__
build/
dist/
sdist/
*.egg-info/
vivado_prj
.vscode
my-hls-test
Expand Down
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include LICENSE
include README.md
graft example-prjs
graft example-models
graft test
recursive-include hls4ml/hls-templates *
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions hls4ml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import

from . import converters
5 changes: 5 additions & 0 deletions hls4ml/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import absolute_import

from .keras_to_hls import keras_to_hls
#from .pytorch_to_hls import pytorch_to_hls
from .onnx_to_hls import onnx_to_hls
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions hls4ml/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import

from .hls_model import HLSModel, HLSConfig
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added hls4ml/writer/__init__.py
Empty file.
File renamed without changes.
45 changes: 0 additions & 45 deletions onnx-to-hls/converters/keras-to-onnx.py

This file was deleted.

88 changes: 88 additions & 0 deletions scripts/hls4ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env python
from __future__ import absolute_import

__version__ = '0.2.0'

import argparse
import os
import sys
import yaml
import hls4ml

def parse_config(config_file):
print("Loading configuration from", config_file)
config = open(config_file, 'r')
return yaml.load(config, Loader=yaml.SafeLoader)

def main():
parser = argparse.ArgumentParser(description='HLS4ML - Machine learning inference in FPGAs')
subparsers = parser.add_subparsers()

config_parser = subparsers.add_parser("config", help='Create a conversion configuration file')
convert_parser = subparsers.add_parser("convert", help='Convert Keras or ONNX model to HLS')
build_parser = subparsers.add_parser("build")

config_parser.add_argument('-m', '--model', help='Model file to convert (Keras .h5 or .json, or ONNX .onnx file)', default=None)
config_parser.add_argument('-w', '--weights', help='Optional weights file (if Keras .json file is provided))', default=None)
config_parser.add_argument('-o', '--output', help='Output file name', default=None)
config_parser.set_defaults(func=config)

convert_parser.add_argument('-c', '--config', help='Configuration file', default=None)
convert_parser.set_defaults(func=convert)

build_parser.add_argument('-p', '--project', help='Project directory', default=None)
build_parser.add_argument('-c', '--simulation', help='Run C simulation', action='store_true', default=False)
build_parser.add_argument('-s', '--synthesis', help='Run C/RTL synthesis', action='store_true', default=False)
build_parser.add_argument('-r', '--co-simulation', help='Run C/RTL co-simulation (implies -c and -s)', action='store_true', default=False)
build_parser.add_argument('-e', '--export', help='Export IP (implies -s)', action='store_true', default=False)
build_parser.add_argument('-a', '--all', help='Run C simulation, C/RTL synthesis and co-simulation', action='store_true')
build_parser.set_defaults(func=build)

parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(version=__version__))

args = parser.parse_args()
if hasattr(args, 'func'):
args.func(args)
else:
parser.print_usage()

def config(args):
raise NotImplementedError

def convert(args):
yamlConfig = parse_config(args.config)
if 'OnnxModel' in yamlConfig:
hls4ml.converters.onnx_to_hls(yamlConfig)
elif 'PytorchModel' in yamlConfig:
hls4ml.converters.pytorch_to_hls(yamlConfig)
else:
hls4ml.converters.keras_to_hls(yamlConfig)

def build(args):
if args.project is None:
print('Project directory (-p or --project) must be provided.')
sys.exit(1)

csim = synth = cosim = export = 0
if args.simulation:
csim = 1
if args.synthesis:
synth = 1
if args.co_simulation:
synth = cosim = 1
if args.export:
synth = export = 1
if args.all:
csim = synth = cosim = export = 1

# Check if vivado_hls is available
if 'linux' in sys.platform or 'darwin' in sys.platform:
found = os.system('command -v vivado_hls > /dev/null')
if found is not 0:
print('Vivado HLS installation not found. Make sure "vivado_hls" is on PATH.')
sys.exit(1)

os.system('cd {dir} && vivado_hls -f build_prj.tcl "csim={csim} synth={synth} cosim={cosim} export={export}"'.format(dir=args.project, csim=csim, synth=synth, cosim=cosim, export=export))

if __name__== "__main__":
main()
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
42 changes: 42 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from setuptools import setup
from setuptools import find_packages

long_description = '''
A package for machine learning inference in FPGAs. We create firmware
implementations of machine learning algorithms using high level synthesis
language (HLS). We translate traditional open-source machine learning package
models into HLS that can be configured for your use-case!
For more information visit the webpage:
https://hls-fpga-machine-learning.github.io/hls4ml/
'''

setup(name='hls4ml',
version='0.2.0',
description='Machine learning in FPGAs using HLS',
long_description=long_description,
author='HLS4ML Team',
author_email='[email protected]',
url='https://github.com/hls-fpga-machine-learning/hls4ml',
license='Apache 2.0',
install_requires=['numpy',
'six',
'pyyaml',
'h5py',
'onnx>=1.4.0'],
scripts=['scripts/hls4ml'],
include_package_data=True,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: C++',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
],
packages=find_packages())

0 comments on commit 0cf1344

Please sign in to comment.