P4 to Git Change 2005774 by kjayapra@3_HIPWS_P2P_ROCM2 on 2019/09/27 17:54:03
SWDEV-144570 - Adding extern var support for dynamically loaded modules for Texture reference. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#43 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#42 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#43 edit
Этот коммит содержится в:
@@ -149,6 +149,7 @@ public:
|
||||
size_t size;
|
||||
std::vector< std::pair< hipModule_t, bool > >* modules;
|
||||
std::vector<RegisteredVar> rvars;
|
||||
bool dyn_undef;
|
||||
};
|
||||
private:
|
||||
std::unordered_map<const void*, DeviceFunction > functions_;
|
||||
@@ -172,6 +173,8 @@ public:
|
||||
bool getFuncAttr(const void* hostFunction, hipFuncAttributes* func_attr);
|
||||
bool getGlobalVar(const void* hostVar, int deviceId, hipDeviceptr_t* dev_ptr,
|
||||
size_t* size_ptr);
|
||||
bool getTexRef(const char* hostVar, textureReference** texRef);
|
||||
|
||||
bool getShadowVarInfo(std::string var_name, void** var_addr, size_t* var_size);
|
||||
void setupArgument(const void *arg, size_t size, size_t offset);
|
||||
void configureCall(dim3 gridDim, dim3 blockDim, size_t sharedMem, hipStream_t stream);
|
||||
|
||||
@@ -109,6 +109,34 @@ extern bool __hipExtractCodeObjectFromFatBinary(const void* data,
|
||||
const std::vector<const char*>& devices,
|
||||
std::vector<std::pair<const void*, size_t>>& code_objs);
|
||||
|
||||
bool ihipModuleRegisterUndefined(amd::Program* program, hipModule_t* module) {
|
||||
|
||||
std::vector<std::string> undef_vars;
|
||||
device::Program* dev_program
|
||||
= program->getDeviceProgram(*hip::getCurrentContext()->devices()[0]);
|
||||
|
||||
if (!dev_program->getUndefinedVarFromCodeObj(&undef_vars)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto it = undef_vars.begin(); it != undef_vars.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);
|
||||
}
|
||||
|
||||
texture<float, hipTextureType1D, hipReadModeElementType>* tex_hptr
|
||||
= new texture<float, hipTextureType1D, hipReadModeElementType>();
|
||||
memset(tex_hptr, 0x00, sizeof(texture<float, hipTextureType1D, hipReadModeElementType>));
|
||||
|
||||
PlatformState::DeviceVar dvar{ reinterpret_cast<char*>(tex_hptr), it->c_str(), sizeof(*tex_hptr), modules,
|
||||
std::vector<PlatformState::RegisteredVar>{ g_devices.size()}, true };
|
||||
PlatformState::instance().registerVar(it->c_str(), dvar);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ihipModuleRegisterGlobal(amd::Program* program, hipModule_t* module) {
|
||||
|
||||
size_t var_size = 0;
|
||||
@@ -125,11 +153,11 @@ 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()};
|
||||
for (size_t dev = 0; dev < g_devices.size(); ++dev) {
|
||||
modules->at(dev) = std::make_pair(*module, false);
|
||||
modules->at(dev) = std::make_pair(*module, true);
|
||||
}
|
||||
|
||||
PlatformState::DeviceVar dvar{nullptr, it->c_str(), 0, modules,
|
||||
std::vector<PlatformState::RegisteredVar>{ g_devices.size()} };
|
||||
std::vector<PlatformState::RegisteredVar>{ g_devices.size()}, false };
|
||||
PlatformState::instance().registerVar(it->c_str(), dvar);
|
||||
}
|
||||
|
||||
@@ -149,8 +177,7 @@ hipError_t ihipModuleLoadData(hipModule_t *module, const void *image)
|
||||
|
||||
program->setVarInfoCallBack(&getSvarInfo);
|
||||
|
||||
if (CL_SUCCESS != program->addDeviceProgram(*hip::getCurrentContext()->devices()[0], image, ElfSize(image)) ||
|
||||
CL_SUCCESS != program->build(hip::getCurrentContext()->devices(), nullptr, nullptr, nullptr)) {
|
||||
if (CL_SUCCESS != program->addDeviceProgram(*hip::getCurrentContext()->devices()[0], image, ElfSize(image))) {
|
||||
return hipErrorUnknown;
|
||||
}
|
||||
|
||||
@@ -160,6 +187,14 @@ hipError_t ihipModuleLoadData(hipModule_t *module, const void *image)
|
||||
return hipErrorUnknown;
|
||||
}
|
||||
|
||||
if (!ihipModuleRegisterUndefined(program, module)) {
|
||||
return hipErrorUnknown;
|
||||
}
|
||||
|
||||
if(CL_SUCCESS != program->build(hip::getCurrentContext()->devices(), nullptr, nullptr, nullptr)) {
|
||||
return hipErrorUnknown;
|
||||
}
|
||||
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
@@ -446,21 +481,16 @@ hipError_t hipExtLaunchMultiKernelMultiDevice(hipLaunchParams* launchParamsList,
|
||||
hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const char* name) {
|
||||
HIP_INIT_API(texRef, hmod, name);
|
||||
|
||||
hipDeviceptr_t dptr = nullptr;
|
||||
size_t bytes = 0;
|
||||
|
||||
/* input args check */
|
||||
if ((texRef == nullptr) || (name == nullptr)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
/* Get address and size for the global symbol */
|
||||
if (!PlatformState::instance().getGlobalVar(name, ihipGetDevice(), &dptr,
|
||||
&bytes)) {
|
||||
if (!PlatformState::instance().getTexRef(name, texRef)) {
|
||||
HIP_RETURN(hipErrorUnknown);
|
||||
}
|
||||
|
||||
*texRef = reinterpret_cast<textureReference*>(dptr);
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,6 +173,11 @@ std::vector< std::pair<hipModule_t, bool> >* PlatformState::unregisterVar(hipMod
|
||||
DeviceVar& dvar = it->second;
|
||||
if ((*dvar.modules)[0].first == hmod) {
|
||||
rmodules = dvar.modules;
|
||||
if (dvar.dyn_undef) {
|
||||
texture<float, hipTextureType1D, hipReadModeElementType>* tex_hptr
|
||||
= reinterpret_cast<texture<float, hipTextureType1D, hipReadModeElementType> *>(dvar.shadowVptr);
|
||||
delete tex_hptr;
|
||||
}
|
||||
vars_.erase(it++);
|
||||
} else {
|
||||
++it;
|
||||
@@ -287,6 +292,22 @@ bool PlatformState::getFuncAttr(const void* hostFunction,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformState::getTexRef(const char* hostVar, textureReference** texRef) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
const auto it = vars_.find(std::string(reinterpret_cast<const char*>(hostVar)));
|
||||
if (it == vars_.cend()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DeviceVar& dvar = it->second;
|
||||
if (!dvar.dyn_undef) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*texRef = reinterpret_cast<textureReference *>(dvar.shadowVptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformState::getGlobalVar(const void* hostVar, int deviceId,
|
||||
hipDeviceptr_t* dev_ptr, size_t* size_ptr) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
@@ -380,7 +401,7 @@ extern "C" void __hipRegisterVar(
|
||||
HIP_INIT();
|
||||
|
||||
PlatformState::DeviceVar dvar{var, std::string{ hostVar }, static_cast<size_t>(size), modules,
|
||||
std::vector<PlatformState::RegisteredVar>{ g_devices.size() } };
|
||||
std::vector<PlatformState::RegisteredVar>{ g_devices.size() }, false };
|
||||
|
||||
PlatformState::instance().registerVar(hostVar, dvar);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user