-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
2,084 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
include LICENSE README.md | ||
recursive-include utensor_cgen/backend/snippets/templates * | ||
recursive-include utensor_cgen/backend/utensor/snippets/templates * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# https://github.com/toml-lang/toml | ||
# <target_name>.<component>.<part> | ||
[utensor.backend] | ||
legacy-api = true | ||
|
||
[utensor.backend.legacy_code_generator] | ||
src_fname = "None" | ||
params_dir = "data" | ||
embed_params_dir = "/fs/data" | ||
model_dir = "models" | ||
transform_methods = [ "dropout(name_pattern=r\"(dropout[_\\w\\d]*)/.*\")", "linear_reorder", "quantize", "conv_pool", "inline", "biasAdd", "remove_id_op", "fake_gather_v2", "refcnt",] | ||
save_graph = false | ||
debug_cmt = false | ||
|
||
[utensor.backend.graph_lower] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from textwrap import wrap | ||
|
||
from utensor_cgen.backend.base import Backend | ||
from utensor_cgen.backend import BackendManager | ||
from utensor_cgen.utils import class_property | ||
|
||
@BackendManager.register | ||
class DummyBackend(Backend): | ||
TARGET = 'dummy-backend' | ||
|
||
def __init__(self, config): | ||
if not config: | ||
config = self.default_config | ||
self.output_file = config[self.TARGET][self.COMPONENT]['output-file'] | ||
|
||
def apply(self, ugraph): | ||
with open(self.output_file, 'w') as fid: | ||
fid.write('#include <stdio.h>\n\n') | ||
fid.write('int main(int argc, char* argv[]) {\n') | ||
fid.write(' printf("graph name: {}\\n");\n'.format(ugraph.name)) | ||
fid.write(' printf("ops in topological sorted order:\\n");\n') | ||
for op_name in ugraph.topo_order: | ||
fid.write(' printf(" {}\\n");\n'.format(op_name)) | ||
fid.write(' return 0;\n}') | ||
|
||
@class_property | ||
def default_config(cls): | ||
return { | ||
cls.TARGET: { | ||
cls.COMPONENT: { | ||
'output-file': 'list_op.c' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,27 +3,48 @@ | |
import os | ||
|
||
from setuptools import find_packages, setup | ||
from setuptools.command.develop import develop as _develop | ||
from setuptools.command.install import install as _install | ||
|
||
root_dir = os.path.abspath(os.path.dirname(__file__)) | ||
with open(os.path.join(root_dir, "LICENSE")) as rf: | ||
license = rf.read() | ||
|
||
|
||
class _CompileFlatbuffMixin(object): | ||
|
||
def run(self): | ||
super(_CompileFlatbuffMixin, self).run() | ||
self._build_flatbuffer() | ||
|
||
def _build_flatbuffer(self): | ||
install_dir = self.install_platlib | ||
if install_dir is None: | ||
install_dir = os.path.abspath('utensor') | ||
|
||
|
||
class _Install(_CompileFlatbuffMixin, _install): pass | ||
|
||
|
||
class _Develop(_CompileFlatbuffMixin, _develop): pass | ||
|
||
|
||
setup( | ||
name='utensor_cgen', | ||
version_config={ | ||
"starting_version": "0.0.0", | ||
"version_format": "{tag}.dev{sha:.7s}" | ||
"version_format": "{tag}.{sha:.7s}.dev" | ||
}, | ||
setup_requires=['better-setuptools-git-version'], | ||
cmdclass={'install': _Install, 'develop': _Develop}, | ||
description="C code generation program for uTensor", | ||
long_description="please go to [doc](https://utensor-cgen.readthedocs.io/en/latest/) page for more information", | ||
url="https://github.com/dboyliao/utensor_cgen", | ||
url="https://github.com/uTensor/utensor_cgen", | ||
author="Dboy Liao", | ||
author_email="[email protected]", | ||
license=license, | ||
packages=find_packages(), | ||
include_package_data=True, | ||
package_data={"utensor_cgen": ["backend/snippets/templates/*"]}, | ||
package_data={'utensor_cgen.backend.utensor.snippets': ["templates/*/*/*"]}, | ||
entry_points={ | ||
"console_scripts": [ | ||
"utensor-cli=utensor_cgen.cli:cli" | ||
|
@@ -38,7 +59,8 @@ | |
'torchvision', | ||
'onnx-tf==1.2.1', | ||
'graphviz', | ||
'flatbuffers' | ||
'flatbuffers', | ||
'toml', | ||
], | ||
extras_require={ | ||
'dev': ['pytest'] | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
from pytest import fixture | ||
|
||
@fixture(scope='session', name='mlp_ugraph') | ||
def mlp_ugraph(): | ||
from utensor_cgen.frontend import FrontendSelector | ||
model_file = os.path.join( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.dirname(__file__), '..') | ||
), | ||
'deep_mlp/simple_mnist.pb' | ||
) | ||
return FrontendSelector.parse(model_file, output_nodes=['y_pred']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
def test_legacy_utensor(mlp_ugraph): | ||
from utensor_cgen.backend.utensor import uTensorBackend | ||
|
||
this_dir = os.path.dirname(__file__) | ||
|
||
uTensorBackend(config={ | ||
'utensor': { | ||
'backend': { | ||
'legacy-api': True, | ||
'code_generator': { | ||
'model_dir': os.path.join(this_dir, 'models'), | ||
'params_dir': os.path.join(this_dir, 'data'), | ||
}, | ||
'graph_lower': {} | ||
}, | ||
} | ||
}).apply(mlp_ugraph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sys | ||
|
||
import pkg_resources | ||
|
||
from utensor_cgen._extensions import _ExtensionsLoader | ||
|
||
__version__ = ( | ||
pkg_resources | ||
.get_distribution('utensor_cgen') | ||
.version | ||
) | ||
sys.modules['utensor_cgen.extensions'] = _ExtensionsLoader() |
Oops, something went wrong.