changeset 11634:bff2b88444f5

Start of PTX array passing
author Morris Meyer <morris.meyer@oracle.com>
date Sat, 14 Sep 2013 17:31:25 -0400
parents a0566c8dcabf
children 3f8bb25fb0a1
files graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java 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/ControlPTXTest.java graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlTest.java graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXBackend.java graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotRegisterConfig.java graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXParameterOp.java src/gpu/ptx/vm/gpu_ptx.cpp
diffstat 9 files changed, 175 insertions(+), 131 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java	Fri Sep 13 17:54:59 2013 +0200
+++ b/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java	Sat Sep 14 17:31:25 2013 -0400
@@ -553,6 +553,14 @@
         emitString(".param" + " " + ".s8" + " " + d + (lastParam ? "" : ","));
     }
 
+    public final void param_16_decl(Register d, boolean lastParam) {
+        emitString(".param" + " " + ".s16" + " " + d + (lastParam ? "" : ","));
+    }
+
+    public final void param_u16_decl(Register d, boolean lastParam) {
+        emitString(".param" + " " + ".s16" + " " + d + (lastParam ? "" : ","));
+    }
+
     public final void param_32_decl(Register d, boolean lastParam) {
         emitString(".param" + " " + ".s32" + " " + d + (lastParam ? "" : ","));
     }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Fri Sep 13 17:54:59 2013 +0200
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Sat Sep 14 17:31:25 2013 -0400
@@ -31,20 +31,24 @@
     @Ignore
     @Test
     public void testArray() {
-        compile("testArray1I");
-        compile("testArray1J");
-        compile("testArray1B");
-        compile("testArray1S");
-        compile("testArray1C");
-        compile("testArray1F");
-        compile("testArray1D");
-        compile("testArray1L");
-        compile("testStoreArray1I");
-        compile("testStoreArray1J");
-        compile("testStoreArray1B");
-        compile("testStoreArray1S");
-        compile("testStoreArray1F");
-        compile("testStoreArray1D");
+        int[] arrayI = {
+            1, 2, 3, 4, 5
+        };
+        Integer resI = (Integer) invoke(compile("testArray1I"), arrayI, 3);
+        printReport("testArray1I: " + resI);
+        // compile("testArray1J");
+        // compile("testArray1B");
+        // compile("testArray1S");
+        // compile("testArray1C");
+        // compile("testArray1F");
+        // compile("testArray1D");
+        // compile("testArray1L");
+        // compile("testStoreArray1I");
+        // compile("testStoreArray1J");
+        // compile("testStoreArray1B");
+        // compile("testStoreArray1S");
+        // compile("testStoreArray1F");
+        // compile("testStoreArray1D");
     }
 
     public static int testArray1I(int[] array, int i) {
@@ -103,6 +107,13 @@
         array[i] = val;
     }
 
