aboutsummaryrefslogtreecommitdiff
path: root/ethosu
diff options
context:
space:
mode:
Diffstat (limited to 'ethosu')
-rw-r--r--ethosu/mlw_codec/mlw_codecmodule.c17
-rw-r--r--ethosu/vela/weight_compressor.py25
2 files changed, 37 insertions, 5 deletions
diff --git a/ethosu/mlw_codec/mlw_codecmodule.c b/ethosu/mlw_codec/mlw_codecmodule.c
index 61ae6a47..8c540d61 100644
--- a/ethosu/mlw_codec/mlw_codecmodule.c
+++ b/ethosu/mlw_codec/mlw_codecmodule.c
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright 2020-2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ * SPDX-FileCopyrightText: Copyright 2020-2021, 2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <numpy/ndarrayobject.h>
@@ -307,7 +306,19 @@ static struct PyModuleDef mlw_codecmodule = {
PyMODINIT_FUNC PyInit_mlw_codec(void)
{
+ PyObject *ptype, *pvalue, *ptraceback;
PyObject* ret = PyModule_Create(&mlw_codecmodule);
- import_array();
+ if (_import_array() < 0)
+ {
+ // Fetch currently set error
+ PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+ // Extract the error message
+ const char *pStrErrorMessage = PyUnicode_AsUTF8(pvalue);
+ // Re-format error message to start with "mlw_codec Error: " so it is
+ // clearer it comes from mlw_codec.
+ PyErr_Format(PyExc_RuntimeError, "mlw_codec error: %s", pStrErrorMessage);
+ return NULL;
+ }
+
return ret;
}
diff --git a/ethosu/vela/weight_compressor.py b/ethosu/vela/weight_compressor.py
index e3e318c3..e56cc5e5 100644
--- a/ethosu/vela/weight_compressor.py
+++ b/ethosu/vela/weight_compressor.py
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Copyright 2020-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -37,7 +37,28 @@ from .scaling import reduced_quantise_scale
from .tensor import Tensor
from .tensor import TensorFormat
from .tensor import TensorPurpose
-from ethosu import mlw_codec
+
+# Handle any errors thrown by NumPy while importing mlw_codec module
+try:
+ from ethosu import mlw_codec
+except RuntimeError as ex:
+ if "mlw_codec error: module compiled against API version" in str(ex):
+ # Extract API versions from error message
+ matches = [s for s in str(ex).split() if "0x" in s]
+ if len(matches) == 2:
+ # Raise new exception with more detailed message
+ raise ImportError( # pylint: disable=W0707
+ "NumPy C API version mismatch "
+ f"(Build-time version: {matches[0]}, "
+ f"Run-time version: {matches[1]})"
+ "\nThis is a known issue most likely caused by a change in the API "
+ "version in NumPy after installing ethos-u-vela.\nYou can find more "
+ "information about the issue and possible solutions in the "
+ "'Known Issues' section at https://review.mlplatform.org/"
+ "plugins/gitiles/ml/ethos-u/ethos-u-vela/+/refs/heads/main/"
+ "README.md#known-issues"
+ )
+ raise
# Contains meta info for a weight compression. If two tensors have identical weight compression config,