comparison src/share/vm/runtime/gpu.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 f1a55428a8d7
children 66e3af78ea96
comparison
equal deleted inserted replaced
13818:d2f520f46180 13819:49db2c1e3bee
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "runtime/gpu.hpp" 26 #include "runtime/gpu.hpp"
27 #include "runtime/handles.hpp" 27 #include "runtime/handles.hpp"
28 28
29 bool gpu::_available = false; // does the hardware exist? 29 int gpu::_initialized_gpus = 0;
30 bool gpu::_gpu_linkage = false; // is the driver library to access the GPU installed
31 bool gpu::_initialized = false; // is the GPU device initialized
32 gpu::TargetGPUIL gpu::_targetIL = gpu::NONE; // No GPU detected yet.
33 30
34 void gpu::init() { 31 void gpu::initialized_gpu(const char* name) {
35 #if defined(TARGET_OS_FAMILY_bsd) || defined(TARGET_OS_FAMILY_linux) || defined(TARGET_OS_FAMILY_windows) 32 _initialized_gpus++;
36 gpu::probe_gpu(); 33 if (TraceGPUInteraction) {
37 if (gpu::get_target_il_type() == gpu::PTX) { 34 tty->print_cr("[GPU] registered initialization of %s (total initialized: %d)", name, _initialized_gpus);
38 set_gpu_linkage(gpu::Ptx::probe_linkage()); 35 }
39 } else if (gpu::get_target_il_type() == gpu::HSAIL) {
40 set_gpu_linkage(gpu::Hsail::probe_linkage());
41 } else {
42 set_gpu_linkage(false);
43 }
44 #endif
45 } 36 }
46
47 void gpu::initialize_gpu() {
48 if (gpu::has_gpu_linkage()) {
49 if (gpu::get_target_il_type() == gpu::PTX) {
50 set_initialized(gpu::Ptx::initialize_gpu());
51 } else if (gpu::get_target_il_type() == gpu::HSAIL) {
52 set_initialized(gpu::Hsail::initialize_gpu());
53 }
54 }
55 }
56
57 void * gpu::generate_kernel(unsigned char *code, int code_len, const char *name) {
58 if (gpu::has_gpu_linkage()) {
59 if (gpu::get_target_il_type() == gpu::PTX) {
60 return (gpu::Ptx::generate_kernel(code, code_len, name));
61 } else if (gpu::get_target_il_type() == gpu::HSAIL) {
62 return (gpu::Hsail::generate_kernel(code, code_len, name));
63 }
64 }
65 return NULL;
66 }
67
68 bool gpu::execute_kernel(address kernel, PTXKernelArguments & ptxka, JavaValue& ret) {
69 if (gpu::has_gpu_linkage()) {
70 if (gpu::get_target_il_type() == gpu::PTX) {
71 return (gpu::Ptx::execute_kernel(kernel, ptxka, ret));
72 }
73 // Add kernel execution functionality of other GPUs here
74 }
75 return false;
76 }
77
78 // This is HSAIL specific to work with Sumatra JDK
79 bool gpu::execute_kernel_void_1d(address kernel, int dimX, jobject args, methodHandle& mh) {
80 if (gpu::has_gpu_linkage()) {
81 if (gpu::get_target_il_type() == gpu::HSAIL) {
82 return (gpu::Hsail::execute_kernel_void_1d(kernel, dimX, args, mh));
83 }
84 }
85 return false;
86
87 }
88
89
90 bool gpu::execute_warp(int dimX, int dimY, int dimZ,
91 address kernel, PTXKernelArguments & ptxka, JavaValue& ret) {
92 if (gpu::has_gpu_linkage()) {
93 if (gpu::get_target_il_type() == gpu::PTX) {
94 return (gpu::Ptx::execute_warp(dimX, dimY, dimZ, kernel, ptxka, ret));
95 }
96 // Add kernel execution functionality of other GPUs here
97 }
98 return false;
99 }
100
101 int gpu::available_processors() {
102 if (gpu::has_gpu_linkage()) {
103 if (gpu::get_target_il_type() == gpu::PTX) {
104 return (gpu::Ptx::total_cores());
105 }
106 // Add kernel execution functionality of other GPUs here
107 }
108 return 0;
109 }
110