Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Fix issues when profiling ComputeCpp applications in both local and r…
Browse files Browse the repository at this point in the history
…emote.
  • Loading branch information
Thales Sabino committed Sep 12, 2018
1 parent e6a7ee3 commit 4b86511
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define LPGPU2_CODEXL_APPLICATION_VERSION_MAJOR 3
#define LPGPU2_CODEXL_APPLICATION_VERSION_MINOR 9
#define LPGPU2_CODEXL_APPLICATION_VERSION_PATCH 3
#define LPGPU2_CODEXL_APPLICATION_VERSION_PATCH 4
#define LPGPU2_CODEXL_APPLICATION_VERSION_SUFFIX ""

#endif // LPGPU2_APPLICATION_DEFS_H
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="..\..\..\Common\Lib\Ext\ComputeCpp\ComputeCpp-Version.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="..\..\..\Common\Lib\Ext\ComputeCpp\ComputeCpp-Version.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<CustomBuildAfterTargets>
</CustomBuildAfterTargets>
Expand Down
4 changes: 0 additions & 4 deletions CodeXL/AllProjectsBuild/CopyFiles_Debug.bat
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,3 @@ XCopy /r /d /y "..\..\Common\Lib\Ext\Qt\5.5\plugins\platforms\qwindows%D_SUFFIX%
rem copy other files qcustomplot
XCopy /r /d /y "..\..\Common\Lib\Ext\qcustomplot\1.3.1\lib\Win32\%CONFIG_NAME%\qcustomplot%D_SUFFIX%.dll" "..\Output\%CONFIG_NAME%\bin\"
XCopy /r /d /y "..\..\Common\Lib\Ext\qcustomplot\1.3.1\lib\Win32\%CONFIG_NAME%\qcustomplot%D_SUFFIX%.pdb" "..\Output\%CONFIG_NAME%\bin\"

:: ++TLRS: LPGPU2: Copy the debug version of the ComputeCpp runtime version to CodeXL's output folder.
XCopy /r /d /y "..\..\Common\Lib\Ext\ComputeCpp\ComputeCpp-%ComputeCppVersion%\lib\ComputeCpp_vs2015_%D_SUFFIX%.dll" "..\Output\%CONFIG_NAME%\bin\"
:: --TLRS: LPGPU2: Copy the debug version of the ComputeCpp runtime version to CodeXL's output folder.
5 changes: 0 additions & 5 deletions CodeXL/AllProjectsBuild/CopyFiles_Release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,3 @@ XCopy /r /d /y "..\..\Common\Lib\Ext\Qt\5.5\plugins\platforms\qwindows%D_SUFFIX%

rem copy other files qcustomplot
XCopy /r /d /y "..\..\Common\Lib\Ext\qcustomplot\1.3.1\lib\Win32\%CONFIG_NAME%\qcustomplot%D_SUFFIX%.dll" "..\Output\%CONFIG_NAME%\bin\"

:: ++TLRS: LPGPU2: Copy the debug version of the ComputeCpp runtime version to CodeXL's output folder.
:: TODO: Read the version of ComputeCpp from a configuration variable
XCopy /r /d /y "..\..\Common\Lib\Ext\ComputeCpp\ComputeCpp-%ComputeCppVersion%\lib\ComputeCpp_vs2015.dll" "..\Output\%CONFIG_NAME%\bin\"
:: --TLRS: LPGPU2: Copy the debug version of the ComputeCpp runtime version to CodeXL's output folder.
6 changes: 4 additions & 2 deletions CodeXL/Components/GpuProfiling/Backend/Common/Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ using namespace GPULogger;
#elif ARCH_AARCH64
#define CL_ICD_LOADER_DLL "OpenCLICDLoaderDetours/aarch64/" LIB_PREFIX "OpenCL" LIB_SUFFIX
#elif AMDT_ADDRESS_SPACE_TYPE == AMDT_64_BIT_ADDRESS_SPACE
#define CL_ICD_LOADER_DLL "OpenCLICDLoaderDetours/x86_64/" LIB_PREFIX "OpenCL" LIB_SUFFIX
#define CL_ICD_LOADER_DIR "OpenCLICDLoaderDetours/x86_64"
#define CL_ICD_LOADER_DLL CL_ICD_LOADER_DIR "/" LIB_PREFIX "OpenCL" LIB_SUFFIX
#else
#define CL_ICD_LOADER_DLL "OpenCLICDLoaderDetours/x86/" LIB_PREFIX "OpenCL" LIB_SUFFIX
#define CL_ICD_LOADER_DIR "OpenCLICDLoaderDetours/x86"
#define CL_ICD_LOADER_DLL CL_ICD_LOADER_DIR "/" LIB_PREFIX "OpenCL" LIB_SUFFIX
#endif
//--CF:LPGPU2

Expand Down
82 changes: 57 additions & 25 deletions CodeXL/Components/GpuProfiling/Backend/sprofile/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static bool PrintLastError(wchar_t* szPre)
return true;
}

