-
Notifications
You must be signed in to change notification settings - Fork 20
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
Integrate Java Triton example with Intel Triton Backend #241
base: code-reflection
Are you sure you want to change the base?
Conversation
👋 Welcome back hanklo6! A progress list of the required criteria for merging this PR into |
@hanklo6 This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 1203 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@PaulSandoz) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Webrevs
|
@hanklo6 This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Keep alive |
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.
Thank you for this effort. It's not easy to hook this up and you did it without any help!
Initially i have just focused on the code in the triton package.
cr-examples/triton/src/main/java/oracle/code/triton/ArithMathOps.java
Outdated
Show resolved
Hide resolved
int stride_am, @Constant int stride_ak, | ||
int stride_bk, @Constant int stride_bn, | ||
int stride_cm, @Constant int stride_cn, |
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.
Why the marking as constants?
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.
Triton will mark these three stride values as constants if they are equal to one at compile time. We mark them as constants directly as our code is not compiled by Triton.
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.
Oh i see, i don't see those equivalent parameters marked as tl.constexpr
in the Python matmul example. I think we need the concept of optional constants e.g., a boolean on the @Constant
annotation. An optional constant parameter can be associated with type or a constant type.
(Alternatively we could drop the constant annotation, but it seems useful to distinguish various parameters)
@@ -1018,8 +1051,15 @@ public Value dot(TensorType rType, Op.Result r, | |||
TypeElement bType, Value b) { | |||
a = block.context().getValue(a); | |||
b = block.context().getValue(b); | |||
|
|||
return block.op(TritonOps.dot(rType, a, b)); | |||
Object zero; |
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.
Add a comment such as
// Computed result is tensor of floats, regardless of inputs
like when we compute the type. Since the result is hard coded we don't need to use reflection and can directly use the constant expression "0.0".
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.
Fixed.
cr-examples/triton/src/main/java/oracle/code/triton/TritonTransformer.java
Outdated
Show resolved
Hide resolved
int stride_am, @Constant int stride_ak, | ||
int stride_bk, @Constant int stride_bn, | ||
int stride_cm, @Constant int stride_cn, |
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.
Oh i see, i don't see those equivalent parameters marked as tl.constexpr
in the Python matmul example. I think we need the concept of optional constants e.g., a boolean on the @Constant
annotation. An optional constant parameter can be associated with type or a constant type.
(Alternatively we could drop the constant annotation, but it seems useful to distinguish various parameters)
@@ -107,6 +111,17 @@ void test(CoreOp.FuncOp javaKernel, | |||
return TritonTransformer.tritonModule(javaKernel, JavaType.VOID, argTypes); | |||
}); | |||
|
|||
String mlirText = MLIRGenerator.transform(actualTritonKernel); |
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.
We should write the files to the maven target directory. Add the following to the surefire plugin configuration:
<systemPropertyVariables>
<project.build.directory>${project.build.directory}</project.build.directory>
</systemPropertyVariables>
Then replace the code below with:
Path buildDir = Path.of(System.getProperty("project.build.directory", ""));
Path mlirDir = buildDir.resolve("mlir");
try {
Files.createDirectories(mlirDir);
Files.writeString(mlirDir.resolve(javaKernelName + ".mlir"), mlirText, StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
}
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, fixed.
Babylon Java Triton example translates Java source code with Java Triton API into code model by code reflection.
In this PR, we traverse the given code model and output Triton MLIR dialect in the generic form, and then inject generated MLIR dialect into the Intel Triton backend. We then utilize Intel Triton backend to compile the Triton MLIR dialect into a SPIR-V module. Use
Jextract
to create Java binding of Intel Level Zero runtime and launch the given kernel function with it on Intel GPUs.Usage
Navigate to the
cr-example/triton
directory and executemvn clean test
. This will generate multiple MLIR files in theresult
directory ready to be processed by the Triton backend.Next, modify the
compiler.py
file within theintel-xpu-triton-backend
project by applying the patchgit apply add-mlir-insertion.patch
. Then run the Triton backend by runningpython3 translate.py
.The Triton backend will generate SPIR-V files, which will be located under
~/.triton/cache/{hash_value}/{kernel_name}/{kernel_name}.spv
.To create a binding for Level Zero, execute the below commands:
The will generate
levelzero.jar
in the current directory.After getting JAR files for Level Zero and
JSON-java
, proceed to compile and run the launcherLevelZero.java
with the following commands:Ensure the hash values in
~/.triton/cache
match those used in theLevelZero.java
.Dependencies
Progress
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/241/head:pull/241
$ git checkout pull/241
Update a local copy of the PR:
$ git checkout pull/241
$ git pull https://git.openjdk.org/babylon.git pull/241/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 241
View PR using the GUI difftool:
$ git pr show -t 241
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/241.diff
Using Webrev
Link to Webrev Comment