annotate graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodySpillTest.java @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents 1fdecc36c8ac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24 package com.oracle.graal.compiler.hsail.test;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import java.util.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import org.junit.*;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29
12470
458676bcc4e0 marked HSAIL tests that rely on unimplemented features
Doug Simon <doug.simon@oracle.com>
parents: 10662
diff changeset
30 import com.oracle.graal.compiler.hsail.test.infra.*;
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 * This version of NBody causes Graal to generate register spilling code.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 public class StaticNBodySpillTest extends GraalKernelTester {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 static final int bodies = 5;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 static final float delT = .005f;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 static final float espSqr = 1.0f;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 static final float mass = 5f;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 static final int width = 768;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 static final int height = 768;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 // Positions xy and z of bodies.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 @Result private float[] inxyz = new float[bodies * 3];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 // Positions xy and z of bodies.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 @Result private float[] outxyz = new float[bodies * 3]; // positions xy and z of bodies
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 // Velocity component of x,y and z of bodies.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 @Result private float[] invxyz = new float[bodies * 3];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 @Result private float[] outvxyz = new float[bodies * 3];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 static float[] seedxyz = new float[bodies * 3];
12664
1fdecc36c8ac HSAIL updates to integrate recent changes to the providers infrastructure.
Doug Simon <doug.simon@oracle.com>
parents: 12588
diff changeset
51 static {
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 final float maxDist = width / 4;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 for (int body = 0; body < (bodies * 3); body += 3) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 final float theta = (float) (Math.random() * Math.PI * 2);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 final float phi = (float) (Math.random() * Math.PI * 2);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 final float radius = (float) (Math.random() * maxDist);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 seedxyz[body + 0] = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 seedxyz[body + 1] = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 seedxyz[body + 2] = (float) (radius * Math.cos(phi));
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 public static void run(float[] inxyz, float[] outxyz, float[] invxyz, float[] outvxyz, int gid) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 final int count = bodies * 3;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 final int globalId = gid * 3;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 float accx = 0.f;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 float accy = 0.f;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 float accz = 0.f;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 for (int i = 0; i < count; i += 3) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 final float dx = inxyz[i + 0] - inxyz[globalId + 0];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 final float dy = inxyz[i + 1] - inxyz[globalId + 1];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 final float dz = inxyz[i + 2] - inxyz[globalId + 2];
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 final float invDist = (float) (1.0 / (Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr)));
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 accx += mass * invDist * invDist * invDist * dx;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 accy += mass * invDist * invDist * invDist * dy;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 accz += mass * invDist * invDist * invDist * dz;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78 accx *= delT;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 accy *= delT;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 accz *= delT;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 outxyz[globalId + 0] = inxyz[globalId + 0] + (invxyz[globalId + 0] * delT) + (accx * .5f * delT);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 outxyz[globalId + 1] = inxyz[globalId + 1] + (invxyz[globalId + 1] * delT) + (accy * .5f * delT);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 outxyz[globalId + 2] = inxyz[globalId + 2] + (invxyz[globalId + 2] * delT) + (accz * .5f * delT);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 outvxyz[globalId + 0] = invxyz[globalId + 0] + accx;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 outvxyz[globalId + 1] = invxyz[globalId + 1] + accy;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86 outvxyz[globalId + 2] = invxyz[globalId + 2] + accz;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 @Override
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 public void runTest() {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 System.arraycopy(seedxyz, 0, inxyz, 0, seedxyz.length);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 Arrays.fill(outxyz, 0f);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 Arrays.fill(outvxyz, 0f);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 Arrays.fill(invxyz, 0f);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 dispatchMethodKernel(bodies, inxyz, outxyz, invxyz, outvxyz);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97
12588
3b178baf3edb fleshed out HSAIL backend a little to demonstrate changes needed after recent API/infrastructure updates
Doug Simon <doug.simon@oracle.com>
parents: 12470
diff changeset
98 @Test
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 public void test() {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 testGeneratedHsail();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102 }