annotate src/os_gpu/linux_ptx/vm/gpu_linux.cpp @ 13705:ac5b0f31f7a2

Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
author Christian Humer <christian.humer@gmail.com>
date Fri, 17 Jan 2014 17:06:08 +0100
parents 5465ba051280
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
1 /*
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
4 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
8 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
14 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
18 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
21 * questions.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
22 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
23 */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
24
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
25 #include "runtime/gpu.hpp"
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
26 #include "utilities/ostream.hpp"
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
27
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
28 void gpu::probe_gpu() {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
29 set_available(gpu::Linux::probe_gpu());
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
30 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
31 tty->print_cr("gpu_linux::probe_gpu(): %d", gpu::is_available());
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
32 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
33 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
34
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
35 /*
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
36 * Probe for CUDA device on PCI bus using /proc/bus/pci/devices. Do
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
37 * not rely on CUDA tool kit being installed. We will check if CUDA
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
38 * library is installed later.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
39 */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
40
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
41 static unsigned int nvidia_vendor_id = 0x10de;
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
42 static unsigned int amd_vendor_id = 0x1002;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
43
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
44 bool gpu::Linux::probe_gpu() {
12743
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
45
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
46 /*
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
47 * The simulator only depends on shared libraries.
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
48 * That linkage is checked in a later step.
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
49 */
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
50 if (UseHSAILSimulator) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
51 set_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: 11606
diff changeset
52 if (TraceGPUInteraction) {
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
53 tty->print_cr("Setup HSAIL Simulator");
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
54 }
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
55 return true;
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
56 }
f1a55428a8d7 more HSAIL support in the C++ layer for executing HSAIL code on the simulator
Doug Simon <doug.simon@oracle.com>
parents: 11606
diff changeset
57
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
58 /*
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
59 * Open /proc/bus/pci/devices to look for the first GPU device. For
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
60 * now, we will just find the first GPU device. Will need to revisit
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
61 * this to support execution on multiple GPU devices, if they exist.
11292
5040ec3ff3aa Defer PTX on Mac probe to the CUDA driver initialization call
Morris Meyer <morris.meyer@oracle.com>
parents: 10879
diff changeset
62 */
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
63 FILE *pci_devices = fopen("/proc/bus/pci/devices", "r");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
64 char contents[4096];
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
65 unsigned int bus_num_devfn_ign;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
66 unsigned int vendor;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
67 unsigned int device;
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
68 bool gpu_device_exists = false;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
69 if (pci_devices == NULL) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
70 tty->print_cr("*** Failed to open /proc/bus/pci/devices");
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
71 return gpu_device_exists;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
72 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
73
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
74 while (fgets(contents, sizeof(contents)-1, pci_devices)) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
75 sscanf(contents, "%04x%04x%04x", &bus_num_devfn_ign, &vendor, &device);
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
76 /* Break after finding the first GPU device. */
11485
49bb1bc983c6 Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents: 11292
diff changeset
77 if (vendor == nvidia_vendor_id) {
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
78 gpu_device_exists = true;
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
79 set_target_il_type(gpu::PTX);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
80 if (TraceGPUInteraction) {
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
81 tty->print_cr("Found supported nVidia GPU device vendor : 0x%04x device 0x%04x", vendor, device);
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
82 }
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
83 break;
13114
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
84 /*
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
85 * Remove AMD detection until we decide how to detect real HSA hardware.
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
86 * In the current form this check does not work correctly on AMD CPU system with
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
87 * Nvidia GPU.
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
88 *
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
89 * } else if (vendor == amd_vendor_id) {
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
90 * gpu_device_exists = true;
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
91 * set_target_il_type(gpu::HSAIL);
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
92 * if (TraceGPUInteraction) {
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
93 * tty->print_cr("Found supported AMD GPU device vendor : 0x%04x device 0x%04x", vendor, device);
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
94 * }
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
95 * break;
5465ba051280 HSAIL: removed AMD GPU detection until a) clashing AMD CPU and GPU vendor ID issue is resolved and b) HSA port is more complete
Doug Simon <doug.simon@oracle.com>
parents: 12743
diff changeset
96 */
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
97 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
98 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
99
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
100 // Close file pointer.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
101 fclose(pci_devices);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
102
11606
4f69a5189e77 Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents: 11485
diff changeset
103 return gpu_device_exists;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
104 }