aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/errors.py
diff options
context:
space:
mode:
authorTim Hall <tim.hall@arm.com>2020-06-17 14:53:11 +0100
committerTim Hall <tim.hall@arm.com>2020-06-18 17:53:52 +0100
commitc8310b1432f7a77df3c95e8ecf8248c8a953b411 (patch)
treeeaddfe6ae80db3c85ddca824e0fc70739d05a9d5 /ethosu/vela/errors.py
parent10a6618784aae35de389e0291fd2d78cbfa03bb7 (diff)
downloadethos-u-vela-c8310b1432f7a77df3c95e8ecf8248c8a953b411.tar.gz
MLBEDSW-2528: MLCE-219: Custom operator pass through
- Fixed custom operator pass through - Added error printing functions for operators and tensor - Minor cleanup of custom exception handling Signed-off-by: Tim Hall <tim.hall@arm.com> Change-Id: Idf295df1e4c544381dc480244d880c32fb285e38
Diffstat (limited to 'ethosu/vela/errors.py')
-rw-r--r--ethosu/vela/errors.py79
1 files changed, 77 insertions, 2 deletions
diff --git a/ethosu/vela/errors.py b/ethosu/vela/errors.py
index efe64d5c..2c93fbc6 100644
--- a/ethosu/vela/errors.py
+++ b/ethosu/vela/errors.py
@@ -15,6 +15,10 @@
# limitations under the License.
# Description:
# Defines custom exceptions.
+import sys
+
+from .operation import Operation
+from .tensor import Tensor
class VelaError(Exception):
@@ -31,7 +35,7 @@ class InputFileError(VelaError):
"""Raised when reading the input file results in errors"""
def __init__(self, file_name, msg):
- self.data = "Error reading {}: {}".format(file_name, msg)
+ self.data = "Error reading input file {}: {}".format(file_name, msg)
class UnsupportedFeatureError(VelaError):
@@ -45,4 +49,75 @@ class OptionError(VelaError):
"""Raised when an incorrect command line option is used"""
def __init__(self, option, option_value, msg):
- self.data = "Incorrect argument: {} {}: {}".format(option, option_value, msg)
+ self.data = "Incorrect argument to CLI option: {} {}: {}".format(option, option_value, msg)
+
+
+def OperatorError(op, msg):
+ """Called when parsing an operator results in errors"""
+
+ assert isinstance(op, Operation)
+
+ if op.op_index is None:
+ data = "Invalid {} (name = {}) operator in the internal representation.".format(op.type, op.name)
+ else:
+ data = "Invalid {} (op_index = {}) operator in the input network.".format(op.type, op.op_index)
+
+ data += " {}\n".format(msg)
+
+ data += " Input tensors:\n"
+ for idx, tens in enumerate(op.inputs):
+ if isinstance(tens, Tensor):
+ tens_name = tens.name
+ else:
+ tens_name = "Not a Tensor"
+
+ data += " {} = {}\n".format(idx, tens_name)
+
+ data += " Output tensors:\n"
+ for idx, tens in enumerate(op.outputs):
+ if isinstance(tens, Tensor):
+ tens_name = tens.name
+ else:
+ tens_name = "Not a Tensor"
+
+ data += " {} = {}\n".format(idx, tens_name)
+
+ data = data[:-1] # remove last newline
+
+ print("Error: {}".format(data))
+ sys.exit(1)
+
+
+def TensorError(tens, msg):
+ """Called when parsing a tensor results in errors"""
+
+ assert isinstance(tens, Tensor)
+
+ data = "Invalid {} tensor. {}\n".format(tens.name, msg)
+
+ data += " Driving operators:\n"
+ for idx, op in enumerate(tens.ops):
+ if isinstance(op, Operation):
+ op_type = op.type
+ op_id = op.op_index
+ else:
+ op_type = "Not an Operation"
+ op_id = ""
+
+ data += " {} = {} ({})\n".format(idx, op_type, op_id)
+
+ data += " Consuming operators:\n"
+ for idx, op in enumerate(tens.consumer_list):
+ if isinstance(op, Operation):
+ op_type = op.type
+ op_id = op.op_index
+ else:
+ op_type = "Not an Operation"
+ op_id = ""
+
+ data += " {} = {} ({})\n".format(idx, op_type, op_id)
+
+ data = data[:-1] # remove last newline
+
+ print("Error: {}".format(data))
+ sys.exit(1)