P4 to Git Change 2033779 by kjayapra@0_HIPWS_LNX1_ROCM on 2019/11/20 07:17:56
SWDEV-144570 - Update function global during hipModuleLoad. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#47 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#48 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#50 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#69 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#35 edit
Šī revīzija ir iekļauta:
@@ -154,12 +154,13 @@ public:
|
||||
bool dyn_undef;
|
||||
};
|
||||
private:
|
||||
std::unordered_map<const void*, DeviceFunction > functions_;
|
||||
std::unordered_map<std::string, DeviceFunction > functions_;
|
||||
std::unordered_multimap<std::string, DeviceVar > vars_;
|
||||
|
||||
static PlatformState* platform_;
|
||||
|
||||
PlatformState() : lock_("Guards global function map") {}
|
||||
// the lock_ is recursive
|
||||
PlatformState() : lock_("Guards global function map", true) {}
|
||||
~PlatformState() {}
|
||||
public:
|
||||
static PlatformState& instance() {
|
||||
|
||||
@@ -114,6 +114,28 @@ extern bool __hipExtractCodeObjectFromFatBinary(const void* data,
|
||||
const std::vector<const char*>& devices,
|
||||
std::vector<std::pair<const void*, size_t>>& code_objs);
|
||||
|
||||
bool ihipModuleRegisterFunc(amd::Program* program, hipModule_t* module) {
|
||||
std::vector<std::string> func_names;
|
||||
device::Program* dev_program
|
||||
= program->getDeviceProgram(*hip::getCurrentContext()->devices()[0]);
|
||||
|
||||
if (!dev_program->getFuncsFromCodeObj(&func_names)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto it = func_names.begin(); it != func_names.end(); ++it) {
|
||||
auto modules = new std::vector<std::pair<hipModule_t, bool>>(g_devices.size());
|
||||
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
||||
modules->at(dev) = std::make_pair(*module, true);
|
||||
}
|
||||
|
||||
PlatformState::DeviceFunction dfunc{std::string{it->c_str()}, modules,
|
||||
std::vector<hipFunction_t>(g_devices.size())};
|
||||
PlatformState::instance().registerFunction(it->c_str(), dfunc);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool ihipModuleRegisterUndefined(amd::Program* program, hipModule_t* module) {
|
||||
|
||||
std::vector<std::string> undef_vars;
|
||||
@@ -125,7 +147,7 @@ bool ihipModuleRegisterUndefined(amd::Program* program, hipModule_t* module) {
|
||||
}
|
||||
|
||||
for (auto it = undef_vars.begin(); it != undef_vars.end(); ++it) {
|
||||
auto modules = new std::vector<std::pair<hipModule_t, bool> >{g_devices.size()};
|
||||
auto modules = new std::vector<std::pair<hipModule_t, bool> >(g_devices.size());
|
||||
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
||||
modules->at(dev) = std::make_pair(*module, true);
|
||||
}
|
||||
@@ -156,7 +178,7 @@ bool ihipModuleRegisterGlobal(amd::Program* program, hipModule_t* module) {
|
||||
}
|
||||
|
||||
for (auto it = var_names.begin(); it != var_names.end(); ++it) {
|
||||
auto modules = new std::vector<std::pair<hipModule_t, bool> >{g_devices.size()};
|
||||
auto modules = new std::vector<std::pair<hipModule_t, bool> >(g_devices.size());
|
||||
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
||||
modules->at(dev) = std::make_pair(*module, true);
|
||||
}
|
||||
@@ -196,6 +218,10 @@ hipError_t ihipModuleLoadData(hipModule_t *module, const void *image)
|
||||
return hipErrorSharedObjectSymbolNotFound;
|
||||
}
|
||||
|
||||
if (!ihipModuleRegisterFunc(program, module)) {
|
||||
return hipErrorSharedObjectSymbolNotFound;
|
||||
}
|
||||
|
||||
if(CL_SUCCESS != program->build(hip::getCurrentContext()->devices(), nullptr, nullptr, nullptr)) {
|
||||
return hipErrorSharedObjectInitFailed;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ extern "C" std::vector< std::pair<hipModule_t, bool> >* __hipRegisterFatBinary(c
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto programs = new std::vector< std::pair<hipModule_t, bool> >{g_devices.size()};
|
||||
auto programs = new std::vector< std::pair<hipModule_t, bool> >(g_devices.size());
|
||||
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
||||
amd::Context* ctx = g_devices[dev];
|
||||
amd::Program* program = new amd::Program(*ctx);
|
||||
@@ -231,7 +231,7 @@ void PlatformState::registerVar(const void* hostvar,
|
||||
void PlatformState::registerFunction(const void* hostFunction,
|
||||
const DeviceFunction& func) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
functions_.insert(std::make_pair(hostFunction, func));
|
||||
functions_.insert(std::make_pair(std::string(reinterpret_cast<const char*>(hostFunction)), func));
|
||||
}
|
||||
|
||||
bool ihipGetFuncAttributes(const char* func_name, amd::Program* program, hipFuncAttributes* func_attr) {
|
||||
@@ -272,7 +272,7 @@ bool CL_CALLBACK getSvarInfo(cl_program program, std::string var_name, void** va
|
||||
|
||||
hipFunction_t PlatformState::getFunc(const void* hostFunction, int deviceId) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
const auto it = functions_.find(hostFunction);
|
||||
const auto it = functions_.find(std::string(reinterpret_cast<const char*>(hostFunction)));
|
||||
if (it != functions_.cend()) {
|
||||
PlatformState::DeviceFunction& devFunc = it->second;
|
||||
if (devFunc.functions[deviceId] == 0) {
|
||||
@@ -302,12 +302,12 @@ hipFunction_t PlatformState::getFunc(const void* hostFunction, int deviceId) {
|
||||
|
||||
bool PlatformState::getFuncAttr(const void* hostFunction,
|
||||
hipFuncAttributes* func_attr) {
|
||||
|
||||
amd::ScopedLock lock(lock_);
|
||||
if (func_attr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto it = functions_.find(hostFunction);
|
||||
const auto it = functions_.find(std::string(reinterpret_cast<const char*>(hostFunction)));
|
||||
if (it == functions_.cend()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Atsaukties uz šo jaunā problēmā
Block a user