aboutsummaryrefslogtreecommitdiff
path: root/ethosu/mlw_codec/mlw_codecmodule.c
diff options
context:
space:
mode:
authorFredrik Svedberg <fredrik.svedberg@arm.com>2024-01-25 19:52:16 +0100
committerFredrik Svedberg <fredrik.svedberg@arm.com>2024-01-26 13:18:16 +0000
commitcbec599c97b8620580ed5f80ea253770df872fa1 (patch)
tree69b5c6f8362e8bb5687d4ce755b3fe64f4ccbb12 /ethosu/mlw_codec/mlw_codecmodule.c
parent1c8f92d0bf0bfe032ada2a0d8cb234c486b96548 (diff)
downloadethos-u-vela-cbec599c97b8620580ed5f80ea253770df872fa1.tar.gz
MLBEDSW-8575 Tests fails on conv networks
Fixed a problem where the compiler incorrectly called the mlw_codec to create an empty weight stream for the second weight core. Also added code to the mlw_codec to detect this as an value error rather than a memory error. Change-Id: I463846cecb1178f8fbf04dc3e39bd6965cb8ddfc Signed-off-by: Fredrik Svedberg <fredrik.svedberg@arm.com>
Diffstat (limited to 'ethosu/mlw_codec/mlw_codecmodule.c')
-rw-r--r--ethosu/mlw_codec/mlw_codecmodule.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/ethosu/mlw_codec/mlw_codecmodule.c b/ethosu/mlw_codec/mlw_codecmodule.c
index 1f172eed..5d37302d 100644
--- a/ethosu/mlw_codec/mlw_codecmodule.c
+++ b/ethosu/mlw_codec/mlw_codecmodule.c
@@ -91,6 +91,7 @@ method_reorder_encode (PyObject *self, PyObject *args)
if ((int)PyArray_NDIM(input_ndarray_object) < 4)
{
PyErr_SetString(PyExc_ValueError, "Invalid input shape");
+ Py_DECREF(input_ndarray_object);
return NULL;
}
@@ -99,6 +100,34 @@ method_reorder_encode (PyObject *self, PyObject *args)
int kernel_width = (int)PyArray_DIM(input_ndarray_object, 2);
int ifm_depth = (int)PyArray_DIM(input_ndarray_object, 3);
+ if (ofm_depth < 1)
+ {
+ PyErr_SetString(PyExc_ValueError, "Invalid output depth");
+ Py_DECREF(input_ndarray_object);
+ return NULL;
+ }
+
+ if (ifm_depth < 1)
+ {
+ PyErr_SetString(PyExc_ValueError, "Invalid input depth");
+ Py_DECREF(input_ndarray_object);
+ return NULL;
+ }
+
+ if (kernel_height < 1)
+ {
+ PyErr_SetString(PyExc_ValueError, "Invalid kernel height");
+ Py_DECREF(input_ndarray_object);
+ return NULL;
+ }
+
+ if (kernel_width < 1)
+ {
+ PyErr_SetString(PyExc_ValueError, "Invalid kernel width");
+ Py_DECREF(input_ndarray_object);
+ return NULL;
+ }
+
int16_t* brick_weights = (int16_t*)PyArray_DATA(input_ndarray_object);
int brick_strides[4];
for (int i = 0; i < 4; i++)
@@ -107,6 +136,7 @@ method_reorder_encode (PyObject *self, PyObject *args)
if (stride % sizeof(int16_t))
{
PyErr_SetString(PyExc_ValueError, "Invalid stride");
+ Py_DECREF(input_ndarray_object);
return NULL;
}
brick_strides[i] = stride / sizeof(int16_t);
@@ -114,6 +144,7 @@ method_reorder_encode (PyObject *self, PyObject *args)
if ((unsigned)PyArray_ITEMSIZE(input_ndarray_object) != sizeof(int16_t))
{
PyErr_SetString(PyExc_ValueError, "Invalid input type");
+ Py_DECREF(input_ndarray_object);
return NULL;
}
uint8_t* output_buffer = NULL;