changeset 13650:1095dcf7f028

reworked PTX unit tests to PTX kernel call wrapper
author Doug Simon <doug.simon@oracle.com>
date Wed, 15 Jan 2014 20:25:55 +0100
parents 36d4faef2c56
children 1274feb0efe6
files graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java graal/com.oracle.graal.hotspot.ptx.test/src/com/oracle/graal/hotspot/ptx/test/PTXLaunchKernelTest.java
diffstat 9 files changed, 207 insertions(+), 779 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -24,34 +24,28 @@
 
 import static com.oracle.graal.lir.ptx.ThreadDimension.*;
 
-import java.lang.reflect.*;
-import java.util.*;
-
 import org.junit.*;
 
 import com.oracle.graal.lir.ptx.*;
 
-public class ArrayPTXTest extends PTXTestBase {
+public class ArrayPTXTest extends PTXTest {
 
+    @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented")
     @Test
-    public void testArray() {
-        int[] array1 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
-        int[] array2 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
-        int[] array3 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+    public void test1() {
+        test("testStoreArray1I", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2);
+    }
 
-        invoke(compile("testStoreArray1I"), array1, 2);
-        if (array1[2] == 42) {
-            printReport("testStoreArray1I: " + Arrays.toString(array1) + " PASSED");
-        } else {
-            printReport("testStoreArray1I: " + Arrays.toString(array1) + " FAILED");
-        }
+    @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented")
+    @Test
+    public void test2() {
+        test("testStoreArrayWarp0", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2);
+    }
 
-        invoke(compile("testStoreArrayWarp0"), array2, 2);
-        printReport("testStoreArrayWarp0: " + Arrays.toString(array2));
-
-        invoke(compile("testStoreArrayWarp1I"), array3, 2);
-        printReport("testStoreArrayWarp1I: " + Arrays.toString(array3));
-
+    @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented")
+    @Test
+    public void test3() {
+        test("testStoreArrayWarp1I", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2);
     }
 
     public static void testStoreArray1I(int[] array, int i) {
@@ -67,12 +61,6 @@
     }
 
     public static void main(String[] args) {
-        ArrayPTXTest test = new ArrayPTXTest();
-        for (Method m : ArrayPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new ArrayPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -22,37 +22,41 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.*;
-
 import org.junit.*;
 
 /**
  * Test class for small Java methods compiled to PTX kernels.
  */
-public class BasicPTXTest extends PTXTestBase {
+public class BasicPTXTest extends PTXTest {
 
     @Test
-    public void testAdd() {
-        invoke(compile("testConstI"));
-    }
-
-    @Test
-    public void testInvoke() {
-        invoke(compile("testConstI"));
+    public void test() {
+        test("testConstI");
     }
 
     public static int testConstI() {
         return 42;
     }
 
+    @Test
+    public void testStaticIntKernel() {
+        test("staticIntKernel", 'a', 42);
+    }
+
+    @Test
+    public void testVirtualIntKernel() {
+        test("virtualIntKernel", 'a', 42);
+    }
+
+    public static int staticIntKernel(char p0, int p1) {
+        return p1 + p0;
+    }
+
+    public int virtualIntKernel(char p0, int p1) {
+        return p1 + p0;
+    }
+
     public static void main(String[] args) {
-        BasicPTXTest test = new BasicPTXTest();
-        Method[] methods = BasicPTXTest.class.getMethods();
-        for (Method m : methods) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new BasicPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -22,96 +22,22 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.*;
-
 import org.junit.*;
 
-public class ControlPTXTest extends PTXTestBase {
+public class ControlPTXTest extends PTXTest {
 
     @Test
     public void testControl() {
-        String testName = "testLoop";
-        int argVal1 = 42;
-        int argVal2;
-        Integer ret = (Integer) invoke(compile(testName), argVal1);
-        int jres = testLoop(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
-
-        testName = "testSwitchDefault1I";
-        argVal1 = 3;
-        ret = (Integer) invoke(compile(testName), argVal1);
-        jres = testSwitchDefault1I(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
+        test("testLoop", 42);
+        test("testSwitchDefault1I", 3);
+        test("testSwitch1I", 2);
+        test("testIfElse1I", 222);
+        test("testIfElse2I", 19, 64);
 
-        testName = "testSwitch1I";
-        argVal1 = 2;
-        ret = (Integer) invoke(compile(testName), argVal1);
-        jres = testSwitch1I(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
-
-        testName = "testIfElse1I";
-        argVal1 = 222;
-        ret = (Integer) invoke(compile(testName), argVal1);
-        jres = testIfElse1I(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
-
-        testName = "testIfElse2I";
-        argVal1 = 19;
-        argVal2 = 64;
-        ret = (Integer) invoke(compile(testName), argVal1, argVal2);
-        jres = testIfElse2I(argVal1, argVal2);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-        }
-
-        Boolean bret = (Boolean) invoke(compile("testIntegerTestBranch2I"), 0xff00, 0x00ff);
-        if (bret != null) {
-            printReport("testIntegerTestBranch2I: " + bret);
-            printReport("testIntegerTestBranch2I: actual: " + testIntegerTestBranch2I(0xff00, 0x00ff));
-        } else {
-            printReport("testIntegerTestBranch2I: no VALUE");
-        }
-        compile("testStatic");
-        compile("testCall");
-        compile("testLookupSwitch1I");
+        test("testIntegerTestBranch2I", 0xff00, 0x00ff);
+        compileKernel("testStatic");
+        compileKernel("testCall");
+        compileKernel("testLookupSwitch1I");
     }
 
     public static boolean testIntegerTestBranch2I(int x, int y) {
@@ -210,12 +136,6 @@
     }
 
     public static void main(String[] args) {
-        ControlPTXTest test = new ControlPTXTest();
-        for (Method m : ControlPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new ControlPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -22,45 +22,17 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.Method;
-
 import org.junit.*;
 
-import com.oracle.graal.api.code.CompilationResult;
-
 /* PTX ISA 3.1 - 8.7.3 Floating-Point Instructions */
-public class FloatPTXTest extends PTXTestBase {
+public class FloatPTXTest extends PTXTest {
 
     @Test
     public void testAdd() {
-        Float ret = (Float) invoke(compile("testAdd2I"), 42, 43);
-        if (ret != null) {
-            printReport("testAdd2I: " + ret);
-        } else {
-            printReport("testAdd2I: no VALUE");
-        }
-
-        ret = (Float) invoke(compile("testAdd2F"), 42.1F, 43.5F);
-        if (ret != null) {
-            printReport("testAdd2F: " + ret);
-        } else {
-            printReport("testAdd2F: no VALUE");
-        }
-
-        ret = (Float) invoke(compile("testAddFConst"), 42.1F);
-        if (ret != null) {
-            printReport("testAddFConst: " + ret);
-        } else {
-            printReport("testAddFConst: no VALUE");
-        }
-
-        Double dret = (Double) invoke(compile("testAdd2D"), 42.1, 43.5);
-        if (dret != null) {
-            printReport("testAdd2D: " + dret);
-        } else {
-            printReport("testAdd2D: no VALUE");
-        }
-
+        test("testAdd2I", 42, 43);
+        test("testAdd2F", 42.1F, 43.5F);
+        test("testAddFConst", 42.1F);
+        test("testAdd2D", 42.1, 43.5);
     }
 
     public static float testAdd2I(int a, int b) {
@@ -94,35 +66,12 @@
     @Ignore
     @Test
     public void testSub() {
-        CompilationResult r = compile("testSub2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSub2F FAILED");
-        }
-
-        r = compile("testSub2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSub2D FAILED");
-        }
-
-        r = compile("testSubFConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSubFConst FAILED");
-        }
-
-        r = compile("testSubConstF");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSubConstF FAILED");
-        }
-
-        r = compile("testSubDConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSubDconst FAILED");
-        }
-
-        r = compile("testSubConstD");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testConstD FAILED");
-        }
+        compileKernel("testSub2F");
+        compileKernel("testSub2D");
+        compileKernel("testSubFConst");
+        compileKernel("testSubConstF");
+        compileKernel("testSubDConst");
+        compileKernel("testSubConstD");
     }
 
     public static float testSub2F(float a, float b) {
@@ -152,35 +101,12 @@
     @Ignore
     @Test
     public void testMul() {
-        CompilationResult r = compile("testMul2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMul2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulFConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulConstF");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulDConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulConstD");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
+        compileKernel("testMul2F");
+        compileKernel("testMul2D");
+        compileKernel("testMulFConst");
+        compileKernel("testMulConstF");
+        compileKernel("testMulDConst");
+        compileKernel("testMulConstD");
     }
 
     public static float testMul2F(float a, float b) {
@@ -210,35 +136,12 @@
     @Ignore
     @Test
     public void testDiv() {
-        CompilationResult r = compile("testDiv2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDiv2F FAILED");
-        }
-
-        r = compile("testDiv2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDiv2D FAILED");
-        }
-
-        r = compile("testDivFConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivFConst FAILED");
-        }
-
-        r = compile("testDivConstF");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivConstF FAILED");
-        }
-
-        r = compile("testDivDConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivDConst FAILED");
-        }
-
-        r = compile("testDivConstD");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivConstD FAILED");
-        }
+        compileKernel("testDiv2F");
+        compileKernel("testDiv2D");
+        compileKernel("testDivFConst");
+        compileKernel("testDivConstF");
+        compileKernel("testDivDConst");
+        compileKernel("testDivConstD");
     }
 
     public static float testDiv2F(float a, float b) {
@@ -268,15 +171,8 @@
     @Ignore
     @Test
     public void testNeg() {
-        CompilationResult r = compile("testNeg2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testNeg2F FAILED");
-        }
-
-        r = compile("testNeg2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testNeg2D FAILED");
-        }
+        compileKernel("testNeg2F");
+        compileKernel("testNeg2D");
     }
 
     public static float testNeg2F(float a) {
@@ -291,8 +187,8 @@
     @Test
     public void testRem() {
         // need linkage to PTX remainder()
-        // compile("testRem2F");
-        // compile("testRem2D");
+        // compileKernel("testRem2F");
+        // compileKernel("testRem2D");
     }
 
     public static float testRem2F(float a, float b) {
@@ -306,35 +202,12 @@
     @Ignore
     @Test
     public void testFloatConversion() {
-        CompilationResult r = compile("testF2I");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of tesF2I FAILED");
-        }
-
-        r = compile("testF2L");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testF2L FAILED");
-        }
-
-        r = compile("testF2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testF2D FAILED");
-        }
-
-        r = compile("testD2I");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testD2I FAILED");
-        }
-
-        r = compile("testD2L");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testD2L FAILED");
-        }
-
-        r = compile("testD2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testD2F FAILED");
-        }
+        compileKernel("testF2I");
+        compileKernel("testF2L");
+        compileKernel("testF2D");
+        compileKernel("testD2I");
+        compileKernel("testD2L");
+        compileKernel("testD2F");
     }
 
     public static int testF2I(float a) {
@@ -362,12 +235,6 @@
     }
 
     public static void main(String[] args) {
-        FloatPTXTest test = new FloatPTXTest();
-        for (Method m : FloatPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test") && name.startsWith("testRem") == false) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new FloatPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -24,59 +24,18 @@
 
 import org.junit.*;
 
+import java.io.*;
 import java.lang.reflect.Method;
 
-public class IntegerPTXTest extends PTXTestBase {
+public class IntegerPTXTest extends PTXTest {
 
     @Test
     public void testAdd() {
-
-        // @formatter:off
-        Integer r4 = (Integer) invoke(compile("testAdd2B"), (byte) 6, (byte) 4);
-        if (r4 == null) {
-            printReport("testAdd2B FAILED");
-        } else if (r4.intValue() == testAdd2B((byte) 6, (byte) 4)) {
-            printReport("testAdd2B PASSED");
-        } else {
-            printReport("testAdd2B FAILED");
-        }
-        // @formatter:on
-
-        r4 = (Integer) invoke(compile("testAdd2I"), 18, 24);
-        if (r4 == null) {
-            printReport("testAdd2I FAILED");
-        } else if (r4.intValue() == testAdd2I(18, 24)) {
-            printReport("testAdd2I PASSED");
-        } else {
-            printReport("testAdd2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testAdd2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testAdd2L FAILED");
-        } else if (r2.longValue() == testAdd2L(12, 6)) {
-            printReport("testAdd2L PASSED");
-        } else {
-            printReport("testAdd2L FAILED");
-        }
-
-        r4 = (Integer) invoke(compile("testAddIConst"), 5);
-        if (r4 == null) {
-            printReport("testAddIConst FAILED");
-        } else if (r4.intValue() == testAddIConst(5)) {
-            printReport("testAddIConst PASSED");
-        } else {
-            printReport("testAddIConst FAILED");
-        }
-
-        r4 = (Integer) invoke(compile("testAddConstI"), 7);
-        if (r4 == null) {
-            printReport("testAddConstI FAILED");
-        } else if (r4.intValue() == testAddConstI(7)) {
-            printReport("testAddConstI PASSED");
-        } else {
-            printReport("testAddConstI FAILED");
-        }
+        test("testAdd2B", (byte) 6, (byte) 4);
+        test("testAdd2I", 18, 24);
+        test("testAdd2L", (long) 12, (long) 6);
+        test("testAddIConst", 5);
+        test("testAddConstI", 7);
     }
 
     public static int testAdd2I(int a, int b) {
@@ -101,43 +60,10 @@
 
     @Test
     public void testSub() {
-
-        Integer r1 = (Integer) invoke(compile("testSub2I"), 18, 4);
-
-        if (r1 == null) {
-            printReport("testSub2I FAILED");
-        } else if (r1.intValue() == testSub2I(18, 4)) {
-            printReport("testSub2I PASSED");
-        } else {
-            printReport("testSub2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testSub2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testSub2I FAILED (null return value)");
-        } else if (r2.longValue() == testSub2L(12, 6)) {
-            printReport("testSub2I PASSED");
-        } else {
-            printReport("testSub2I FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testSubIConst"), 35);
-        if (r1 == null) {
-            printReport("testSubIConst FAILED");
-        } else if (r1.intValue() == testSubIConst(35)) {
-            printReport("testSubIConst PASSED");
-        } else {
-            printReport("testSubIConst FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testSubConstI"), 12);
-        if (r1 == null) {
-            printReport("testSubConstI FAILED");
-        } else if (r1.intValue() == testSubConstI(12)) {
-            printReport("testSubConstI PASSED");
-        } else {
-            printReport("testSubConstI FAILED");
-        }
+        test("testSub2I", 18, 4);
+        test("testSub2L", (long) 12, (long) 6);
+        test("testSubIConst", 35);
+        test("testSubConstI", 12);
     }
 
     public static int testSub2I(int a, int b) {
@@ -158,42 +84,10 @@
 
     @Test
     public void testMul() {
-
-        Integer r1 = (Integer) invoke(compile("testMul2I"), 8, 4);
-        if (r1 == null) {
-            printReport("testMul2I FAILED");
-        } else if (r1.intValue() == testMul2I(8, 4)) {
-            printReport("testMul2I PASSED");
-        } else {
-            printReport("testMul2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testMul2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testMul2L FAILED");
-        } else if (r2.longValue() == testMul2L(12, 6)) {
-            printReport("testMul2L PASSED");
-        } else {
-            printReport("testMul2L FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testMulIConst"), 4);
-        if (r1 == null) {
-            printReport("testMulIConst FAILED");
-        } else if (r1.intValue() == testMulIConst(4)) {
-            printReport("testMulIConst PASSED");
-        } else {
-            printReport("testMulIConst FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testMulConstI"), 5);
-        if (r1 == null) {
-            printReport("testMulConstI FAILED");
-        } else if (r1.intValue() == testMulConstI(5)) {
-            printReport("testMulConstI PASSED");
-        } else {
-            printReport("testMulConstI FAILED");
-        }
+        test("testMul2I", 8, 4);
+        test("testMul2L", (long) 12, (long) 6);
+        test("testMulIConst", 4);
+        test("testMulConstI", 5);
     }
 
     public static int testMul2I(int a, int b) {
@@ -214,41 +108,10 @@
 
     @Test
     public void testDiv() {
-        Integer r1 = (Integer) invoke(compile("testDiv2I"), 8, 4);
-        if (r1 == null) {
-            printReport("testDiv2I FAILED (null value returned)");
-        } else if (r1.intValue() == testDiv2I(8, 4)) {
-            printReport("testDiv2I PASSED");
-        } else {
-            printReport("testDiv2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testDiv2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testDiv2L FAILED (null value returned)");
-        } else if (r2.longValue() == testDiv2L(12, 6)) {
-            printReport("testDiv2L PASSED");
-        } else {
-            printReport("testDiv2L FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testDivIConst"), 64);
-        if (r1 == null) {
-            printReport("testDivIConst FAILED (null value returned)");
-        } else if (r1.intValue() == testDivIConst(64)) {
-            printReport("testDivIConst PASSED");
-        } else {
-            printReport("testDivIConst FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testDivConstI"), 8);
-        if (r1 == null) {
-            printReport("testDivConstI FAILED (null value returned)");
-        } else if (r1.intValue() == testDivConstI(8)) {
-            printReport("testDivConstI PASSED");
-        } else {
-            printReport("testDivConstI FAILED");
-        }
+        test("testDiv2I", 8, 4);
+        test("testDiv2L", (long) 12, (long) 6);
+        test("testDivIConst", 64);
+        test("testDivConstI", 8);
     }
 
     public static int testDiv2I(int a, int b) {
@@ -269,23 +132,8 @@
 
     @Test
     public void testRem() {
-        Integer r1 = (Integer) invoke(compile("testRem2I"), 8, 4);
-        if (r1 == null) {
-            printReport("testRem2I FAILED (null value returned)");
-        } else if (r1.intValue() == testRem2I(8, 4)) {
-            printReport("testRem2I PASSED");
-        } else {
-            printReport("testRem2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testRem2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testRem2L FAILED (null value returned)");
-        } else if (r1.longValue() == testRem2L(12, 6)) {
-            printReport("testRem2L PASSED");
-        } else {
-            printReport("testRem2L FAILED");
-        }
+        test("testRem2I", 8, 4);
+        test("testRem2L", (long) 12, (long) 6);
     }
 
     public static int testRem2I(int a, int b) {
@@ -299,28 +147,12 @@
     @Ignore
     @Test
     public void testIntConversion() {
-        Long r1 = (Long) invoke(compile("testI2L"), 8);
-        if (r1 == null) {
-            printReport("testI2L FAILED (null value returned)");
-        } else if (r1.longValue() == testI2L(8)) {
-            printReport("testI2L PASSED");
-        } else {
-            printReport("testI2L FAILED");
-        }
-
-        Integer r2 = (Integer) invoke(compile("testL2I"), (long) 12);
-        if (r2 == null) {
-            printReport("testL2I FAILED (null value returned)");
-        } else if (r1.longValue() == testL2I(12)) {
-            printReport("testL2I PASSED");
-        } else {
-            printReport("testL2I FAILED");
-        }
-
-        // invoke(compile("testI2C"), 65);
-        // invoke(compile("testI2B"), 9);
-        // invoke(compile("testI2F"), 17);
-        // invoke(compile("testI2D"), 22);
+        test("testI2L", 8);
+        test("testL2I", (long) 12);
+        // test("testI2C", 65);
+        // test("testI2B", 9);
+        // test("testI2F", 17);
+        // test("testI2D", 22);
     }
 
     public static long testI2L(int a) {
@@ -352,7 +184,8 @@
         for (Method m : IntegerPTXTest.class.getMethods()) {
             String name = m.getName();
             if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
+                PrintStream out = System.out;
+                out.println(name + ": \n" + new String(test.compileKernel(name).getTargetCode()));
             }
         }
     }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -22,17 +22,15 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.Method;
-
-import org.junit.Test;
+import org.junit.*;
 
 /* PTX ISA 3.1 - 8.7.5 Logic and Shift Instructions */
-public class LogicPTXTest extends PTXTestBase {
+public class LogicPTXTest extends PTXTest {
 
     @Test
     public void testAnd() {
-        compile("testAnd2I");
-        compile("testAnd2L");
+        compileKernel("testAnd2I");
+        compileKernel("testAnd2L");
     }
 
     public static int testAnd2I(int a, int b) {
@@ -45,8 +43,8 @@
 
     @Test
     public void testOr() {
-        compile("testOr2I");
-        compile("testOr2L");
+        compileKernel("testOr2I");
+        compileKernel("testOr2L");
     }
 
     public static int testOr2I(int a, int b) {
@@ -59,8 +57,8 @@
 
     @Test
     public void testXor() {
-        compile("testXor2I");
-        compile("testXor2L");
+        compileKernel("testXor2I");
+        compileKernel("testXor2L");
     }
 
     public static int testXor2I(int a, int b) {
@@ -73,8 +71,8 @@
 
     @Test
     public void testNot() {
-        compile("testNot1I");
-        compile("testNot1L");
+        compileKernel("testNot1I");
+        compileKernel("testNot1L");
     }
 
     public static int testNot1I(int a) {
@@ -87,8 +85,8 @@
 
     @Test
     public void testShiftLeft() {
-        compile("testShiftLeft2I");
-        compile("testShiftLeft2L");
+        compileKernel("testShiftLeft2I");
+        compileKernel("testShiftLeft2L");
     }
 
     public static int testShiftLeft2I(int a, int b) {
@@ -101,10 +99,10 @@
 
     @Test
     public void testShiftRight() {
-        compile("testShiftRight2I");
-        compile("testShiftRight2L");
-        compile("testUnsignedShiftRight2I");
-        // compile("testUnsignedShiftRight2L");
+        compileKernel("testShiftRight2I");
+        compileKernel("testShiftRight2L");
+        compileKernel("testUnsignedShiftRight2I");
+        // compileKernel("testUnsignedShiftRight2L");
     }
 
     public static int testShiftRight2I(int a, int b) {
@@ -124,12 +122,6 @@
     }
 
     public static void main(String[] args) {
-        LogicPTXTest test = new LogicPTXTest();
-        for (Method m : LogicPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new LogicPTXTest());
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java	Wed Jan 15 20:25:55 2014 +0100
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.ptx.test;
+
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+import org.junit.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.compiler.target.*;
+import com.oracle.graal.compiler.test.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.hotspot.ptx.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.ptx.*;
+
+/**
+ * Base class for PTX tests.
+ */
+public abstract class PTXTest extends GraalCompilerTest {
+
+    private static PTXHotSpotBackend getPTXBackend() {
+        Backend backend = runtime().getBackend(PTX.class);
+        Assume.assumeTrue(backend instanceof PTXHotSpotBackend);
+        return (PTXHotSpotBackend) backend;
+    }
+
+    protected ExternalCompilationResult compileKernel(ResolvedJavaMethod method) {
+        return getPTXBackend().compileKernel(method, getPTXBackend().isDeviceInitialized());
+    }
+
+    protected ExternalCompilationResult compileKernel(String test) {
+        return compileKernel(getMetaAccess().lookupJavaMethod(getMethod(test)));
+    }
+
+    @Override
+    protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
+        PTXHotSpotBackend ptxBackend = getPTXBackend();
+        ExternalCompilationResult ptxCode = compileKernel(method);
+        Assume.assumeTrue(ptxBackend.isDeviceInitialized());
+        InstalledCode installedPTXCode = ptxBackend.installKernel(method, ptxCode);
+        StructuredGraph kernelWrapper = new PTXLaunchKernelGraphKit(method, installedPTXCode.getStart(), (HotSpotProviders) getProviders()).getGraph();
+        return super.getCode(method, kernelWrapper);
+    }
+
+    protected static void compileAndPrintCode(PTXTest test) {
+        for (Method m : test.getClass().getMethods()) {
+            String name = m.getName();
+            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
+                PrintStream out = System.out;
+                out.println(name + ": \n" + new String(test.compileKernel(name).getTargetCode()));
+            }
+        }
+    }
+}
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java	Wed Jan 15 20:24:44 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.compiler.ptx.test;
-
-import static com.oracle.graal.api.code.CodeUtil.*;
-import static com.oracle.graal.compiler.GraalCompiler.*;
-
-import java.lang.annotation.*;
-import java.lang.reflect.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.code.CallingConvention.Type;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.compiler.target.*;
-import com.oracle.graal.compiler.test.*;
-import com.oracle.graal.debug.*;
-import com.oracle.graal.hotspot.*;
-import com.oracle.graal.hotspot.bridge.*;
-import com.oracle.graal.hotspot.meta.*;
-import com.oracle.graal.hotspot.ptx.*;
-import com.oracle.graal.lir.asm.*;
-import com.oracle.graal.lir.ptx.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.phases.*;
-import com.oracle.graal.phases.tiers.*;
-import com.oracle.graal.ptx.*;
-
-public abstract class PTXTestBase extends GraalCompilerTest {
-
-    private StructuredGraph sg;
-
-    public static void printReport(String message) {
-        // Use -G:Log=Test to see these messages on the console
-        Debug.log(message);
-    }
-
-    public PTXTestBase() {
-        super(PTX.class);
-    }
-
-    private static CompilerToGPU toGPU = HotSpotGraalRuntime.runtime().getCompilerToGPU();
-
-    private static boolean validDevice = toGPU.deviceInit();
-
-    private static final int totalProcessors = (validDevice ? toGPU.availableProcessors() : 0);
-
-    protected CompilationResult compile(String test) {
-        if (getBackend() instanceof PTXHotSpotBackend) {
-            StructuredGraph graph = parse(test);
-            sg = graph;
-            Debug.dump(graph, "Graph");
-            Backend ptxBackend = getBackend();
-            TargetDescription target = ptxBackend.getTarget();
-            PhaseSuite<HighTierContext> graphBuilderSuite = getDefaultGraphBuilderSuite().copy();
-            graphBuilderSuite.appendPhase(new PTXPhase());
-            new PTXPhase().apply(graph);
-            CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false);
-            /*
-             * Use Suites.createDefaultSuites() instead of GraalCompilerTest.suites. The
-             * GraalCompilerTest.suites variable contains the Suites for the HotSpotRuntime. This
-             * code will not run on hotspot, so it should use the plain Graal default suites,
-             * without hotspot specific phases.
-             * 
-             * Ultimately we might want to have both the kernel and the code natively compiled for
-             * GPU fallback to CPU in cases of ECC failure on kernel invocation.
-             */
-            Suites suites = Suites.createDefaultSuites();
-            ExternalCompilationResult result = compileGraph(graph, cc, graph.method(), getProviders(), ptxBackend, target, null, graphBuilderSuite, OptimisticOptimizations.NONE,
-                            getProfilingInfo(graph), new SpeculationLog(), suites, true, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default);
-
-            ResolvedJavaMethod method = graph.method();
-
-            try {
-                if ((validDevice) && (result.getTargetCode() != null)) {
-                    long kernel = toGPU.generateKernel(result.getTargetCode(), method.getName());
-                    result.setEntryPoint(kernel);
-                }
-            } catch (Throwable th) {
-                th.printStackTrace();
-            }
-
-            return result;
-        } else {
-            return null;
-        }
-    }
-
-    protected StructuredGraph getStructuredGraph() {
-        return sg;
-    }
-
-    protected Object invoke(CompilationResult result, Object... args) {
-        if (result == null) {
-            return null;
-        }
-        try {
-            if (((ExternalCompilationResult) result).getEntryPoint() == 0) {
-                Debug.dump(result, "[CUDA] *** Null entry point - Not launching kernel");
-                return null;
-            }
-
-            /* Check if the method compiled is static */
-            HotSpotResolvedJavaMethod compiledMethod = (HotSpotResolvedJavaMethod) sg.method();
-            boolean isStatic = Modifier.isStatic(compiledMethod.getModifiers());
-            Object[] executeArgs = argsWithReceiver((isStatic ? null : this), args);
-            HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) getCodeCache();
-            InstalledCode installedCode = codeCache.addExternalMethod(compiledMethod, result);
-            Annotation[][] params = compiledMethod.getParameterAnnotations();
-
-            int dimensionX = 1;
-            int dimensionY = 1;
-            int dimensionZ = 1;
-
-            for (int p = 0; p < params.length; p++) {
-                Annotation[] annos = params[p];
-                if (annos != null) {
-                    for (int a = 0; a < annos.length; a++) {
-                        Annotation aa = annos[a];
-                        if (args[p] instanceof int[] && aa.annotationType().equals(ParallelOver.class)) {
-                            int[] iarray = (int[]) args[p];
-                            ParallelOver threadBlockDimension = (ParallelOver) aa;
-                            switch (threadBlockDimension.dimension()) {
-                                case X:
-                                    dimensionX = iarray.length;
-                                    break;
-                                case Y:
-                                    dimensionY = iarray.length;
-                                    break;
-                                case Z:
-                                    dimensionZ = iarray.length;
-                                    break;
-                            }
-                        }
-                    }
-                }
-            }
-            Object r;
-            if (dimensionX != 1 || dimensionY != 1 || dimensionZ != 1) {
-                /*
-                 * for now assert that the warp array block is no larger than the number of physical
-                 * gpu cores.
-                 */
-                assert dimensionX * dimensionY * dimensionZ < totalProcessors;
-
-                r = ((HotSpotNmethod) installedCode).executeParallel(dimensionX, dimensionY, dimensionZ, executeArgs);
-            } else {
-                r = installedCode.executeVarargs(executeArgs);
-            }
-            return r;
-        } catch (Throwable th) {
-            th.printStackTrace();
-            return null;
-        }
-    }
-}
--- a/graal/com.oracle.graal.hotspot.ptx.test/src/com/oracle/graal/hotspot/ptx/test/PTXLaunchKernelTest.java	Wed Jan 15 20:24:44 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.hotspot.ptx.test;
-
-import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
-
-import org.junit.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.compiler.target.*;
-import com.oracle.graal.compiler.test.*;
-import com.oracle.graal.hotspot.ptx.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.ptx.*;
-
-/**
- * Tests the mechanism for launching a PTX kernel method via wrapper code.
- */
-public class PTXLaunchKernelTest extends GraalCompilerTest {
-
-    /**
-     * Compiles and installs PTX kernel code for a given method.
-     */
-    StructuredGraph getKernelGraph(final ResolvedJavaMethod method) {
-        Backend backend = runtime().getBackend(PTX.class);
-        Assume.assumeTrue(backend instanceof PTXHotSpotBackend);
-        PTXHotSpotBackend ptxBackend = (PTXHotSpotBackend) backend;
-        Assume.assumeTrue(ptxBackend.isDeviceInitialized());
-        return new PTXGraphProducer(runtime().getHostBackend(), ptxBackend) {
-            @Override
-            protected boolean canOffloadToGPU(ResolvedJavaMethod m) {
-                return m == method;
-            }
-        }.getGraphFor(method);
-    }
-
-    @Override
-    protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
-        return super.getCode(method, getKernelGraph(method));
-    }
-
-    @Test
-    public void testStaticIntKernel() {
-        test("staticIntKernel", 'a', 42);
-    }
-
-    @Test
-    public void testVirtualIntKernel() {
-        test("virtualIntKernel", 'a', 42);
-    }
-
-    public static int staticIntKernel(char p0, int p1) {
-        return p1 + p0;
-    }
-
-    public int virtualIntKernel(char p0, int p1) {
-        return p1 + p0;
-    }
-}