-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix isSigned usage for scalar prints. #201
Fix isSigned usage for scalar prints. #201
Conversation
Signed-off-by: Ilya Enkovich <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just about to send a PR, was figuring out some build things. Can confirm this PR fixes the example in #200.
dtype int32
(0, 0, 0) n: -1
Seems almost identical!
diff --git a/third_party/cpu/lib/TritonCPUToLLVM/DebugOpsToLLVM.cpp b/third_party/cpu/lib/TritonCPUToLLVM/DebugOpsToLLVM.cpp
index 21b4756b..5599ef8d 100644
--- a/third_party/cpu/lib/TritonCPUToLLVM/DebugOpsToLLVM.cpp
+++ b/third_party/cpu/lib/TritonCPUToLLVM/DebugOpsToLLVM.cpp
@@ -32,8 +32,10 @@ public:
// TODO: This code is the same as the GPU-backend code. Consider refactoring.
std::string getFormatSubstr(Value value, bool hex = false,
- std::optional<int> width = std::nullopt) {
+ std::optional<int> width = std::nullopt,
+ bool isSigned = false) {
Type type = value.getType();
+ // If the `value` is a pointer, just return %p.
if (isa<LLVM::LLVMPointerType>(type)) {
return "%p";
}
@@ -54,21 +56,16 @@ std::string getFormatSubstr(Value value, bool hex = false,
prefix += std::to_string(*width);
} else if (hex) {
prefix += "0";
- prefix += std::to_string(value.getType().getIntOrFloatBitWidth() / 4);
+ prefix += std::to_string(type.getIntOrFloatBitWidth() / 4);
}
if (type.isBF16() || type.isF16() || type.isF32() || type.isF64()) {
return prefix + "f";
- } else if (type.isSignedInteger()) {
+ } else if (type.isInteger()) {
if (type.getIntOrFloatBitWidth() == 64)
- return prefix + "lli";
+ return prefix + (isSigned ? "lli" : "llu");
else
- return prefix + "i";
- } else if (type.isUnsignedInteger() || type.isSignlessInteger()) {
- if (type.getIntOrFloatBitWidth() == 64)
- return prefix + "llu";
- else
- return prefix + "u";
+ return prefix + (isSigned ? "i" : "u");
}
assert(false && "not supported type");
return "";
@@ -163,7 +160,8 @@ static StringRef makeNullTerminatedString(StringRef s) {
void createRuntimePrintScalarCall(ConversionPatternRewriter &rewriter,
std::array<Value, 3> pid, StringRef prefix,
- std::optional<Value> arg, bool hex = false) {
+ std::optional<Value> arg,
+ bool isSigned = false, bool hex = false) {
assert(!prefix.empty() && "printf with empty string not supported");
auto loc = UnknownLoc::get(rewriter.getContext());
@@ -172,7 +170,7 @@ void createRuntimePrintScalarCall(ConversionPatternRewriter &rewriter,
os << "(" << getFormatSubstr(pid[0]) << ", " << getFormatSubstr(pid[1])
<< ", " << getFormatSubstr(pid[2]) << ")" << prefix;
if (arg.has_value())
- os << getFormatSubstr(arg.value(), hex);
+ os << getFormatSubstr(arg.value(), hex, std::nullopt, isSigned);
llvm::SmallString<64> formatStrNewline(formatStr);
formatStrNewline.push_back('\n');
@@ -242,7 +240,8 @@ struct PrintOpConversion : public ConvertOpToLLVMPattern<triton::cpu::PrintOp> {
std::nullopt);
} else {
createRuntimePrintScalarCall(rewriter, pid, op.getPrefix(),
- adaptor.getOperands()[0], op.getHex());
+ adaptor.getOperands()[0],
+ op.getIsSigned()[0], op.getHex());
}
rewriter.eraseOp(op);
return success();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
Merging it as a quick patch! |
Resolves #200