From 7eeba830f88ad9f60fce7a1fbf940764fe54c057 Mon Sep 17 00:00:00 2001 From: Graham Sider Date: Wed, 9 Mar 2022 10:47:27 -0500 Subject: [PATCH] kfdtest: Add KFDASMTest Includes a simple AssembleShader test which loops through all shaders for all supported targets, dispatching a RunAssemble call for each shader. Also adds extra safety on a couple shaders that only work on gfx9/gfx90a. Signed-off-by: Graham Sider Change-Id: I3ca1c92136f3871eb62fcb9645694f22287aaeec --- tests/kfdtest/CMakeLists.txt | 1 + tests/kfdtest/src/Assemble.hpp | 2 + tests/kfdtest/src/KFDASMTest.cpp | 73 +++++++++++++++++++++++++++++++ tests/kfdtest/src/KFDASMTest.hpp | 39 +++++++++++++++++ tests/kfdtest/src/ShaderStore.cpp | 48 +++++++++++++++----- tests/kfdtest/src/ShaderStore.hpp | 5 +++ 6 files changed, 157 insertions(+), 11 deletions(-) create mode 100644 tests/kfdtest/src/KFDASMTest.cpp create mode 100644 tests/kfdtest/src/KFDASMTest.hpp diff --git a/tests/kfdtest/CMakeLists.txt b/tests/kfdtest/CMakeLists.txt index b1208f54c2..a2b122d42b 100644 --- a/tests/kfdtest/CMakeLists.txt +++ b/tests/kfdtest/CMakeLists.txt @@ -169,6 +169,7 @@ set (SRC_FILES gtest-1.6.0/gtest-all.cpp src/KFDDBGTest.cpp src/KFDGWSTest.cpp src/KFDIPCTest.cpp + src/KFDASMTest.cpp src/KFDEvictTest.cpp src/KFDHWSTest.cpp diff --git a/tests/kfdtest/src/Assemble.hpp b/tests/kfdtest/src/Assemble.hpp index d61229a5a5..46fb946a84 100644 --- a/tests/kfdtest/src/Assemble.hpp +++ b/tests/kfdtest/src/Assemble.hpp @@ -43,6 +43,8 @@ #ifndef _ASSEMBLE_H_ #define _ASSEMBLE_H_ +#include "OSWrapper.hpp" + #define ASM_MCPU_LEN 16 class Assembler { diff --git a/tests/kfdtest/src/KFDASMTest.cpp b/tests/kfdtest/src/KFDASMTest.cpp new file mode 100644 index 0000000000..4b9f5d69c8 --- /dev/null +++ b/tests/kfdtest/src/KFDASMTest.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 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 "GoogleTestExtension.hpp" +#include "KFDASMTest.hpp" +#include "ShaderStore.hpp" +#include "Assemble.hpp" + +void KFDASMTest::SetUp() {} +void KFDASMTest::TearDown() {} + +static const std::vector TargetList = { + 0x080001, + 0x080002, + 0x080003, + 0x080005, + 0x080100, + 0x090000, + 0x090002, + 0x090004, + 0x090006, + 0x090008, + 0x090009, + 0x09000a, + 0x09000c, + 0x0a0100, + 0x0a0101, + 0x0a0102, + 0x0a0103, + 0x0a0300, + 0x0a0301, + 0x0a0302, + 0x0a0303, + 0x0a0304, + 0x0a0305, + 0x0a0306, +}; + +TEST_F(KFDASMTest, AssembleShaders) { + TEST_START(TESTPROFILE_RUNALL) + + for (auto &t : TargetList) { + Assembler asmblr(t); + + LOG() << "Running ASM test for target " << asmblr.GetTargetAsic() << std::endl; + + for (auto &s : ShaderList) { + EXPECT_SUCCESS(asmblr.RunAssemble(s)); + } + } + + TEST_END +} diff --git a/tests/kfdtest/src/KFDASMTest.hpp b/tests/kfdtest/src/KFDASMTest.hpp new file mode 100644 index 0000000000..5f601e165a --- /dev/null +++ b/tests/kfdtest/src/KFDASMTest.hpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 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. + * + */ + +#ifndef __KFD_ASM_TEST__H__ +#define __KFD_ASM_TEST__H__ + +#include + +class KFDASMTest : public testing::Test { + public: + KFDASMTest() {} + ~KFDASMTest() {} + + protected: + virtual void SetUp(); + virtual void TearDown(); +}; + +#endif // __KFD_ASM_TEST__H__ diff --git a/tests/kfdtest/src/ShaderStore.cpp b/tests/kfdtest/src/ShaderStore.cpp index 63cd68a063..8b40351f04 100644 --- a/tests/kfdtest/src/ShaderStore.cpp +++ b/tests/kfdtest/src/ShaderStore.cpp @@ -21,6 +21,30 @@ * */ +#include "ShaderStore.hpp" + +/** + * KFDASMTest List + */ + +const std::vector ShaderList = { + NoopIsa, + CopyDwordIsa, + InfiniteLoopIsa, + AtomicIncIsa, + ScratchCopyDwordIsa, + PollMemoryIsa, + CopyOnSignalIsa, + PollAndCopyIsa, + WriteFlagAndValueIsa, + WriteAndSignalIsa, + LoopIsa, + IterateIsa, + ReadMemoryIsa, + GwsInitIsa, + GwsAtomicIncreaseIsa, +}; + /** * Macros */ @@ -251,7 +275,7 @@ const char *PollAndCopyIsa = R"( s_store_dword s17, s[2:3], 0x0 glc s_waitcnt vmcnt(0) & lgkmcnt(0) buffer_wbl2 - .else + .elseif (.amdgcn.gfx_generation_number == 9) s_movk_i32 s18, 0x1 LOOP: s_load_dword s16, s[0:1], 0x0 glc @@ -277,16 +301,18 @@ const char *PollAndCopyIsa = R"( const char *WriteFlagAndValueIsa = R"( .text // Assume two inputs buffer in s[0:1] and s[2:3] - v_mov_b32 v0, s0 - v_mov_b32 v1, s1 - s_load_dword s18, s[2:3], 0x0 glc - s_waitcnt vmcnt(0) & lgkmcnt(0) - s_store_dword s18, s[0:1], 0x4 glc - s_waitcnt vmcnt(0) & lgkmcnt(0) - buffer_wbl2 - s_waitcnt vmcnt(0) & lgkmcnt(0) - v_mov_b32 v16, 0x1 - flat_store_dword v[0:1], v16 glc + .if (.amdgcn.gfx_generation_number == 9 && .amdgcn.gfx_generation_stepping == 10) + v_mov_b32 v0, s0 + v_mov_b32 v1, s1 + s_load_dword s18, s[2:3], 0x0 glc + s_waitcnt vmcnt(0) & lgkmcnt(0) + s_store_dword s18, s[0:1], 0x4 glc + s_waitcnt vmcnt(0) & lgkmcnt(0) + buffer_wbl2 + s_waitcnt vmcnt(0) & lgkmcnt(0) + v_mov_b32 v16, 0x1 + flat_store_dword v[0:1], v16 glc + .endif s_endpgm )"; diff --git a/tests/kfdtest/src/ShaderStore.hpp b/tests/kfdtest/src/ShaderStore.hpp index 231e7f73d6..e0151a6537 100644 --- a/tests/kfdtest/src/ShaderStore.hpp +++ b/tests/kfdtest/src/ShaderStore.hpp @@ -24,6 +24,11 @@ #ifndef _SHADERSTORE_H_ #define _SHADERSTORE_H_ +#include + +/* KFDASMTest List */ +extern const std::vector ShaderList; + /* Common */ extern const char *NoopIsa; extern const char *CopyDwordIsa;