// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "CustomAssertions.hpp" #include "CustomSections.hpp" #include "TestContext.hpp" namespace ModelAddressesTest { using namespace rocRoller; using namespace rocRoller::KernelGraph; using namespace rocRoller::KernelGraph::ControlGraph; using namespace rocRoller::KernelGraph::CoordinateGraph; TEST_CASE("LDS Address Modelling", "[mem-addressing]") { struct Patterns { std::vector> load; std::vector> store; }; struct Variants { std::string name; Patterns patterns; decltype(GEMMProblem::padA) padA = GEMMProblem{}.padA; decltype(GEMMProblem::padB) padB = GEMMProblem{}.padB; }; Patterns noPaddingPatterns{ .load = {{0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 7936, 4, 260, 516, 772, 1028, 1284, 1540, 1796, 2052, 2308, 2564, 2820, 3076, 3332, 3588, 3844, 4100, 4356, 4612, 4868, 5124, 5380, 5636, 5892, 6148, 6404, 6660, 6916, 7172, 7428, 7684, 7940, 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 7936, 4, 260, 516, 772, 1028, 1284, 1540, 1796, 2052, 2308, 2564, 2820, 3076, 3332, 3588, 3844, 4100, 4356, 4612, 4868, 5124, 5380, 5636, 5892, 6148, 6404, 6660, 6916, 7172, 7428, 7684, 7940, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15616, 15872, 16128, 8196, 8452, 8708, 8964, 9220, 9476, 9732, 9988, 10244, 10500, 10756, 11012, 11268, 11524, 11780, 12036, 12292, 12548, 12804, 13060, 13316, 13572, 13828, 14084, 14340, 14596, 14852, 15108, 15364, 15620, 15876, 16132, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15616, 15872, 16128, 8196, 8452, 8708, 8964, 9220, 9476, 9732, 9988, 10244, 10500, 10756, 11012, 11268, 11524, 11780, 12036, 12292, 12548, 12804, 13060, 13316, 13572, 13828, 14084, 14340, 14596, 14852, 15108, 15364, 15620, 15876, 16132}, {0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 7936, 4, 260, 516, 772, 1028, 1284, 1540, 1796, 2052, 2308, 2564, 2820, 3076, 3332, 3588, 3844, 4100, 4356, 4612, 4868, 5124, 5380, 5636, 5892, 6148, 6404, 6660, 6916, 7172, 7428, 7684, 7940, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15616, 15872, 16128, 8196, 8452, 8708, 8964, 9220, 9476, 9732, 9988, 10244, 10500, 10756, 11012, 11268, 11524, 11780, 12036, 12292, 12548, 12804, 13060, 13316, 13572, 13828, 14084, 14340, 14596, 14852, 15108, 15364, 15620, 15876, 16132, 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 7936, 4, 260, 516, 772, 1028, 1284, 1540, 1796, 2052, 2308, 2564, 2820, 3076, 3332, 3588, 3844, 4100, 4356, 4612, 4868, 5124, 5380, 5636, 5892, 6148, 6404, 6660, 6916, 7172, 7428, 7684, 7940, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15616, 15872, 16128, 8196, 8452, 8708, 8964, 9220, 9476, 9732, 9988, 10244, 10500, 10756, 11012, 11268, 11524, 11780, 12036, 12292, 12548, 12804, 13060, 13316, 13572, 13828, 14084, 14340, 14596, 14852, 15108, 15364, 15620, 15876, 16132}}, .store = {{0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 1024, 1040, 1056, 1072, 1088, 1104, 1120, 1136, 1152, 1168, 1184, 1200, 1216, 1232, 1248, 1264, 2048, 2064, 2080, 2096, 2112, 2128, 2144, 2160, 2176, 2192, 2208, 2224, 2240, 2256, 2272, 2288, 3072, 3088, 3104, 3120, 3136, 3152, 3168, 3184, 3200, 3216, 3232, 3248, 3264, 3280, 3296, 3312, 4096, 4112, 4128, 4144, 4160, 4176, 4192, 4208, 4224, 4240, 4256, 4272, 4288, 4304, 4320, 4336, 5120, 5136, 5152, 5168, 5184, 5200, 5216, 5232, 5248, 5264, 5280, 5296, 5312, 5328, 5344, 5360, 6144, 6160, 6176, 6192, 6208, 6224, 6240, 6256, 6272, 6288, 6304, 6320, 6336, 6352, 6368, 6384, 7168, 7184, 7200, 7216, 7232, 7248, 7264, 7280, 7296, 7312, 7328, 7344, 7360, 7376, 7392, 7408, 8192, 8208, 8224, 8240, 8256, 8272, 8288, 8304, 8320, 8336, 8352, 8368, 8384, 8400, 8416, 8432, 9216, 9232, 9248, 9264, 9280, 9296, 9312, 9328, 9344, 9360, 9376, 9392, 9408, 9424, 9440, 9456, 10240, 10256, 10272, 10288, 10304, 10320, 10336, 10352, 10368, 10384, 10400, 10416, 10432, 10448, 10464, 10480, 11264, 11280, 11296, 11312, 11328, 11344, 11360, 11376, 11392, 11408, 11424, 11440, 11456, 11472, 11488, 11504, 12288, 12304, 12320, 12336, 12352, 12368, 12384, 12400, 12416, 12432, 12448, 12464, 12480, 12496, 12512, 12528, 13312, 13328, 13344, 13360, 13376, 13392, 13408, 13424, 13440, 13456, 13472, 13488, 13504, 13520, 13536, 13552, 14336, 14352, 14368, 14384, 14400, 14416, 14432, 14448, 14464, 14480, 14496, 14512, 14528, 14544, 14560, 14576, 15360, 15376, 15392, 15408, 15424, 15440, 15456, 15472, 15488, 15504, 15520, 15536, 15552, 15568, 15584, 15600}}}; Patterns yesPaddingPatterns{ .load = {{0, 256, 512, 768, 1024, 1280, 1536, 1792, 2052, 2308, 2564, 2820, 3076, 3332, 3588, 3844, 4104, 4360, 4616, 4872, 5128, 5384, 5640, 5896, 6156, 6412, 6668, 6924, 7180, 7436, 7692, 7948, 4, 260, 516, 772, 1028, 1284, 1540, 1796, 2056, 2312, 2568, 2824, 3080, 3336, 3592, 3848, 4108, 4364, 4620, 4876, 5132, 5388, 5644, 5900, 6160, 6416, 6672, 6928, 7184, 7440, 7696, 7952, 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2052, 2308, 2564, 2820, 3076, 3332, 3588, 3844, 4104, 4360, 4616, 4872, 5128, 5384, 5640, 5896, 6156, 6412, 6668, 6924, 7180, 7436, 7692, 7948, 4, 260, 516, 772, 1028, 1284, 1540, 1796, 2056, 2312, 2568, 2824, 3080, 3336, 3592, 3848, 4108, 4364, 4620, 4876, 5132, 5388, 5644, 5900, 6160, 6416, 6672, 6928, 7184, 7440, 7696, 7952, 8208, 8464, 8720, 8976, 9232, 9488, 9744, 10000, 10260, 10516, 10772, 11028, 11284, 11540, 11796, 12052, 12312, 12568, 12824, 13080, 13336, 13592, 13848, 14104, 14364, 14620, 14876, 15132, 15388, 15644, 15900, 16156, 8212, 8468, 8724, 8980, 9236, 9492, 9748, 10004, 10264, 10520, 10776, 11032, 11288, 11544, 11800, 12056, 12316, 12572, 12828, 13084, 13340, 13596, 13852, 14108, 14368, 14624, 14880, 15136, 15392, 15648, 15904, 16160, 8208, 8464, 8720, 8976, 9232, 9488, 9744, 10000, 10260, 10516, 10772, 11028, 11284, 11540, 11796, 12052, 12312, 12568, 12824, 13080, 13336, 13592, 13848, 14104, 14364, 14620, 14876, 15132, 15388, 15644, 15900, 16156, 8212, 8468, 8724, 8980, 9236, 9492, 9748, 10004, 10264, 10520, 10776, 11032, 11288, 11544, 11800, 12056, 12316, 12572, 12828, 13084, 13340, 13596, 13852, 14108, 14368, 14624, 14880, 15136, 15392, 15648, 15904, 16160}, {0, 256, 512, 768, 1028, 1284, 1540, 1796, 2056, 2312, 2568, 2824, 3084, 3340, 3596, 3852, 4112, 4368, 4624, 4880, 5140, 5396, 5652, 5908, 6168, 6424, 6680, 6936, 7196, 7452, 7708, 7964, 4, 260, 516, 772, 1032, 1288, 1544, 1800, 2060, 2316, 2572, 2828, 3088, 3344, 3600, 3856, 4116, 4372, 4628, 4884, 5144, 5400, 5656, 5912, 6172, 6428, 6684, 6940, 7200, 7456, 7712, 7968, 8224, 8480, 8736, 8992, 9252, 9508, 9764, 10020, 10280, 10536, 10792, 11048, 11308, 11564, 11820, 12076, 12336, 12592, 12848, 13104, 13364, 13620, 13876, 14132, 14392, 14648, 14904, 15160, 15420, 15676, 15932, 16188, 8228, 8484, 8740, 8996, 9256, 9512, 9768, 10024, 10284, 10540, 10796, 11052, 11312, 11568, 11824, 12080, 12340, 12596, 12852, 13108, 13368, 13624, 13880, 14136, 14396, 14652, 14908, 15164, 15424, 15680, 15936, 16192, 0, 256, 512, 768, 1028, 1284, 1540, 1796, 2056, 2312, 2568, 2824, 3084, 3340, 3596, 3852, 4112, 4368, 4624, 4880, 5140, 5396, 5652, 5908, 6168, 6424, 6680, 6936, 7196, 7452, 7708, 7964, 4, 260, 516, 772, 1032, 1288, 1544, 1800, 2060, 2316, 2572, 2828, 3088, 3344, 3600, 3856, 4116, 4372, 4628, 4884, 5144, 5400, 5656, 5912, 6172, 6428, 6684, 6940, 7200, 7456, 7712, 7968, 8224, 8480, 8736, 8992, 9252, 9508, 9764, 10020, 10280, 10536, 10792, 11048, 11308, 11564, 11820, 12076, 12336, 12592, 12848, 13104, 13364, 13620, 13876, 14132, 14392, 14648, 14904, 15160, 15420, 15676, 15932, 16188, 8228, 8484, 8740, 8996, 9256, 9512, 9768, 10024, 10284, 10540, 10796, 11052, 11312, 11568, 11824, 12080, 12340, 12596, 12852, 13108, 13368, 13624, 13880, 14136, 14396, 14652, 14908, 15164, 15424, 15680, 15936, 16192}}, .store = {{0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 1024, 1040, 1056, 1072, 1088, 1104, 1120, 1136, 1152, 1168, 1184, 1200, 1216, 1232, 1248, 1264, 2052, 2068, 2084, 2100, 2116, 2132, 2148, 2164, 2180, 2196, 2212, 2228, 2244, 2260, 2276, 2292, 3076, 3092, 3108, 3124, 3140, 3156, 3172, 3188, 3204, 3220, 3236, 3252, 3268, 3284, 3300, 3316, 4104, 4120, 4136, 4152, 4168, 4184, 4200, 4216, 4232, 4248, 4264, 4280, 4296, 4312, 4328, 4344, 5128, 5144, 5160, 5176, 5192, 5208, 5224, 5240, 5256, 5272, 5288, 5304, 5320, 5336, 5352, 5368, 6156, 6172, 6188, 6204, 6220, 6236, 6252, 6268, 6284, 6300, 6316, 6332, 6348, 6364, 6380, 6396, 7180, 7196, 7212, 7228, 7244, 7260, 7276, 7292, 7308, 7324, 7340, 7356, 7372, 7388, 7404, 7420, 8208, 8224, 8240, 8256, 8272, 8288, 8304, 8320, 8336, 8352, 8368, 8384, 8400, 8416, 8432, 8448, 9232, 9248, 9264, 9280, 9296, 9312, 9328, 9344, 9360, 9376, 9392, 9408, 9424, 9440, 9456, 9472, 10260, 10276, 10292, 10308, 10324, 10340, 10356, 10372, 10388, 10404, 10420, 10436, 10452, 10468, 10484, 10500, 11284, 11300, 11316, 11332, 11348, 11364, 11380, 11396, 11412, 11428, 11444, 11460, 11476, 11492, 11508, 11524, 12312, 12328, 12344, 12360, 12376, 12392, 12408, 12424, 12440, 12456, 12472, 12488, 12504, 12520, 12536, 12552, 13336, 13352, 13368, 13384, 13400, 13416, 13432, 13448, 13464, 13480, 13496, 13512, 13528, 13544, 13560, 13576, 14364, 14380, 14396, 14412, 14428, 14444, 14460, 14476, 14492, 14508, 14524, 14540, 14556, 14572, 14588, 14604, 15388, 15404, 15420, 15436, 15452, 15468, 15484, 15500, 15516, 15532, 15548, 15564, 15580, 15596, 15612, 15628}, {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 1028, 1044, 1060, 1076, 1092, 1108, 1124, 1140, 1156, 1172, 1188, 1204, 1220, 1236, 1252, 1268, 2056, 2072, 2088, 2104, 2120, 2136, 2152, 2168, 2184, 2200, 2216, 2232, 2248, 2264, 2280, 2296, 3084, 3100, 3116, 3132, 3148, 3164, 3180, 3196, 3212, 3228, 3244, 3260, 3276, 3292, 3308, 3324, 4112, 4128, 4144, 4160, 4176, 4192, 4208, 4224, 4240, 4256, 4272, 4288, 4304, 4320, 4336, 4352, 5140, 5156, 5172, 5188, 5204, 5220, 5236, 5252, 5268, 5284, 5300, 5316, 5332, 5348, 5364, 5380, 6168, 6184, 6200, 6216, 6232, 6248, 6264, 6280, 6296, 6312, 6328, 6344, 6360, 6376, 6392, 6408, 7196, 7212, 7228, 7244, 7260, 7276, 7292, 7308, 7324, 7340, 7356, 7372, 7388, 7404, 7420, 7436, 8224, 8240, 8256, 8272, 8288, 8304, 8320, 8336, 8352, 8368, 8384, 8400, 8416, 8432, 8448, 8464, 9252, 9268, 9284, 9300, 9316, 9332, 9348, 9364, 9380, 9396, 9412, 9428, 9444, 9460, 9476, 9492, 10280, 10296, 10312, 10328, 10344, 10360, 10376, 10392, 10408, 10424, 10440, 10456, 10472, 10488, 10504, 10520, 11308, 11324, 11340, 11356, 11372, 11388, 11404, 11420, 11436, 11452, 11468, 11484, 11500, 11516, 11532, 11548, 12336, 12352, 12368, 12384, 12400, 12416, 12432, 12448, 12464, 12480, 12496, 12512, 12528, 12544, 12560, 12576, 13364, 13380, 13396, 13412, 13428, 13444, 13460, 13476, 13492, 13508, 13524, 13540, 13556, 13572, 13588, 13604, 14392, 14408, 14424, 14440, 14456, 14472, 14488, 14504, 14520, 14536, 14552, 14568, 14584, 14600, 14616, 14632, 15420, 15436, 15452, 15468, 15484, 15500, 15516, 15532, 15548, 15564, 15580, 15596, 15612, 15628, 15644, 15660}}}; const auto variants = GENERATE_COPY( Variants{"No padding", noPaddingPatterns}, Variants{"Yes padding", yesPaddingPatterns, {32 * 64, 4}, {16 * 64, 4}}); SECTION(variants.name) { auto context = TestContext::ForTestDevice( {{.dsObserver = DSObserverType::WeightlessDSMemObserver}}, variants.name); auto const& arch = context->targetArchitecture(); if(!arch.HasCapability(GPUCapability::HasMFMA)) { SKIP("The asserted pattern is only true for MFMA archs"); } auto example = rocRollerTest::Graphs::GEMM(DataType::Float); example.setUseLDS(true, true, false); example.setTranspose("T", "N"); example.setPad(variants.padA, variants.padB); auto command = example.getCommand(); auto params = example.getCommandParameters(); CommandKernel commandKernel(command, context.KernelName()); commandKernel.setContext(context.get()); commandKernel.setCommandParameters(params); commandKernel.generateKernelGraph(); auto graph = commandKernel.getKernelGraph(); for(auto inst : kernelInstructions(context.get(), command, graph)) { context.get()->schedule(inst); if(GPUInstructionInfo::isLDS(inst.getOpCode())) { REQUIRE(inst.getModelledAddresses().has_value()); } if(inst.getModelledAddresses().has_value()) { auto addresses = inst.getModelledAddresses().value(); auto opCode = inst.getOpCode(); INFO(addresses); INFO(opCode); auto matchesAny = [&](auto const& validPatterns) { return std::any_of(validPatterns.begin(), validPatterns.end(), [&](auto const& p) { return addresses == p; }); }; if(opCode.find("ds_read") != std::string::npos) { CHECK(matchesAny(variants.patterns.load)); } else if(opCode.find("ds_write") != std::string::npos) { CHECK(matchesAny(variants.patterns.store)); } else if(!opCode.empty()) { FAIL("LDS instruction with modelled addresses not classified as ds_read or " "ds_write: " + opCode); } } } // Kernel best be launchable to inspect registers in rocgdb auto [commandArgs, deviceA, deviceB, deviceC, deviceD] = example.getCommandArguments(context.get()); commandKernel.launchKernel(commandArgs.runtimeArguments()); /* KERNEL_NAME="LDS_Address_Modelling_Yes_padding" rocgdb -x ../scripts/rocgdb_print_lds_instr_addrs.py --args test/rocroller-tests-catch "LDS Address Modelling" -c "Yes padding" | python ../scripts/parse_rocgdb_registers.py KERNEL_NAME="LDS_Address_Modelling_No_padding" rocgdb -x ../scripts/rocgdb_print_lds_instr_addrs.py --args test/rocroller-tests-catch "LDS Address Modelling" -c "No padding" | python ../scripts/parse_rocgdb_registers.py */ } } }