[polly] r241452 - Print thread-identifiers in GPU debug output
Tobias Grosser
tobias at grosser.es
Mon Jul 6 08:36:16 PDT 2015
Author: grosser
Date: Mon Jul 6 10:36:16 2015
New Revision: 241452
URL: http://llvm.org/viewvc/llvm-project?rev=241452&view=rev
Log:
Print thread-identifiers in GPU debug output
This helps us to understand which thread prints which information.
Modified:
polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h
polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp
Modified: polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h?rev=241452&r1=241451&r2=241452&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h (original)
+++ polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h Mon Jul 6 10:36:16 2015
@@ -15,6 +15,7 @@
#include "polly/CodeGen/IRBuilder.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
+#include <vector>
namespace llvm {
class Value;
@@ -119,6 +120,16 @@ private:
unsigned Src, unsigned Dst,
unsigned SrcBits = 8,
unsigned DstBits = 8);
+
+ /// @brief Get identifiers that describe the currently executed GPU thread.
+ ///
+ /// The result will be a vector that if passed to the GPU printer will result
+ /// into a string (initialized to values corresponding to the printing
+ /// thread):
+ ///
+ /// "> block-id: bidx bid1y bidz | thread-id: tidx tidy tidz "
+ static std::vector<llvm::Value *>
+ getGPUThreadIdentifiers(PollyIRBuilder &Builder);
};
}
Modified: polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp?rev=241452&r1=241451&r2=241452&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp Mon Jul 6 10:36:16 2015
@@ -10,6 +10,7 @@
//===----------------------------------------------------------------------===//
#include "polly/CodeGen/RuntimeDebugBuilder.h"
+#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include <string>
@@ -55,6 +56,45 @@ Function *RuntimeDebugBuilder::getAddres
return F;
}
+std::vector<Value *>
+RuntimeDebugBuilder::getGPUThreadIdentifiers(PollyIRBuilder &Builder) {
+ std::vector<Value *> Identifiers;
+
+ auto M = Builder.GetInsertBlock()->getParent()->getParent();
+
+ std::vector<Function *> BlockIDs = {
+ Intrinsic::getDeclaration(M, Intrinsic::ptx_read_ctaid_x),
+ Intrinsic::getDeclaration(M, Intrinsic::ptx_read_ctaid_y),
+ Intrinsic::getDeclaration(M, Intrinsic::ptx_read_ctaid_z),
+ };
+
+ Identifiers.push_back(Builder.CreateGlobalStringPtr("> block-id: ", "", 4));
+ for (auto GetID : BlockIDs) {
+ Value *Id = Builder.CreateCall(GetID, {});
+ Id = Builder.CreateIntCast(Id, Builder.getInt64Ty(), false);
+ Identifiers.push_back(Id);
+ Identifiers.push_back(Builder.CreateGlobalStringPtr(" ", "", 4));
+ }
+
+ Identifiers.push_back(Builder.CreateGlobalStringPtr("| ", "", 4));
+
+ std::vector<Function *> ThreadIDs = {
+ Intrinsic::getDeclaration(M, Intrinsic::ptx_read_tid_x),
+ Intrinsic::getDeclaration(M, Intrinsic::ptx_read_tid_y),
+ Intrinsic::getDeclaration(M, Intrinsic::ptx_read_tid_z),
+ };
+
+ Identifiers.push_back(Builder.CreateGlobalStringPtr("thread-id: ", "", 4));
+ for (auto GetId : ThreadIDs) {
+ Value *Id = Builder.CreateCall(GetId, {});
+ Id = Builder.CreateIntCast(Id, Builder.getInt64Ty(), false);
+ Identifiers.push_back(Id);
+ Identifiers.push_back(Builder.CreateGlobalStringPtr(" ", "", 4));
+ }
+
+ return Identifiers;
+}
+
void RuntimeDebugBuilder::createGPUVAPrinter(PollyIRBuilder &Builder,
ArrayRef<Value *> Values) {
std::string str;
@@ -68,8 +108,13 @@ void RuntimeDebugBuilder::createGPUVAPri
auto *Zero = Builder.getInt64(0);
auto *DataPtr = Builder.CreateGEP(Data, {Zero, Zero});
+ auto ToPrint = getGPUThreadIdentifiers(Builder);
+
+ ToPrint.push_back(Builder.CreateGlobalStringPtr("\n ", "", 4));
+ ToPrint.insert(ToPrint.end(), Values.begin(), Values.end());
+
int Offset = 0;
- for (auto Val : Values) {
+ for (auto Val : ToPrint) {
auto Ptr = Builder.CreateGEP(DataPtr, Builder.getInt64(Offset));
Type *Ty = Val->getType();
More information about the llvm-commits
mailing list