Skip to content

Commit

Permalink
[ROCM] Enable ROCM Backend #1.5: Address Remaining Comments from trit…
Browse files Browse the repository at this point in the history
…on-lang#1312 (triton-lang#1434)

This PR address the remaing issues from triton-lang#1312. It does the following
*  LLVM String Join
* adds comment to GCNBuilder Class

---------

Co-authored-by: Rahul Batra <rahbatra@amd.com>
  • Loading branch information
micmelesse and Rahul Batra authored Mar 29, 2023
1 parent 888cbad commit 5293288
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
10 changes: 2 additions & 8 deletions include/triton/Conversion/TritonGPUToLLVM/AsmFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "mlir/IR/Value.h"
#include "triton/Dialect/Triton/IR/Dialect.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include <memory>
#include <string>
Expand All @@ -17,14 +18,7 @@ using llvm::StringRef;

inline std::string strJoin(llvm::ArrayRef<std::string> strs,
llvm::StringRef delimiter) {
std::string osStr;
llvm::raw_string_ostream os(osStr);
for (size_t i = 0; !strs.empty() && i < strs.size() - 1; ++i)
os << strs[i] << delimiter;
if (!strs.empty())
os << strs.back();
os.flush();
return osStr;
return llvm::join(strs.begin(), strs.end(), delimiter);
}

} // namespace triton
Expand Down
63 changes: 63 additions & 0 deletions include/triton/Conversion/TritonGPUToLLVM/GCNAsmFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,69 @@ class GCNInstr;
class GCNInstrCommon;
class GCNInstrExecution;

// GCNBuilder helps to manage a GCN asm program consists of one or multiple
// instructions.
//
// A helper for building an ASM program, the objective of GCNBuilder is to give
// a thin encapsulation and make the ASM code for MLIR LLVM Dialect more clear.
// Currently, several factors are introduced to reduce the need for mixing
// string and C++ if-else code.
//
// Usage:
// To create a multiplcation operation
//
//
// GCNBuilder gcnBuilder;
// unsigned bitwidth = elemTy.getIntOrFloatBitWidth();
//
// const std::string readConstraint = "v";
// const std::string writeConstraint = "=v";
// auto res = gcnBuilder.newOperand(writeConstraint);
// auto lhs = gcnBuilder.newOperand(operands[0], readConstraint);
// auto rhs = gcnBuilder.newOperand(operands[1], readConstraint);
//
// create inst
// auto &mul_inst =
// gcnBuilder.create<GCNInstr>("v_mul")->float_op_type(bitwidth);
//
// launch insts
// mul_inst(res, lhs, rhs);
//
// return result
// Value ret = gcnBuilder.launch(rewriter, loc, elemTy, false);
// return ret;
// To get the asm code:
// builder.dump()
//
// To get all the mlir::Value used in the GCN code,
//
// builder.getAllMlirArgs() // get {pVal, iVal, jVal, kVal}
//
// To get the string containing all the constraints with "," separated,
// builder.getConstraints() // get "=v,v,v"
//
// GCNBuilder can build a GCN asm with multiple instructions, sample code:
//
// GCNBuilder builder;
// auto &rcp = gcnBuilder.create<GCNInstr>("v_rcp")->float_op_type(bitwidth);
// auto &mul_inst =
// gcnBuilder.create<GCNInstr>("v_mul")->float_op_type(bitwidth);
//
// rcp(...);
// mul_inst(...);
// This will get a GCN code with two instructions.
//
// Similar to a C function, a declared GCNInstr instance can be launched
// multiple times with different operands, e.g.
//
// auto &mul_inst =
// gcnBuilder.create<GCNInstr>("v_mul")->float_op_type(bitwidth); mul_inst(...
// some operands ...); mul_inst(... some different operands ...);
//
// Finally, we will get a GCN code with two mov instructions.
//
// There are several derived instruction type for typical instructions, for
// example, the GCNIOInstr for ld and st instructions.
struct GCNBuilder {
struct Operand {
std::string constraint;
Expand Down

0 comments on commit 5293288

Please sign in to comment.