Skip to content

Commit

Permalink
[onert] Simplify code using SFINAE technique
Browse files Browse the repository at this point in the history
This commit simplify code using the SFINAE technique.

ONE-DCO-1.0-Signed-off-by: ragmani <[email protected]>
  • Loading branch information
ragmani committed Feb 19, 2025
1 parent c425c09 commit 95600ac
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions runtime/onert/backend/trix/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data_type convertDataType(const ir::DataType type);
* @param tensors Tensors that have data information
* @param info tensors_data_info to be set
*/
template <typename T, std::enable_if_t<std::is_base_of<IPortableTensor, T>::value, bool> = true>
template <typename T, std::enable_if_t<std::is_base_of_v<IPortableTensor, T>, bool> = true>
void setDataInfo(const std::vector<T *> &tensors, tensors_data_info *info)
{
info->num_info = static_cast<uint32_t>(tensors.size());
Expand All @@ -61,7 +61,7 @@ void setDataInfo(const std::vector<T *> &tensors, tensors_data_info *info)
* @param tensors Tensors that have buffer information
* @param buf generic_buffers to be set
*/
template <typename T, std::enable_if_t<std::is_base_of<IPortableTensor, T>::value, bool> = true>
template <typename T, std::enable_if_t<std::is_base_of_v<IPortableTensor, T>, bool> = true>
void setBuffers(const std::vector<T *> &tensors, generic_buffers *buf)
{
buf->num_buffers = static_cast<uint32_t>(tensors.size());
Expand Down
4 changes: 1 addition & 3 deletions runtime/onert/core/include/ir/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Model
*
* @return true if the model has only typename Graph, otherwise false
*/
template <typename Graph, std::enable_if_t<std::is_base_of<IGraph, Graph>::value, bool> = true>
template <typename Graph, std::enable_if_t<std::is_base_of_v<IGraph, Graph>, bool> = true>
bool hasOnly()
{
for (const auto &e : _subgraphs)
Expand Down Expand Up @@ -193,8 +193,6 @@ class Model
}

private:
// TODO: Apply Heterogeneous lookup for unordered containers (transparent hashing) since C++20
// to use `std::string_view` with lookup functions in unordered containers
std::unordered_map<std::string, std::unique_ptr<const ir::Data>> _metadatas;
};
} // namespace onert::ir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace onert::ir::train::operation
// `UntrainableOperation` wraps operations that are not yet supported for training.
// This class can be removed if all operations are supported for training.
template <typename OperationType,
typename = std::enable_if_t<std::is_base_of<Operation, OperationType>::value>>
std::enable_if_t<std::is_base_of_v<Operation, OperationType>, bool> = true>
class UntrainableOperation : public OperationType, public TrainableOperation
{
public:
Expand Down
2 changes: 1 addition & 1 deletion runtime/onert/core/src/compiler/CompilerHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace onert::compiler
* @return Shape inferer map
*/
template <typename LoweredGraphType,
typename = std::enable_if_t<std::is_base_of<ILoweredGraph, LoweredGraphType>::value>>
std::enable_if_t<std::is_base_of_v<ILoweredGraph, LoweredGraphType>, bool> = true>
static std::unordered_map<ir::SubgraphIndex, std::unique_ptr<StaticShapeInferer>>
createStaticShapeInferers(
const std::unordered_map<ir::SubgraphIndex, std::unique_ptr<LoweredGraphType>> &lowered_subgs)
Expand Down
4 changes: 2 additions & 2 deletions runtime/onert/core/src/exec/IPermuteFunction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ void dequantize(const backend::ITensor *src_tensor, backend::ITensor *dst_tensor
}

template <typename SRC_T, typename DST_T,
std::enable_if_t<std::is_base_of<backend::ITensor, SRC_T>::value &&
std::is_base_of<backend::ITensor, DST_T>::value,
std::enable_if_t<std::is_base_of_v<backend::ITensor, SRC_T> &&
std::is_base_of_v<backend::ITensor, DST_T>,
bool> = true>
void typeAwareQuantize(const SRC_T *src_tensor, DST_T *dst_tensor, const ir::PermuteType &type)
{
Expand Down
9 changes: 4 additions & 5 deletions runtime/onert/core/src/util/ShapeInference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ namespace onert::shape_inference
namespace
{

template <typename T, typename U>
typename std::enable_if<std::is_integral<T>::value && std::is_integral<U>::value,
typename std::common_type<T, U>::type>::type
ceil_div(T dividend, U divisor)
template <typename T, typename U,
std::enable_if_t<std::is_integral_v<T> && std::is_integral_v<U>, bool> = true>
std::common_type_t<T, U> ceil_div(T dividend, U divisor)
{
assert(dividend > 0 && divisor > 0 && "this implementations is for positive numbers only");
assert(dividend > 0 && divisor > 0 && "this implementation is for positive numbers only");
return (dividend + divisor - 1) / divisor;
}

Expand Down

0 comments on commit 95600ac

Please sign in to comment.