Mercurial > hg > truffle
annotate src/os/linux/vm/gpu_linux.cpp @ 17095:174f78c24747
Truffle: simplify byte section tests.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Wed, 10 Sep 2014 21:38:26 +0100 |
parents | 66e3af78ea96 |
children |
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" | |
13888
51584f76462d
pulled Ptx and Hsail classes out of gpu class namespace
Doug Simon <doug.simon@oracle.com>
parents:
13828
diff
changeset
|
26 #include "ptx/vm/gpu_ptx.hpp" |
51584f76462d
pulled Ptx and Hsail classes out of gpu class namespace
Doug Simon <doug.simon@oracle.com>
parents:
13828
diff
changeset
|
27 #include "hsail/vm/gpu_hsail.hpp" |
10879 | 28 #include "utilities/ostream.hpp" |
29 | |
30 /* | |
31 * Probe for CUDA device on PCI bus using /proc/bus/pci/devices. Do | |
32 * not rely on CUDA tool kit being installed. We will check if CUDA | |
33 * library is installed later. | |
34 */ | |
35 | |
36 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
|
37 static unsigned int amd_vendor_id = 0x1002; |
10879 | 38 |
13828
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
39 #define PCI_DRIVER_NAME_START_POS 255 |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
40 |
15177
66e3af78ea96
HSAIL: added safepoint support
Doug Simon <doug.simon@oracle.com>
parents:
13890
diff
changeset
|
41 jobject Gpu::probe_gpus(JNIEnv* env) { |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
42 bool hsail = false; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
43 bool ptx = false; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
44 |
13890
4cbe077ab49a
removed UseHSAILSimulator option
Doug Simon <doug.simon@oracle.com>
parents:
13888
diff
changeset
|
45 if (Hsail::register_natives(env)) { |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
46 hsail = true; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
47 } |
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
|
48 |
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 /* |
11606
4f69a5189e77
Create runtime object based on GPUIL type newly added to gpu class; some code refactoring.
bharadwaj
parents:
11485
diff
changeset
|
50 * 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
|
51 * 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
|
52 * 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
|
53 */ |
10879 | 54 FILE *pci_devices = fopen("/proc/bus/pci/devices", "r"); |
55 char contents[4096]; | |
56 unsigned int bus_num_devfn_ign; | |
57 unsigned int vendor; | |
58 unsigned int device; | |
13828
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
59 const char *driver_name_string = "nvidia"; |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
60 const int driver_name_string_len = strlen(driver_name_string); |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
61 |
10879 | 62 if (pci_devices == NULL) { |
63 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
|
64 return NULL; |
10879 | 65 } |
66 | |
67 while (fgets(contents, sizeof(contents)-1, pci_devices)) { | |
68 sscanf(contents, "%04x%04x%04x", &bus_num_devfn_ign, &vendor, &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
|
69 if (vendor == nvidia_vendor_id) { |
13828
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
70 /* Check if this device is registered to be using nvidia driver */ |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
71 if (strncmp(&contents[PCI_DRIVER_NAME_START_POS], |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
72 driver_name_string, driver_name_string_len) == 0) { |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
73 if (TraceGPUInteraction) { |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
74 tty->print_cr("Found supported nVidia device [vendor=0x%04x, device=0x%04x]", vendor, device); |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
75 } |
13888
51584f76462d
pulled Ptx and Hsail classes out of gpu class namespace
Doug Simon <doug.simon@oracle.com>
parents:
13828
diff
changeset
|
76 if (!ptx && Ptx::register_natives(env)) { |
13828
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
77 ptx = true; |
5c8a3c09397b
Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents:
13819
diff
changeset
|
78 } |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
79 } |
10879 | 80 } |
81 } | |
82 | |
83 // Close file pointer. | |
84 fclose(pci_devices); | |
85 | |
13819
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
86 const char* gpus = ""; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
87 if (ptx && hsail) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
88 gpus = "PTX,HSAIL"; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
89 } else if (ptx) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
90 gpus = "PTX"; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
91 } else if (hsail) { |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
92 gpus = "HSAIL"; |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
93 } |
49db2c1e3bee
added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents:
13114
diff
changeset
|
94 return env->NewStringUTF(gpus); |
10879 | 95 } |