Skip to content
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

[Draft] Update the fast math pass #2507

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion third_party/intel/backend/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def make_llir(src, metadata, options):
if os.getenv("TRITON_INTEL_REDUCE_TRANSPOSE", "0") != "1":
intel.passes.ttgpuir.add_allocate_shared_memory(pm)
intel.passes.ttgpuir.add_to_llvmir(pm)
intel.set_fast_math(mod)
passes.convert.add_arith_to_llvmir(pm)
passes.common.add_canonicalizer(pm)
passes.common.add_cse(pm)
Expand All @@ -292,6 +291,7 @@ def make_llir(src, metadata, options):
context = llvm.context()
llvm_mod = llvm.to_module(mod, context)
intel.set_spv_target_triple(llvm_mod)
intel.set_fast_math(llvm_mod)
if options.extern_libs:
paths = [path for (name, path) in options.extern_libs]
llvm.link_extern_libs(llvm_mod, paths)
Expand Down
22 changes: 13 additions & 9 deletions third_party/intel/triton_xpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,19 @@ void init_triton_intel(py::module &&m) {
});

// May do this after llvm ir according to user fmath flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR moves it to LLVMIR, we can remove this comment.

m.def("set_fast_math", [](mlir::ModuleOp mod) {
using namespace mlir;
MLIRContext *ctx = mod.getContext();
mod.walk([&](Operation *op) {
if (auto fmIf = dyn_cast<arith::ArithFastMathInterface>(op))
op->setAttr(
fmIf.getFastMathAttrName(),
arith::FastMathFlagsAttr::get(ctx, arith::FastMathFlags::fast));
});
m.def("set_fast_math", [](llvm::Module *mod) {
using namespace llvm;
for (auto &func : *mod) {
for (auto &bb : func) {
for (auto &inst : bb) {
if (auto *op = dyn_cast<FPMathOperator>(&inst)) {
Comment on lines +221 to +224
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a walker on FPMathOperator?

FastMathFlags FMF;
FMF.setFast(true);
inst.setFastMathFlags(FMF);
}
}
}
}
});

m.def("set_spv_target_triple", [](llvm::Module *mod) {
Expand Down
Loading