Skip to content

Fix fused quantize op functionality/template #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ tests/*/cpp
*/*/models
tests/deep_mlp/data
.vscode
*.pyc
.*.pyc
*.swp
.*.swp
10 changes: 5 additions & 5 deletions utensor_cgen/backend/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,19 @@ class _QuantizedFusedConv2DMaxpoolOperator(_Operator):
def __init__(self, op_info, **kwargs):
_Operator.__init__(self)
inputs = [tensor_info.name for tensor_info in op_info.input_tensors]
output = op_info.output_tensors[0].name
outputs = [tensor_info.name for tensor_info in op_info.output_tensors]
in_dtype, filter_dtype = (op_info.input_tensors[0].dtype,
op_info.input_tensors[1].dtype)
out_dtype = op_info.output_tensors[0].dtype
out_dtypes = [tensor_info.dtype for tensor_info in op_info.output_tensors]
strides = op_info.op_attr['_utensor_conv']["strides"].value.ints_value
ksize = op_info.op_attr['_utensor_pool']["ksize"].value.ints_value
padding = op_info.op_attr['_utensor_conv']["padding"].value.decode('utf8')
parser = NamescopedKWArgsParser(RefCntOptimizer.KWARGS_NAMESCOPE,
op_info.op_attr)
ref_count = parser.get('ref_counts', [0])[0]
to_eval = parser.get('to_eval', False)
self._snippet = QuantizedFusedConv2DMaxpoolOpSnippet(inputs, output, strides, ksize, padding,
in_dtype=in_dtype, filter_dtype=filter_dtype, out_dtype=out_dtype,
self._snippet = QuantizedFusedConv2DMaxpoolOpSnippet(inputs, outputs, strides, ksize, padding,
in_dtype=in_dtype, filter_dtype=filter_dtype, out_dtypes=out_dtypes,
ref_count=ref_count, to_eval=to_eval)

@OperatorFactory.register
Expand Down Expand Up @@ -726,7 +726,7 @@ def __init__(self, op_info, **kwargs):
@OperatorFactory.register
class _GatherOperator(_Operator):

op_type = "Gather" # tf op type
op_type = "GatherV2" # tf op type

def __init__(self, op_info, **kwargs):
_Operator.__init__(self)
Expand Down
12 changes: 7 additions & 5 deletions utensor_cgen/backend/snippets/_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,21 +666,23 @@ def __init__(self, inputs, output, strides, ksize, padding,
self.template_vars["to_eval"] = to_eval

class QuantizedFusedConv2DMaxpoolOpSnippet(Snippet):
__template_name__ = "snippets/fused_conv2d_maxpool_op.cpp"
__template_name__ = "snippets/quantized_fused_conv2d_maxpool_op.cpp"
__headers__ = set(['"uTensor/ops/MatrixOps.hpp"'])

def __init__(self, inputs, output, strides, ksize, padding,
in_dtype, filter_dtype, out_dtype,
def __init__(self, inputs, outputs, strides, ksize, padding,
in_dtype, filter_dtype, out_dtypes,
ref_count=0,
to_eval=False):
Snippet.__init__(self)
if ref_count:
self.template_vars["ref_count"] = ref_count
print(outputs)
print(out_dtypes)
self.template_vars["inputs"] = inputs
self.template_vars["output"] = output
self.template_vars["outputs"] = outputs
self.template_vars["in_dtype"] = NP_TYPES_MAP[in_dtype].tensor_type_str
self.template_vars["filter_dtype"] = NP_TYPES_MAP[filter_dtype].tensor_type_str
self.template_vars["out_dtype"] = NP_TYPES_MAP[out_dtype].tensor_type_str
self.template_vars["out_dtypes"] = [NP_TYPES_MAP[out_dtype].tensor_type_str for out_dtype in out_dtypes]
self.template_vars["strides"] = strides
self.template_vars["ksize"] = ksize
self.template_vars["padding"] = padding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ctx.add(new RamTensor<{{out_dtypes[1]}}>({1}), "{{outputs[1]}}");
ctx.add(new RamTensor<{{out_dtypes[2]}}>({1}), "{{outputs[2]}}");
{% endif %}
ctx.push(new QuantizedFusedConvMaxpoolOp<{{in_dtype}}, {{filter_dtype}}, {{out_dtype}}>({ {% for s in strides[:-1]%}{{s}}, {%endfor%}{{strides[-1]}} }, { {% for s in ksize[:-1]%}{{s}}, {%endfor%}{{ksize[-1]}} },{{padding}}),
ctx.push(new QuantizedFusedConvMaxpoolOp<{{in_dtype}}, {{filter_dtype}}, {{out_dtypes[0]}}>({ {% for s in strides[:-1]%}{{s}}, {%endfor%}{{strides[-1]}} }, { {% for s in ksize[:-1]%}{{s}}, {%endfor%}{{ksize[-1]}} },{{padding}}),
{ {% for tname in inputs[:-1]%}"{{tname}}", {%endfor%}"{{inputs[-1]}}" },
{ {% for tname in outputs[:-1]%}"{{tname}}", {%endfor%}"{{outputs[-1]}}" });
{% if to_eval %}
Expand Down