kfdtest: Separate LLVM initialization and instantiation
Assembler function from LLVM is not multi-thread safe and is ASIC dependent. To extend kfdtest to test on multiple GPU separate LLVM initialization and assembler instantiation. Each test uses its own assembler. Signed-off-by: Xiaogang Chen <Xiaogang.Chen@amd.com> Change-Id: I94c996e807b81d8b19361b450be985b12042477c
This commit is contained in:
committed by
Xiaogang Chen
parent
5da1889fb7
commit
e1fdd6fb5f
@@ -79,16 +79,29 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
/* Assembler implementation is not multi-thread safe and is
|
||||
* asic type dependent. Instantiate it per thread/gpu use case,
|
||||
* delete each assembler after assembling
|
||||
*/
|
||||
|
||||
void Init_LLVM() {
|
||||
LLVMInitializeAMDGPUTargetInfo();
|
||||
LLVMInitializeAMDGPUTargetMC();
|
||||
LLVMInitializeAMDGPUAsmParser();
|
||||
}
|
||||
|
||||
void Shutdown_LLVM() {
|
||||
llvm_shutdown();
|
||||
}
|
||||
|
||||
Assembler::Assembler(const uint32_t Gfxv) {
|
||||
SetTargetAsic(Gfxv);
|
||||
TextData = nullptr;
|
||||
TextSize = 0;
|
||||
LLVMInit();
|
||||
}
|
||||
|
||||
Assembler::~Assembler() {
|
||||
FlushText();
|
||||
llvm_shutdown();
|
||||
}
|
||||
|
||||
const char* Assembler::GetInstrStream() {
|
||||
@@ -123,15 +136,6 @@ void Assembler::SetTargetAsic(const uint32_t Gfxv) {
|
||||
snprintf(MCPU, ASM_MCPU_LEN, "gfx%d%d%x", Major, Minor, Step);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize LLVM targets and assembly printers/parsers
|
||||
*/
|
||||
void Assembler::LLVMInit() {
|
||||
LLVMInitializeAMDGPUTargetInfo();
|
||||
LLVMInitializeAMDGPUTargetMC();
|
||||
LLVMInitializeAMDGPUAsmParser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush/reset TextData and TextSize to initial state
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,11 @@
|
||||
|
||||
#define ASM_MCPU_LEN 16
|
||||
|
||||
/* initialize LLVM targets and assembly printers/parsers */
|
||||
void Init_LLVM();
|
||||
/* shutdown LLVM */
|
||||
void Shutdown_LLVM();
|
||||
|
||||
class Assembler {
|
||||
private:
|
||||
const char* ArchName = "amdgcn";
|
||||
@@ -62,7 +67,6 @@ class Assembler {
|
||||
|
||||
void SetTargetAsic(const uint32_t Gfxv);
|
||||
|
||||
void LLVMInit();
|
||||
void FlushText();
|
||||
void PrintELFHex(const std::string Data);
|
||||
int ExtractELFText(const char* RawData);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "KFDTestUtil.hpp"
|
||||
#include "GoogleTestExtension.hpp"
|
||||
#include "OSWrapper.hpp"
|
||||
#include "Assemble.hpp"
|
||||
|
||||
#define KFD_TEST_DEFAULT_TIMEOUT 60000
|
||||
|
||||
@@ -72,6 +73,7 @@ GTEST_API_ int main(int argc, char **argv) {
|
||||
bool success = GetCommandLineArguments(argc, argv, args);
|
||||
|
||||
if (success) {
|
||||
int r;
|
||||
if ((GetHwCapabilityHWS() || args.HwsEnabled == HWCAP__FORCE_ENABLED) &&
|
||||
(args.HwsEnabled != HWCAP__FORCE_DISABLED))
|
||||
g_TestENVCaps |= ENVCAPS_HWSCHEDULING;
|
||||
@@ -104,6 +106,15 @@ GTEST_API_ int main(int argc, char **argv) {
|
||||
LOG() << "Sleep time in seconds as specified by user: " << std::dec << g_SleepTime << std::endl;
|
||||
}
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
/* init LLVM one time*/
|
||||
Init_LLVM();
|
||||
|
||||
r = RUN_ALL_TESTS();
|
||||
|
||||
/* shutdown LLVM after tests finish */
|
||||
Shutdown_LLVM();
|
||||
|
||||
LOG() << "kfdtest finished with return code: " << r << std::endl;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user