diff --git a/.gitignore b/.gitignore index 6d40de30..bb03a7b6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ tests/*/cpp */*/models tests/deep_mlp/data .vscode +*.pyc +.*.pyc +*.swp +.*.swp diff --git a/utensor_cgen/backend/operators.py b/utensor_cgen/backend/operators.py index a5d0209d..83062db9 100644 --- a/utensor_cgen/backend/operators.py +++ b/utensor_cgen/backend/operators.py @@ -477,10 +477,10 @@ 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') @@ -488,8 +488,8 @@ def __init__(self, op_info, **kwargs): 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 @@ -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) diff --git a/utensor_cgen/backend/snippets/_snippets.py b/utensor_cgen/backend/snippets/_snippets.py index 2314a7a6..f4e65169 100644 --- a/utensor_cgen/backend/snippets/_snippets.py +++ b/utensor_cgen/backend/snippets/_snippets.py @@ -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 diff --git a/utensor_cgen/backend/snippets/templates/snippets/quantized_fused_conv2d_maxpool_op.cpp b/utensor_cgen/backend/snippets/templates/snippets/quantized_fused_conv2d_maxpool_op.cpp index 7aa4f07a..1161e3df 100644 --- a/utensor_cgen/backend/snippets/templates/snippets/quantized_fused_conv2d_maxpool_op.cpp +++ b/utensor_cgen/backend/snippets/templates/snippets/quantized_fused_conv2d_maxpool_op.cpp @@ -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 %}