+    public static void printReport(String message) {
+        // CheckStyle: stop system..print check
+        System.out.println(message);
+        // CheckStyle: resume system..print check
+
+    }
+
     public static void main(String[] args) {
         ArrayPTXTest test = new ArrayPTXTest();
         for (Method m : ArrayPTXTest.class.getMethods()) {
--- /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/ControlPTXTest.java	Sat Sep 14 17:31:25 2013 -0400
@@ -0,0 +1,118 @@
+/*
+ * 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 org.junit.*;
+
+import java.lang.reflect.Method;
+
+public class ControlPTXTest extends PTXTestBase {
+
+    @Ignore
+    @Test
+    public void testControl() {
+        compile("testLoop");
+        // compile("testSwitch1I");
+        // compile("testStatic");
+        // compile("testCall");
+        // compile("testLookupSwitch1I");
+    }
+
+    public static int testLoop(int n) {
+        int sum = 0;
+
+        for (int i = 0; i < n; i++) {
+            sum++;
+        }
+        return sum;
+    }
+
+    public static int testSwitch1I(int a) {
+        switch (a) {
+            case 1:
+                return 2;
+            case 2:
+                return 3;
+            default:
+                return 4;
+        }
+    }
+
+    public static int testLookupSwitch1I(int a) {
+        switch (a) {
+            case 0:
+                return 1;
+            case 1:
+                return 2;
+            case 2:
+                return 3;
+            case 3:
+                return 1;
+            case 4:
+                return 2;
+            case 5:
+                return 3;
+            case 6:
+                return 1;
+            case 7:
+                return 2;
+            case 8:
+                return 3;
+            case 9:
+                return 1;
+            case 10:
+                return 2;
+            case 11:
+                return 3;
+            default:
+                return -1;
+        }
+    }
+
+    @SuppressWarnings("unused") private static Object foo = null;
+
+    public static boolean testStatic(Object o) {
+        foo = o;
+        return true;
+    }
+
+    private static int method(int a, int b) {
+        return a + b;
+    }
+
+    public static int testCall(@SuppressWarnings("unused") Object o, int a, int b) {
+        return method(a, b);
+    }
+
+    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")) {
+                // CheckStyle: stop system..print check
+                System.out.println(name + ": \n" + new String(test.compile(name).getTargetCode()));
+                // CheckStyle: resume system..print check
+            }
+        }
+    }
+}
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlTest.java	Fri Sep 13 17:54:59 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +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 org.junit.*;
-
-import java.lang.reflect.Method;
-
-public class ControlTest extends PTXTestBase {
-
-    @Ignore
-    @Test
-    public void testControl() {
-        compile("testSwitch1I");
-        compile("testStatic");
-        compile("testCall");
-        compile("testLookupSwitch1I");
-    }
-
-    public static int testSwitch1I(int a) {
-        switch (a) {
-            case 1:
-                return 2;
-            case 2:
-                return 3;
-            default:
-                return 4;
-        }
-    }
-
-    public static int testLookupSwitch1I(int a) {
-        switch (a) {
-            case 0:
-                return 1;
-            case 1:
-                return 2;
-            case 2:
-                return 3;
-            case 3:
-                return 1;
-            case 4:
-                return 2;
-            case 5:
-                return 3;
-            case 6:
-                return 1;
-            case 7:
-                return 2;
-            case 8:
-                return 3;
-            case 9:
-                return 1;
-            case 10:
-                return 2;
-            case 11:
-                return 3;
-            default:
-                return -1;
-        }
-    }
-
-    @SuppressWarnings("unused") private static Object foo = null;
-
-    public static boolean testStatic(Object o) {
-        foo = o;
-        return true;
-    }
-
-    private static int method(int a, int b) {
-        return a + b;
-    }
-
-    public static int testCall(@SuppressWarnings("unused") Object o, int a, int b) {
-        return method(a, b);
-    }
-
-    public static void main(String[] args) {
-        ControlTest test = new ControlTest();
-        for (Method m : ControlTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                // CheckStyle: stop system..print check
-                System.out.println(name + ": \n" + new String(test.compile(name).getTargetCode()));
-                // CheckStyle: resume system..print check
-            }
-        }
-    }
-}
--- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXBackend.java	Fri Sep 13 17:54:59 2013 +0200
+++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXBackend.java	Sat Sep 14 17:31:25 2013 -0400
@@ -165,6 +165,9 @@
                        case Double:
                            float64.add(regVal.getRegister().encoding());
                            break;
+                       case Object:
+                           signed64.add(regVal.getRegister().encoding());
+                           break;
                        default :
                            throw GraalInternalError.shouldNotReachHere("unhandled register type "  + value.toString());
                     }
@@ -204,6 +207,7 @@
         try {
             emitRegisterDecl(tasm, lirGen, codeCacheOwner);
         } catch (GraalInternalError e) {
+            e.printStackTrace();
             // TODO : Better error handling needs to be done once
             //        all types of parameters are handled.
             codeBuffer.setPosition(0);
@@ -214,6 +218,7 @@
         try {
             lirGen.lir.emitCode(tasm);
         } catch (GraalInternalError e) {
+            e.printStackTrace();
             // TODO : Better error handling needs to be done once
             //        all types of parameters are handled.
             codeBuffer.setPosition(0);
--- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java	Fri Sep 13 17:54:59 2013 +0200
+++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java	Sat Sep 14 17:31:25 2013 -0400
@@ -32,6 +32,7 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.asm.*;
 import com.oracle.graal.compiler.gen.*;
+import com.oracle.graal.debug.Debug;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.StandardOp.JumpOp;
@@ -786,9 +787,9 @@
 
     @Override
     public void visitSafepointNode(SafepointNode i) {
-        // LIRFrameState info = state();
+        // LIRFrameState info = state(i);
         // append(new PTXSafepointOp(info, runtime().config, this));
-        throw new InternalError("NYI");
+        Debug.log("visitSafePointNode unimplemented");
     }
 
     @Override
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotRegisterConfig.java	Fri Sep 13 17:54:59 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotRegisterConfig.java	Sat Sep 14 17:31:25 2013 -0400
@@ -78,7 +78,7 @@
             param4, param5, param6, param7,
             r0,  r1,  r2,  r3,  r4,  r5,  r6,  r7,
             r8,  r9,  r10, r11, r12, r13, r14, r15,
-            retReg,
+            // retReg,
         };
 
         return registers;
--- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXParameterOp.java	Fri Sep 13 17:54:59 2013 +0200
+++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXParameterOp.java	Sat Sep 14 17:31:25 2013 -0400
@@ -48,21 +48,30 @@
         for (int i = 0; i < argCount; i++) {
             Kind paramKind = params[i].getKind();
             switch (paramKind) {
-            case Byte :
+            case Byte:
                 masm.param_8_decl(asRegister(params[i]), (i == (argCount - 1)));
                 break;
-            case Int :
+            case Short:
+                masm.param_16_decl(asRegister(params[i]), (i == (argCount - 1)));
+                break;
+            case Char:
+                masm.param_u16_decl(asRegister(params[i]), (i == (argCount - 1)));
+                break;
+            case Int:
                 masm.param_32_decl(asIntReg(params[i]), (i == (argCount - 1)));
                 break;
-            case Long :
+            case Long:
                 masm.param_64_decl(asLongReg(params[i]), (i == (argCount - 1)));
                 break;
-            case Float :
+            case Float:
                 masm.param_32_decl(asFloatReg(params[i]), (i == (argCount - 1)));
                 break;
-            case Double :
+            case Double:
                 masm.param_64_decl(asDoubleReg(params[i]), (i == (argCount - 1)));
                 break;
+            case Object:
+                masm.param_64_decl(asObjectReg(params[i]), (i == (argCount - 1)));
+                break;
             default :
                 throw GraalInternalError.shouldNotReachHere("unhandled parameter type "  + paramKind.toString());
             }
--- a/src/gpu/ptx/vm/gpu_ptx.cpp	Fri Sep 13 17:54:59 2013 +0200
+++ b/src/gpu/ptx/vm/gpu_ptx.cpp	Sat Sep 14 17:31:25 2013 -0400
@@ -170,7 +170,7 @@
   int status = _cuda_cu_ctx_create(&_device_context, 0, _cu_device);
 
   if (status != GRAAL_CUDA_SUCCESS) {
-    tty->print_cr("[CUDA] Failed to create CUDA context for device: %d", _cu_device);
+    tty->print_cr("[CUDA] Failed to create CUDA context for device(%d): %d", _cu_device, status);
     return NULL;
   }