2016-07-21 12:41:26 -04:00
|
|
|
#include "roccompilerlib.hpp"
|
|
|
|
|
#include "utils/flags.hpp"
|
|
|
|
|
|
|
|
|
|
#include "acl.h"
|
|
|
|
|
|
|
|
|
|
namespace roc {
|
|
|
|
|
|
2017-03-14 16:47:51 -04:00
|
|
|
void* g_complibModule = nullptr;
|
2016-07-21 12:41:26 -04:00
|
|
|
struct CompLibApi g_complibApi;
|
|
|
|
|
|
|
|
|
|
//
|
2017-04-13 13:56:38 -04:00
|
|
|
// g_complibModule is defined in LoadCompLib(). This macro must be used only in LoadCompLib()
|
|
|
|
|
// function.
|
2016-07-21 12:41:26 -04:00
|
|
|
//
|
2017-07-13 14:18:44 -04:00
|
|
|
#if defined(BUILD_HSA_TARGET)
|
2017-04-13 13:56:38 -04:00
|
|
|
#define LOADSYMBOL(api) \
|
|
|
|
|
g_complibApi._##api = (pfn_##api)amd::Os::getSymbol(g_complibModule, #api); \
|
|
|
|
|
if (g_complibApi._##api == nullptr) { \
|
|
|
|
|
LogError("amd::Os::getSymbol() for exported func " #api " failed."); \
|
|
|
|
|
amd::Os::unloadLibrary(g_complibModule); \
|
|
|
|
|
return false; \
|
|
|
|
|
}
|
2017-07-13 14:18:44 -04:00
|
|
|
#else // !defined(BUILD_HSA_TARGET)
|
|
|
|
|
#define LOADSYMBOL(api) g_complibApi._##api = (pfn_##api)&(api);
|
|
|
|
|
#endif // !defined(BUILD_HSA_TARGET)
|
2017-04-13 13:56:38 -04:00
|
|
|
|
|
|
|
|
bool LoadCompLib(bool offline) {
|
2017-07-13 14:18:44 -04:00
|
|
|
#if defined(BUILD_HSA_TARGET)
|
2017-04-13 13:56:38 -04:00
|
|
|
g_complibModule = amd::Os::loadLibrary("amdhsacl" LP64_SWITCH(LINUX_SWITCH("32", ""), "64"));
|
|
|
|
|
if (g_complibModule == nullptr) {
|
|
|
|
|
if (!offline) {
|
|
|
|
|
LogError("amd::Os::loadLibrary() for loading of amdhsacl.dll failed.");
|
2016-07-21 12:41:26 -04:00
|
|
|
}
|
2017-04-13 13:56:38 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-07-13 14:18:44 -04:00
|
|
|
#endif // defined(BUILD_HSA_TARGET)
|
2017-04-13 13:56:38 -04:00
|
|
|
|
|
|
|
|
LOADSYMBOL(aclCompilerInit)
|
|
|
|
|
LOADSYMBOL(aclGetTargetInfo)
|
|
|
|
|
LOADSYMBOL(aclBinaryInit)
|
|
|
|
|
LOADSYMBOL(aclInsertSection)
|
|
|
|
|
LOADSYMBOL(aclCompile)
|
|
|
|
|
LOADSYMBOL(aclCompilerFini)
|
|
|
|
|
LOADSYMBOL(aclBinaryFini)
|
|
|
|
|
LOADSYMBOL(aclWriteToMem)
|
|
|
|
|
LOADSYMBOL(aclQueryInfo)
|
|
|
|
|
LOADSYMBOL(aclExtractSymbol)
|
|
|
|
|
LOADSYMBOL(aclGetCompilerLog)
|
|
|
|
|
LOADSYMBOL(aclCreateFromBinary)
|
|
|
|
|
LOADSYMBOL(aclReadFromMem)
|
|
|
|
|
LOADSYMBOL(aclBinaryVersion)
|
|
|
|
|
LOADSYMBOL(aclLink)
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-07-21 12:41:26 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
void UnloadCompLib() {
|
|
|
|
|
if (g_complibModule) {
|
|
|
|
|
amd::Os::unloadLibrary(g_complibModule);
|
|
|
|
|
}
|
2016-07-21 12:41:26 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
} // namespace roc
|