Skip to content

Commit

Permalink
Support opernad size of chunk type directly without data size
Browse files Browse the repository at this point in the history
  • Loading branch information
hseok-oh committed Aug 23, 2024
1 parent c255156 commit b782c53
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtime/onert/core/include/ir/OperandInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
7 changes: 3 additions & 4 deletions runtime/onert/core/src/ir/DataType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}
Expand Down
50 changes: 50 additions & 0 deletions runtime/onert/core/src/ir/OperandInfo.cc
Original file line number Diff line number Diff line change
@@ -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 <cassert>

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

0 comments on commit b782c53

Please sign in to comment.