-
Notifications
You must be signed in to change notification settings - Fork 608
Buckify op_add for FusionG3 and add cxx tests. #7102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <executorch/runtime/core/exec_aten/exec_aten.h> | ||
#include <executorch/runtime/kernel/kernel_runtime_context.h> | ||
|
||
namespace cadence { | ||
namespace impl { | ||
namespace G3 { | ||
namespace native { | ||
|
||
::executorch::aten::Tensor& add_out( | ||
::executorch::runtime::KernelRuntimeContext& ctx, | ||
const ::executorch::aten::Tensor& a, | ||
const ::executorch::aten::Tensor& b, | ||
const ::executorch::aten::Scalar& alpha, | ||
::executorch::aten::Tensor& out); | ||
|
||
::executorch::aten::Tensor& add_scalar_out( | ||
::executorch::runtime::KernelRuntimeContext& ctx, | ||
const ::executorch::aten::Tensor& a, | ||
const ::executorch::aten::Scalar& b, | ||
const ::executorch::aten::Scalar& alpha, | ||
::executorch::aten::Tensor& out); | ||
|
||
} // namespace native | ||
} // namespace G3 | ||
} // namespace impl | ||
} // namespace cadence |
84 changes: 84 additions & 0 deletions
84
backends/cadence/fusion_g3/operators/tests/test_op_add.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <stdio.h> | ||
|
||
#include <executorch/backends/cadence/fusion_g3/operators/operators.h> | ||
#include <executorch/runtime/core/exec_aten/exec_aten.h> | ||
#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h> | ||
#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h> | ||
#include <executorch/runtime/platform/runtime.h> | ||
|
||
namespace cadence { | ||
namespace impl { | ||
namespace G3 { | ||
namespace native { | ||
namespace { | ||
|
||
using ::executorch::aten::Scalar; | ||
using ::executorch::aten::ScalarType; | ||
using ::executorch::aten::Tensor; | ||
using ::executorch::runtime::KernelRuntimeContext; | ||
using ::executorch::runtime::runtime_init; | ||
using ::executorch::runtime::testing::TensorFactory; | ||
using ::testing::Test; | ||
|
||
class FusionG3OperatorTest : public Test { | ||
public: | ||
void SetUp() override { | ||
runtime_init(); | ||
} | ||
|
||
protected: | ||
Tensor& | ||
add_out(const Tensor& a, const Tensor& b, const Scalar& alpha, Tensor& out) { | ||
return cadence::impl::G3::native::add_out(context_, a, b, alpha, out); | ||
} | ||
|
||
KernelRuntimeContext context_; | ||
}; | ||
|
||
TEST_F(FusionG3OperatorTest, TwoDimFloatTensorAddTest) { | ||
TensorFactory<ScalarType::Float> tf; | ||
const std::vector<int> sizes{2, 2}; | ||
Tensor out = tf.zeros(sizes); | ||
|
||
// Add two 2x2 tensors. | ||
add_out(tf.make(sizes, {1, 2, 3, 4}), tf.make(sizes, {2, 2, 2, 2}), 1, out); | ||
|
||
EXPECT_TENSOR_EQ(out, tf.make(sizes, {3, 4, 5, 6})); | ||
} | ||
|
||
TEST_F(FusionG3OperatorTest, TensorScalarAddTest) { | ||
TensorFactory<ScalarType::Float> tf; | ||
const std::vector<int> sizes{2, 2}; | ||
Tensor out = tf.zeros(sizes); | ||
|
||
// Add 2x2 tensor with scalar. | ||
add_out(tf.make(sizes, {1, 2, 3, 4}), tf.make({1}, {2}), 1, out); | ||
|
||
EXPECT_TENSOR_EQ(out, tf.make(sizes, {3, 4, 5, 6})); | ||
} | ||
|
||
TEST_F(FusionG3OperatorTest, AddWithBroadcastTest) { | ||
TensorFactory<ScalarType::Float> tf; | ||
// Broadcast add. | ||
const std::vector<int> size_a{1, 3, 2, 4}, size_b{2, 4}; | ||
Tensor out = tf.zeros(size_a); | ||
|
||
add_out(tf.ones(size_a), tf.ones(size_b), 1, out); | ||
|
||
EXPECT_TENSOR_EQ(out, tf.full(size_a, 2)); | ||
} | ||
|
||
} // namespace | ||
} // namespace native | ||
} // namespace G3 | ||
} // namespace impl | ||
} // namespace cadence |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to parameterize the test inputs for multiple shapes?