Mercurial > hg > truffle
annotate src/gpu/ptx/vm/gpu_ptx.cpp @ 11843:372bacc13022
gtx_ptx.cpp: fix switch default label and operator precedence in ncores().
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Mon, 30 Sep 2013 21:46:41 +0200 |
parents | 8d8f63069f58 |
children | c7abc8411011 |
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" |
11596
91e5f927af63
Initial implementation of PTXRuntime (RegisterConfig, PTX description etc); guarded with new flag UseGPU. Specify -XX:+UseGPU to exercise this new implementation.
bharadwaj
parents:
11527
diff
changeset
|
32 #include "ptxKernelArguments.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; |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
41 gpu::Ptx::cuda_cu_ctx_set_current_func_t gpu::Ptx::_cuda_cu_ctx_set_current; |
10879 | 42 gpu::Ptx::cuda_cu_device_get_count_func_t gpu::Ptx::_cuda_cu_device_get_count; |
43 gpu::Ptx::cuda_cu_device_get_name_func_t gpu::Ptx::_cuda_cu_device_get_name; | |
44 gpu::Ptx::cuda_cu_device_get_func_t gpu::Ptx::_cuda_cu_device_get; | |
45 gpu::Ptx::cuda_cu_device_compute_capability_func_t gpu::Ptx::_cuda_cu_device_compute_capability; | |
46 gpu::Ptx::cuda_cu_device_get_attribute_func_t gpu::Ptx::_cuda_cu_device_get_attribute; | |
47 gpu::Ptx::cuda_cu_launch_kernel_func_t gpu::Ptx::_cuda_cu_launch_kernel; | |
48 gpu::Ptx::cuda_cu_module_get_function_func_t gpu::Ptx::_cuda_cu_module_get_function; | |
49 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
|
50 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
|
51 gpu::Ptx::cuda_cu_memfree_func_t gpu::Ptx::_cuda_cu_memfree; |
10879 | 52 |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
53 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
54 /* |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
55 * see http://en.wikipedia.org/wiki/CUDA#Supported_GPUs |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
56 */ |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
57 int ncores(int major, int minor) { |
11843
372bacc13022
gtx_ptx.cpp: fix switch default label and operator precedence in ncores().
Andreas Woess <andreas.woess@jku.at>
parents:
11842
diff
changeset
|
58 int device_type = (major << 4) + minor; |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
59 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
60 switch (device_type) { |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
61 case 0x10: return 8; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
62 case 0x11: return 8; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
63 case 0x12: return 8; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
64 case 0x13: return 8; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
65 case 0x20: return 32; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
66 case 0x21: return 48; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
67 case 0x30: return 192; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
68 case 0x35: return 192; |
11843
372bacc13022
gtx_ptx.cpp: fix switch default label and operator precedence in ncores().
Andreas Woess <andreas.woess@jku.at>
parents:
11842
diff
changeset
|
69 default: |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
70 tty->print_cr("[CUDA] Warning: Unhandled device %x", device_type); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
71 return 0; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
72 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
73 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
74 |
10879 | 75 bool gpu::Ptx::initialize_gpu() { |
76 | |
77 /* Initialize CUDA driver API */ | |
78 int status = _cuda_cu_init(0); | |
79 if (status != GRAAL_CUDA_SUCCESS) { | |
80 tty->print_cr("Failed to initialize CUDA device"); | |
81 return false; | |
82 } | |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
83 |
10879 | 84 if (TraceGPUInteraction) { |
85 tty->print_cr("CUDA driver initialization: Success"); | |
86 } | |
87 | |
88 /* Get the number of compute-capable device count */ | |
89 int device_count = 0; | |
90 status = _cuda_cu_device_get_count(&device_count); | |
91 if (status != GRAAL_CUDA_SUCCESS) { | |
92 tty->print_cr("[CUDA] Failed to get compute-capable device count"); | |
93 return false; | |
94 } | |
95 | |
96 if (device_count == 0) { | |
97 tty->print_cr("[CUDA] Found no device supporting CUDA"); | |
98 return false; | |
99 } | |
100 | |
101 if (TraceGPUInteraction) { | |
102 tty->print_cr("[CUDA] Number of compute-capable devices found: %d", device_count); | |
103 } | |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
104 |
10879 | 105 /* Get the handle to the first compute device */ |
106 int device_id = 0; | |
107 /* 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
|
108 status = _cuda_cu_device_get(&_cu_device, device_id); |
10879 | 109 |
110 if (status != GRAAL_CUDA_SUCCESS) { | |
111 tty->print_cr("[CUDA] Failed to get handle of first compute-capable device i.e., the one at ordinal: %d", device_id); | |
112 return false; | |
113 } | |
114 | |
115 if (TraceGPUInteraction) { | |
116 tty->print_cr("[CUDA] Got the handle of first compute-device"); | |
117 } | |
118 | |
119 /* Get device attributes */ | |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
120 int unified_addressing; |
10879 | 121 |
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
|
122 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
|
123 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
124 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
|
125 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
|
126 return false; |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
127 } |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
128 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
129 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
|
130 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
|
131 } |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
132 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
133 |
10879 | 134 /* Get device name */ |
135 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
|
136 status = _cuda_cu_device_get_name(device_name, 256, _cu_device); |
10879 | 137 |
138 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
|
139 tty->print_cr("[CUDA] Failed to get name of device: %d", _cu_device); |
10879 | 140 return false; |
141 } | |
142 | |
143 if (TraceGPUInteraction) { | |
144 tty->print_cr("[CUDA] Using %s", device_name); | |
145 } | |
146 | |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
147 |
10879 | 148 return true; |
149 } | |
150 | |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
151 unsigned int gpu::Ptx::total_cores() { |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
152 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
153 int minor, major, nmp; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
154 int status = _cuda_cu_device_get_attribute(&minor, |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
155 GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
156 _cu_device); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
157 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
158 if (status != GRAAL_CUDA_SUCCESS) { |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
159 tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
160 return 0; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
161 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
162 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
163 status = _cuda_cu_device_get_attribute(&major, |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
164 GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
165 _cu_device); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
166 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
167 if (status != GRAAL_CUDA_SUCCESS) { |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
168 tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
169 return 0; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
170 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
171 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
172 status = _cuda_cu_device_get_attribute(&nmp, |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
173 GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
174 _cu_device); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
175 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
176 if (status != GRAAL_CUDA_SUCCESS) { |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
177 tty->print_cr("[CUDA] Failed to get numberof MPs on device: %d", _cu_device); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
178 return 0; |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
179 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
180 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
181 int total = nmp * ncores(major, minor); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
182 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
183 if (TraceGPUInteraction) { |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
184 tty->print_cr("[CUDA] Compatibility version of device %d: %d.%d", _cu_device, major, minor); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
185 tty->print_cr("[CUDA] Number of cores: %d", total); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
186 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
187 return (total); |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
188 |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
189 } |
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
190 |
10879 | 191 void *gpu::Ptx::generate_kernel(unsigned char *code, int code_len, const char *name) { |
192 | |
193 struct CUmod_st * cu_module; | |
194 // Use three JIT compiler options | |
195 const unsigned int jit_num_options = 3; | |
196 int *jit_options = NEW_C_HEAP_ARRAY(int, jit_num_options, mtCompiler); | |
197 void **jit_option_values = NEW_C_HEAP_ARRAY(void *, jit_num_options, mtCompiler); | |
198 | |
199 // Set up PTX JIT compiler options | |
200 // 1. set size of compilation log buffer | |
201 int jit_log_buffer_size = 1024; | |
202 jit_options[0] = GRAAL_CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES; | |
203 jit_option_values[0] = (void *)(size_t)jit_log_buffer_size; | |
204 | |
205 // 2. set pointer to compilation log buffer | |
206 char *jit_log_buffer = NEW_C_HEAP_ARRAY(char, jit_log_buffer_size, mtCompiler); | |
207 jit_options[1] = GRAAL_CU_JIT_INFO_LOG_BUFFER; | |
208 jit_option_values[1] = jit_log_buffer; | |
209 | |
210 // 3. set pointer to set the Maximum # of registers (32) for the kernel | |
211 int jit_register_count = 32; | |
212 jit_options[2] = GRAAL_CU_JIT_MAX_REGISTERS; | |
213 jit_option_values[2] = (void *)(size_t)jit_register_count; | |
214 | |
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
|
215 /* 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
|
216 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
|
217 |
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
|
218 if (status != GRAAL_CUDA_SUCCESS) { |
11634
bff2b88444f5
Start of PTX array passing
Morris Meyer <morris.meyer@oracle.com>
parents:
11606
diff
changeset
|
219 tty->print_cr("[CUDA] Failed to create CUDA context for device(%d): %d", _cu_device, status); |
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
|
220 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
|
221 } |
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
|
222 |
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
|
223 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
|
224 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
|
225 } |
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
|
226 |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
227 status = _cuda_cu_ctx_set_current(_device_context); |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
228 |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
229 if (status != GRAAL_CUDA_SUCCESS) { |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
230 tty->print_cr("[CUDA] Failed to set current context for device: %d", _cu_device); |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
231 return NULL; |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
232 } |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
233 |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
234 if (TraceGPUInteraction) { |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
235 tty->print_cr("[CUDA] Success: Set current context for device: %d", _cu_device); |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
236 } |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
237 |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
238 if (TraceGPUInteraction) { |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
239 tty->print_cr("[CUDA] PTX Kernel\n%s", code); |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
240 tty->print_cr("[CUDA] Function name : %s", name); |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
241 |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
242 } |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
243 |
10879 | 244 /* 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
|
245 status = _cuda_cu_module_load_data_ex(&cu_module, (void*) code, jit_num_options, |
10879 | 246 jit_options, (void **)jit_option_values); |
247 if (status != GRAAL_CUDA_SUCCESS) { | |
248 if (status == GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU) { | |
249 tty->print_cr("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options"); | |
250 } | |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
251 tty->print_cr("[CUDA] *** Error (%d) Failed to load module data with online compiler options for method %s", |
10879 | 252 status, name); |
253 return NULL; | |
254 } | |
255 | |
256 if (TraceGPUInteraction) { | |
257 tty->print_cr("[CUDA] Loaded data for PTX Kernel"); | |
258 } | |
259 | |
260 struct CUfunc_st * cu_function; | |
261 | |
262 status = _cuda_cu_module_get_function(&cu_function, cu_module, name); | |
263 | |
264 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
|
265 tty->print_cr("[CUDA] *** Error: Failed to get function %s", name); |
10879 | 266 return NULL; |
267 } | |
268 | |
269 if (TraceGPUInteraction) { | |
270 tty->print_cr("[CUDA] Got function handle for %s", name); | |
271 } | |
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
|
272 |
10879 | 273 return cu_function; |
274 } | |
275 | |
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
|
276 bool gpu::Ptx::execute_kernel(address kernel, PTXKernelArguments &ptxka, JavaValue &ret) { |
11822
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
277 return gpu::Ptx::execute_warp(1, 1, 1, kernel, ptxka, ret); |
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
278 } |
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
279 |
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
280 bool gpu::Ptx::execute_warp(int dimX, int dimY, int dimZ, |
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
281 address kernel, PTXKernelArguments &ptxka, JavaValue &ret) { |
10879 | 282 // grid dimensionality |
283 unsigned int gridX = 1; | |
284 unsigned int gridY = 1; | |
285 unsigned int gridZ = 1; | |
286 | |
287 // thread dimensionality | |
11822
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
288 unsigned int blockX = dimX; |
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
289 unsigned int blockY = dimY; |
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
290 unsigned int blockZ = dimZ; |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
291 |
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
|
292 struct CUfunc_st* cu_function = (struct CUfunc_st*) kernel; |
10879 | 293 |
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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 }; |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10884
diff
changeset
|
299 |
10879 | 300 if (kernel == NULL) { |
301 return false; | |
302 } | |
303 | |
304 if (TraceGPUInteraction) { | |
305 tty->print_cr("[CUDA] launching kernel"); | |
306 } | |
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
|
307 |
10879 | 308 int status = _cuda_cu_launch_kernel(cu_function, |
309 gridX, gridY, gridZ, | |
310 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
|
311 0, NULL, NULL, (void **) &config); |
10879 | 312 if (status != GRAAL_CUDA_SUCCESS) { |
313 tty->print_cr("[CUDA] Failed to launch kernel"); | |
314 return false; | |
315 } | |
316 | |
317 if (TraceGPUInteraction) { | |
11822
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11821
diff
changeset
|
318 tty->print_cr("[CUDA] Success: Kernel Launch: X: %d Y: %d Z: %d", blockX, blockY, blockZ); |
10879 | 319 } |
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
|
320 |
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 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
|
322 |
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 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
|
324 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
|
325 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
|
326 } |
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 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
|
329 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
|
330 } |
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 |
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 |
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 // 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
|
334 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
|
335 switch (return_type) { |
11821
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
336 case T_INT: |
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
|
337 { |
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 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 } |
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 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
|
345 } |
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 break; |
11821
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
347 case T_LONG: |
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
|
348 { |
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 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 } |
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
|
355 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
|
356 } |
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
|
357 break; |
11821
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
358 case T_VOID: |
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
359 break; |
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
|
360 default: |
11821
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
361 tty->print_cr("[CUDA] TODO *** Unhandled return type: %d", return_type); |
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
|
362 } |
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
|
363 |
11821
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
364 // handle post-invocation object and array arguemtn |
d8659ad83fcc
PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11634
diff
changeset
|
365 ptxka.reiterate(); |
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
|
366 |
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
|
367 // 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 } |
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
|
373 |
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
|
374 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
|
375 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
|
376 } |
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
|
377 |
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
|
378 // 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 } |
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
|
384 |
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
|
385 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
|
386 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
|
387 } |
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
|
388 |
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
|
389 return (status == GRAAL_CUDA_SUCCESS); |
10879 | 390 } |
391 | |
392 #if defined(LINUX) | |
393 static const char cuda_library_name[] = "libcuda.so"; | |
394 #elif defined(__APPLE__) | |
395 static char const cuda_library_name[] = "/usr/local/cuda/lib/libcuda.dylib"; | |
396 #else | |
397 static char const cuda_library_name[] = ""; | |
398 #endif | |
399 | |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
400 #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
|
401 |
10879 | 402 bool gpu::Ptx::probe_linkage() { |
403 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
|
404 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
|
405 void *handle = os::dll_load(cuda_library_name, buffer, STD_BUFFER_SIZE); |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
406 free(buffer); |
10879 | 407 if (handle != NULL) { |
408 _cuda_cu_init = | |
10882
6a2d65cb5d7d
fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents:
10879
diff
changeset
|
409 CAST_TO_FN_PTR(cuda_cu_init_func_t, os::dll_lookup(handle, "cuInit")); |
10879 | 410 _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
|
411 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
|
412 _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
|
413 CAST_TO_FN_PTR(cuda_cu_ctx_destroy_func_t, os::dll_lookup(handle, "cuCtxDestroy")); |
10879 | 414 _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
|
415 CAST_TO_FN_PTR(cuda_cu_ctx_synchronize_func_t, os::dll_lookup(handle, "cuCtxSynchronize")); |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
416 _cuda_cu_ctx_set_current = |
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
417 CAST_TO_FN_PTR(cuda_cu_ctx_set_current_func_t, os::dll_lookup(handle, "cuCtxSetCurrent")); |
10879 | 418 _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
|
419 CAST_TO_FN_PTR(cuda_cu_device_get_count_func_t, os::dll_lookup(handle, "cuDeviceGetCount")); |
10879 | 420 _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
|
421 CAST_TO_FN_PTR(cuda_cu_device_get_name_func_t, os::dll_lookup(handle, "cuDeviceGetName")); |
10879 | 422 _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
|
423 CAST_TO_FN_PTR(cuda_cu_device_get_func_t, os::dll_lookup(handle, "cuDeviceGet")); |
10879 | 424 _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
|
425 CAST_TO_FN_PTR(cuda_cu_device_compute_capability_func_t, os::dll_lookup(handle, "cuDeviceComputeCapability")); |
10879 | 426 _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
|
427 CAST_TO_FN_PTR(cuda_cu_device_get_attribute_func_t, os::dll_lookup(handle, "cuDeviceGetAttribute")); |
10879 | 428 _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
|
429 CAST_TO_FN_PTR(cuda_cu_module_get_function_func_t, os::dll_lookup(handle, "cuModuleGetFunction")); |
10879 | 430 _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
|
431 CAST_TO_FN_PTR(cuda_cu_module_load_data_ex_func_t, os::dll_lookup(handle, "cuModuleLoadDataEx")); |
10879 | 432 _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
|
433 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
|
434 _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
|
435 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
|
436 _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
|
437 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
|
438 _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
|
439 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
|
440 _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
|
441 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
|
442 |
10879 | 443 if (TraceGPUInteraction) { |
444 tty->print_cr("[CUDA] Success: library linkage"); | |
445 } | |
446 return true; | |
447 } else { | |
448 // Unable to dlopen libcuda | |
449 return false; | |
450 } | |
451 } else { | |
452 tty->print_cr("Unsupported CUDA platform"); | |
453 return false; | |
454 } | |
455 tty->print_cr("Failed to find CUDA linkage"); | |
456 return false; | |
457 } |