Mercurial > hg > truffle
annotate src/os_gpu/linux_ptx/vm/gpu_linux.cpp @ 11484:2aac62d79af4
Truffle-DSL: fixed bug if node class was used also as child.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 30 Aug 2013 17:31:59 +0200 |
parents | 5040ec3ff3aa |
children | 49bb1bc983c6 |
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 void gpu::probe_gpu() { | |
29 set_available(gpu::Linux::probe_gpu()); | |
30 if (TraceGPUInteraction) { | |
31 tty->print_cr("gpu_linux::probe_gpu(): %d", gpu::is_available()); | |
32 } | |
33 } | |
34 | |
35 /* | |
36 * Probe for CUDA device on PCI bus using /proc/bus/pci/devices. Do | |
37 * not rely on CUDA tool kit being installed. We will check if CUDA | |
38 * library is installed later. | |
39 */ | |
40 | |
41 static unsigned int nvidia_vendor_id = 0x10de; | |
42 static unsigned int nvidia_gk110_dev_id = 0x1005; | |
43 | |
44 bool gpu::Linux::probe_gpu() { | |
45 /* | |
11292
5040ec3ff3aa
Defer PTX on Mac probe to the CUDA driver initialization call
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
46 * Open /proc/bus/pci/devices to look for the first CUDA enabled |
5040ec3ff3aa
Defer PTX on Mac probe to the CUDA driver initialization call
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
47 * device. For now, finding the first CUDA device. Will need to |
5040ec3ff3aa
Defer PTX on Mac probe to the CUDA driver initialization call
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
48 * revisit this to support execution on multiple CUDA devices if |
5040ec3ff3aa
Defer PTX on Mac probe to the CUDA driver initialization call
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
49 * they exist. |
5040ec3ff3aa
Defer PTX on Mac probe to the CUDA driver initialization call
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
50 */ |
10879 | 51 FILE *pci_devices = fopen("/proc/bus/pci/devices", "r"); |
52 char contents[4096]; | |
53 unsigned int bus_num_devfn_ign; | |
54 unsigned int vendor; | |
55 unsigned int device; | |
56 bool cuda_device_exists = false; | |
57 if (pci_devices == NULL) { | |
58 tty->print_cr("*** Failed to open /proc/bus/pci/devices"); | |
59 return cuda_device_exists; | |
60 } | |
61 | |
62 while (fgets(contents, sizeof(contents)-1, pci_devices)) { | |
63 sscanf(contents, "%04x%04x%04x", &bus_num_devfn_ign, &vendor, &device); | |
64 /* Break after finding the first CUDA device. */ | |
65 if ((vendor == nvidia_vendor_id) && (device = nvidia_gk110_dev_id)) { | |
66 cuda_device_exists = true; | |
67 if (TraceGPUInteraction) { | |
68 tty->print_cr("Found supported nVidia CUDA device vendor : 0x%04x device 0x%04x", vendor, device); | |
69 } | |
70 break; | |
71 } | |
72 } | |
73 | |
74 // Close file pointer. | |
75 fclose(pci_devices); | |
76 | |
77 return cuda_device_exists; | |
78 } |