Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runtime/onert/core/src/loader/BaseLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,9 @@ void BaseLoader<LoaderDomain>::loadOperation(const Operator *op, ir::Graph &subg
case BuiltinOperator::BuiltinOperator_BATCH_MATMUL:
loadBatchMatMul(op, subg);
return;
case BuiltinOperator::BuiltinOperator_BROADCAST_TO:
loadOperationTo<ir::operation::BroadcastTo>(op, subg);
return;
case BuiltinOperator::BuiltinOperator_LOG_SOFTMAX:
loadLogSoftmax(op, subg);
return;
Expand Down
7 changes: 7 additions & 0 deletions runtime/tests/nnfw_api/lib/CircleGen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ uint32_t CircleGen::addOperatorBatchMatMul(const OperatorParams &params, bool ad
circle::BuiltinOptions_BatchMatMulOptions, options);
}

uint32_t CircleGen::addOperatorBroadcastTo(const OperatorParams &params)
{
auto options = circle::CreateBroadcastToOptions(_fbb).Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_BROADCAST_TO,
circle::BuiltinOptions_BroadcastToOptions, options);
}

uint32_t CircleGen::addOperatorCast(const OperatorParams &params, circle::TensorType input_type,
circle::TensorType output_type)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/tests/nnfw_api/lib/CircleGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class CircleGen
uint32_t addOperatorBatchMatMul(const OperatorParams &params, bool adj_x, bool adj_y,
bool asymmetric_quantize_inputs = false);
uint32_t addOperatorBatchToSpaceND(const OperatorParams &params);
uint32_t addOperatorBroadcastTo(const OperatorParams &params);
uint32_t addOperatorCast(const OperatorParams &params, circle::TensorType input_type,
circle::TensorType output_type);
uint32_t addOperatorConcatenation(const OperatorParams &params, int axis,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2025 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 "GenModelTest.h"

TEST_F(GenModelTest, OneOp_BroadcastTo_1D_to_2D)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seockho-kim We have a requirement to have # of positive tc = # of negative tc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seockho-kim We have a requirement to have # of positive tc = # of negative tc.

Okay, I'll update.

{
CircleGen cgen;
const uint32_t shape_buf = cgen.addBuffer(std::vector<int32_t>{3, 3});
int shape = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32, shape_buf});
int in = cgen.addTensor({{3}, circle::TensorType::TensorType_FLOAT32});
int out = cgen.addTensor({{3, 3}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorBroadcastTo({{in, shape}, {out}});
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3}}, {{1, 2, 3, 1, 2, 3, 1, 2, 3}}));
_context->setBackends({"cpu"});

SUCCEED();
}

TEST_F(GenModelTest, OneOp_BroadcastTo_2D_to_3D)
{
CircleGen cgen;
const uint32_t shape_buf = cgen.addBuffer(std::vector<int32_t>{3, 2, 2});
int shape = cgen.addTensor({{3}, circle::TensorType::TensorType_INT32, shape_buf});
int in = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});
int out = cgen.addTensor({{3, 2, 2}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorBroadcastTo({{in, shape}, {out}});
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}}));
_context->setBackends({"cpu"});

SUCCEED();
}

TEST_F(GenModelTest, OneOp_BroadcastTo_3D_to_3D)
{
CircleGen cgen;
const uint32_t shape_buf = cgen.addBuffer(std::vector<int32_t>{2, 3, 2});
int shape = cgen.addTensor({{3}, circle::TensorType::TensorType_INT32, shape_buf});
int in = cgen.addTensor({{2, 1, 2}, circle::TensorType::TensorType_FLOAT32});
int out = cgen.addTensor({{2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorBroadcastTo({{in, shape}, {out}});
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4}}));
_context->setBackends({"cpu"});

SUCCEED();
}