VectorAPI reduction operation support for testing infrastructure

Paul Sandoz paul.sandoz at oracle.com
Thu Mar 29 22:03:31 UTC 2018



> On Mar 29, 2018, at 2:36 PM, Halimi, Jean-Philippe <jean-philippe.halimi at intel.com> wrote:
> 
> Razvan just made me realize that we can actually enable the reduction tests even without the intrinsics. I will uncomment them.
> 

Right, i was just replying to say exactly that :-) In fact we should run the tests with the intrinsics enabled and disabled, so we test both code paths.

On the other point, using a scalar function for reduction:

  99     static void assertReductionArraysEquals($type$[] a, $type$[] b, FReductionOp f) {
 100       int i = 0;
 101       try {
 102         for (; i < a.length; i += SPECIES.length()) {
 103           Assert.assertEquals(f.apply(a, i), b[i]);
 104         }
 105       } catch (AssertionError e) {
 106         Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i);
 107       }
 108     }

You can abstract out the scalar function in many cases:

   1     static $type$ [[TEST]]($type$[] a, int idx) {
   2         $type$ res = [[TEST_INIT]];
   3         for (int i = idx; i < (idx + SPECIES.length()); i++) {
   4           res [[TEST_OP]]= a[i];
   5         }
   6 
   7         return res;
   8     }

e.g. embed lines 3-4 into the loop of 102-104 and use the binary function where the first argument is the accumulated result. Or, perhaps even better, define an implementation of the reduction op composed from a scalar binary op where the first argument is the accumulated result.  That works for the general associative case. Then we can specialize if needed for any non-associative cases, probably for FP (which might also inform what the actual Java implementation should be too, depending on how lax we want to be regarding rounding errors).

If we keep the reduction operation i think it should accept a length rather than binding to species. Even if not reusable now, it might be opportunistic so later on if code is eventually shared. (Same for the mask accepting assert methods too with regards to SPECIES.)

Its use might look like:

  assertReductionArraysEquals(a, b, SPECIES.length(), reducing(Long512VectorTests::add));

i.e. we can reuse the add function that has already been generated.

Paul.

> Jp
> 
> -----Original Message-----
> From: panama-dev [mailto:panama-dev-bounces at openjdk.java.net] On Behalf Of Halimi, Jean-Philippe
> Sent: Thursday, March 29, 2018 2:21 PM
> To: Paul Sandoz <paul.sandoz at oracle.com>
> Cc: panama-dev at openjdk.java.net
> Subject: RE: VectorAPI reduction operation support for testing infrastructure
> 
> Thanks for the review :-) Sorry for the delayed answer. Let me answer in the email.
> 
> -----Original Message-----
> From: Paul Sandoz [mailto:paul.sandoz at oracle.com] 
> Sent: Tuesday, March 27, 2018 6:05 PM
> To: Halimi, Jean-Philippe <jean-philippe.halimi at intel.com>
> Cc: panama-dev at openjdk.java.net
> Subject: Re: VectorAPI reduction operation support for testing infrastructure
> 
> 
> 
>> On Mar 27, 2018, at 4:45 PM, Halimi, Jean-Philippe <jean-philippe.halimi at intel.com> wrote:
>> 
>> Hi all,
>> 
>> I would like to share a patch adding support for reduction operations testing in VectorAPI.
>> 
>> Could you please review the patch here:
>> http://cr.openjdk.java.net/~jphalimi/webrev_reduction_testing_v1.1/
>> 
> 
> 122 # Reductions.
> 123 #gen_reduction_op "andAll" "\&" $template_file "BITWISE" "-1"
> 124 #gen_reduction_op "orAll" "|" $template_file "BITWISE" "0"
> 125 #gen_reduction_op "xorAll" "^" $template_file "BITWISE" "0"
> 126 #gen_reduction_op "subAll" "-" $template_file "" "0"
> 
> The actual reduction generation is commented out, is that intentional?
> Include addAll, minAll, maxAll, mullAll. For FP we need to be careful about rounding errors.
> 
>>> It is intentional. Currently, there is no support for orAll, xorAll and subAll. My hope was to uncomment these tests as we get the other patches merged.
> 
> For the reductive tests i would generate the simplest scalar binary function without a loop (like in the Java implementations) and push the looping logic into the assertReductionArraysEquals, which would accept the binary function e.g.  this is what the Java implementations do:
> 
> int rOp(int v, FBinOp f) {
>    int[] vec = getElements();
>    for (int i = 0; i < length(); i++) {
>        v = f.apply(i, v, vec[i]);
>    }
>    return v;
> }
> 
> public int addAll() {
>    return rOp((int) 0, (i, a, b) -> (int) (a + b)); }
> 
>>> I understand that you want to factorize the reductions in one simple method. However it looks a bit complicated to do this way since you can't reach the vector from rOp. Or perhaps I missed something here?
> 
> Paul.



More information about the panama-dev mailing list