Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
80bcc2b
adding unit test basic files for op builders
gchinora Jul 29, 2025
d2858f3
first test for batchnorm
gchinora Aug 1, 2025
5734d5e
2. test for batchnorm
gchinora Aug 1, 2025
edcfc8c
remove unnecessary .at(.) call
gchinora Aug 1, 2025
4ceac20
test for celu
gchinora Aug 4, 2025
6319bc5
add a comment
gchinora Aug 4, 2025
7246287
rename one file
gchinora Aug 4, 2025
2dddb15
new batchnorm tests
gchinora Aug 5, 2025
9cee884
new celu tests
gchinora Aug 5, 2025
c013fcf
modify failing tests to check error messages
gchinora Aug 5, 2025
79c6dc4
introducing a helper builder to reduce test sizes
gchinora Aug 13, 2025
62c05b3
modify to inline in order to avoid linker errors
gchinora Aug 13, 2025
6a29d2d
making use of the new helper builder function to reduce test size
gchinora Aug 13, 2025
54823ed
document formatting
gchinora Aug 13, 2025
abf4084
adding negative unit tests for einsum op-builder
gchinora Aug 14, 2025
9afad70
remove unnecessary include
gchinora Aug 14, 2025
cee08f7
first tests for gelu op-builders
gchinora Aug 14, 2025
e5f14bb
extending gelu tests
gchinora Aug 15, 2025
085decb
introducing the first two gemm tests
gchinora Aug 15, 2025
d624e6e
remove unnecessray include
gchinora Aug 18, 2025
4f613f9
the rest of the gemm tests
gchinora Aug 19, 2025
d8deaf1
change copyright dates
gchinora Aug 19, 2025
2b1019b
introducing tests for mean variance normalization op builder
gchinora Aug 19, 2025
74286c1
format-checking fixes
gchinora Aug 19, 2025
ba2ffcf
fixing tidy check errors
gchinora Aug 19, 2025
e2572e7
adding positive einsum test cases
gchinora Aug 21, 2025
81277d1
remove unnecessray include
gchinora Aug 22, 2025
0f544be
fixing copyright date
gchinora Aug 22, 2025
38e343b
fixing cppcheck warning
gchinora Aug 22, 2025
7607695
the pipeline complained about formatting error; there was a mismatch …
gchinora Aug 22, 2025
07179b2
Merge branch 'develop' into upstream/feature/op_bldr_unit_tests_1
gchinora Aug 22, 2025
b89f989
adding positive einsum test cases
gchinora Aug 27, 2025
b601fa7
fixing input params for literal ctor
gchinora Aug 28, 2025
c09d4d0
fixing format check error
gchinora Sep 17, 2025
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
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -96,6 +96,10 @@ if(MIGRAPHX_ENABLE_PYTHON)
add_subdirectory(py)
endif()

# Op builder test
set(TEST_OP_BUILDER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/op)
add_subdirectory(op)

# multitarget test
if(MIGRAPHX_ENABLE_GPU AND MIGRAPHX_ENABLE_CPU AND MIGRAPHX_ENABLE_FPGA)
set(TEST_MULTI_TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/multi_target)
Expand Down
30 changes: 30 additions & 0 deletions test/op/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################

