diff --git a/projects/clr/rocclr/runtime/device/appprofile.cpp b/projects/clr/rocclr/runtime/device/appprofile.cpp index c32bc0a701..fdf40906c9 100644 --- a/projects/clr/rocclr/runtime/device/appprofile.cpp +++ b/projects/clr/rocclr/runtime/device/appprofile.cpp @@ -134,7 +134,7 @@ bool ADL::init() { #endif // BRAHMA AppProfile::AppProfile() : gpuvmHighAddr_(false), profileOverridesAllSettings_(false) { - appFileName_ = amd::Os::getAppFileName(); + amd::Os::getAppPathAndFileName(appFileName_, appPathAndFileName_); propertyDataMap_.insert( DataMap::value_type("BuildOptsAppend", PropertyData(DataType_String, &buildOptsAppend_))); } @@ -148,7 +148,8 @@ bool AppProfile::init() { // Convert appName to wide char for X2_Search ADL interface size_t strLength = appFileName_.length() + 1; - wchar_t* appName = new wchar_t[strLength]; + size_t strPathLength = appPathAndFileName_.length() + 1; + wchar_t* appName = new wchar_t[strPathLength]; size_t success = mbstowcs(appName, appFileName_.c_str(), strLength); if (success > 0) { @@ -158,6 +159,14 @@ bool AppProfile::init() { wsAppFileName_ = appName; + success = mbstowcs(appName, appPathAndFileName_.c_str(), strPathLength); + if (success > 0) { + // mbstowcs was able to convert to wide character successfully. + appName[strPathLength - 1] = L'\0'; + } + + wsAppPathAndFileName_ = appName; + delete[] appName; ParseApplicationProfile(); diff --git a/projects/clr/rocclr/runtime/device/appprofile.hpp b/projects/clr/rocclr/runtime/device/appprofile.hpp index e2bca4a408..fb651b3dbc 100644 --- a/projects/clr/rocclr/runtime/device/appprofile.hpp +++ b/projects/clr/rocclr/runtime/device/appprofile.hpp @@ -19,6 +19,7 @@ class AppProfile { const std::string& GetBuildOptsAppend() const { return buildOptsAppend_; } const std::string& appFileName() const { return appFileName_; } + const std::wstring& wsAppPathAndFileName() const { return wsAppPathAndFileName_; } protected: enum DataTypes { @@ -38,6 +39,8 @@ class AppProfile { DataMap propertyDataMap_; std::string appFileName_; // without extension std::wstring wsAppFileName_; + std::string appPathAndFileName_; // with path and extension + std::wstring wsAppPathAndFileName_; virtual bool ParseApplicationProfile(); diff --git a/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp b/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp index bce0b937b9..ef80455ddd 100644 --- a/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp @@ -14,6 +14,7 @@ #include "device/pal/paltimestamp.hpp" #include "device/pal/palblit.hpp" #include "device/pal/paldebugger.hpp" +#include "device/appprofile.hpp" #include "hsa.h" #include "amd_hsa_kernel_code.h" #include "amd_hsa_queue.h" @@ -90,7 +91,7 @@ VirtualGPU::Queue* VirtualGPU::Queue::Create(Pal::IDevice* palDev, Pal::QueueTyp delete queue; return nullptr; } - + queue->UpdateAppPowerProfile(); address addrCmd = addrQ + qSize; address addrF = addrCmd + MaxCmdBuffers * cmdSize; Pal::CmdBufferBuildInfo cmdBuildInfo = {}; @@ -146,6 +147,18 @@ VirtualGPU::Queue::~Queue() { } } +Pal::Result VirtualGPU::Queue::UpdateAppPowerProfile() +{ + std::wstring wsAppPathAndFileName = Device::appProfile()->wsAppPathAndFileName(); + + const wchar_t* wAppPathAndName = wsAppPathAndFileName.c_str(); + // Find the last occurance of the '\\' character and extract the name of the application as wide char. + const wchar_t* wAppNamePtr = wcsrchr(wAppPathAndName, '\\'); + const wchar_t* wAppName = wAppNamePtr ? wAppNamePtr + 1 : wAppPathAndName; + + return iQueue_->UpdateAppPowerProfile(wAppName, wAppPathAndName); +} + void VirtualGPU::Queue::addCmdMemRef(GpuMemoryReference* mem) { Pal::IGpuMemory* iMem = mem->iMem(); auto it = memReferences_.find(mem); diff --git a/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp b/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp index 5304ccbfd4..2bfe742bb6 100644 --- a/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp +++ b/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp @@ -96,6 +96,9 @@ class VirtualGPU : public device::VirtualDevice { iDev_->RemoveGpuMemoryReferences(1, &iMem, nullptr); } + // Notice KMD to update applicaiton profile + Pal::Result UpdateAppPowerProfile(); + // ibReuse forces event wait without polling, to make sure event occured template bool waifForFence(uint cbId) const { diff --git a/projects/clr/rocclr/runtime/os/os.hpp b/projects/clr/rocclr/runtime/os/os.hpp index 1febb40c99..6a3d6a6c30 100644 --- a/projects/clr/rocclr/runtime/os/os.hpp +++ b/projects/clr/rocclr/runtime/os/os.hpp @@ -249,8 +249,8 @@ class Os : AllStatic { // return gloabal memory size to be assigned to device info static size_t getPhysicalMemSize(); - //! get Application file name - static std::string getAppFileName(); + //! get Application file name and path + static void getAppPathAndFileName(std::string& appName, std::string& appPathAndName); //! Install SIGFPE handler for CPU device static bool installSigfpeHandler(); diff --git a/projects/clr/rocclr/runtime/os/os_posix.cpp b/projects/clr/rocclr/runtime/os/os_posix.cpp index b82ca1861e..074996c264 100644 --- a/projects/clr/rocclr/runtime/os/os_posix.cpp +++ b/projects/clr/rocclr/runtime/os/os_posix.cpp @@ -729,15 +729,19 @@ size_t Os::getPhysicalMemSize() { return (size_t)si.totalram * si.mem_unit; } -std::string Os::getAppFileName() { +void Os::getAppPathAndFileName(std::string& appName, std::string& appPathAndName) { std::unique_ptr buff(new char[FILE_PATH_MAX_LENGTH]()); if (readlink("/proc/self/exe", buff.get(), FILE_PATH_MAX_LENGTH) > 0) { // Get filename without path and extension. - return std::string(basename(buff.get())); + appName = std::string(basename(buff.get())); + appPathAndName = std::string(buff.get()); } - - return ""; + else { + appName = ""; + appPathAndName = ""; + } + return; } } // namespace amd diff --git a/projects/clr/rocclr/runtime/os/os_win32.cpp b/projects/clr/rocclr/runtime/os/os_win32.cpp index 0cb98534d3..b30d4e62e8 100644 --- a/projects/clr/rocclr/runtime/os/os_win32.cpp +++ b/projects/clr/rocclr/runtime/os/os_win32.cpp @@ -931,19 +931,22 @@ size_t Os::getPhysicalMemSize() { return (size_t)statex.ullTotalPhys; } -std::string Os::getAppFileName() { - std::string strFileName; +void Os::getAppPathAndFileName(std::string& appName, std::string& appPathAndName) { char* buff = new char[FILE_PATH_MAX_LENGTH]; if (GetModuleFileNameA(NULL, buff, FILE_PATH_MAX_LENGTH) != 0) { // Get filename without path and extension. - strFileName = strrchr(buff, '\\') ? strrchr(buff, '\\') + 1 : buff; + appPathAndName = buff; + appName = strrchr(buff, '\\') ? strrchr(buff, '\\') + 1 : buff; + } + else { + appPathAndName = ""; + appName = ""; } delete[] buff; - return strFileName; + return; } - } // namespace amd #endif // _WIN32 || __CYGWIN__