Skip to content

Commit a99b8c2

Browse files
committed
[onert] Dedicated exception for invalid data type
This commit introduces dedicated exception for reporting unsupported or invalid data type. ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <[email protected]>
1 parent 0f0f5b3 commit a99b8c2

File tree

83 files changed

+331
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+331
-192
lines changed

runtime/onert/api/nnfw/include/nnfw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ typedef enum
125125
NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE = 5,
126126
/** When API is deprecated */
127127
NNFW_STATUS_DEPRECATED_API = 6,
128+
/** When given input or ouput data type is not supported. */
129+
NNFW_STATUS_UNSUPPORTED_DATA_TYPE = 7,
128130
} NNFW_STATUS;
129131

130132
/**

runtime/onert/api/nnfw/src/CustomKernel.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "CustomKernel.h"
1818

19+
#include <util/Exceptions.h>
20+
1921
namespace onert::api
2022
{
2123

@@ -54,7 +56,7 @@ class APIConverter
5456
api_type.dtype = NNFW_TYPE_TENSOR_BOOL;
5557
break;
5658
default:
57-
throw std::runtime_error("Unsupported tensor datatype");
59+
throw UnsupportedDataTypeException("Converter", type.dtype);
5860
}
5961
return api_type;
6062
}

runtime/onert/api/nnfw/src/nnfw_session.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@ NNFW_STATUS nnfw_session::run()
481481
std::cerr << "Error during nnfw_session::run : " << e.what() << std::endl;
482482
return NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE;
483483
}
484+
catch (const onert::UnsupportedDataTypeException &e)
485+
{
486+
std::cerr << "Error during nnfw_session::run : " << e.what() << std::endl;
487+
return NNFW_STATUS_UNSUPPORTED_DATA_TYPE;
488+
}
484489
catch (const std::exception &e)
485490
{
486491
std::cerr << "Error during nnfw_session::run : " << e.what() << std::endl;

runtime/onert/api/python/include/nnfw_exceptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ struct NnfwDeprecatedApiError : public NnfwError
4949
{
5050
using NnfwError::NnfwError;
5151
};
52+
struct NnfwUnsupportedDataTypeError : public NnfwError
53+
{
54+
using NnfwError::NnfwError;
55+
};
5256

5357
} // namespace onert::api::python
5458

runtime/onert/api/python/src/bindings/nnfw_exception_bindings.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void bind_nnfw_exceptions(py::module_ &m)
4141
m.attr("OnertError").cast<py::object>());
4242
py::register_exception<NnfwDeprecatedApiError>(m, "OnertDeprecatedApiError",
4343
m.attr("OnertError").cast<py::object>());
44+
py::register_exception<NnfwUnsupportedDataTypeError>(m, "OnertUnsupportedDataTypeError",
45+
m.attr("OnertError").cast<py::object>());
4446
}
4547

4648
} // namespace onert::api::python

runtime/onert/api/python/src/wrapper/nnfw_api_wrapper.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ void ensure_status(NNFW_STATUS status)
4242
throw NnfwInsufficientOutputError("NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE");
4343
case NNFW_STATUS::NNFW_STATUS_DEPRECATED_API:
4444
throw NnfwDeprecatedApiError("NNFW_STATUS_DEPRECATED_API");
45-
default:
46-
throw NnfwError("NNFW_UNKNOWN_ERROR");
45+
case NNFW_STATUS::NNFW_STATUS_UNSUPPORTED_DATA_TYPE:
46+
throw NnfwUnsupportedDataTypeError("NNFW_STATUS_UNSUPPORTED_DATA_TYPE");
4747
}
48+
throw NnfwError("NNFW_UNKNOWN_ERROR");
4849
}
4950

5051
NNFW_LAYOUT getLayout(const char *layout)

runtime/onert/backend/acl_common/Convert.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Swizzle.h"
2020
#include "ir/DataType.h"
2121
#include "ir/operation/ElementwiseActivation.h"
22+
#include <util/Exceptions.h>
2223
#include <memory>
2324

2425
namespace onert::backend::acl_common
@@ -96,8 +97,7 @@ ::arm_compute::DataType asDataType(const ir::DataType type)
9697
case ir::DataType::QUANT_INT8_SYMM_PER_CHANNEL:
9798
return ::arm_compute::DataType::QSYMM8_PER_CHANNEL;
9899
default:
99-
throw std::runtime_error("Not supported internal data type, yet");
100-
break;
100+
throw UnsupportedDataTypeException(type);
101101
}
102102
}
103103

@@ -224,7 +224,8 @@ std::set<uint32_t> asSet(const ir::Operand &operand, int32_t rank)
224224
for (size_t i = 0; i < operand.shape().num_elements(); ++i)
225225
{
226226
int32_t axis = 0;
227-
switch (operand.typeInfo().type())
227+
const auto data_type = operand.typeInfo().type();
228+
switch (data_type)
228229
{
229230
case ir::DataType::INT32:
230231
axis = reinterpret_cast<const int32_t *>(operand.data()->base())[i];
@@ -233,7 +234,7 @@ std::set<uint32_t> asSet(const ir::Operand &operand, int32_t rank)
233234
axis = reinterpret_cast<const int64_t *>(operand.data()->base())[i];
234235
break;
235236
default:
236-
throw std::runtime_error("acl_common::asSet: Not supported data type");
237+
throw UnsupportedDataTypeException("asSet", data_type);
237238
}
238239
if (axis < 0)
239240
axis += rank;
@@ -273,8 +274,7 @@ ir::DataType asRuntimeDataType(::arm_compute::DataType data_type)
273274
case ::arm_compute::DataType::QSYMM16:
274275
return ir::DataType::QUANT_INT16_SYMM;
275276
default:
276-
throw std::runtime_error{"Not supported acl data type, yet"};
277-
break;
277+
throw UnsupportedDataTypeException("asRuntimeDataType", data_type);
278278
}
279279
}
280280

@@ -312,7 +312,8 @@ arm_compute::PixelValue asPixelValue(const ir::Operand &operand)
312312
{
313313
assert(operand.isConstant());
314314
assert(operand.shape().num_elements() == 1);
315-
switch (operand.typeInfo().type())
315+
const auto data_type = operand.typeInfo().type();
316+
switch (data_type)
316317
{
317318
case ir::DataType::INT32:
318319
return arm_compute::PixelValue(operand.asScalar<int32_t>());
@@ -325,7 +326,7 @@ arm_compute::PixelValue asPixelValue(const ir::Operand &operand)
325326
case ir::DataType::FLOAT32:
326327
return arm_compute::PixelValue(operand.asScalar<float>());
327328
default:
328-
throw std::runtime_error("asPixelValue : Not supported datatype yet");
329+
throw UnsupportedDataTypeException("asPixelValue", data_type);
329330
}
330331
}
331332

runtime/onert/backend/cpu/ops/AddNLayer.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "OperationUtils.h"
2020

2121
#include <cker/operation/AddN.h>
22+
#include <util/Exceptions.h>
2223
#include <assert.h>
2324

2425
namespace onert::backend::cpu::ops
@@ -53,7 +54,7 @@ void AddNLayer::run()
5354
}
5455
else
5556
{
56-
throw std::runtime_error("AddN: unsupported data type");
57+
throw UnsupportedDataTypeException{"AddN", _output->data_type()};
5758
}
5859
}
5960

runtime/onert/backend/cpu/ops/ArgMinMaxLayer.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "OperationUtils.h"
2020

2121
#include <cker/operation/ArgMinMax.h>
22+
#include <util/Exceptions.h>
2223
#include <assert.h>
2324

2425
namespace onert::backend::cpu::ops
@@ -79,7 +80,7 @@ void ArgMinMaxLayer::run()
7980
TF_LITE_ARG_MIN_MAX(int32_t, int32_t, int32_t);
8081
break;
8182
default:
82-
throw std::runtime_error("ArgMinMax: unsupported data type");
83+
throw UnsupportedDataTypeException{"ArgMinMax", _input->data_type()};
8384
}
8485
}
8586
else if (_output->data_type() == ir::DataType::INT64)
@@ -100,12 +101,12 @@ void ArgMinMaxLayer::run()
100101
TF_LITE_ARG_MIN_MAX(int32_t, int32_t, int64_t);
101102
break;
102103
default:
103-
throw std::runtime_error("ArgMinMax: unsupported data type");
104+
throw UnsupportedDataTypeException{"ArgMinMax", _input->data_type()};
104105
}
105106
}
106107
else
107108
{
108-
throw std::runtime_error("ArgMinMax: unsupported data type");
109+
throw UnsupportedDataTypeException{"ArgMinMax", _output->data_type()};
109110
}
110111

111112
#undef TF_LITE_ARG_MIN_MAX

runtime/onert/backend/cpu/ops/BatchMatMulLayer.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "BatchMatMulLayer.h"
1818

1919
#include <cker/operation/BatchMatMul.h>
20+
#include <util/Exceptions.h>
2021

2122
namespace onert::backend::cpu::ops
2223
{
@@ -60,14 +61,11 @@ void BatchMatMulLayer::configure(const IPortableTensor *lhs, const IPortableTens
6061

6162
void BatchMatMulLayer::run()
6263
{
63-
if ((_lhs->data_type() == OperandType::FLOAT32) && (_rhs->data_type() == OperandType::FLOAT32))
64-
{
65-
batchMatMulFloat32();
66-
}
67-
else
68-
{
69-
throw std::runtime_error{"BatchMatMul: unsupported data type"};
70-
}
64+
if (_lhs->data_type() != OperandType::FLOAT32)
65+
throw UnsupportedDataTypeException{"BatchMatMul", _lhs->data_type()};
66+
if (_rhs->data_type() != OperandType::FLOAT32)
67+
throw UnsupportedDataTypeException{"BatchMatMul", _rhs->data_type()};
68+
batchMatMulFloat32();
7169
}
7270

7371
#undef AVGPOOLING_PARAMETERS

0 commit comments

Comments
 (0)