/******************************************************************************* * * MIT License * * Copyright (C) 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 #include TEST(Predicates, ArithmeticIntensity) { using namespace TensileLite; ContractionProblemGemm a = ContractionProblemGemm::GEMM( false, true, 1000, 1500, 500, 2000, 2000, 2000, 3.0, false, 1); // 88.4 ContractionProblemGemm b = ContractionProblemGemm::GEMM( false, true, 500, 1000, 1000, 2000, 2000, 2000, 0.0, false, 5); // 125 ContractionProblemGemm c = ContractionProblemGemm::GEMM( false, true, 2000, 100, 2000, 2000, 2000, 2000, 1.0, false, 10); // 43.5 ContractionProblemGemm d = ContractionProblemGemm::GEMM( false, true, 2000, 2000, 450, 2000, 2000, 2000, 2.0, false, 1); // 92.04 auto pg1 = std::make_shared(100); auto pg2 = std::make_shared(75); auto pl1 = std::make_shared(100); auto pl2 = std::make_shared(75); EXPECT_EQ(false, (*pg1)(a)); EXPECT_EQ(true, (*pg2)(a)); EXPECT_EQ(true, (*pl1)(a)); EXPECT_EQ(false, (*pl2)(a)); EXPECT_EQ(true, (*pg1)(b)); EXPECT_EQ(true, (*pg2)(b)); EXPECT_EQ(false, (*pl1)(b)); EXPECT_EQ(false, (*pl2)(b)); EXPECT_EQ(false, (*pg1)(c)); EXPECT_EQ(false, (*pg2)(c)); EXPECT_EQ(true, (*pl1)(c)); EXPECT_EQ(true, (*pl2)(c)); EXPECT_EQ(false, (*pg1)(d)); EXPECT_EQ(true, (*pg2)(d)); EXPECT_EQ(true, (*pl1)(d)); EXPECT_EQ(false, (*pl2)(d)); } // ---------------------------------------------------------------------------- // WorkgroupMappingXCCCheck: CPU-only tests with injected cuCount (ROCM-2963). // These use the test-only constructor so we don't need a GPU. See // docs/solution-selection-unit-test-pattern.md. // ---------------------------------------------------------------------------- TEST(Predicates, WorkgroupMappingXCCCheck_38CU_XCC4_Fails) { using namespace TensileLite; // 38 % 4 != 0 -> predicate must reject (would have caught ROCM-2963). auto pred = std::make_shared( std::array{4, -1}, 38u); auto problem = ContractionProblemGemm::GEMM(false, false, 1024, 1024, 1024, 1024, 1024, 1024, 1.0, false, 1); EXPECT_FALSE((*pred)(problem)) << "38 CUs with XCC=4 should fail (38 % 4 != 0)"; } TEST(Predicates, WorkgroupMappingXCCCheck_38CU_XCC1_Passes) { using namespace TensileLite; // 38 % 1 == 0 -> predicate must accept (fix for ROCM-2963). auto pred = std::make_shared( std::array{1, -1}, 38u); auto problem = ContractionProblemGemm::GEMM(false, false, 1024, 1024, 1024, 1024, 1024, 1024, 1.0, false, 1); EXPECT_TRUE((*pred)(problem)) << "38 CUs with XCC=1 should pass (38 % 1 == 0)"; } TEST(Predicates, WorkgroupMappingXCCCheck_80CU_XCC4_Passes) { using namespace TensileLite; // 80 % 4 == 0 -> predicate must accept. auto pred = std::make_shared( std::array{4, -1}, 80u); auto problem = ContractionProblemGemm::GEMM(false, false, 1024, 1024, 1024, 1024, 1024, 1024, 1.0, false, 1); EXPECT_TRUE((*pred)(problem)) << "80 CUs with XCC=4 should pass (80 % 4 == 0)"; } TEST(Predicates, WorkgroupMappingXCCCheck_XCCMinus1_AlwaysPasses) { using namespace TensileLite; // value[0] == -1 means no check. auto pred = std::make_shared( std::array{-1, -1}, 38u); auto problem = ContractionProblemGemm::GEMM(false, false, 4, 4, 4, 4, 4, 4, 1.0, false, 1); EXPECT_TRUE((*pred)(problem)) << "XCC=-1 should always pass"; } TEST(Predicates, WorkgroupMappingXCCCheck_FallbackTreatsXCCAs1) { using namespace TensileLite; // When problem is cu-fallback, effective XCC is 1 so 38 % 1 == 0 -> pass. auto pred = std::make_shared( std::array{4, -1}, 38u); auto problem = ContractionProblemGemm::GEMM(false, false, 1024, 1024, 1024, 1024, 1024, 1024, 1.0, false, 1); problem.setParams().setFallbackStatus(true); EXPECT_TRUE((*pred)(problem)) << "With fallback status, effective XCC=1 so 38 % 1 == 0"; }