From c845b976d0e297c769f5ce8a5e31d9293464e5de Mon Sep 17 00:00:00 2001 From: Graham Sider Date: Fri, 24 Sep 2021 18:47:23 -0400 Subject: [PATCH] kfdtest: Update KFDCWSRTest to LLVM Asm - Reformat shaders for legibility - Move assembly processes to from IsaGen (CompileShader) to Assembler (RunAssembleBuf) Signed-off-by: Graham Sider Change-Id: I174f1ea5332c499440b30d9bcf06836274428a0f --- tests/kfdtest/src/KFDCWSRTest.cpp | 122 +++++++++++++----------------- tests/kfdtest/src/KFDCWSRTest.hpp | 4 +- 2 files changed, 54 insertions(+), 72 deletions(-) diff --git a/tests/kfdtest/src/KFDCWSRTest.cpp b/tests/kfdtest/src/KFDCWSRTest.cpp index e12e697566..c7a2e4b312 100644 --- a/tests/kfdtest/src/KFDCWSRTest.cpp +++ b/tests/kfdtest/src/KFDCWSRTest.cpp @@ -38,76 +38,63 @@ * v6 - counter */ -static const char* iterate_isa_gfx8 = \ -"\ -shader iterate_isa\n\ -wave_size(32)\n\ -type(CS)\n\ - // copy the parameters from scalar registers to vector registers\n\ - v_mov_b32 v2, s0 // v[2:3] = s[0:1] \n\ - v_mov_b32 v3, s1 // v[2:3] = s[0:1] \n\ - v_mov_b32 v0, s4 // use workgroup id as index \n\ - v_lshlrev_b32 v0, 2, v0 // v0 *= 4 \n\ - v_add_u32 v4, vcc, s2, v0 // v[4:5] = s[2:3] + v0 * 4 \n\ - v_mov_b32 v5, s3 // v[4:5] = s[2:3] + v0 * 4 \n\ - v_add_u32 v5, vcc, v5, vcc_lo // v[4:5] = s[2:3] + v0 * 4 \n\ - v_mov_b32 v6, 0 \n\ -LOOP: \n\ - v_add_u32 v6, vcc, 1, v6 \n\ - // compare the result value (v6) to iteration value (v2), and \n\ - // jump if equal (i.e. if VCC is not zero after the comparison) \n\ - v_cmp_lt_u32 vcc, v6, v2 \n\ - s_cbranch_vccnz LOOP \n\ - flat_store_dword v[4:5], v6 \n\ - s_waitcnt vmcnt(0)&lgkmcnt(0) \n\ - s_endpgm \n\ -end \n\ -"; +static const char* IterateIsa_gfx8 = R"( + .text + // Copy the parameters from scalar registers to vector registers + v_mov_b32 v2, s0 // v[2:3] = s[0:1] + v_mov_b32 v3, s1 // v[2:3] = s[0:1] + v_mov_b32 v0, s4 // use workgroup id as index + v_lshlrev_b32 v0, 2, v0 // v0 *= 4 + v_add_u32 v4, vcc, s2, v0 // v[4:5] = s[2:3] + v0 * 4 + v_mov_b32 v5, s3 // v[4:5] = s[2:3] + v0 * 4 + v_add_u32 v5, vcc, v5, vcc_lo // v[4:5] = s[2:3] + v0 * 4 + v_mov_b32 v6, 0 + LOOP: + v_add_u32 v6, vcc, 1, v6 + // Compare the result value (v6) to iteration value (v2), and + // jump if equal (i.e. if VCC is not zero after the comparison) + v_cmp_lt_u32 vcc, v6, v2 + s_cbranch_vccnz LOOP + flat_store_dword v[4:5], v6 + s_waitcnt vmcnt(0) & lgkmcnt(0) + s_endpgm +)"; -//This shader can be used by gfx9 and gfx10 -static const char* iterate_isa_gfx9 = \ -"\ -shader iterate_isa\n\ -wave_size(32)\n\ -type(CS)\n\ - // copy the parameters from scalar registers to vector registers\n\ - v_mov_b32 v2, s0 // v[2:3] = s[0:1] \n\ - v_mov_b32 v3, s1 // v[2:3] = s[0:1] \n\ - v_mov_b32 v0, s4 // use workgroup id as index \n\ - v_lshlrev_b32 v0, 2, v0 // v0 *= 4 \n\ - v_add_co_u32 v4, vcc, s2, v0 // v[4:5] = s[2:3] + v0 * 4 \n\ - v_mov_b32 v5, s3 // v[4:5] = s[2:3] + v0 * 4 \n\ - v_add_co_u32 v5, vcc, v5, vcc_lo // v[4:5] = s[2:3] + v0 * 4 \n\ - v_mov_b32 v6, 0 \n\ -LOOP: \n\ - v_add_co_u32 v6, vcc, 1, v6 \n\ - // compare the result value (v6) to iteration value (v2), and \n\ - // jump if equal (i.e. if VCC is not zero after the comparison) \n\ - v_cmp_lt_u32 vcc, v6, v2 \n\ - s_cbranch_vccnz LOOP \n\ - flat_store_dword v[4:5], v6 \n\ - s_waitcnt vmcnt(0)&lgkmcnt(0) \n\ - s_endpgm \n\ -end \n\ -"; +// This shader can be used by gfx9 and gfx10 +static const char* IterateIsa_gfx9 = R"( + .text + // Copy the parameters from scalar registers to vector registers + v_mov_b32 v2, s0 // v[2:3] = s[0:1] + v_mov_b32 v3, s1 // v[2:3] = s[0:1] + v_mov_b32 v0, s4 // use workgroup id as index + v_lshlrev_b32 v0, 2, v0 // v0 *= 4 + v_add_co_u32 v4, vcc, s2, v0 // v[4:5] = s[2:3] + v0 * 4 + v_mov_b32 v5, s3 // v[4:5] = s[2:3] + v0 * 4 + v_add_co_u32 v5, vcc, v5, vcc_lo // v[4:5] = s[2:3] + v0 * 4 + v_mov_b32 v6, 0 + LOOP: + v_add_co_u32 v6, vcc, 1, v6 + // Compare the result value (v6) to iteration value (v2), and + // jump if equal (i.e. if VCC is not zero after the comparison) + v_cmp_lt_u32 vcc, v6, v2 + s_cbranch_vccnz LOOP + flat_store_dword v[4:5], v6 + s_waitcnt vmcnt(0) & lgkmcnt(0) + s_endpgm +)"; -static const char* infinite_isa = \ -"\ -shader infinite_isa \n\ -wave_size(32) \n\ -type(CS) \n\ -LOOP: \n\ - s_branch LOOP \n\ -end \n\ -"; +static const char* InfiniteIsa = R"( + .text + LOOP: + s_branch LOOP + s_endpgm +)"; void KFDCWSRTest::SetUp() { ROUTINE_START KFDBaseComponentTest::SetUp(); - m_pIsaGen = IsaGenerator::Create(m_FamilyId); - wave_number = 1; ROUTINE_END @@ -115,9 +102,6 @@ void KFDCWSRTest::SetUp() { void KFDCWSRTest::TearDown() { ROUTINE_START - if (m_pIsaGen) - delete m_pIsaGen; - m_pIsaGen = NULL; KFDBaseComponentTest::TearDown(); @@ -159,9 +143,9 @@ TEST_F(KFDCWSRTest, BasicTest) { uint64_t count1 = 400000000; if (m_FamilyId < FAMILY_AI) - pIterateIsa = iterate_isa_gfx8; + pIterateIsa = IterateIsa_gfx8; else - pIterateIsa = iterate_isa_gfx9; + pIterateIsa = IterateIsa_gfx9; if (isOnEmulator()) { // Divide the iterator times by 10000 so that the test can @@ -172,7 +156,7 @@ TEST_F(KFDCWSRTest, BasicTest) { unsigned int* result1 = resultBuf1.As(); - m_pIsaGen->CompileShader(pIterateIsa, "iterate_isa", isaBuffer); + ASSERT_SUCCESS(m_pAsm->RunAssembleBuf(pIterateIsa, isaBuffer.As())); PM4Queue queue1; @@ -236,7 +220,7 @@ TEST_F(KFDCWSRTest, InterruptRestore) { if ((m_FamilyId >= FAMILY_VI) && (checkCWSREnabled())) { HsaMemoryBuffer isaBuffer(PAGE_SIZE, defaultGPUNode, true/*zero*/, false/*local*/, true/*exec*/); - m_pIsaGen->CompileShader(infinite_isa, "infinite_isa", isaBuffer); + ASSERT_SUCCESS(m_pAsm->RunAssembleBuf(InfiniteIsa, isaBuffer.As())); PM4Queue queue1, queue2, queue3; diff --git a/tests/kfdtest/src/KFDCWSRTest.hpp b/tests/kfdtest/src/KFDCWSRTest.hpp index 779180ea3d..53c925b0aa 100644 --- a/tests/kfdtest/src/KFDCWSRTest.hpp +++ b/tests/kfdtest/src/KFDCWSRTest.hpp @@ -27,12 +27,11 @@ #include #include "PM4Queue.hpp" -#include "IsaGenerator.hpp" #include "KFDBaseComponentTest.hpp" class KFDCWSRTest : public KFDBaseComponentTest { public: - KFDCWSRTest() :m_pIsaGen(NULL) {} + KFDCWSRTest() {} ~KFDCWSRTest() {} protected: @@ -41,7 +40,6 @@ class KFDCWSRTest : public KFDBaseComponentTest { protected: // Members unsigned wave_number; - IsaGenerator* m_pIsaGen; }; #endif // __KFD_CWSR_TEST__H__