/******************************************************************************* * * MIT License * * Copyright (c) 2022 Advanced Micro Devices, Inc. * * 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 #include #include #include #include #include #include #include #include #include #include #include "tensor_util.hpp" #include "get_handle.hpp" #include "cba_find2.hpp" namespace cba_find2_infer { bool IsTestSupportedForDevice() { using e_mask = enabled; // gfx120X is not enabled due to WORKAROUND_SWDEV_479810 using d_mask = disabled; return ::IsTestSupportedForDevMask(); } struct GPU_ConvBiasActivFind2Infer_FP32 : ConvBiasActivInferFind2Test { }; struct GPU_ConvBiasActivFind2InferFusionFind_FP32 : ConvBiasActivInferFind2Test { }; struct GPU_ConvBiasActivFind2Infer_FP16 : ConvBiasActivInferFind2Test { }; template void RunSolver(miopen::FusedProblem& problem, const miopen::AnyInvokeParams& invoke_ctx, const TestCase& conv_config, bool& test_skipped) { auto& handle = get_handle(); Solver solv{}; const auto plan = problem.AsFusionPlan(); const auto fusion_desc = miopen::FusionDescription{&plan}; auto fusion_ctx = miopen::FusionContext{handle}; if(!solv.IsApplicable(fusion_ctx, fusion_desc)) { test_skipped = true; GTEST_SKIP() << solv.SolverDbId() << " Not Applicable" << conv_config; } ASSERT_TRUE(solv.IsApplicable(fusion_ctx, fusion_desc)); auto sol = solv.GetSolution(fusion_ctx, fusion_desc); ASSERT_TRUE(sol.Succeeded()); ASSERT_TRUE(sol.invoker_factory); const auto invoker = handle.PrepareInvoker(*sol.invoker_factory, sol.construction_params); (invoker)(handle, invoke_ctx); handle.Finish(); } template void RunTunableSolver(miopen::FusedProblem& problem, const miopen::AnyInvokeParams& invoke_ctx, const ConvTestCaseBase& conv_config, bool& test_skipped) { auto& handle = get_handle(); Solver solv{}; const auto plan = problem.AsFusionPlan(); const auto fusion_desc = miopen::FusionDescription{&plan}; auto fusion_ctx = miopen::FusionContext{handle}; if(!solv.IsApplicable(fusion_ctx, fusion_desc)) { test_skipped = true; GTEST_SKIP() << solv.SolverDbId() << " Not Applicable" << conv_config; } ASSERT_TRUE(solv.IsApplicable(fusion_ctx, fusion_desc)); auto sol = solv.GetSolution( fusion_ctx, fusion_desc, solv.GetDefaultPerformanceConfig(fusion_ctx, fusion_desc)); ASSERT_TRUE(sol.Succeeded()); ASSERT_TRUE(sol.invoker_factory); const auto invoker = handle.PrepareInvoker(*sol.invoker_factory, sol.construction_params); (invoker)(handle, invoke_ctx); handle.Finish(); } bool SkipTest() { return get_handle_xnack(); } } // namespace cba_find2_infer using namespace cba_find2_infer; TEST_P(GPU_ConvBiasActivFind2Infer_FP32, ConvBiasActivAsm1x1UFind2Float) { RunTunableSolver( fused_problem, invoke_params, conv_config, test_skipped); } TEST_P(GPU_ConvBiasActivFind2Infer_FP32, ConvHipDirectFwdFind2Fused) { RunTunableSolver( fused_problem, invoke_params, conv_config, test_skipped); } TEST_P(GPU_ConvBiasActivFind2Infer_FP32, ConvBinWinogradRxSFind2Fused) { RunSolver( fused_problem, invoke_params, conv_config, test_skipped); } TEST_P(GPU_ConvBiasActivFind2Infer_FP32, ConvBinWinogradRxSf2x3g1Find2Fused) { RunSolver( fused_problem, invoke_params, conv_config, test_skipped); } TEST_P(GPU_ConvBiasActivFind2Infer_FP16, ConvWinoFuryRxSf2x3Find2Fused) { RunSolver>( fused_problem, invoke_params, conv_config, test_skipped); } TEST_P(GPU_ConvBiasActivFind2Infer_FP16, ConvWinoRageRxSf2x3Find2Fused) { RunSolver>( fused_problem, invoke_params, conv_config, test_skipped); } TEST_P(GPU_ConvBiasActivFind2Infer_FP16, ConvCKIgemmFwdBiasActivFind2Fused) { RunTunableSolver( fused_problem, invoke_params, conv_config, test_skipped); } #if MIOPEN_BACKEND_HIP TEST_P(GPU_ConvBiasActivFind2InferFusionFind_FP32, ConvBiasActivFind2Float_testFind) { if(SkipTest()) { test_skipped = true; GTEST_SKIP() << "Fusion does not support xnack"; } if(!IsTestSupportedForDevice()) { test_skipped = true; GTEST_SKIP() << "Fusion not supported for this device"; } miopen::solver::debug::TuningIterationScopedLimiter tuning_limit{5}; std::vector solutions; auto options = miopen::FindOptions{}; options.find_enforce = miopen::FindEnforce{miopen::FindEnforceAction::SearchDbUpdate}; ASSERT_NO_THROW(solutions = fused_problem.FindSolutions(get_handle(), options, 10)); auto tensors = std::unordered_map{ {miopenTensorConvolutionX, in_dev.get()}, {miopenTensorConvolutionW, wei_dev.get()}, {miopenTensorActivationY, out_dev.get()}, {miopenTensorBias, bias_dev.get()}, }; Workspace wspace; for(auto& solution : solutions) { auto cur_sol_ws = solution.GetWorkspaceSize(); wspace.resize(cur_sol_ws); ASSERT_NO_THROW(solution.Run(get_handle(), tensors, wspace.ptr(), cur_sol_ws)); ValidateResult(); } } INSTANTIATE_TEST_SUITE_P( Full, GPU_ConvBiasActivFind2InferFusionFind_FP32, testing::Combine(testing::Values(miopenActivationRELU), testing::ValuesIn(GetNetworkForFusionCompileStepTest()), testing::Values(miopenTensorNCHW))); #endif INSTANTIATE_TEST_SUITE_P(Full, GPU_ConvBiasActivFind2Infer_FP32, testing::Combine(testing::Values(miopenActivationRELU), testing::ValuesIn(GetNetwork1()), testing::Values(miopenTensorNCHW))); INSTANTIATE_TEST_SUITE_P(Full, GPU_ConvBiasActivFind2Infer_FP16, testing::Combine(testing::Values(miopenActivationPASTHRU, miopenActivationLOGISTIC, miopenActivationTANH, miopenActivationRELU, miopenActivationLEAKYRELU), testing::ValuesIn(GetNetwork1()), testing::Values(miopenTensorNCHW)));