aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ethosu/mlw_codec/mlw_codecmodule.c31
-rw-r--r--ethosu/vela/weight_compressor.py4
2 files changed, 33 insertions, 2 deletions
diff --git a/ethosu/mlw_codec/mlw_codecmodule.c b/ethosu/mlw_codec/mlw_codecmodule.c
index 1f172ee..5d37302 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;
diff --git a/ethosu/vela/weight_compressor.py b/ethosu/vela/weight_compressor.py
index 50ae26c..a580fb6 100644
--- a/ethosu/vela/weight_compressor.py
+++ b/ethosu/vela/weight_compressor.py
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2020-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -420,7 +420,7 @@ def encode_weight_and_scale_tensor(
# For each core, deinterleave weights/scales from the larger volume
# and generate separate compressed streams.
- for core in range(0, min(arch.ncores, full_ofm_depth)):
+ for core in range(0, min(arch.ncores, depth_length)):
core_block_depth = int((ofm_block_depth + arch.ncores - 1 - core) // arch.ncores)