static int CreateProcessWithDetour(gtString& strDirPath, gtString& strAppCommandLine, gtString& strAppWorkingDirectory, bool useDetours, bool syclTrace)
static int CreateProcessWithDetour(gtString& strDirPath, gtString& strAppCommandLine, gtString& strAppWorkingDirectory, bool useDetours)
{
// set the detoured and microDLL server's path
string dirPathAsUTF8;
Expand Down Expand Up @@ -197,19 +197,20 @@ static int CreateProcessWithDetour(gtString& strDirPath, gtString& strAppCommand

std::string syclDll;

if (syclTrace)
LPCSTR szMicroDLLPath = szMicroDllPath;

dllPaths[0] = { szMicroDLLPath };

int numDlls = 1;

if (config.bSYCLTrace)
{
syclDll = FileUtils::GetExePath() + "/";
syclDll += SYCL_DLL;
dllPaths[1] = syclDll.c_str();
}


LPCSTR szMicroDLLPath = szMicroDllPath;

dllPaths[0] = { szMicroDLLPath };

int numDlls = syclTrace ? 2 : 1;
numDlls++;
}

// Run the app with DCServer enabled so that app with both OpenCL and DirectCompute can run
createProcRetVal = AMDT::CreateProcessAndInjectDllsW(config.strInjectedApp.asCharArray(),
Expand Down Expand Up @@ -704,13 +705,40 @@ static void GetOutputFilePath()
{
SetHSASoftCPEnvVar(reportPerfCounterEnablement);
}
// OS_OUTPUT_DEBUG_LOG(L"....", OS_DEBUG_LOG_ERROR );
if (!config.strSYCLRuntimeLib.empty())
{
SetSYCLRuntimeEnvVar(config.strSYCLRuntimeLib);
}

// Set the value
if (!config.strSYCLRuntimeLib.empty())
{
SetSYCLRuntimeEnvVar(config.strSYCLRuntimeLib);
}

if (config.bSYCLTrace)
{
// Creates the ComputeCpp configuration file to enable the profiling API
// This is required by the ComputeCpp runtime in order to
const gtString computeCppConfigFileEnvVar = L"COMPUTECPP_CONFIGURATION_FILE";
if (config.mapEnvVars.find(computeCppConfigFileEnvVar) == config.mapEnvVars.end())
{
// If the ComputeCpp configuration file is not set, it needs to be created here in order to enable SYCL tracing
osFilePath tmpSyclConfigFilePath{ osFilePath::OS_TEMP_DIRECTORY, L"sycl_config_file", L"" };
osFile tmpSyclConfigFile;

if (!tmpSyclConfigFile.open(tmpSyclConfigFilePath, osChannel::OS_UNICODE_TEXT_CHANNEL, osFile::OS_OPEN_TO_WRITE))
{
return -1;
}

if (!tmpSyclConfigFile.writeString(L"enable_profiling = true"))
{
return -1;
}

tmpSyclConfigFile.close();


// Finally, add the ComputeCpp file to map of environment variables.
config.mapEnvVars[computeCppConfigFileEnvVar] = tmpSyclConfigFilePath.asString();
}
}

#ifdef _WIN32

Expand All @@ -724,33 +752,37 @@ static void GetOutputFilePath()
strAppCommandLine.appendFormattedString(L" %ls", config.strInjectedAppArgs.asCharArray());
}

// call SetDllDirectory so that the app being profiled can locate and load AMDTBaseTools/AMDTOSWrappers DLLs
SetDllDirectory(strDirPath.asCharArray());
// Call SetDllDirectoryA so the profiled application is able to load our custom OpenCL ICD loader.
std::string icdDirectory = FileUtils::GetExePath();
icdDirectory += std::string{ "/" } + std::string{ CL_ICD_LOADER_DIR };
SetDllDirectoryA(icdDirectory.data());

int ret = CreateProcessWithDetour(strDirPath, strAppCommandLine, strAppWorkingDirectory, !config.bNoDetours, config.bSYCLTrace);
int ret = CreateProcessWithDetour(strDirPath, strAppCommandLine, strAppWorkingDirectory, !config.bNoDetours);

if (ret != 0)
{
FileUtils::DeleteTmpFile();
return -1;
}

#else

//add SYCLTraceAgent.so to LD_PRELOAD so it loads it with the executable
if(config.bSYCLTrace){
if(config.bSYCLTrace)
{
config.strPreloadLib += ":" + FileUtils::GetExePath() + "/" + SYCL_DLL;
}

if(config.bTrace){
if(config.bTrace)
{
config.strPreloadLib += ":" + FileUtils::GetExePath() + "/" + CL_ICD_LOADER_DLL; //":/home/callum/OpenCL-ICD-Loader/build/lib/libOpenCL.so";
config.strPreloadLib += ":" + FileUtils::GetExePath() + "/" + CL_TRACE_AGENT_DLL;
}

SetPreLoadLibs();

// Codeplay JIRA: CST-148
// TODO: WHY DO I NEED TO DO THIS?
config.mapEnvVars[L"LD_PRELOAD"].fromASCIIString(config.strPreloadLib.data());
// config.mapEnvVars[L"LD_PRELOAD"].fromASCIIString(config.strPreloadLib.data());

std::string strAppCommandLine;

Expand Down Expand Up @@ -920,7 +952,7 @@ static void MergeTraceFile(int sig)

AtpFileWriter writer(config, pid);

SYCLAtpFilePart* pSyclTrace = nullptr;
SYCLAtpFilePart* pSyclTrace = nullptr;
CLAtpFilePart* pOclTrace = nullptr;
StackTraceAtpFilePart* pClStackTrace = nullptr;
StackTraceAtpFilePart* pHsaStackTrace = nullptr;
Expand Down Expand Up @@ -1353,8 +1385,8 @@ static bool UnsetPreLoadLibs()

static bool SetSYCLRuntimeEnvVar(const std::string& runtimePath)
{
OSUtils::Instance()->SetEnvVar("SYCL_RUNTIME_LIB", runtimePath.c_str());
return true;
OSUtils::Instance()->SetEnvVar("SYCL_RUNTIME_LIB", runtimePath.c_str());
return true;
}

EnvSysBlockString GetEnvironmentBlock(EnvVarMap mapUserBlock, bool bIncludeSystemEnv)
Expand Down
13 changes: 10 additions & 3 deletions CodeXL/Remote/AMDTRemoteAgent/CodeXLRemoteAgent
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# ----------------------------------------------------------------------------------------------------------------------------------
# File name: CodeXLRemoteAgent
# This script sets CodeXLRemoteAgent's related environment variables and
# This script sets CodeXLRemoteAgent's related environment variables and
# executed the CodeXLRemoteAgent binary executable.
#
# (c) 2013 Advanced Micro Devices Inc. All Rights Reserved.
Expand Down Expand Up @@ -41,7 +41,7 @@ fi
# Obtain libstdc++ needed version
LDCONFIG="ldconfig"
command -v "$LDCONFIG" &> /dev/null || LDCONFIG="/sbin/ldconfig"
CRUNTIMEPATH=$(${LDCONFIG} -p | grep libstdc++.so.6 | grep $ArchHint)
CRUNTIMEPATH=$(${LDCONFIG} -p | grep libstdc++.so.6 | grep -i $ArchHint)
CRUNTIMEFILE=${CRUNTIMEPATH##*>}

# Test if current system C++ runtime is older from CodeXL version needed
Expand All @@ -52,6 +52,14 @@ if [ -z "$NEWCRUNTIME" ];then
CXL_CLIB="${CodeXLBinariesDir}/RuntimeLibs"
fi

if ! ${LDCONFIG} -p | grep libX11.so.6 ; then
# In systems where X11 is not available, the remote agent will try to load
# libX11.so.6. This file is not strictly required for non-GUI applications
# but the remote agent needs this library to run. This will create a placeholder
# shared object for the remote agent to load in systems where it is not available.
cp -f libLPGPU2InputOutput.so libX11.so.6
fi

# Add CodeXLRemoteAgent's binaries directory to LD_LIBRARY_PATH:
if [ -z "$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH="${CodeXLBinariesDir}:${CXL_CLIB}"
Expand All @@ -61,4 +69,3 @@ fi

# Run CodeXLRemoteAgent:
eval "$CodeXLRemoteAgentBinaryExePath $@"

6 changes: 2 additions & 4 deletions Common/Src/LPGPU2SyclInfo/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ setup_computecpp = imp.load_source("", setup_computecpp_script)
computecpp_folder, _ = setup_computecpp.get_computecpp_folder_and_version(full_path=True)

env.Append(CPPFLAGS = '-std=c++11')
env.Append( CPPPATH = [
env.Append(CPPPATH = [
env['CXL_commonproj_dir'],
os.path.join(computecpp_folder, "include"),
env['CXL_commonproj_dir'] + '/../../CodeXL',
])
env.Append(LIBPATH = os.path.join(computecpp_folder, "lib"))

UseAPPSDK(env)

Expand Down Expand Up @@ -54,7 +55,4 @@ libInstall = env.Install(
dir = env['CXL_lib_dir'],
source = (install))

computecpp_lib = os.path.join(computecpp_folder, 'lib/libComputeCpp.so')
libInstall += env.Install(env['CXL_lib_dir'], computecpp_lib)

Return('libInstall')
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ CodeXL, previously a tool developed as closed-source by Advanced Micro Devices,

To encourage 3rd party contribution and adoption, CodeXL is no longer branded as an AMD product. AMD will still continue development of this tool and upload new versions and features to GPUOpen.


## Installation and Build

* Windows: To install CodeXL, use the [provided](https://github.com/GPUOpen-Tools/CodeXL/releases) executable file CodeXL_*.exe
Expand Down

0 comments on commit 4b86511

Please sign in to comment.