From b782c531c98d777e70589e0fbecd377a4cb8ed23 Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Thu, 22 Aug 2024 10:07:12 +0900 Subject: [PATCH] Support opernad size of chunk type directly without data size --- runtime/onert/core/include/ir/OperandInfo.h | 2 +- runtime/onert/core/src/ir/DataType.cc | 7 ++- runtime/onert/core/src/ir/OperandInfo.cc | 50 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 runtime/onert/core/src/ir/OperandInfo.cc diff --git a/runtime/onert/core/include/ir/OperandInfo.h b/runtime/onert/core/include/ir/OperandInfo.h index 2957be23e99..f6739033e24 100644 --- a/runtime/onert/core/include/ir/OperandInfo.h +++ b/runtime/onert/core/include/ir/OperandInfo.h @@ -120,7 +120,7 @@ class OperandInfo * @brief Return size of tensor (bytes) * @return Tensor size */ - size_t total_size() const { return _shape.num_elements() * sizeOfDataType(_typeInfo.type()); } + size_t total_size() const; MemAllocType memAllocType() const { return _alloc_type; } void setAsConstant() { _const = true; } diff --git a/runtime/onert/core/src/ir/DataType.cc b/runtime/onert/core/src/ir/DataType.cc index d3c381f41ef..3b5636ba262 100644 --- a/runtime/onert/core/src/ir/DataType.cc +++ b/runtime/onert/core/src/ir/DataType.cc @@ -52,10 +52,9 @@ size_t sizeOfDataType(DataType data_type) return sizeof(int16_t); case DataType::QUANT_INT16_SYMM: return sizeof(int16_t); - case DataType::QUANT_UINT4_SYMM_PER_CHUNK: - return sizeof(uint8_t) * 32 / 2 + sizeof(uint16_t); - case DataType::QUANT_INT8_SYMM_PER_CHUNK: - return sizeof(uint8_t) * 32 + sizeof(uint16_t); + // Chunk type size is not supported + // case DataType::QUANT_UINT4_SYMM_PER_CHUNK: + // case DataType::QUANT_INT8_SYMM_PER_CHUNK default: throw std::runtime_error{"Unsupported type size"}; } diff --git a/runtime/onert/core/src/ir/OperandInfo.cc b/runtime/onert/core/src/ir/OperandInfo.cc new file mode 100644 index 00000000000..99a84955059 --- /dev/null +++ b/runtime/onert/core/src/ir/OperandInfo.cc @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ir/OperandInfo.h" + +#include + +namespace onert +{ +namespace ir +{ + +size_t OperandInfo::total_size() const +{ + const auto data_type = _typeInfo.type(); + try + { + return _shape.num_elements() * sizeOfDataType(data_type); + } + catch (const std::runtime_error &e) + { + if (data_type != DataType::QUANT_UINT4_SYMM_PER_CHUNK && + data_type != DataType::QUANT_INT8_SYMM_PER_CHUNK) + throw e; + + // Assume last dim is multiple of chunk size (32) + assert(_shape.dim(_shape.rank() - 1) % 32 == 0); + const auto num_chunks = _shape.num_elements() / 32; + const auto chunk_size = data_type == DataType::QUANT_UINT4_SYMM_PER_CHUNK + ? (sizeof(uint8_t) * 32 / 2 + sizeof(uint16_t)) + : (sizeof(uint8_t) * 32 + sizeof(uint16_t)); + return num_chunks * chunk_size; + } +} + +} // namespace ir +} // namespace onert