From 0eb4127eaf10bfbb0ca731ae789935f7ef002a4f Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 6 Jan 2016 10:55:08 -0500
Subject: [PATCH] P4 to Git Change 1225189 by yaxunl@yaxunl_stg_win50 on
2016/01/06 10:45:41
SWDEV-84848 - Add timing for drop-in SPIRV translation. Fix timing for loading libraries.
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#137 edit
---
.../compiler/lib/backends/common/linker.cpp | 27 +++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/rocclr/compiler/lib/backends/common/linker.cpp b/rocclr/compiler/lib/backends/common/linker.cpp
index 58cd27eb38..9b21c76911 100644
--- a/rocclr/compiler/lib/backends/common/linker.cpp
+++ b/rocclr/compiler/lib/backends/common/linker.cpp
@@ -503,14 +503,21 @@ checkAndFixAclBinaryTarget(llvm::Module* module, aclBinary* elf,
#ifdef HAS_SPIRV
bool
translateSpirv(llvm::Module *&M, const std::string &DumpSpirv,
- const std::string &DumpLlvm){
+ const std::string &DumpLlvm, bool Timing, std::string &TimeStr){
+ uint64_t ReadTime = 0;
+ uint64_t WriteTime = 0;
std::string S;
llvm::raw_string_ostream RSS(S);
std::string Err;
+
+ if (Timing)
+ WriteTime = amd::Os::timeNanos();
if (!llvm::WriteSPIRV(M, RSS, Err)) {
llvm::errs() << "Fails to save LLVM as SPIR-V: " << Err << '\n';
return false;
}
+ if (Timing)
+ WriteTime = amd::Os::timeNanos() - WriteTime;
if (!DumpSpirv.empty()) {
std::ofstream OFS(DumpSpirv, std::ios::binary);
@@ -524,11 +531,23 @@ translateSpirv(llvm::Module *&M, const std::string &DumpSpirv,
auto &Ctx = M->getContext();
delete M;
M = nullptr;
+ if (Timing)
+ ReadTime = amd::Os::timeNanos();
if (!llvm::ReadSPIRV(Ctx, SS, M, Err)) {
llvm::errs() << "Fails to load SPIR-V as LLVM Module: " << Err << '\n';
return false;
}
+ if (Timing) {
+ ReadTime = amd::Os::timeNanos() - ReadTime;
+ std::stringstream tmp_ss;
+ tmp_ss << " LLVM/SPIRV translation time: "
+ << WriteTime/1000ULL << " us\n"
+ << " SPIRV/LLVM translation time: "
+ << ReadTime/1000ULL << " us\n";
+ TimeStr = tmp_ss.str();
+ }
+
if (!DumpLlvm.empty()) {
std::error_code EC;
llvm::raw_fd_ostream outs(DumpLlvm.c_str(), EC, llvm::sys::fs::F_None);
@@ -615,7 +634,11 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs)
DumpSpirv = Options()->getDumpFileName(".spv");
DumpLlvm = Options()->getDumpFileName("_fromspv.bc");
}
- translateSpirv(llvmbinary_, DumpSpirv, DumpLlvm);
+ std::string TimeStr;
+ translateSpirv(llvmbinary_, DumpSpirv, DumpLlvm,
+ Options()->oVariables->EnableBuildTiming, TimeStr);
+ if (!TimeStr.empty())
+ appendLogToCL(CL(), TimeStr);
}
#endif