// Copyright © Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #include "engines/plans/MiopenBatchnormFwdTrainingPlan.hpp" #include #include #include using namespace miopen_plugin; TEST(TestBatchnormFwdTrainingParams, InitializesRequiredTensorsFromValidGraph) { auto builder = hipdnn_test_sdk::utilities::createValidBatchnormFwdTrainingGraph(); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph( builder.GetBufferPointer(), builder.GetSize()); const auto& node = graph.getNode(0); auto* attrs = node.attributes_as_BatchnormAttributes(); ASSERT_NE(attrs, nullptr); const BatchnormFwdTrainingParams params(*attrs, graph.getTensorMap()); // All required tensors should be initialized EXPECT_NO_THROW(params.x()); EXPECT_NO_THROW(params.y()); EXPECT_NO_THROW(params.scale()); EXPECT_NO_THROW(params.bias()); } TEST(TestBatchnormFwdTrainingParams, ExtractsEpsilonValueCorrectly) { auto builder = hipdnn_test_sdk::utilities::createValidBatchnormFwdTrainingGraph(); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph( builder.GetBufferPointer(), builder.GetSize()); const auto& node = graph.getNode(0); auto* attrs = node.attributes_as_BatchnormAttributes(); ASSERT_NE(attrs, nullptr); const BatchnormFwdTrainingParams params(*attrs, graph.getTensorMap()); // Epsilon should be extracted as double EXPECT_NEAR(params.epsilonValue(nullptr, 0), 1e-5, 1e-10); } TEST(TestBatchnormFwdTrainingParams, HandlesMeanVariancePresent) { auto builder = hipdnn_test_sdk::utilities::createValidBatchnormFwdTrainingGraph( {1, 3, 14, 14}, {1, 3, 14, 14}, true); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph( builder.GetBufferPointer(), builder.GetSize()); const auto& node = graph.getNode(0); auto* attrs = node.attributes_as_BatchnormAttributes(); ASSERT_NE(attrs, nullptr); const BatchnormFwdTrainingParams params(*attrs, graph.getTensorMap()); EXPECT_TRUE(params.hasSaveMeanVariance()); EXPECT_NO_THROW(params.mean()); EXPECT_NO_THROW(params.invVariance()); } TEST(TestBatchnormFwdTrainingParams, HandlesMeanVarianceMissing) { auto builder = hipdnn_test_sdk::utilities::createValidBatchnormFwdTrainingGraph( {1, 3, 14, 14}, {1, 3, 14, 14}, false); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph( builder.GetBufferPointer(), builder.GetSize()); const auto& node = graph.getNode(0); auto* attrs = node.attributes_as_BatchnormAttributes(); ASSERT_NE(attrs, nullptr); const BatchnormFwdTrainingParams params(*attrs, graph.getTensorMap()); EXPECT_FALSE(params.hasSaveMeanVariance()); } TEST(TestBatchnormFwdTrainingParams, HasRunningStatsReturnsFalseWhenNotProvided) { auto builder = hipdnn_test_sdk::utilities::createValidBatchnormFwdTrainingGraph(); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph( builder.GetBufferPointer(), builder.GetSize()); const auto& node = graph.getNode(0); auto* attrs = node.attributes_as_BatchnormAttributes(); ASSERT_NE(attrs, nullptr); const BatchnormFwdTrainingParams params(*attrs, graph.getTensorMap()); EXPECT_FALSE(params.hasRunningStats()); }