Mercurial > hg > truffle
annotate src/gpu/ptx/vm/gpu_ptx.cpp @ 11503:8056b2a9865c
LocalNode: remove special handling, they should be reachable via inputs of other nodes if connected
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Mon, 02 Sep 2013 15:51:06 +0200 |
parents | 49bb1bc983c6 |
children | c99e65785936 |
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 "precompiled.hpp" | |
11284
d876002b98e6
ptx: fix include for non-precompiledheader build in gpu_ptx.cpp
Bernhard Urban <bernhard.urban@jku.at>
parents:
11283
diff
changeset
|
26 #include "runtime/javaCalls.hpp" |
10879 | 27 #include "runtime/gpu.hpp" |
28 #include "utilities/globalDefinitions.hpp" | |
29 #include "utilities/ostream.hpp" | |
10883
5fcb30bcb90a
Fix compilation without precompiled headers.
Roland Schatz <roland.schatz@oracle.com>
parents:
10882
diff
changeset
|
30 #include "memory/allocation.hpp" |
5fcb30bcb90a
Fix compilation without precompiled headers.
Roland Schatz <roland.schatz@oracle.com>
parents:
10882
diff
changeset
|
31 #include "memory/allocation.inline.hpp" |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
32 #include "kernelArguments.hpp" |
10879 | 33 |
34 void * gpu::Ptx::_device_context; | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
35 int gpu::Ptx::_cu_device = 0; |
10879 | 36 |
37 gpu::Ptx::cuda_cu_init_func_t gpu::Ptx::_cuda_cu_init; | |
38 gpu::Ptx::cuda_cu_ctx_create_func_t gpu::Ptx::_cuda_cu_ctx_create; | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
39 gpu::Ptx::cuda_cu_ctx_destroy_func_t gpu::Ptx::_cuda_cu_ctx_destroy; |
10879 | 40 gpu::Ptx::cuda_cu_ctx_synchronize_func_t gpu::Ptx::_cuda_cu_ctx_synchronize; |
41 gpu::Ptx::cuda_cu_device_get_count_func_t gpu::Ptx::_cuda_cu_device_get_count; | |
42 gpu::Ptx::cuda_cu_device_get_name_func_t gpu::Ptx::_cuda_cu_device_get_name; | |
43 gpu::Ptx::cuda_cu_device_get_func_t gpu::Ptx::_cuda_cu_device_get; | |
44 gpu::Ptx::cuda_cu_device_compute_capability_func_t gpu::Ptx::_cuda_cu_device_compute_capability; | |
45 gpu::Ptx::cuda_cu_device_get_attribute_func_t gpu::Ptx::_cuda_cu_device_get_attribute; | |
46 gpu::Ptx::cuda_cu_launch_kernel_func_t gpu::Ptx::_cuda_cu_launch_kernel; | |
47 gpu::Ptx::cuda_cu_module_get_function_func_t gpu::Ptx::_cuda_cu_module_get_function; | |
48 gpu::Ptx::cuda_cu_module_load_data_ex_func_t gpu::Ptx::_cuda_cu_module_load_data_ex; | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
49 gpu::Ptx::cuda_cu_memcpy_dtoh_func_t gpu::Ptx::_cuda_cu_memcpy_dtoh; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
50 gpu::Ptx::cuda_cu_memfree_func_t gpu::Ptx::_cuda_cu_memfree; |
10879 | 51 |
52 void gpu::probe_linkage() { | |
53 #if defined(__APPLE__) || defined(LINUX) | |
54 set_gpu_linkage(gpu::Ptx::probe_linkage()); | |
55 #else | |
56 set_gpu_linkage(false); | |
57 #endif | |
58 } | |
59 | |
60 void gpu::initialize_gpu() { | |
61 if (gpu::has_gpu_linkage()) { | |
62 set_initialized(gpu::Ptx::initialize_gpu()); | |
63 } | |
64 } | |
65 | |
66 void * gpu::generate_kernel(unsigned char *code, int code_len, const char *name) { | |
67 if (gpu::has_gpu_linkage()) { | |
68 return (gpu::Ptx::generate_kernel(code, code_len, name)); | |
69 } else { | |
70 return NULL; | |
71 } | |
72 } | |
73 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
74 bool gpu::execute_kernel(address kernel, PTXKernelArguments & ptxka, JavaValue& ret) { |
10879 | 75 if (gpu::has_gpu_linkage()) { |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
76 return (gpu::Ptx::execute_kernel(kernel, ptxka, ret)); |
10879 | 77 } else { |
78 return false; | |
79 } | |
80 } | |
81 | |
82 bool gpu::Ptx::initialize_gpu() { | |
83 | |
84 /* Initialize CUDA driver API */ | |
85 int status = _cuda_cu_init(0); | |
86 if (status != GRAAL_CUDA_SUCCESS) { | |
87 tty->print_cr("Failed to initialize CUDA device"); | |
88 return false; | |
89 } | |
90 | |
91 if (TraceGPUInteraction) { | |
92 tty->print_cr("CUDA driver initialization: Success"); | |
93 } | |
94 | |
95 /* Get the number of compute-capable device count */ | |
96 int device_count = 0; | |
97 status = _cuda_cu_device_get_count(&device_count); | |
98 if (status != GRAAL_CUDA_SUCCESS) { | |
99 tty->print_cr("[CUDA] Failed to get compute-capable device count"); | |
100 return false; | |
101 } | |
102 | |
103 if (device_count == 0) { | |
104 tty->print_cr("[CUDA] Found no device supporting CUDA"); | |
105 return false; | |
106 } | |
107 | |
108 if (TraceGPUInteraction) { | |
109 tty->print_cr("[CUDA] Number of compute-capable devices found: %d", device_count); | |
110 } | |
111 | |
112 /* Get the handle to the first compute device */ | |
113 int device_id = 0; | |
114 /* Compute-capable device handle */ | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
115 status = _cuda_cu_device_get(&_cu_device, device_id); |
10879 | 116 |
117 if (status != GRAAL_CUDA_SUCCESS) { | |
118 tty->print_cr("[CUDA] Failed to get handle of first compute-capable device i.e., the one at ordinal: %d", device_id); | |
119 return false; | |
120 } | |
121 | |
122 if (TraceGPUInteraction) { | |
123 tty->print_cr("[CUDA] Got the handle of first compute-device"); | |
124 } | |
125 | |
126 /* Get device attributes */ | |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
127 int minor, major, unified_addressing; |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
128 status = _cuda_cu_device_get_attribute(&minor, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, _cu_device); |
10879 | 129 |
130 if (status != GRAAL_CUDA_SUCCESS) { | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
131 tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device); |
10879 | 132 return false; |
133 } | |
134 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
135 status = _cuda_cu_device_get_attribute(&major, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, _cu_device); |
10879 | 136 |
137 if (status != GRAAL_CUDA_SUCCESS) { | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
138 tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device); |
10879 | 139 return false; |
140 } | |
141 | |
142 if (TraceGPUInteraction) { | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
143 tty->print_cr("[CUDA] Compatibility version of device %d: %d.%d", _cu_device, major, minor); |
10879 | 144 } |
145 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
146 status = _cuda_cu_device_get_attribute(&unified_addressing, GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, _cu_device); |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
147 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
148 if (status != GRAAL_CUDA_SUCCESS) { |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
149 tty->print_cr("[CUDA] Failed to query unified addressing mode of device: %d", _cu_device); |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
150 return false; |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
151 } |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
152 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
153 if (TraceGPUInteraction) { |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
154 tty->print_cr("[CUDA] Unified addressing support on device %d: %d", _cu_device, unified_addressing); |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
155 } |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
156 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
157 |
10879 | 158 /* Get device name */ |
159 char device_name[256]; | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
160 status = _cuda_cu_device_get_name(device_name, 256, _cu_device); |
10879 | 161 |
162 if (status != GRAAL_CUDA_SUCCESS) { | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
163 tty->print_cr("[CUDA] Failed to get name of device: %d", _cu_device); |
10879 | 164 return false; |
165 } | |
166 | |
167 if (TraceGPUInteraction) { | |
168 tty->print_cr("[CUDA] Using %s", device_name); | |
169 } | |
170 | |
171 return true; | |
172 } | |
173 | |
174 void *gpu::Ptx::generate_kernel(unsigned char *code, int code_len, const char *name) { | |
175 | |
176 struct CUmod_st * cu_module; | |
177 // Use three JIT compiler options | |
178 const unsigned int jit_num_options = 3; | |
179 int *jit_options = NEW_C_HEAP_ARRAY(int, jit_num_options, mtCompiler); | |
180 void **jit_option_values = NEW_C_HEAP_ARRAY(void *, jit_num_options, mtCompiler); | |
181 | |
182 // Set up PTX JIT compiler options | |
183 // 1. set size of compilation log buffer | |
184 int jit_log_buffer_size = 1024; | |
185 jit_options[0] = GRAAL_CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES; | |
186 jit_option_values[0] = (void *)(size_t)jit_log_buffer_size; | |
187 | |
188 // 2. set pointer to compilation log buffer | |
189 char *jit_log_buffer = NEW_C_HEAP_ARRAY(char, jit_log_buffer_size, mtCompiler); | |
190 jit_options[1] = GRAAL_CU_JIT_INFO_LOG_BUFFER; | |
191 jit_option_values[1] = jit_log_buffer; | |
192 | |
193 // 3. set pointer to set the Maximum # of registers (32) for the kernel | |
194 int jit_register_count = 32; | |
195 jit_options[2] = GRAAL_CU_JIT_MAX_REGISTERS; | |
196 jit_option_values[2] = (void *)(size_t)jit_register_count; | |
197 | |
198 if (TraceGPUInteraction) { | |
199 tty->print_cr("[CUDA] PTX Kernel\n%s", code); | |
200 tty->print_cr("[CUDA] Function name : %s", name); | |
201 | |
202 } | |
203 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
204 /* Create CUDA context to compile and execute the kernel */ |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
205 int status = _cuda_cu_ctx_create(&_device_context, 0, _cu_device); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
206 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
207 if (status != GRAAL_CUDA_SUCCESS) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
208 tty->print_cr("[CUDA] Failed to create CUDA context for device: %d", _cu_device); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
209 return NULL; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
210 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
211 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
212 if (TraceGPUInteraction) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
213 tty->print_cr("[CUDA] Success: Created context for device: %d", _cu_device); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
214 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
215 |
10879 | 216 /* Load module's data with compiler options */ |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
217 status = _cuda_cu_module_load_data_ex(&cu_module, (void*) code, jit_num_options, |
10879 | 218 jit_options, (void **)jit_option_values); |
219 if (status != GRAAL_CUDA_SUCCESS) { | |
220 if (status == GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU) { | |
221 tty->print_cr("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options"); | |
222 } | |
223 tty->print_cr("[CUDA] *** Error (%d) Failed to load module data with online compiler options for method %s", | |
224 status, name); | |
225 return NULL; | |
226 } | |
227 | |
228 if (TraceGPUInteraction) { | |
229 tty->print_cr("[CUDA] Loaded data for PTX Kernel"); | |
230 } | |
231 | |
232 struct CUfunc_st * cu_function; | |
233 | |
234 status = _cuda_cu_module_get_function(&cu_function, cu_module, name); | |
235 | |
236 if (status != GRAAL_CUDA_SUCCESS) { | |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
237 tty->print_cr("[CUDA] *** Error: Failed to get function %s", name); |
10879 | 238 return NULL; |
239 } | |
240 | |
241 if (TraceGPUInteraction) { | |
242 tty->print_cr("[CUDA] Got function handle for %s", name); | |
243 } | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
244 |
10879 | 245 return cu_function; |
246 } | |
247 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
248 bool gpu::Ptx::execute_kernel(address kernel, PTXKernelArguments &ptxka, JavaValue &ret) { |
10879 | 249 // grid dimensionality |
250 unsigned int gridX = 1; | |
251 unsigned int gridY = 1; | |
252 unsigned int gridZ = 1; | |
253 | |
254 // thread dimensionality | |
255 unsigned int blockX = 1; | |
256 unsigned int blockY = 1; | |
257 unsigned int blockZ = 1; | |
258 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
259 struct CUfunc_st* cu_function = (struct CUfunc_st*) kernel; |
10879 | 260 |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
261 void * config[5] = { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
262 GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER, ptxka._kernelArgBuffer, |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
263 GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE, &(ptxka._bufferOffset), |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
264 GRAAL_CU_LAUNCH_PARAM_END |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
265 }; |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
266 |
10879 | 267 if (kernel == NULL) { |
268 return false; | |
269 } | |
270 | |
271 if (TraceGPUInteraction) { | |
272 tty->print_cr("[CUDA] launching kernel"); | |
273 } | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
274 |
10879 | 275 int status = _cuda_cu_launch_kernel(cu_function, |
276 gridX, gridY, gridZ, | |
277 blockX, blockY, blockZ, | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
278 0, NULL, NULL, (void **) &config); |
10879 | 279 if (status != GRAAL_CUDA_SUCCESS) { |
280 tty->print_cr("[CUDA] Failed to launch kernel"); | |
281 return false; | |
282 } | |
283 | |
284 if (TraceGPUInteraction) { | |
285 tty->print_cr("[CUDA] Success: Kernel Launch"); | |
286 } | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
287 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
288 status = _cuda_cu_ctx_synchronize(); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
289 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
290 if (status != GRAAL_CUDA_SUCCESS) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
291 tty->print_cr("[CUDA] Failed to synchronize launched kernel (%d)", status); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
292 return false; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
293 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
294 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
295 if (TraceGPUInteraction) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
296 tty->print_cr("[CUDA] Success: Synchronized launch kernel"); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
297 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
298 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
299 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
300 // Get the result. TODO: Move this code to get_return_oop() |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
301 BasicType return_type = ptxka.get_ret_type(); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
302 switch (return_type) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
303 case T_INT : |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
304 { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
305 int return_val; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
306 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._return_value_ptr, T_INT_BYTE_SIZE); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
307 if (status != GRAAL_CUDA_SUCCESS) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
308 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value to device argument", status); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
309 return false; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
310 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
311 ret.set_jint(return_val); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
312 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
313 break; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
314 case T_LONG : |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
315 { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
316 long return_val; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
317 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._return_value_ptr, T_LONG_BYTE_SIZE); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
318 if (status != GRAAL_CUDA_SUCCESS) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
319 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value to device argument", status); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
320 return false; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
321 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
322 ret.set_jlong(return_val); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
323 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
324 break; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
325 default: |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
326 tty->print_cr("[CUDA] TODO *** Unhandled return type"); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
327 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
328 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
329 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
330 // Free device memory allocated for result |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
331 status = gpu::Ptx::_cuda_cu_memfree(ptxka._return_value_ptr); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
332 if (status != GRAAL_CUDA_SUCCESS) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
333 tty->print_cr("[CUDA] *** Error (%d) Failed to free device memory of return value", status); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
334 return false; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
335 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
336 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
337 if (TraceGPUInteraction) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
338 tty->print_cr("[CUDA] Success: Freed device memory of return value"); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
339 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
340 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
341 // Destroy context |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
342 status = gpu::Ptx::_cuda_cu_ctx_destroy(_device_context); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
343 if (status != GRAAL_CUDA_SUCCESS) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
344 tty->print_cr("[CUDA] *** Error (%d) Failed to destroy context", status); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
345 return false; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
346 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
347 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
348 if (TraceGPUInteraction) { |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
349 tty->print_cr("[CUDA] Success: Destroy context"); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
350 } |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
351 |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
352 return (status == GRAAL_CUDA_SUCCESS); |
10879 | 353 } |
354 | |
355 #if defined(LINUX) | |
356 static const char cuda_library_name[] = "libcuda.so"; | |
357 #elif defined(__APPLE__) | |
358 static char const cuda_library_name[] = "/usr/local/cuda/lib/libcuda.dylib"; | |
359 #else | |
360 static char const cuda_library_name[] = ""; | |
361 #endif | |
362 | |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
363 #define STD_BUFFER_SIZE 1024 |
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
364 |
10879 | 365 bool gpu::Ptx::probe_linkage() { |
366 if (cuda_library_name != NULL) { | |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
367 char *buffer = (char*)malloc(STD_BUFFER_SIZE); |
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
368 void *handle = os::dll_load(cuda_library_name, buffer, STD_BUFFER_SIZE); |
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
369 free(buffer); |
10879 | 370 if (handle != NULL) { |
371 _cuda_cu_init = | |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
372 CAST_TO_FN_PTR(cuda_cu_init_func_t, os::dll_lookup(handle, "cuInit")); |
10879 | 373 _cuda_cu_ctx_create = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
374 CAST_TO_FN_PTR(cuda_cu_ctx_create_func_t, os::dll_lookup(handle, "cuCtxCreate")); |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
375 _cuda_cu_ctx_destroy = |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
376 CAST_TO_FN_PTR(cuda_cu_ctx_destroy_func_t, os::dll_lookup(handle, "cuCtxDestroy")); |
10879 | 377 _cuda_cu_ctx_synchronize = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
378 CAST_TO_FN_PTR(cuda_cu_ctx_synchronize_func_t, os::dll_lookup(handle, "cuCtxSynchronize")); |
10879 | 379 _cuda_cu_device_get_count = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
380 CAST_TO_FN_PTR(cuda_cu_device_get_count_func_t, os::dll_lookup(handle, "cuDeviceGetCount")); |
10879 | 381 _cuda_cu_device_get_name = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
382 CAST_TO_FN_PTR(cuda_cu_device_get_name_func_t, os::dll_lookup(handle, "cuDeviceGetName")); |
10879 | 383 _cuda_cu_device_get = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
384 CAST_TO_FN_PTR(cuda_cu_device_get_func_t, os::dll_lookup(handle, "cuDeviceGet")); |
10879 | 385 _cuda_cu_device_compute_capability = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
386 CAST_TO_FN_PTR(cuda_cu_device_compute_capability_func_t, os::dll_lookup(handle, "cuDeviceComputeCapability")); |
10879 | 387 _cuda_cu_device_get_attribute = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
388 CAST_TO_FN_PTR(cuda_cu_device_get_attribute_func_t, os::dll_lookup(handle, "cuDeviceGetAttribute")); |
10879 | 389 _cuda_cu_module_get_function = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
390 CAST_TO_FN_PTR(cuda_cu_module_get_function_func_t, os::dll_lookup(handle, "cuModuleGetFunction")); |
10879 | 391 _cuda_cu_module_load_data_ex = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
392 CAST_TO_FN_PTR(cuda_cu_module_load_data_ex_func_t, os::dll_lookup(handle, "cuModuleLoadDataEx")); |
10879 | 393 _cuda_cu_launch_kernel = |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
394 CAST_TO_FN_PTR(cuda_cu_launch_kernel_func_t, os::dll_lookup(handle, "cuLaunchKernel")); |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
395 _cuda_cu_memalloc = |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
396 CAST_TO_FN_PTR(cuda_cu_memalloc_func_t, os::dll_lookup(handle, "cuMemAlloc")); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
397 _cuda_cu_memfree = |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
398 CAST_TO_FN_PTR(cuda_cu_memfree_func_t, os::dll_lookup(handle, "cuMemFree")); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
399 _cuda_cu_memcpy_htod = |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
400 CAST_TO_FN_PTR(cuda_cu_memcpy_htod_func_t, os::dll_lookup(handle, "cuMemcpyHtoD")); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
401 _cuda_cu_memcpy_dtoh = |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
402 CAST_TO_FN_PTR(cuda_cu_memcpy_dtoh_func_t, os::dll_lookup(handle, "cuMemcpyDtoH")); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11284
diff
changeset
|
403 |
10879 | 404 if (TraceGPUInteraction) { |
405 tty->print_cr("[CUDA] Success: library linkage"); | |
406 } | |
407 return true; | |
408 } else { | |
409 // Unable to dlopen libcuda | |
410 return false; | |
411 } | |
412 } else { | |
413 tty->print_cr("Unsupported CUDA platform"); | |
414 return false; | |
415 } | |
416 tty->print_cr("Failed to find CUDA linkage"); | |
417 return false; | |
418 } | |
419 |