Mercurial > hg > truffle
annotate src/os/linux/vm/gpu_linux.cpp @ 13819:49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 30 Jan 2014 00:52:33 +0100 |
parents | src/os_gpu/linux_ptx/vm/gpu_linux.cpp@5465ba051280 |
children | 5c8a3c09397b |
rev | line source |
---|---|
10879 | 1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #include "runtime/gpu.hpp" | |
26 #include "utilities/ostream.hpp" | |
27 | |
28 /* | |
29 * Probe for CUDA device on PCI bus using /proc/bus/pci/devices. Do | |
30 * not rely on CUDA tool kit being installed. We will check if CUDA | |
31 * library is installed later. | |
32 */ | |
33 | |
34 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
|
35 static unsigned int amd_vendor_id = 0x1002; |
10879 | 36 |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
37 jobject gpu::probe_gpus(JNIEnv* env) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
38 bool hsail = false; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
39 bool ptx = false; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
40 |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
41 if (UseHSAILSimulator && gpu::Hsail::register_natives(env)) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
42 hsail = true; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
43 } |
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
|
44 |
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 /* |
11606
4f69a5189e77
Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents:
11485
diff
changeset
|
46 * 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
|
47 * 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
|
48 * 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
|
49 */ |
10879 | 50 FILE *pci_devices = fopen("/proc/bus/pci/devices", "r"); |
51 char contents[4096]; | |
52 unsigned int bus_num_devfn_ign; | |
53 unsigned int vendor; | |
54 unsigned int device; | |
55 if (pci_devices == NULL) { | |
56 tty->print_cr("*** Failed to open /proc/bus/pci/devices"); | |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
57 return NULL; |
10879 | 58 } |
59 | |
60 while (fgets(contents, sizeof(contents)-1, pci_devices)) { | |
61 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
|
62 /* 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
|
63 if (vendor == nvidia_vendor_id) { |
10879 | 64 if (TraceGPUInteraction) { |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
65 tty->print_cr("Found supported nVidia GPU: vendor=0x%04x, device=0x%04x", vendor, device); |
11606
4f69a5189e77
Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents:
11485
diff
changeset
|
66 } |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
67 if (!ptx && gpu::Ptx::register_natives(env)) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
68 ptx = true; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
69 } |
10879 | 70 } |
71 } | |
72 | |
73 // Close file pointer. | |
74 fclose(pci_devices); | |
75 | |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
76 const char* gpus = ""; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
77 if (ptx && hsail) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
78 gpus = "PTX,HSAIL"; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
79 } else if (ptx) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
80 gpus = "PTX"; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
81 } else if (hsail) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
82 gpus = "HSAIL"; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
83 } |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
84 return env->NewStringUTF(gpus); |
10879 | 85 } |