Mercurial > hg > truffle
comparison src/os_gpu/bsd_ptx/vm/gpu_bsd.cpp @ 10879:d55f24eac4b1
PTX support for Linux
author | Morris Meyer <morris.meyer@oracle.com> |
---|---|
date | Thu, 25 Jul 2013 22:15:30 -0400 |
parents | |
children | 5040ec3ff3aa |
comparison
equal
deleted
inserted
replaced
10878:d9fcc82766da | 10879:d55f24eac4b1 |
---|---|
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 #ifdef __APPLE__ | |
29 #include <ApplicationServices/ApplicationServices.h> | |
30 #include <IOKit/IOKitLib.h> | |
31 #endif | |
32 | |
33 void gpu::probe_gpu() { | |
34 #ifdef __APPLE__ | |
35 set_available(gpu::Bsd::probe_gpu_apple()); | |
36 if (TraceGPUInteraction) { | |
37 tty->print_cr("gpu_bsd::probe_gpu(APPLE): %d", gpu::is_available()); | |
38 } | |
39 #else | |
40 if (TraceGPUInteraction) { | |
41 tty->print_cr("gpu_bsd::probe_gpu(not APPLE)"); | |
42 } | |
43 set_available(false); | |
44 #endif | |
45 } | |
46 | |
47 #ifdef __APPLE__ | |
48 /* | |
49 * This is rudimentary at best, but until we decide on a CUDA Compiler Compatibility | |
50 * level, this will have to suffice. | |
51 */ | |
52 bool gpu::Bsd::probe_gpu_apple() { | |
53 CGError err = CGDisplayNoErr; | |
54 CGDisplayCount displayCount = 0; | |
55 CFDataRef vendorID, deviceID, model; | |
56 CGDirectDisplayID *displays; | |
57 IOOptionBits options = kIORegistryIterateRecursively | kIORegistryIterateParents; | |
58 io_registry_entry_t displayPort; | |
59 | |
60 err = CGGetActiveDisplayList(0, NULL, &displayCount); | |
61 displays = (CGDirectDisplayID *)calloc((size_t)displayCount, sizeof(CGDirectDisplayID)); | |
62 err = CGGetActiveDisplayList(displayCount, displays, &displayCount); | |
63 | |
64 for (CGDisplayCount i = 0; i < displayCount; i++) { | |
65 displayPort = CGDisplayIOServicePort(displays[i]); | |
66 vendorID = (CFDataRef)IORegistryEntrySearchCFProperty(displayPort, kIOServicePlane, CFSTR("vendor-id"), | |
67 kCFAllocatorDefault, options); | |
68 deviceID = (CFDataRef)IORegistryEntrySearchCFProperty(displayPort, kIOServicePlane, CFSTR("device-id"), | |
69 kCFAllocatorDefault, options); | |
70 model = (CFDataRef)IORegistryEntrySearchCFProperty(displayPort, kIOServicePlane, CFSTR("model"), | |
71 kCFAllocatorDefault, options); | |
72 if (TraceGPUInteraction) { | |
73 tty->print_cr("vendor: 0x%08X", *((UInt32*)CFDataGetBytePtr(vendorID))); | |
74 tty->print_cr("device: 0x%08X", *((UInt32*)CFDataGetBytePtr(deviceID))); | |
75 tty->print_cr("model: %s", CFDataGetBytePtr(model)); | |
76 } | |
77 UInt32 vendor = *((UInt32*)CFDataGetBytePtr(vendorID)); | |
78 if (vendor != 0x10DE) { | |
79 return false; | |
80 } else { | |
81 /* | |
82 * see https://developer.nvidia.com/cuda-gpus | |
83 * see http://en.wikipedia.org/wiki/CUDA#Supported_GPUs | |
84 * see http://www.pcidatabase.com/reports.php?type=csv | |
85 * | |
86 * Only supporting GK104, GK106, GK107 and GK110 GPUs for now, | |
87 * which is CUDA Computer Capability 3.0 and greater. | |
88 */ | |
89 switch (*((UInt32*)CFDataGetBytePtr(deviceID))) { | |
90 case 0x11C0: | |
91 return true; // NVIDIA GeForce GTX 660 | |
92 default: | |
93 return false; | |
94 } | |
95 } | |
96 } | |
97 return false; | |
98 } | |
99 #endif |