<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Apologies all. I forgot 'reply to all'<br>
<br>
Gary</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Gary Frost <gary.frost@oracle.com><br>
<b>Sent:</b> Monday, June 24, 2024 3:47 PM<br>
<b>To:</b> Juan Fumero <juan.fumero@paravox.ai><br>
<b>Subject:</b> Re: [External] : Re: Some questions about HAT and Babylon</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
We don't yet. But yes the plan is to have 1d,2d and 3d variants of the KernelContext<br>
<br>
Actually some code may be there, I just have not hooked it up to the ComputeContext. </div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
So in Java terms<br>
<br>
class KernelContext {<br>
class F32{<br>
float invsqrt(float f){};</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
}<br>
class F64{<br>
double hypot(double x,double y){};</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
}</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
void barrier(){};</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
}<br>
class KernelContext3D extends KernelContext{<br>
int x, y, z;<br>
int maxX, maxY, maxZ;<br>
int groupX, groupY, groupZ;<br>
int groupMaxX, groupMaxY, groupMaxZ<br>
}<br>
<br>
Clearly we can use the time honored mod/mul pattern (y%width and y/width) to flatten our grid to 1d from 2d.<br>
<br>
I think the Mandel example uses a 1d grid to execute a fake 2d sweep 😉<br>
<br>
<br>
The KernelContext will also likely be the hook for common 'kernely' functions<br>
<br>
KernelContext kc;<br>
kc.barrier()<br>
kc.F32.invsqrt(x)</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
kc.F64.hypot(x,y)</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
kc.I32.atomicInc(?)<br>
kc.I32.inclusiveScan(?)<br>
<br>
</div>
<div class="x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
Gary<br>
<br>
<br>
<br>
<br>
</div>
<div id="x_appendonsend"></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Juan Fumero <juan.fumero@paravox.ai><br>
<b>Sent:</b> Monday, June 24, 2024 3:24 PM<br>
<b>To:</b> Gary Frost <gary.frost@oracle.com><br>
<b>Subject:</b> [External] : Re: Some questions about HAT and Babylon</font>
<div> </div>
</div>
<div>
<p>Thanks Gary, <br>
</p>
<p> I will take a look at the pom files. <br>
</p>
<p><br>
</p>
<p>Another question. Going a bit deeper into the KernelContext (I guess an inspired by TornadoVM Data Structure), is the any variant to represent a 2D NDRange?<br>
</p>
<p><br>
</p>
<p><a class="x_x_moz-txt-link-freetext" href="https://urldefense.com/v3/__https://github.com/openjdk/babylon/blob/e7ada25d4c01c76461bf5cd73b928138050f11f8/hat/examples/experiments/src/main/java/experiments/spirv/MatrixMultiply.java*L77__;Iw!!ACWV5N9M2RV99hQ!O9nmXwQoYr3FSnQdIT4xud0fnalAmTtGiQxx7yNO43sVuRj3p0oEECInHId0SNdH7pTEr7Qukqydo9h7nNcAF9fKCA$">https://github.com/openjdk/babylon/blob/e7ada25d4c01c76461bf5cd73b928138050f11f8/hat/examples/experiments/src/main/java/experiments/spirv/MatrixMultiply.java#L77</a>
<br>
</p>
<p><br>
</p>
<p>I wanted to run some examples with 2D Matrix Multiplication. <br>
</p>
<p><br>
</p>
<p>I guess:</p>
<p><br>
</p>
<p>```java</p>
<div style="background-color:#1e1f22; color:#bcbec4">
<pre style="font-family:'JetBrains Mono',monospace; font-size:9.8pt"><span style="color:#cf8e6d">public class </span>KernelContext {
<span style="color:#cf8e6d">public final </span>NDRange <span style="color:#c77dbb">ndRange</span>;
<span style="color:#cf8e6d">public int </span><span style="color:#c77dbb">x</span>;
<span style="color:#cf8e6d">public final int </span><span style="color:#c77dbb">maxX</span>;
<span style="color:#cf8e6d">public </span><span style="color:#56a8f5">KernelContext</span>(NDRange ndRange, <span style="color:#cf8e6d">int </span>maxX, <span style="color:#cf8e6d">int </span>x) {
<span style="color:#cf8e6d">this</span>.<span style="color:#c77dbb">ndRange </span>= ndRange;
<span style="color:#cf8e6d">this</span>.<span style="color:#c77dbb">maxX </span>= maxX;
<span style="color:#cf8e6d">this</span>.<span style="color:#c77dbb">x </span>= x;
}
}</pre>
</div>
<p></p>
<p>```</p>
<p><br>
</p>
<p>The NDRange object itself can return `maxX`, `maxY` and `maxZ` for each dimension as well as the thread-id per dimension. Could this be the way to go?
<br>
</p>
<p><br>
</p>
<p>In TornadoVM, we have the concept of `WorkerGrid` [1], which can be 1D, 2D or 3D as a sub-type.</p>
<p>The `KernelContext` [2] gives us access to the corresponding thread-ids as well as access to barriers, local memory (in OpenCL terms), etc.
<br>
</p>
<p><br>
</p>
<p>[1] <a class="x_x_moz-txt-link-freetext" href="https://urldefense.com/v3/__https://github.com/beehive-lab/TornadoVM/blob/master/tornado-api/src/main/java/uk/ac/manchester/tornado/api/WorkerGrid.java*L20__;Iw!!ACWV5N9M2RV99hQ!O9nmXwQoYr3FSnQdIT4xud0fnalAmTtGiQxx7yNO43sVuRj3p0oEECInHId0SNdH7pTEr7Qukqydo9h7nNejJ3l5qQ$">
https://github.com/beehive-lab/TornadoVM/blob/master/tornado-api/src/main/java/uk/ac/manchester/tornado/api/WorkerGrid.java#L20</a>
<br>
</p>
<p>[2] <a class="x_x_moz-txt-link-freetext" href="https://urldefense.com/v3/__https://github.com/beehive-lab/TornadoVM/blob/master/tornado-api/src/main/java/uk/ac/manchester/tornado/api/KernelContext.java__;!!ACWV5N9M2RV99hQ!O9nmXwQoYr3FSnQdIT4xud0fnalAmTtGiQxx7yNO43sVuRj3p0oEECInHId0SNdH7pTEr7Qukqydo9h7nNdy-kC-eg$">
https://github.com/beehive-lab/TornadoVM/blob/master/tornado-api/src/main/java/uk/ac/manchester/tornado/api/KernelContext.java</a><br>
</p>
<p><br>
</p>
<p><br>
</p>
<p>Thanks<br>
</p>
<p>Juan<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="x_x_moz-cite-prefix">On 24/06/2024 15:57, Gary Frost wrote:<br>
</div>
<blockquote type="cite"><style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hey Juan<br>
<br>
I would like to see your top level pom.xml<br>
<br>
Specifically the pom.xml...properties which usually have these defaults<br>
<br>
<properties></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<babylon.repo.name>babylon</babylon.repo.name> <!--replace with your fork name --></div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<maven.compiler.source>23</maven.compiler.source></div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<maven.compiler.target>23</maven.compiler.target></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<github.dir>${env.HOME}/github</github.dir></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<beehive.spirv.toolkit.dir>${github.dir}/beehive-spirv-toolkit/</beehive.spirv.toolkit.dir></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<babylon.dir>${github.dir}/${babylon.repo.name}</babylon.dir></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<hat.dir>${babylon.dir}/hat</hat.dir></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<hat.target>${hat.dir}/maven-build</hat.target></div>
<div class="x_x_elementToProof" style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
</properties><br>
<br>
Which assumes a layout under github which looks like this.<br>
<br>
github/<br>
babylon/<br>
build/<br>
YOUR_OS-YOUR_ARCH-server-release<br>
hat/<br>
beehive-spirv-toolkit/<br>
<br>
<br>
Yours might be something like this.<br>
<br>
github/<br>
babylon/<br>
babylon/ <---?<br>
build/<br>
YOUR_OS-YOUR_ARCH-server-release<br>
hat/<br>
beehive-spirv-toolkit/<br>
<br>
In which case you may need<br>
<babylon.dir>${github.dir}/babylon/${babylon.repo.name}</babylon.dir><br>
<br>
Most important is that ${babylon.dir}/hat == ${hat.dir}<br>
<br>
There is a 'sanity.java' script in the hat root. Which (hopefully) can just be run via java (23) directly<br>
<br>
java sanity.java<br>
<br>
Which will attempt to sanity check your pom properties. I switch repos frequently, and this script has saved my bacon a few times.<br>
<br>
The native code (C++/C) in the SPIRV backend is essentially a mock backend, enough to load the lib and hook up the 'native trampoline' points. My idea was that someone 😉 would crib from the OpenCL one, or build a HIP or Level0 variant... <br>
<br>
Gary<br>
<br>
<br>
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> babylon-dev
<a class="x_x_moz-txt-link-rfc2396E" href="mailto:babylon-dev-retn@openjdk.org"><babylon-dev-retn@openjdk.org></a> on behalf of Juan Fumero
<a class="x_x_moz-txt-link-rfc2396E" href="mailto:juan.fumero@paravox.ai"><juan.fumero@paravox.ai></a><br>
<b>Sent:</b> Monday, June 24, 2024 2:29 PM<br>
<b>To:</b> <a class="x_x_moz-txt-link-abbreviated" href="mailto:babylon-dev@openjdk.org">
babylon-dev@openjdk.org</a> <a class="x_x_moz-txt-link-rfc2396E" href="mailto:babylon-dev@openjdk.org">
<babylon-dev@openjdk.org></a><br>
<b>Subject:</b> Some questions about HAT and Babylon</font>
<div> </div>
</div>
<div class="x_x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_x_PlainText">Hi all,<br>
<br>
I am building and testing a few examples and I have a few questions:<br>
<br>
<br>
1) During the installation of the HAT component, the JAR files and <br>
binaries where place under the $HOME directory, instead of under the HAT <br>
sub directory within Babylon:<br>
<br>
For example, in my case, the installation was copied here:<br>
<br>
/home/juan/github/babylon/hat/maven-build<br>
<br>
<br>
However, my Babylon install is here:<br>
<br>
/home/juan/repos/hat/babylon/babylon<br>
<br>
<br>
2) I saw the C-code code of HAT, I noticed that there are several <br>
directories per backend. One for OpenCL, PTX, etc. SPIR-V is also a <br>
directory. However, SPIR-V is an intermediate representation and it is <br>
dispatched via a) OpenCL, or b) Level Zero. Is there any reason why <br>
SPIR-V has this C-library?<br>
<br>
<br>
I hope to find more time during the week to do some testing.<br>
<br>
<br>
Kind regards,<br>
<br>
Juan<br>
<br>
<br>
</div>
</span></font></div>
</blockquote>
</div>
</div>
</body>
</html>