From ccb7c62b79c4877b76e384c834c3a7ff533b797e Mon Sep 17 00:00:00 2001 From: Graham Sider Date: Tue, 18 Apr 2023 10:48:02 -0400 Subject: [PATCH] kfdtest: Add Assembler::RunAssembleBuf overload Overload Assembler::RunAssembleBuf to take in an extra Gfxv parameter. Using this overload will temporarily set the target ASIC to Gfxv before calling RunAssemble, and copy back the original MCPU literal upon completion. The copy to reset the original MCPU in this case is safe as the MCPU length is always known. This will be useful in multi-device test cases whereby the devices are not necessarily the same gfx version. The overload is explicitly for the RunAssembleBuf wrapper rather than RunAssemble to ensure the default MCPU is always reset independent of errors in RunAssemble. Signed-off-by: Graham Sider Change-Id: I7fe5a962876314b6df32e4b7160174949d98f9e3 [ROCm/ROCR-Runtime commit: 54136f60a094589a233d2984ca8405d1d53c7b67] --- projects/rocr-runtime/tests/kfdtest/src/Assemble.cpp | 9 +++++++++ projects/rocr-runtime/tests/kfdtest/src/Assemble.hpp | 2 ++ 2 files changed, 11 insertions(+) diff --git a/projects/rocr-runtime/tests/kfdtest/src/Assemble.cpp b/projects/rocr-runtime/tests/kfdtest/src/Assemble.cpp index cf4b9e7de0..2077375ea2 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/Assemble.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/Assemble.cpp @@ -224,6 +224,7 @@ int Assembler::ExtractELFText(const char* RawData) { * @param AssemblySource Shader source represented as a raw C string * @param OutBuf Raw instruction stream output buffer * @param BufSize Size of OutBuf (defaults to PAGE_SIZE) + * @param Gfxv Optional overload to temporarily set target ASIC * @return Value of RunAssemble() (0 on success) */ int Assembler::RunAssembleBuf(const char* const AssemblySource, char* OutBuf, @@ -231,6 +232,14 @@ int Assembler::RunAssembleBuf(const char* const AssemblySource, char* OutBuf, int ret = RunAssemble(AssemblySource); return ret ? ret : CopyInstrStream(OutBuf, BufSize); } +int Assembler::RunAssembleBuf(const char* const AssemblySource, char* OutBuf, + const size_t BufSize, const uint32_t Gfxv) { + const char* defaultMCPU = GetTargetAsic(); + SetTargetAsic(Gfxv); + int ret = RunAssemble(AssemblySource); + strncpy(MCPU, defaultMCPU, ASM_MCPU_LEN); + return ret ? ret : CopyInstrStream(OutBuf, BufSize); +} /** * Assemble shader and fill member vars diff --git a/projects/rocr-runtime/tests/kfdtest/src/Assemble.hpp b/projects/rocr-runtime/tests/kfdtest/src/Assemble.hpp index 46fb946a84..a519129ed8 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/Assemble.hpp +++ b/projects/rocr-runtime/tests/kfdtest/src/Assemble.hpp @@ -81,6 +81,8 @@ class Assembler { int RunAssemble(const char* const AssemblySource); int RunAssembleBuf(const char* const AssemblySource, char* OutBuf, const size_t BufSize = PAGE_SIZE); + int RunAssembleBuf(const char* const AssemblySource, char* OutBuf, + const size_t BufSize, const uint32_t Gfxv); }; #endif // _ASSEMBLE_H_