diff --git a/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp b/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp index 57bcf3537d9cfbfc4d05b33cfd9d30c846505138..91fee32c86163eb3ad42968b05b7c70505b1278c 100644 --- a/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp +++ b/ethosu/regor/architecture/ethosu85/ethos_u85_constraints.cpp @@ -27,8 +27,11 @@ namespace regor { // Table of allowed ifm/ofm data type combinations for each HWOp -static const std::array s_defaultAllTypes = {DataType::UInt8, DataType::Int8, DataType::Int16, DataType::Int32, DataType::Int64}; -static const std::array s_defaultAllTypesExcl64 = { +static const std::array s_defaultAllTypes = { + DataType::Bool8, DataType::UInt8, DataType::Int8, DataType::Int16, DataType::Int32, DataType::Int64}; +static const std::array s_defaultIntegerTypes = { + DataType::UInt8, DataType::Int8, DataType::Int16, DataType::Int32, DataType::Int64}; +static const std::array s_defaultIntegerTypesExcl64 = { DataType::UInt8, DataType::Int8, DataType::Int16, DataType::Int32, DataType::Int64}; static const std::array s_reduceMinMaxTypes = { DataType::Bool8, DataType::UInt8, DataType::Int8, DataType::Int16, DataType::Int32}; @@ -43,21 +46,21 @@ static const std::array s_defaultInt32_64 = {DataType::Int32, DataT static const std::unordered_map>> s_opDataTypeSupport = { {EthosU85NpuOp::Convolution, { - {DataType::UInt8, s_defaultAllTypes}, - {DataType::Int8, s_defaultAllTypes}, - {DataType::Int16, s_defaultAllTypes}, + {DataType::UInt8, s_defaultIntegerTypes}, + {DataType::Int8, s_defaultIntegerTypes}, + {DataType::Int16, s_defaultIntegerTypes}, }}, {EthosU85NpuOp::Depthwise, { - {DataType::UInt8, s_defaultAllTypes}, - {DataType::Int8, s_defaultAllTypes}, - {DataType::Int16, s_defaultAllTypes}, + {DataType::UInt8, s_defaultIntegerTypes}, + {DataType::Int8, s_defaultIntegerTypes}, + {DataType::Int16, s_defaultIntegerTypes}, }}, {EthosU85NpuOp::VectorProduct, { - {DataType::UInt8, s_defaultAllTypes}, - {DataType::Int8, s_defaultAllTypes}, - {DataType::Int16, s_defaultAllTypes}, + {DataType::UInt8, s_defaultIntegerTypes}, + {DataType::Int8, s_defaultIntegerTypes}, + {DataType::Int16, s_defaultIntegerTypes}, }}, {EthosU85NpuOp::Pooling, { @@ -76,10 +79,10 @@ static const std::unordered_map ifmTypes = s_defaultAllTypes; ofmTypes = s_defaultAllTypes; diff --git a/ethosu/regor/common/buffer_view.hpp b/ethosu/regor/common/buffer_view.hpp index 8353757ebe1834d197dfbb86776c4e69d6a06161..b7ec922bd63f5701fb0504c09d3ac61845852f1e 100644 --- a/ethosu/regor/common/buffer_view.hpp +++ b/ethosu/regor/common/buffer_view.hpp @@ -136,10 +136,9 @@ public: Buffer(const ConstValue &value) : _typeHash(TypeHash::value), _utypeHash(TypeHash>::value) { - _refData.constValue = uint64_t(value._value); + _refData.constValue = uint64_t(std::make_unsigned_t(value._value)); _sizeBytes = sizeof(TYPE); _placement = Placement::LocalConst; - _dataHash.v32[0] = uint32_t(value._value); } template::value, int> = 0> diff --git a/ethosu/regor/common/data_type.hpp b/ethosu/regor/common/data_type.hpp index 4d7b1f0abd039c1aa450dfa91f48f10e67d3f885..2d2f9a12fc1f30bd7406465343eba9c7529df001 100644 --- a/ethosu/regor/common/data_type.hpp +++ b/ethosu/regor/common/data_type.hpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2021-2025 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 // @@ -273,6 +273,11 @@ struct DataTypeOf static constexpr DataType value = DataType::None; }; template<> +struct DataTypeOf +{ + static constexpr DataType value = DataType::Bool8; +}; +template<> struct DataTypeOf { static constexpr DataType value = DataType::Int8; diff --git a/ethosu/regor/compiler/graphir_optimiser.cpp b/ethosu/regor/compiler/graphir_optimiser.cpp index ca73a8485b5aee0c1739b3ffb7b3dc9cb64c9735..213266892399d01cd8b714118d73dd8171ff7ca1 100644 --- a/ethosu/regor/compiler/graphir_optimiser.cpp +++ b/ethosu/regor/compiler/graphir_optimiser.cpp @@ -89,7 +89,7 @@ Tensor *GraphIrOptimiser::ConvertBool8Tensors(Graph *graph, Tensor *tensor) // Create and insert an elementwise CMP_NE to convert to internal bool representation auto newOp = std::make_shared(OpType::NotEqual); newOp->ConnectInput(TensorUsage::IFM0, graphInputTensor); - newOp->ConnectInput(TensorUsage::IFM1, CreateConstTensor("const_zero", int8_t(0))); + newOp->ConnectInput(TensorUsage::IFM1, CreateConstTensor("const_zero", bool(false))); newOp->ConnectOutput(TensorUsage::OFM, newTensor); RecordOptimisation(graph, newOp.get()); returnTensor = graphInputTensor.get(); @@ -105,7 +105,7 @@ Tensor *GraphIrOptimiser::ConvertBool8Tensors(Graph *graph, Tensor *tensor) // Create and insert an elementwise BITWISE_AND to convert from internal bool representation auto newOp = std::make_shared(OpType::And); newOp->ConnectInput(TensorUsage::IFM0, newTensor); - newOp->ConnectInput(TensorUsage::IFM1, CreateConstTensor("const_one", int8_t(1))); + newOp->ConnectInput(TensorUsage::IFM1, CreateConstTensor("const_one", bool(true))); newOp->ConnectOutput(TensorUsage::OFM, graphOutputTensor); RecordOptimisation(graph, newOp.get()); returnTensor = newTensor.get(); diff --git a/ethosu/regor/compiler/operation_util.hpp b/ethosu/regor/compiler/operation_util.hpp index f58bacee1033ea7bea860f4caeaae8a57ad69e75..a52640efd411bff2773b6049cec929beac3e1278 100644 --- a/ethosu/regor/compiler/operation_util.hpp +++ b/ethosu/regor/compiler/operation_util.hpp @@ -59,8 +59,8 @@ inline std::shared_ptr CreateConstTensor( template std::shared_ptr CreateConstTensor(const std::string &name, T value) { - auto buf = std::make_shared(std::vector{value}); - return CreateConstTensor(name, DataTypeOf::value, buf); + using T2 = typename std::conditional::value, uint8_t, T>::type; + return CreateConstTensor(name, DataTypeOf::value, std::make_shared(Buffer::ConstValue(T2(value)))); } // Create a single element constant tensor with the specified data type and value (value is not bounds-checked)