annotate graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java @ 7928:47a7e8d80536

Added new basic array PTX test.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 05 Mar 2013 11:03:33 +0100
parents 674a8b9e62f8
children 9ac11c77d128
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.compiler.ptx.test;
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import org.junit.*;
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
27 import com.oracle.graal.api.code.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
28 import com.oracle.graal.api.runtime.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
29 import com.oracle.graal.compiler.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
30 import com.oracle.graal.compiler.ptx.*;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.compiler.test.*;
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.debug.*;
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
33 import com.oracle.graal.java.*;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.nodes.*;
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
35 import com.oracle.graal.phases.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
36 import com.oracle.graal.phases.PhasePlan.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
37 import com.oracle.graal.ptx.*;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 /**
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 * Test class for small Java methods compiled to PTX kernels.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 */
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 public class BasicPTXTest extends GraalCompilerTest {
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 @Test
7928
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
45 public void testAdd() {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
46 test("testAddSnippet");
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
47 }
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
48
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
49 public static int testAddSnippet(int a) {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
50 return a + 1;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 }
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52
7928
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
53 @Test
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
54 public void testArray() {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
55 test("testArraySnippet");
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
56 }
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
57
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
58 public static int testArraySnippet(int[] array) {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
59 return array[0];
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 }
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 private void test(String snippet) {
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 StructuredGraph graph = parse(snippet);
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 Debug.dump(graph, "Graph");
7841
674a8b9e62f8 Remove unused fields in TargetDescription. Use Unsafe.pageSize().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7838
diff changeset
65 TargetDescription target = new TargetDescription(new PTX(), true, 1, 0, true);
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
66 PTXBackend ptxBackend = new PTXBackend(Graal.getRequiredCapability(CodeCacheProvider.class), target);
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
67 PhasePlan phasePlan = new PhasePlan();
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
68 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.NONE);
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
69 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
70 CompilationResult result = GraalCompiler.compileMethod(runtime, ptxBackend, target, graph.method(), graph, null, phasePlan, OptimisticOptimizations.NONE);
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
71 System.out.println("result=" + result);
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 }
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 }