trying to compile filter().forEach() for HSAIL

Eric Caspole eric.caspole at amd.com
Tue Oct 14 21:19:41 UTC 2014


I am trying to offload a multi-step stream of lambdas with Sumatra, 
where I would compile both the filter and the forEach into 1 kernel.

Here is my test code I want to offload:

         MyPoint[] inputs;
         int[] data;
         int[] data2;

         Arrays.stream(inputs).
                 parallel().
                 filter(p -> ((p.x > 6) && (data2 != null))).
                 forEach(p -> {
                     p.y = data[p.x] + data2[p.x];
                 });

I am trying to do it by using a helper method that will become the 
"main" of the kernel so to speak:

     public static final <S> void accept(Predicate<S> predicate,
             Consumer<S> forEachConsumer,
             S iterationVariable) {
         if (predicate.test(iterationVariable)) {
             forEachConsumer.accept(iterationVariable);
         }
     }

In the kernel args, the iterationVariable is replaced by the stream 
source array so each GPU workitem gets its own unique array element to 
work on.

Since the HSA runtime does not have actual method/function call support 
yet, everything will have to get inlined into this method for the time 
being. In this naive prototype, I "train" this method 500 times through 
the normal CPU execution to get some profile, then divert to HSAIL.

With my junit for this work my actual types are:

predicate class: 
com.oracle.graal.compiler.hsail.test.lambda.MultiTest$$Lambda$1/1606304070
consumer class : 
com.oracle.graal.compiler.hsail.test.lambda.MultiTest$$Lambda$2/1525409936

The problem I have met is that the compilation dependency checks fail on 
"abstract_with_unique_concrete_subtype" because there is more than 1 
Predicate implementor loaded in the system, because Graal itself uses 
some Stream API, for example.

Is there a legitimate way to bypass this dependency check when compiling 
for HSAIL, where everything is funnelled through an offload pipeline 
under our control? Or is there a graceful solution to narrow the types 
going into the method? I am compiling this method specifically for HSAIL 
and it is sort of not really exposed to all the other types in the CPU 
side system.

Thanks,
Eric



More information about the graal-dev mailing list