From 6ef56f09f181de818e52de7dac0cd6796cb8600d Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Tue, 26 Oct 2021 13:53:22 +0000 Subject: [PATCH] SWDEV-304151 - Reset file descriptor after Module Load File descriptors opened during hipModuleLoad are not closed until hipModuleUnLoad. In large models, this exceeds the ulimit for no. of open file descriptors causing out of resource issues. Hence, close the file descriptors once the required data is read from the file, and not wait until unload. Change-Id: Ic50d424e5ca388715b1e6309a0de72a480321582 [ROCm/clr commit: 3b157b3d5f1eeb6cfd6cdb9ee2b329b867fb7718] --- projects/clr/hipamd/src/hip_code_object.cpp | 3 +++ projects/clr/hipamd/src/hip_fatbin.cpp | 15 +-------------- projects/clr/hipamd/src/hip_fatbin.hpp | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/projects/clr/hipamd/src/hip_code_object.cpp b/projects/clr/hipamd/src/hip_code_object.cpp index c719a68024..d36ad9e9e6 100644 --- a/projects/clr/hipamd/src/hip_code_object.cpp +++ b/projects/clr/hipamd/src/hip_code_object.cpp @@ -509,6 +509,9 @@ hipError_t DynCO::loadCodeObject(const char* fname, const void* image) { // Define Global functions IHIP_RETURN_ONFAIL(populateDynGlobalFuncs()); + // Resets the file info such as desc, size and name + // as they are not necessary once the code object is loaded + fb_info_->ResetFileInfo(); return hipSuccess; } diff --git a/projects/clr/hipamd/src/hip_fatbin.cpp b/projects/clr/hipamd/src/hip_fatbin.cpp index 04ae382bdf..5407cde476 100644 --- a/projects/clr/hipamd/src/hip_fatbin.cpp +++ b/projects/clr/hipamd/src/hip_fatbin.cpp @@ -29,20 +29,7 @@ FatBinaryInfo::~FatBinaryInfo() { delete fbd; } - if (fdesc_ > 0) { - if (fsize_ && !amd::Os::MemoryUnmapFile(image_, fsize_)) { - guarantee(false, "Cannot unmap file"); - } - if (!amd::Os::CloseFileHandle(fdesc_)) { - guarantee(false, "Cannot close file"); - } - } - - fname_ = std::string(); - fdesc_ = amd::Os::FDescInit(); - fsize_ = 0; - image_ = nullptr; - uri_ = std::string(); + ResetFileInfo(); } hipError_t FatBinaryInfo::ExtractFatBinary(const std::vector& devices) { diff --git a/projects/clr/hipamd/src/hip_fatbin.hpp b/projects/clr/hipamd/src/hip_fatbin.hpp index 219a96e802..4692f4d247 100644 --- a/projects/clr/hipamd/src/hip_fatbin.hpp +++ b/projects/clr/hipamd/src/hip_fatbin.hpp @@ -67,6 +67,24 @@ public: return hipSuccess; } + // Resets the file information + void ResetFileInfo() { + if (fdesc_ > 0) { + if (fsize_ && !amd::Os::MemoryUnmapFile(image_, fsize_)) { + guarantee(false, "Cannot unmap file"); + } + if (!amd::Os::CloseFileHandle(fdesc_)) { + guarantee(false, "Cannot close file"); + } + } + + fname_ = std::string(); + fdesc_ = amd::Os::FDescInit(); + fsize_ = 0; + image_ = nullptr; + uri_ = std::string(); + } + private: std::string fname_; // File name amd::Os::FileDesc fdesc_; // File descriptor