mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-02 07:06:33 +00:00
Print thread-identifiers in GPU debug output
This helps us to understand which thread prints which information. llvm-svn: 241452
This commit is contained in:
parent
0dd8eb324d
commit
ec46e5376d
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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::getAddressSpaceCast(PollyIRBuilder &Builder,
|
||||
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::createGPUVAPrinter(PollyIRBuilder &Builder,
|
||||
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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user