file(GLOB OP_BUILDER_TESTS CONFIGURE_DEPENDS builder/*.cpp)

rocm_add_test_executable(test_op_builder_test ${OP_BUILDER_TESTS})
target_include_directories(test_op_builder_test PUBLIC ../include include)
target_link_libraries(test_op_builder_test migraphx migraphx_ref)
rocm_clang_tidy_check(test_op_builder_test)
103 changes: 103 additions & 0 deletions test/op/builder/batchnorm_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include <op_builder_test_utils.hpp>

TEST_CASE(batchnorm_rank_0_op_builder_test)
{
migraphx::module mm;

mm.add_parameter("x", {migraphx::shape::half_type, {}});
mm.add_parameter("scale", {migraphx::shape::float_type, {3}});
mm.add_parameter("bias", {migraphx::shape::float_type, {3}});
mm.add_parameter("mean", {migraphx::shape::float_type, {3}});
mm.add_parameter("variance", {migraphx::shape::float_type, {3}});

EXPECT(test::throws<migraphx::exception>(
[&] { make_op_module("batchnorm", {}, mm.get_parameters()); },
"rank 0 input tensor, unhandled data format"));
}

TEST_CASE(batchnorm_rank_1_op_builder_test)
{
migraphx::module mm;

const float epsilon = 1e-6f;

auto x = mm.add_parameter("x", {migraphx::shape::float_type, {10}});
auto scale = mm.add_parameter("scale", {migraphx::shape::float_type, {1}});
auto bias = mm.add_parameter("bias", {migraphx::shape::float_type, {1}});
auto mean = mm.add_parameter("mean", {migraphx::shape::float_type, {1}});
auto var = mm.add_parameter("variance", {migraphx::shape::float_type, {1}});

auto eps = mm.add_literal(migraphx::literal{migraphx::shape::float_type, {epsilon}});

auto x_sub_mean = add_common_op(mm, migraphx::make_op("sub"), {x, mean});
auto var_eps = add_common_op(mm, migraphx::make_op("add"), {var, eps});
auto rsqrt = mm.add_instruction(migraphx::make_op("rsqrt"), {var_eps});
auto mul0 = add_common_op(mm, migraphx::make_op("mul"), {scale, rsqrt});
auto r0 = add_common_op(mm, migraphx::make_op("mul"), {x_sub_mean, mul0});
add_common_op(mm, migraphx::make_op("add"), {r0, bias});

EXPECT(mm == make_op_module("batchnorm", {{"epsilon", epsilon}}, mm.get_parameters()));
}

TEST_CASE(batchnorm_rank_larger_than_2_op_builder_test)
{
migraphx::module mm;

auto x = mm.add_parameter("x", {migraphx::shape::half_type, {2, 3, 4}});
auto scale = mm.add_parameter("scale", {migraphx::shape::float_type, {3}});
auto bias = mm.add_parameter("bias", {migraphx::shape::float_type, {3}});
auto mean = mm.add_parameter("mean", {migraphx::shape::float_type, {3}});
auto var = mm.add_parameter("variance", {migraphx::shape::float_type, {3}});

auto eps = mm.add_literal(migraphx::literal{migraphx::shape::half_type, {1e-5f}});

auto usq_scale = mm.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), scale);
auto usq_bias = mm.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), bias);
auto usq_mean = mm.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), mean);
auto usq_var = mm.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), var);

auto x_sub_mean = add_common_op(mm, migraphx::make_op("sub"), {x, usq_mean});
auto var_eps = add_common_op(mm, migraphx::make_op("add"), {usq_var, eps});
auto rsqrt = mm.add_instruction(migraphx::make_op("rsqrt"), var_eps);
auto mul0 = add_common_op(mm, migraphx::make_op("mul"), {usq_scale, rsqrt});
auto r0 = add_common_op(mm, migraphx::make_op("mul"), {x_sub_mean, mul0});
add_common_op(mm, migraphx::make_op("add"), {r0, usq_bias});

EXPECT(mm == make_op_module("batchnorm", {}, mm.get_parameters()));
}

TEST_CASE(batchnorm_invalid_arguments_op_builder_test)
{
migraphx::module mm;

mm.add_parameter("x", {migraphx::shape::half_type, {2}});
mm.add_parameter("scale", {migraphx::shape::float_type, {3, 2}});

EXPECT(test::throws<migraphx::exception>(
[&] { make_op_module("batchnorm", {}, mm.get_parameters()); },
"argument scale, bias, mean, or var rank != 1"));
}
80 changes: 80 additions & 0 deletions test/op/builder/celu_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include <op_builder_test_utils.hpp>

TEST_CASE(celu_happy_path_op_builder_test)
{
migraphx::module mm;

const float alpha = 0.8;
const migraphx::shape s = {migraphx::shape::float_type, {3}};

auto x = mm.add_parameter("x", s);

const auto& input_lens = s.lens();
const auto& input_type = s.type();
auto zero_lit =
mm.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm.add_literal(migraphx::literal{migraphx::shape{input_type}, {0.}}));
auto one_lit =
mm.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm.add_literal(migraphx::literal{migraphx::shape{input_type}, {1.}}));
auto alpha_lit =
mm.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm.add_literal(migraphx::literal{migraphx::shape{input_type}, {alpha}}));
auto linear_part = mm.add_instruction(migraphx::make_op("max"), zero_lit, x);
auto divi = mm.add_instruction(migraphx::make_op("div"), x, alpha_lit);
auto expo = mm.add_instruction(migraphx::make_op("exp"), divi);
auto sub = mm.add_instruction(migraphx::make_op("sub"), expo, one_lit);
auto mul = mm.add_instruction(migraphx::make_op("mul"), alpha_lit, sub);
auto exp_part = mm.add_instruction(migraphx::make_op("min"), zero_lit, mul);
mm.add_instruction(migraphx::make_op("add"), linear_part, exp_part);

EXPECT(mm == make_op_module("celu", {{"alpha", alpha}}, mm.get_parameters()));
}

TEST_CASE(celu_zero_alpha_op_builder_test)
{
migraphx::module mm;

const float alpha = 0.0f;

EXPECT(
test::throws<migraphx::exception>([&] { make_op_module("celu", {{"alpha", alpha}}, {}); },
"alpha is zero (division by zero)"));
}

TEST_CASE(celu_wrong_shape_type_op_builder_test)
{
migraphx::module mm;
const float alpha = 0.8;
const migraphx::shape s = {migraphx::shape::int8_type, {3}};

mm.add_parameter("x", s);

EXPECT(test::throws<migraphx::exception>(
[&] { make_op_module("celu", {{"alpha", alpha}}, mm.get_parameters()); },
"input tensor not float type"));
}
Loading
Loading