annotate src/gpu/ptx/vm/gpu_ptx.cpp @ 13624:220ed109bf77

initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
author Doug Simon <doug.simon@oracle.com>
date Mon, 13 Jan 2014 22:32:27 +0100
parents 1a7e7011a341
children 27acedac70b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
1 /*
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
4 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
8 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
14 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
18 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
21 * questions.
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
22 *
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
23 */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
24
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
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
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
27 #include "runtime/gpu.hpp"
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
28 #include "utilities/globalDefinitions.hpp"
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
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"
13624
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
32 #include "runtime/interfaceSupport.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
33 #include "ptxKernelArguments.hpp"
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
34
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
35 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
36 int gpu::Ptx::_cu_device = 0;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
37
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
38 gpu::Ptx::cuda_cu_init_func_t gpu::Ptx::_cuda_cu_init;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
39 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
40 gpu::Ptx::cuda_cu_ctx_destroy_func_t gpu::Ptx::_cuda_cu_ctx_destroy;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
41 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
42 gpu::Ptx::cuda_cu_ctx_set_current_func_t gpu::Ptx::_cuda_cu_ctx_set_current;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
43 gpu::Ptx::cuda_cu_device_get_count_func_t gpu::Ptx::_cuda_cu_device_get_count;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
44 gpu::Ptx::cuda_cu_device_get_name_func_t gpu::Ptx::_cuda_cu_device_get_name;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
45 gpu::Ptx::cuda_cu_device_get_func_t gpu::Ptx::_cuda_cu_device_get;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
46 gpu::Ptx::cuda_cu_device_compute_capability_func_t gpu::Ptx::_cuda_cu_device_compute_capability;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
47 gpu::Ptx::cuda_cu_device_get_attribute_func_t gpu::Ptx::_cuda_cu_device_get_attribute;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
48 gpu::Ptx::cuda_cu_launch_kernel_func_t gpu::Ptx::_cuda_cu_launch_kernel;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
49 gpu::Ptx::cuda_cu_module_get_function_func_t gpu::Ptx::_cuda_cu_module_get_function;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
50 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
51 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
52 gpu::Ptx::cuda_cu_memfree_func_t gpu::Ptx::_cuda_cu_memfree;
12653
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
53 gpu::Ptx::cuda_cu_mem_host_register_func_t gpu::Ptx::_cuda_cu_mem_host_register;
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
54 gpu::Ptx::cuda_cu_mem_host_get_device_pointer_func_t gpu::Ptx::_cuda_cu_mem_host_get_device_pointer;
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
55 gpu::Ptx::cuda_cu_mem_host_unregister_func_t gpu::Ptx::_cuda_cu_mem_host_unregister;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
56
12653
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
57 #define STRINGIFY(x) #x
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
58
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
59 #define LOOKUP_CUDA_FUNCTION(name, alias) \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
60 _##alias = \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
61 CAST_TO_FN_PTR(alias##_func_t, os::dll_lookup(handle, STRINGIFY(name))); \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
62 if (_##alias == NULL) { \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
63 tty->print_cr("[CUDA] ***** Error: Failed to lookup %s", STRINGIFY(name)); \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
64 return 0; \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
65 } \
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
66
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
67 #define LOOKUP_CUDA_V2_FUNCTION(name, alias) LOOKUP_CUDA_FUNCTION(name##_v2, alias)
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
68
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
69 /*
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
70 * 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
71 */
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
72 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
73 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
74
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
75 switch (device_type) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
76 case 0x10: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
77 case 0x11: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
78 case 0x12: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
79 case 0x13: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
80 case 0x20: return 32;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
81 case 0x21: return 48;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
82 case 0x30: return 192;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
83 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
84 default:
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
85 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
86 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
87 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
88 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
89
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
90 bool gpu::Ptx::initialize_gpu() {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
91
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
92 /* Initialize CUDA driver API */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
93 int status = _cuda_cu_init(0);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
94 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
95 tty->print_cr("Failed to initialize CUDA device");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
96 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
97 }
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
98
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
99 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
100 tty->print_cr("CUDA driver initialization: Success");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
101 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
102
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
103 /* Get the number of compute-capable device count */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
104 int device_count = 0;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
105 status = _cuda_cu_device_get_count(&device_count);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
106 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
107 tty->print_cr("[CUDA] Failed to get compute-capable device count");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
108 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
109 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
110
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
111 if (device_count == 0) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
112 tty->print_cr("[CUDA] Found no device supporting CUDA");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
113 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
114 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
115
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
116 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
117 tty->print_cr("[CUDA] Number of compute-capable devices found: %d", device_count);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
118 }
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
119
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
120 /* Get the handle to the first compute device */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
121 int device_id = 0;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
122 /* 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
123 status = _cuda_cu_device_get(&_cu_device, device_id);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
124
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
125 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
126 tty->print_cr("[CUDA] Failed to get handle of first compute-capable device i.e., the one at ordinal: %d", device_id);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
127 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
128 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
129
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
130 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
131 tty->print_cr("[CUDA] Got the handle of first compute-device");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
132 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
133
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
134 /* Get device attributes */
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
135 int unified_addressing;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
136
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
137 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
138
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
139 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
140 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
141 return false;
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
142 }
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
143
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
144 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
145 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
146 }
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
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
149 /* Get device name */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
150 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
151 status = _cuda_cu_device_get_name(device_name, 256, _cu_device);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
152
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
153 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
154 tty->print_cr("[CUDA] Failed to get name of device: %d", _cu_device);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
155 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
156 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
157
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
158 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
159 tty->print_cr("[CUDA] Using %s", device_name);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
160 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
161
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
162
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
163 return true;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
164 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
165
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
166 unsigned int gpu::Ptx::total_cores() {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
167
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
168 int minor, major, nmp;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
169 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
170 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
171 _cu_device);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
172
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
173 if (status != GRAAL_CUDA_SUCCESS) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
174 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
175 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
176 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
177
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
178 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
179 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
180 _cu_device);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
181
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
182 if (status != GRAAL_CUDA_SUCCESS) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
183 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
184 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
185 }
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 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
188 GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
189 _cu_device);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
190
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
191 if (status != GRAAL_CUDA_SUCCESS) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
192 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
193 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
194 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
195
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
196 int total = nmp * ncores(major, minor);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
197
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
198 int max_threads_per_block, warp_size, async_engines, can_map_host_memory, concurrent_kernels;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
199
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
200 status = _cuda_cu_device_get_attribute(&max_threads_per_block,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
201 GRAAL_CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
202 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
203
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
204 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
205 tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK: %d", _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
206 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
207 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
208
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
209 status = _cuda_cu_device_get_attribute(&warp_size,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
210 GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
211 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
212
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
213 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
214 tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE: %d", _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
215 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
216 }
12653
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
217
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
218 status = _cuda_cu_device_get_attribute(&async_engines,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
219 GRAAL_CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
220 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
221
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
222 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
223 tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE: %d", _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
224 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
225 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
226
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
227 status = _cuda_cu_device_get_attribute(&can_map_host_memory,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
228 GRAAL_CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
229 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
230
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
231 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
232 tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY: %d", _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
233 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
234 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
235
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
236 status = _cuda_cu_device_get_attribute(&concurrent_kernels,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
237 GRAAL_CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
238 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
239
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
240 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
241 tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS: %d", _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
242 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
243 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
244
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
245 if (TraceGPUInteraction) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
246 tty->print_cr("[CUDA] Compatibility version of device %d: %d.%d", _cu_device, major, minor);
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
247 tty->print_cr("[CUDA] Number of cores: %d async engines: %d can map host mem: %d concurrent kernels: %d",
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
248 total, async_engines, can_map_host_memory, concurrent_kernels);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
249 tty->print_cr("[CUDA] Max threads per block: %d warp size: %d", max_threads_per_block, warp_size);
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
250 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
251 return (total);
12653
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
252
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
253 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
254
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
255 void *gpu::Ptx::generate_kernel(unsigned char *code, int code_len, const char *name) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
256
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
257 struct CUmod_st * cu_module;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
258 // Use three JIT compiler options
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
259 const unsigned int jit_num_options = 3;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
260 int *jit_options = NEW_C_HEAP_ARRAY(int, jit_num_options, mtCompiler);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
261 void **jit_option_values = NEW_C_HEAP_ARRAY(void *, jit_num_options, mtCompiler);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
262
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
263 // Set up PTX JIT compiler options
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
264 // 1. set size of compilation log buffer
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
265 int jit_log_buffer_size = 1024;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
266 jit_options[0] = GRAAL_CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
267 jit_option_values[0] = (void *)(size_t)jit_log_buffer_size;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
268
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
269 // 2. set pointer to compilation log buffer
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
270 char *jit_log_buffer = NEW_C_HEAP_ARRAY(char, jit_log_buffer_size, mtCompiler);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
271 jit_options[1] = GRAAL_CU_JIT_INFO_LOG_BUFFER;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
272 jit_option_values[1] = jit_log_buffer;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
273
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
274 // 3. set pointer to set the Maximum # of registers (32) for the kernel
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
275 int jit_register_count = 32;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
276 jit_options[2] = GRAAL_CU_JIT_MAX_REGISTERS;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
277 jit_option_values[2] = (void *)(size_t)jit_register_count;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
278
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
279 /* Create CUDA context to compile and execute the kernel */
12653
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
280 int status = _cuda_cu_ctx_create(&_device_context, GRAAL_CU_CTX_MAP_HOST, _cu_device);
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
281
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
282 if (status != GRAAL_CUDA_SUCCESS) {
11634
bff2b88444f5 Start of PTX array passing
Morris Meyer <morris.meyer@oracle.com>
parents: 11606
diff changeset
283 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
284 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
285 }
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
286
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 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
288 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
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
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
291 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
292
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
293 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
294 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
295 return NULL;
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
296 }
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
297
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
298 if (TraceGPUInteraction) {
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
299 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
300 }
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
301
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
302 if (TraceGPUInteraction) {
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
303 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
304 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
305
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
306 }
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
307
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
308 /* 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
309 status = _cuda_cu_module_load_data_ex(&cu_module, (void*) code, jit_num_options,
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
310 jit_options, (void **)jit_option_values);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
311 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
312 if (status == GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
313 tty->print_cr("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
314 }
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
315 tty->print_cr("[CUDA] *** Error (%d) Failed to load module data with online compiler options for method %s",
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
316 status, name);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
317 return NULL;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
318 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
319
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
320 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
321 tty->print_cr("[CUDA] Loaded data for PTX Kernel");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
322 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
323
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
324 struct CUfunc_st * cu_function;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
325
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
326 status = _cuda_cu_module_get_function(&cu_function, cu_module, name);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
327
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
328 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
329 tty->print_cr("[CUDA] *** Error: Failed to get function %s", name);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
330 return NULL;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
331 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
332
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
333 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
334 tty->print_cr("[CUDA] Got function handle for %s", name);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
335 }
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
336
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
337 return cu_function;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
338 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
339
13624
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
340 JRT_ENTRY(jlong, gpu::Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jlong parametersAndReturnValueBuffer, jint parametersAndReturnValueBufferSize, int encodedReturnTypeSize))
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
341 tty->print_cr("*** gpu::Ptx::execute_kernel_from_vm(kernel=%p, parametersAndReturnValueBuffer=%p, parametersAndReturnValueBufferSize=%d, encodedReturnTypeSize=%d)",
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
342 kernel, parametersAndReturnValueBuffer, parametersAndReturnValueBufferSize, encodedReturnTypeSize);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
343 tty->print(" buffer as bytes: ");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
344 for (int i = 0; i < parametersAndReturnValueBufferSize; i++) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
345 tty->print(" 0x%02x", ((jbyte*) (address) parametersAndReturnValueBuffer)[i] & 0xFF);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
346 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
347 tty->cr();
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
348 tty->print(" buffer as ints: ");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
349 for (int i = 0; i < (parametersAndReturnValueBufferSize / 4); i++) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
350 tty->print(" %d", ((jint*) (address) parametersAndReturnValueBuffer)[i]);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
351 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
352 tty->cr();
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
353 tty->print(" buffer as words: ");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
354 for (unsigned i = 0; i < (parametersAndReturnValueBufferSize / sizeof(void*)); i++) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
355 tty->print(" "INTPTR_FORMAT, ((void**) (address) parametersAndReturnValueBuffer)[i]);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
356 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
357 tty->cr();
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
358 if (kernel == 0L) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
359 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException(), NULL);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
360 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
361 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
362
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
363
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
364 // grid dimensionality
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
365 unsigned int gridX = 1;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
366 unsigned int gridY = 1;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
367 unsigned int gridZ = 1;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
368
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
369 // thread dimensionality
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
370 unsigned int blockX = 1;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
371 unsigned int blockY = 1;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
372 unsigned int blockZ = 1;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
373
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
374 struct CUfunc_st* cu_function = (struct CUfunc_st*) (address) kernel;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
375
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
376 void * config[5] = {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
377 GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER, (char*) (address) parametersAndReturnValueBuffer,
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
378 GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE, &parametersAndReturnValueBufferSize,
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
379 GRAAL_CU_LAUNCH_PARAM_END
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
380 };
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
381
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
382 if (TraceGPUInteraction) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
383 tty->print_cr("[CUDA] launching kernel");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
384 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
385
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
386 bool isObjectReturn = encodedReturnTypeSize < 0;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
387 int returnTypeSize = encodedReturnTypeSize < 0 ? -encodedReturnTypeSize : encodedReturnTypeSize;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
388 gpu::Ptx::CUdeviceptr device_return_value;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
389 int status;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
390 if (returnTypeSize != 0) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
391 status = _cuda_cu_memalloc(&device_return_value, returnTypeSize);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
392 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
393 tty->print_cr("[CUDA] *** Error (%d) Failed to allocate memory for return value pointer on device", status);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
394 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to allocate memory for return value pointer on device");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
395 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
396 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
397 // Push device_return_value to kernelParams
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
398 gpu::Ptx::CUdeviceptr* returnValuePtr = (gpu::Ptx::CUdeviceptr*) (address) parametersAndReturnValueBuffer + parametersAndReturnValueBufferSize - sizeof(device_return_value);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
399 *returnValuePtr = device_return_value;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
400 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
401
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
402 status = _cuda_cu_launch_kernel(cu_function,
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
403 gridX, gridY, gridZ,
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
404 blockX, blockY, blockZ,
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
405 0, NULL, NULL, (void **) &config);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
406
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
407 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
408 tty->print_cr("[CUDA] Failed to launch kernel");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
409 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to launch kernel");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
410 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
411 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
412
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
413 if (TraceGPUInteraction) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
414 tty->print_cr("[CUDA] Success: Kernel Launch: X: %d Y: %d Z: %d", blockX, blockY, blockZ);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
415 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
416
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
417 status = _cuda_cu_ctx_synchronize();
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
418
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
419 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
420 tty->print_cr("[CUDA] Failed to synchronize launched kernel (%d)", status);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
421 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to synchronize launched kernel");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
422 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
423 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
424
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
425 if (TraceGPUInteraction) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
426 tty->print_cr("[CUDA] Success: Synchronized launch kernel");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
427 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
428
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
429 jlong primitiveReturnValue = 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
430 if (isObjectReturn) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
431 oop return_val;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
432 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, device_return_value, T_OBJECT_BYTE_SIZE);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
433 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
434 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value from device argument", status);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
435 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to copy value from device argument");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
436 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
437 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
438 thread->set_vm_result(return_val);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
439 } else if (returnTypeSize > 0) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
440 jlong result;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
441 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&primitiveReturnValue, device_return_value, T_LONG_BYTE_SIZE);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
442 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
443 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value from device argument", status);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
444 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to copy value from device argument");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
445 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
446 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
447 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
448
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
449 // Free device memory allocated for result
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
450 if (returnTypeSize != 0) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
451 status = gpu::Ptx::_cuda_cu_memfree(device_return_value);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
452 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
453 tty->print_cr("[CUDA] *** Error (%d) Failed to free device memory of return value", status);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
454 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to free device memory of return value");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
455 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
456 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
457 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
458
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
459 if (TraceGPUInteraction) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
460 tty->print_cr("[CUDA] Success: Freed device memory of return value");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
461 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
462
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
463 // Destroy context
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
464 status = gpu::Ptx::_cuda_cu_ctx_destroy(_device_context);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
465 if (status != GRAAL_CUDA_SUCCESS) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
466 tty->print_cr("[CUDA] *** Error (%d) Failed to destroy context", status);
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
467 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to destroy context");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
468 return 0L;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
469 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
470
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
471 if (TraceGPUInteraction) {
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
472 tty->print_cr("[CUDA] Success: Destroy context");
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
473 }
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
474
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
475 return primitiveReturnValue;
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
476 JRT_END
220ed109bf77 initial code for calling PTX kernel code from Java with parameter marshaling and return value unmarshaling performed by a wrapper specified via manual graph construction
Doug Simon <doug.simon@oracle.com>
parents: 12653
diff changeset
477
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
478 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
479 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
480 }
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11821
diff changeset
481
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11821
diff changeset
482 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
483 address kernel, PTXKernelArguments &ptxka, JavaValue &ret) {
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
484 // grid dimensionality
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
485 unsigned int gridX = 1;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
486 unsigned int gridY = 1;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
487 unsigned int gridZ = 1;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
488
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
489 // thread dimensionality
11822
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11821
diff changeset
490 unsigned int blockX = dimX;
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11821
diff changeset
491 unsigned int blockY = dimY;
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11821
diff changeset
492 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
493
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
494 struct CUfunc_st* cu_function = (struct CUfunc_st*) kernel;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
495
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
496 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
497 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
498 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
499 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
500 };
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
501
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
502 if (kernel == NULL) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
503 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
504 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
505
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
506 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
507 tty->print_cr("[CUDA] launching kernel");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
508 }
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
509
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
510 int status = _cuda_cu_launch_kernel(cu_function,
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
511 gridX, gridY, gridZ,
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
512 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
513 0, NULL, NULL, (void **) &config);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
514 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
515 tty->print_cr("[CUDA] Failed to launch kernel");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
516 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
517 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
518
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
519 if (TraceGPUInteraction) {
11822
365d8f385fb5 PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11821
diff changeset
520 tty->print_cr("[CUDA] Success: Kernel Launch: X: %d Y: %d Z: %d", blockX, blockY, blockZ);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
521 }
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
522
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
523 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
524
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
525 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
526 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
527 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
528 }
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
529
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
530 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
531 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
532 }
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
533
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
534
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
535 // 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
536 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
537 switch (return_type) {
11821
d8659ad83fcc PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11634
diff changeset
538 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
539 {
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
540 int return_val;
12519
f020e149c1b6 PTX codegen enhancements; fixes to PTX test regressions.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 11902
diff changeset
541 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._dev_return_value, T_INT_BYTE_SIZE);
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
542 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
543 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
544 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
545 }
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
546 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
547 }
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
548 break;
11901
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
549 case T_BOOLEAN:
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
550 {
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
551 int return_val;
12519
f020e149c1b6 PTX codegen enhancements; fixes to PTX test regressions.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 11902
diff changeset
552 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._dev_return_value, T_INT_BYTE_SIZE);
11901
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
553 if (status != GRAAL_CUDA_SUCCESS) {
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
554 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value to device argument", status);
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
555 return false;
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
556 }
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
557 ret.set_jint(return_val);
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
558 }
61767ccd4600 PTX boolean return value, emitIntegerTestMove, warnings
Morris Meyer <morris.meyer@oracle.com>
parents: 11894
diff changeset
559 break;
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
560 case T_FLOAT:
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
561 {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
562 float return_val;
12519
f020e149c1b6 PTX codegen enhancements; fixes to PTX test regressions.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 11902
diff changeset
563 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._dev_return_value, T_FLOAT_BYTE_SIZE);
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
564 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
565 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value to device argument", status);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
566 return false;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
567 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
568 ret.set_jfloat(return_val);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
569 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
570 break;
11902
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
571 case T_DOUBLE:
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
572 {
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
573 double return_val;
12519
f020e149c1b6 PTX codegen enhancements; fixes to PTX test regressions.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 11902
diff changeset
574 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._dev_return_value, T_DOUBLE_BYTE_SIZE);
11902
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
575 if (status != GRAAL_CUDA_SUCCESS) {
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
576 tty->print_cr("[CUDA] *** Error (%d) Failed to copy value to device argument", status);
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
577 return false;
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
578 }
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
579 ret.set_jdouble(return_val);
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
580 }
67a1e27a8dbb PTX initial float and double
Morris Meyer <morris.meyer@oracle.com>
parents: 11901
diff changeset
581 break;
11821
d8659ad83fcc PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11634
diff changeset
582 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
583 {
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
584 long return_val;
12519
f020e149c1b6 PTX codegen enhancements; fixes to PTX test regressions.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 11902
diff changeset
585 status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, ptxka._dev_return_value, T_LONG_BYTE_SIZE);
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
586 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
587 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
588 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
589 }
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
590 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
591 }
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
592 break;
11821
d8659ad83fcc PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11634
diff changeset
593 case T_VOID:
d8659ad83fcc PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11634
diff changeset
594 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
595 default:
11821
d8659ad83fcc PTX single-threaded array store, Warp annotation
Morris Meyer <morris.meyer@oracle.com>
parents: 11634
diff changeset
596 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
597 }
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
598
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
599 // Free device memory allocated for result
12519
f020e149c1b6 PTX codegen enhancements; fixes to PTX test regressions.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 11902
diff changeset
600 status = gpu::Ptx::_cuda_cu_memfree(ptxka._dev_return_value);
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
601 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
602 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
603 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
604 }
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
605
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
606 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
607 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
608 }
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
609
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
610 // 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
611 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
612 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
613 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
614 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
615 }
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
616
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
617 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
618 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
619 }
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
620
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
621 return (status == GRAAL_CUDA_SUCCESS);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
622 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
623
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
624 #if defined(LINUX)
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
625 static const char cuda_library_name[] = "libcuda.so";
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
626 #elif defined(__APPLE__)
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
627 static char const cuda_library_name[] = "/usr/local/cuda/lib/libcuda.dylib";
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
628 #else
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
629 static char const cuda_library_name[] = "";
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
630 #endif
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
631
10882
6a2d65cb5d7d fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents: 10879
diff changeset
632 #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
633
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
634 bool gpu::Ptx::probe_linkage() {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
635 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
636 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
637 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
638 free(buffer);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
639 if (handle != NULL) {
12653
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
640 LOOKUP_CUDA_FUNCTION(cuInit, cuda_cu_init);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
641 LOOKUP_CUDA_FUNCTION(cuCtxSynchronize, cuda_cu_ctx_synchronize);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
642 LOOKUP_CUDA_FUNCTION(cuCtxSetCurrent, cuda_cu_ctx_set_current);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
643 LOOKUP_CUDA_FUNCTION(cuDeviceGetCount, cuda_cu_device_get_count);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
644 LOOKUP_CUDA_FUNCTION(cuDeviceGetName, cuda_cu_device_get_name);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
645 LOOKUP_CUDA_FUNCTION(cuDeviceGet, cuda_cu_device_get);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
646 LOOKUP_CUDA_FUNCTION(cuDeviceComputeCapability, cuda_cu_device_compute_capability);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
647 LOOKUP_CUDA_FUNCTION(cuDeviceGetAttribute, cuda_cu_device_get_attribute);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
648 LOOKUP_CUDA_FUNCTION(cuModuleGetFunction, cuda_cu_module_get_function);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
649 LOOKUP_CUDA_FUNCTION(cuModuleLoadDataEx, cuda_cu_module_load_data_ex);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
650 LOOKUP_CUDA_FUNCTION(cuLaunchKernel, cuda_cu_launch_kernel);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
651 LOOKUP_CUDA_FUNCTION(cuMemHostRegister, cuda_cu_mem_host_register);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
652 LOOKUP_CUDA_FUNCTION(cuMemHostUnregister, cuda_cu_mem_host_unregister);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
653 #if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
654 LOOKUP_CUDA_V2_FUNCTION(cuCtxCreate, cuda_cu_ctx_create);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
655 LOOKUP_CUDA_V2_FUNCTION(cuCtxDestroy, cuda_cu_ctx_destroy);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
656 LOOKUP_CUDA_V2_FUNCTION(cuMemAlloc, cuda_cu_memalloc);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
657 LOOKUP_CUDA_V2_FUNCTION(cuMemFree, cuda_cu_memfree);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
658 LOOKUP_CUDA_V2_FUNCTION(cuMemcpyHtoD, cuda_cu_memcpy_htod);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
659 LOOKUP_CUDA_V2_FUNCTION(cuMemcpyDtoH, cuda_cu_memcpy_dtoh);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
660 LOOKUP_CUDA_V2_FUNCTION(cuMemHostGetDevicePointer, cuda_cu_mem_host_get_device_pointer);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
661 #else
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
662 LOOKUP_CUDA_FUNCTION(cuCtxCreate, cuda_cu_ctx_create);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
663 LOOKUP_CUDA_FUNCTION(cuCtxDestroy, cuda_cu_ctx_destroy);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
664 LOOKUP_CUDA_FUNCTION(cuMemAlloc, cuda_cu_memalloc);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
665 LOOKUP_CUDA_FUNCTION(cuMemFree, cuda_cu_memfree);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
666 LOOKUP_CUDA_FUNCTION(cuMemcpyHtoD, cuda_cu_memcpy_htod);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
667 LOOKUP_CUDA_FUNCTION(cuMemcpyDtoH, cuda_cu_memcpy_dtoh);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
668 LOOKUP_CUDA_FUNCTION(cuMemHostGetDevicePointer, cuda_cu_mem_host_get_device_pointer);
1a7e7011a341 * PTX kernel argument buffer now has naturally aligned arguments as required by PTX JIT compiler.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12519
diff changeset
669 #endif
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
670
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
671 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
672 tty->print_cr("[CUDA] Success: library linkage");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
673 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
674 return true;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
675 } else {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
676 // Unable to dlopen libcuda
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
677 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
678 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
679 } else {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
680 tty->print_cr("Unsupported CUDA platform");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
681 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
682 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
683 tty->print_cr("Failed to find CUDA linkage");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
684 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
685 }