Skip to content

[XeVM] Lowering to LLVM #416

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
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 include/gc/Conversion/Passes.h
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
#ifndef GC_CONVERSION_PASSES_H
#define GC_CONVERSION_PASSES_H

#include "gc/Conversion/XeVMToLLVM.h"
#include "gc/Conversion/XeVMToLLVM/XeVMToLLVM.h"

namespace mlir {

2 changes: 1 addition & 1 deletion include/gc/Conversion/XeVMToLLVM/XeVMToLLVM.h
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class RewritePatternSet;
class Pass;

#define GEN_PASS_DECL_CONVERTXEVMTOLLVMPASS
#include "mlir/Conversion/Passes.h.inc"
#include "gc/Conversion/Passes.h.inc"

void populateXeVMToLLVMConversionPatterns(RewritePatternSet &patterns);

55 changes: 55 additions & 0 deletions include/gc/Dialect/LLVMIR/XeVMOps.td
Original file line number Diff line number Diff line change
@@ -19,6 +19,15 @@ def XeVM_Dialect : Dialect {
let name = "xevm";
let cppNamespace = "::mlir::xevm";
let dependentDialects = ["LLVM::LLVMDialect"];

let extraClassDeclaration = [{
/// Get the name for the attribute used to specify cache control
/// decorations.
static constexpr ::llvm::StringRef getCacheControlsAttrName() {
return ::llvm::StringLiteral("xevm.DecorationCacheControlINTEL");
}
}];

let useDefaultAttributePrinterParser = 1;
}

@@ -161,6 +170,52 @@ def XeVM_BlockStore2dOp : XeVM_Op<"blockstore2d">,
let hasVerifier = 1;
}

def XeVM_BlockPrefetch2dOp : XeVM_Op<"blockprefetch2d">,
Arguments<(ins
Arg<LLVM_AnyPointer, "", [MemRead]>:$ptr,
I32:$base_width,
I32:$base_height,
I32:$base_pitch,
I32:$x,
I32:$y,
I32Attr:$elem_size_in_bits,
I32Attr:$tile_width,
I32Attr:$tile_height,
I32Attr:$v_blocks,
DefaultValuedAttr<XeVM_L1LoadCacheControl, "::mlir::xevm::L1LoadCacheControl::DEFAULT">:$l1_cache_control,
DefaultValuedAttr<XeVM_L3LoadCacheControl, "::mlir::xevm::L3LoadCacheControl::DEFAULT">:$l3_cache_control
)> {

let summary = "2D block prefetch";

let description = [{
The `xevm.blockprefetch2d` operation prefetches a two dimensional tile
from a larger matrix residing in memory. The parameters are:
$ptr - the base address of the matrix containing the tile to prefetch
$base_width, $base_height, $base_pitch - the shape of the matrix
$x, $y, $tile_width, $tile_height - the starting offsets and shape of tile to prefetch
$elem_size_in_bits - the size in bits of the matrix element
- 32 for f32, bf32
- 16 for f16, int16, bf16
- 8 for int8, int4, int2
$v_blocks - number of tiles to prefetch
$cache_control - an enumerator that sets the L1 and L3 cache behaviour

Notes:
- coordinate is provided in elements, while width and pitch are provided in bytes.
}];

let assemblyFormat = [{
operands ` ` `{` `elem_size_in_bits` `=` $elem_size_in_bits `,` `tile_width` `=` $tile_width `,`
`tile_height` `=` $tile_height `,` `v_blocks` `=` $v_blocks `,` `l1_cache_control` `=` $l1_cache_control `,`
`l3_cache_control` `=` $l3_cache_control `}`
attr-dict `:` `(` type(operands) `)`
}];

let hasVerifier = 1;
}


def XeVM_TargetAttr : XeVM_Attr<"XeVMTarget", "target"> {
let description = [{
GPU target attribute for controlling compilation of targets. All
2 changes: 1 addition & 1 deletion include/gc/ExecutionEngine/Driver/Driver.h
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ namespace mlir {
class DialectRegistry;
namespace gc {

const DialectRegistry &initCompilerAndGetDialects();
DialectRegistry &initCompilerAndGetDialects();

// the pointers to XXXMemRefType
using GeneralMemrefPtr = void *;
34 changes: 34 additions & 0 deletions include/gc/Transforms/Passes.td
Original file line number Diff line number Diff line change
@@ -261,4 +261,38 @@ def LowerToTileVector : Pass<"lower-to-tile-vector", "func::FuncOp"> {
];
}

def GpuXeVMAttachTarget: Pass<"xevm-attach-target", ""> {
let summary = "Attaches a XeVM target attribute to a GPU Module.";
let description = [{
This pass searches for all GPU Modules in the immediate regions and attaches
a XeVM target if the module matches the name specified by the `module` argument.

Example:
```
// File: in.mlir:
gpu.module @xevm_module_1 {...}
gpu.module @xevm_module_2 {...}
gpu.module @xevm_module_1 {...}
// mlir-opt --xevm-attach-target="module=xevm.* chip=pvc" in.mlir
gpu.module @xevm_module_1 {...}
gpu.module @xevm_module_2 {...}
gpu.module @xevm_module_1 [#xevm.target<chip = "pvc">] {...}
```
}];
let options = [
Option<"moduleMatcher", "module", "std::string",
/*default=*/ [{""}],
"Regex used to identify the modules to attach the target to.">,
Option<"triple", "triple", "std::string",
/*default=*/ "\"spirv64-unknown-unknown\"",
"Target triple.">,
Option<"chip", "chip", "std::string",
/*default=*/"\"pvc\"",
"Target chip.">,
Option<"optLevel", "O", "unsigned",
/*default=*/"2",
"Optimization level.">
];
}

#endif // GC_DIALECT_GC_PASSES
Loading