annotate src/share/vm/runtime/gpu.cpp @ 12743:f1a55428a8d7

more HSAIL support in the C++ layer for executing HSAIL code on the simulator Contributed-by: Eric Caspole <eric.caspole@amd.com>
author Doug Simon <doug.simon@oracle.com>
date Sun, 10 Nov 2013 13:18:09 +0100
parents 8d8f63069f58
children 49db2c1e3bee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9430
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
1 /*
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
4 *
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
8 *
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
14 *
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
18 *
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
21 * questions.
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
22 *
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
23 */
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
24
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
25 #include "precompiled.hpp"
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
26 #include "runtime/gpu.hpp"
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
27 #include "runtime/handles.hpp"
9430
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
28
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
29 bool gpu::_available = false; // does the hardware exist?
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
30 bool gpu::_gpu_linkage = false; // is the driver library to access the GPU installed
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
31 bool gpu::_initialized = false; // is the GPU device initialized
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
32 gpu::TargetGPUIL gpu::_targetIL = gpu::NONE; // No GPU detected yet.
9430
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
33
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
34 void gpu::init() {
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
35 #if defined(TARGET_OS_FAMILY_bsd) || defined(TARGET_OS_FAMILY_linux) || defined(TARGET_OS_FAMILY_windows)
9430
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
36 gpu::probe_gpu();
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
37 if (gpu::get_target_il_type() == gpu::PTX) {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
38 set_gpu_linkage(gpu::Ptx::probe_linkage());
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
39 } else if (gpu::get_target_il_type() == gpu::HSAIL) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
40 set_gpu_linkage(gpu::Hsail::probe_linkage());
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
41 } else {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
42 set_gpu_linkage(false);
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
43 }
9430
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
44 #endif
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
45 }
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
46
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
47 void gpu::initialize_gpu() {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
48 if (gpu::has_gpu_linkage()) {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
49 if (gpu::get_target_il_type() == gpu::PTX) {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
50 set_initialized(gpu::Ptx::initialize_gpu());
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
51 } else if (gpu::get_target_il_type() == gpu::HSAIL) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
52 set_initialized(gpu::Hsail::initialize_gpu());
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
53 }
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
54 }
9430
147162b27799 GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
55 }
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
56
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
57 void * gpu::generate_kernel(unsigned char *code, int code_len, const char *name) {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
58 if (gpu::has_gpu_linkage()) {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
59 if (gpu::get_target_il_type() == gpu::PTX) {
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
60 return (gpu::Ptx::generate_kernel(code, code_len, name));
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
61 } else if (gpu::get_target_il_type() == gpu::HSAIL) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
62 return (gpu::Hsail::generate_kernel(code, code_len, name));
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
63 }
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
64 }
11609
103795ab699d gpu.cpp: fix warning: not all control paths return a value
Andreas Woess <andreas.woess@jku.at>
parents: 11606
diff changeset
65 return NULL;
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
66 }
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
67
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
68 bool gpu::execute_kernel(address kernel, PTXKernelArguments & ptxka, JavaValue& ret) {
11822
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
69 if (gpu::has_gpu_linkage()) {
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
70 if (gpu::get_target_il_type() == gpu::PTX) {
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
71 return (gpu::Ptx::execute_kernel(kernel, ptxka, ret));
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
72 }
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
73 // Add kernel execution functionality of other GPUs here
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
74 }
11822
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
75 return false;
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
76 }
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 10879
diff changeset
77
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
78 // This is HSAIL specific to work with Sumatra JDK
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
79 bool gpu::execute_kernel_void_1d(address kernel, int dimX, jobject args, methodHandle& mh) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
80 if (gpu::has_gpu_linkage()) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
81 if (gpu::get_target_il_type() == gpu::HSAIL) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
82 return (gpu::Hsail::execute_kernel_void_1d(kernel, dimX, args, mh));
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
83 }
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
84 }
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
85 return false;
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
86
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
87 }
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
88
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11842
diff changeset
89
11822
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
90 bool gpu::execute_warp(int dimX, int dimY, int dimZ,
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
91 address kernel, PTXKernelArguments & ptxka, JavaValue& ret) {
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
92 if (gpu::has_gpu_linkage()) {
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
93 if (gpu::get_target_il_type() == gpu::PTX) {
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
94 return (gpu::Ptx::execute_warp(dimX, dimY, dimZ, kernel, ptxka, ret));
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
95 }
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
96 // Add kernel execution functionality of other GPUs here
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
97 }
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
98 return false;
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
99 }
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11609
diff changeset
100
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
101 int gpu::available_processors() {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
102 if (gpu::has_gpu_linkage()) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
103 if (gpu::get_target_il_type() == gpu::PTX) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
104 return (gpu::Ptx::total_cores());
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
105 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
106 // Add kernel execution functionality of other GPUs here
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
107 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
108 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
109 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
110