Some minor errors observed in while experimenting with a sample
Gary Frost
gary.frost at oracle.com
Mon Dec 15 08:59:32 UTC 2025
Hello Nadesh.
Thanks for checking out HAT and for the feedback.
Basicallyference the question numbers in your email in my response.
1) The access annotations for kernel args (and compute args) are currently needed, but will soon be unnecessary. These annotations indicate a contract with the kernel, indicating how the kernel expects to access its 'buffer' args (MemorySegments) .
We have code which can determine the access patterns by static analysis of the kernel call tree (a closure over the kernel and all methods reachable from it) and at present we are validating that our analysis matches the annotations. So you should endeavour to annotate corrrectly. Failure to do so, will mean that we will treat it as RW. So we may copy unnecessarily to the GPU.
2) Kernels are intended to be run on the GPU (or FPGA or some other accelerator device). So code should be restricted to code that can be executed on those devices.
Basically kernels should only receive primitives and memory segments. It should only operate on its received args using the 'identity' communicated via the KernelContext.
Generally you should not
Allocate any Object (or array) , either directly (via new)or by calling methods that will allocate an object or array.
So sadly no Strings (* 1 see below)
Call any method (static or instance) that is not itself code reflectable via @Reflect annotation. (* 2 see below)
Reference any fields (static or instance) not under HAT's control. (* 3 below again)
We can map certain Math.xxx() methods. but generally even this may need to be controlled
Throw any exceptions or call any method that throws an exception.
You can only call static methods which follow the rules above,
3) System.out.println(...) in a kernel fails for multiple reasons (#1, #2 and #3) above :) because it references a static field of System and then tries to call println() on the object that is retrieved from that field and it tries to pass a String which is allocated (the "literal")
The first check fails because of the field load on System.out ... hence the (sadly cryptic) "What is this field load"?
Regarding ...
UNSUPPORTED (log once): buildComputeProgram: cl2Metal failed
buildStatus =failed
logLen = 186 log = program_source:50:37: error: implicit declaration of function 'squareit' is invalid in OpenCL
array->array[(long)HAT_GIX]=squareit(value);
Can you send a (small as possible) example that creates this error? If we follow all the rules above (and the ones I have forgotten to include ;) ) you shoduring see this. And
The change from @CodeReflection -> @Reflect and requiring lambdas to cast to Compute or Kernel Quotable's is very new. You may have pulled babylon and HAT during a sequence of checkins. Can you try to pull the latest (and rebuild your Babylon enabled JDK) .. and just check that you have the latest version.
Regards
Gary
Confidential- Oracle Internal
________________________________
From: babylon-dev <babylon-dev-retn at openjdk.org> on behalf of nadeesh t v <nadeeshtv at gmail.com>
Sent: Saturday, December 13, 2025 5:22 PM
To: babylon-dev at openjdk.org <babylon-dev at openjdk.org>
Subject: Some minor errors observed in while experimenting with a sample
Hello,
I was experimenting with a HAT Squares sample<https://github.com/openjdk/babylon/blob/code-reflection/hat/examples/squares/src/main/java/squares/Main.java> () and noticed a couple of minor issues ( at least I think). Since this is still in the development stage, I am not sure whether it’s right to bring it up or not.
Let me know if these kinds of minor issues should not be brought up or not. I was using the OpenCL backend.
1 I can mark the argument of kernel function with any one of the RO/RW annotations and still seem to work.
For eg: in the original example it was void squareKernel(@RO KernelContext kc, @RW S32Array array)
But if I change that to `void squareKernel(@WO KernelContext kc, @RO S32Array array) `, it still works. I would expect it to throw some errors because the access byte has changed.
2 If I add a System.out.println("Hello") in the kernel, it is running to the below issue.
```
@Reflect
public static void squareKernel(@WO KernelContext kc, @RO S32Array array) {
System.out.println("Hello");
if (kc.gix < kc.gsx){
….
}
}
```
Is there some rule about what should go into the kernel function?
```
what?org.example.MainWithHAT::squareKernel(hat.KernelContext, hat.buffer.S32Array):void java.lang.IllegalStateException: What is this field load ?jdk.incubator.code.dialect.java.JavaOp$FieldAccessOp$FieldLoadOp at 1fc32e4fjava.lang.IllegalStateException: What is this field load ?jdk.incubator.code.dialect.java.JavaOp$FieldAccessOp$FieldLoadOp at 1fc32e4f
at hat.codebuilders.C99HATKernelBuilder.fieldLoadOp(C99HATKernelBuilder.java:72)
at hat.codebuilders.C99HATKernelBuilder.fieldLoadOp(C99HATKernelBuilder.java:58)
….
```
3. If I comment out the Reflect on the function that is called from kernel function
```
// @Reflect
public static int squareit(int v) {
return v * v;
}
```
Then , I am running into the familiar `c` error.
```
UNSUPPORTED (log once): buildComputeProgram: cl2Metal failed
buildStatus =failed
logLen = 186 log = program_source:50:37: error: implicit declaration of function 'squareit' is invalid in OpenCL
array->array[(long)HAT_GIX]=squareit(value);
```
4. If I comment out the Reflect on the compute method function that is throwing an error from Optional but for that I can create a pull request to throw the one similar to the `did you miss @Reflect annotation?`.
--
Thanks and Regards,
Nadeesh TV
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/babylon-dev/attachments/20251215/2ce6ead4/attachment-0001.htm>
More information about the babylon-dev
mailing list