annotate src/gpu/ptx/vm/gpu_ptx.cpp @ 13848:b97e2515d392

removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
author Doug Simon <doug.simon@oracle.com>
date Fri, 31 Jan 2014 16:05:37 +0100
parents 4ca607fc94e0
children b3e69d1f5da0
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"
13832
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
32 #include "memory/gcLocker.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
33 #include "runtime/interfaceSupport.hpp"
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
34 #include "runtime/vframe.hpp"
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
35 #include "graal/graalEnv.hpp"
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
36 #include "graal/graalCompiler.hpp"
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
37
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
38 #define T_BYTE_SIZE 1
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
39 #define T_BOOLEAN_SIZE 4
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
40 #define T_INT_BYTE_SIZE 4
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
41 #define T_FLOAT_BYTE_SIZE 4
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
42 #define T_DOUBLE_BYTE_SIZE 8
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
43 #define T_LONG_BYTE_SIZE 8
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
44 #define T_OBJECT_BYTE_SIZE sizeof(intptr_t)
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
45 #define T_ARRAY_BYTE_SIZE sizeof(intptr_t)
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
46
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
47 // Entry to GPU native method implementation that transitions current thread to '_thread_in_vm'.
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
48 #define GPU_VMENTRY(result_type, name, signature) \
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
49 JNIEXPORT result_type JNICALL name signature { \
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
50 GRAAL_VM_ENTRY_MARK; \
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
51
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
52 // Entry to GPU native method implementation that calls a JNI function
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
53 // and hence cannot transition current thread to '_thread_in_vm'.
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
54 #define GPU_ENTRY(result_type, name, signature) \
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
55 JNIEXPORT result_type JNICALL name signature { \
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
56
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
57 #define GPU_END }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
58
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
59 #define CC (char*) /*cast a literal from (const char*)*/
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
60 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f))
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
61
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
62 #define STRING "Ljava/lang/String;"
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
63
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
64 JNINativeMethod gpu::Ptx::PTX_methods[] = {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
65 {CC"initialize", CC"()Z", FN_PTR(gpu::Ptx::initialize)},
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
66 {CC"generateKernel", CC"([B" STRING ")J", FN_PTR(gpu::Ptx::generate_kernel)},
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
67 {CC"getLaunchKernelAddress", CC"()J", FN_PTR(gpu::Ptx::get_execute_kernel_from_vm_address)},
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
68 {CC"getAvailableProcessors0", CC"()I", FN_PTR(gpu::Ptx::get_total_cores)},
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
69 };
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
70
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
71 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
72 int gpu::Ptx::_cu_device = 0;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
73
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
74 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
75 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
76 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
77 gpu::Ptx::cuda_cu_ctx_synchronize_func_t gpu::Ptx::_cuda_cu_ctx_synchronize;
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
78 gpu::Ptx::cuda_cu_ctx_get_current_func_t gpu::Ptx::_cuda_cu_ctx_get_current;
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 gpu::Ptx::cuda_cu_module_load_data_ex_func_t gpu::Ptx::_cuda_cu_module_load_data_ex;
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
88 gpu::Ptx::cuda_cu_memcpy_htod_func_t gpu::Ptx::_cuda_cu_memcpy_htod;
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
89 gpu::Ptx::cuda_cu_memcpy_dtoh_func_t gpu::Ptx::_cuda_cu_memcpy_dtoh;
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
90 gpu::Ptx::cuda_cu_memalloc_func_t gpu::Ptx::_cuda_cu_memalloc;
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
91 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
92 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
93 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
94 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
95
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
96 #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
97
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
98 #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
99 _##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
100 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
101 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
102 tty->print_cr("[CUDA] ***** Error: Failed to lookup %s", STRINGIFY(name)); \
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
103 return false; \
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
104 } \
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
105
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
106 #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
107
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
108 /*
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
109 * 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
110 */
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
111 int gpu::Ptx::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
112 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
113
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
114 switch (device_type) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
115 case 0x10: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
116 case 0x11: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
117 case 0x12: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
118 case 0x13: return 8;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
119 case 0x20: return 32;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
120 case 0x21: return 48;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
121 case 0x30: return 192;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
122 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
123 default:
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
124 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
125 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
126 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
127 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
128
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
129 bool gpu::Ptx::register_natives(JNIEnv* env) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
130 jclass klass = env->FindClass("com/oracle/graal/hotspot/ptx/PTXHotSpotBackend");
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
131 if (klass == NULL) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
132 if (TraceGPUInteraction) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
133 tty->print_cr("PTXHotSpotBackend class not found");
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
134 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
135 return false;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
136 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
137 jint status = env->RegisterNatives(klass, PTX_methods, sizeof(PTX_methods) / sizeof(JNINativeMethod));
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
138 if (status != JNI_OK) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
139 if (TraceGPUInteraction) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
140 tty->print_cr("Error registering natives for PTXHotSpotBackend: %d", status);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
141 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
142 return false;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
143 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
144 return true;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
145 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
146
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
147 GPU_ENTRY(jboolean, gpu::Ptx::initialize, (JNIEnv *env, jclass))
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
148
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
149 if (!link()) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
150 return false;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
151 }
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 /* Initialize CUDA driver API */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
154 int status = _cuda_cu_init(0);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
155 if (status != GRAAL_CUDA_SUCCESS) {
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
156 if (TraceGPUInteraction) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
157 tty->print_cr("Failed to initialize CUDA device: %d", status);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
158 }
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
159 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
160 }
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
161
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
162 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
163 tty->print_cr("CUDA driver initialization: Success");
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
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
166 /* Get the number of compute-capable device count */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
167 int device_count = 0;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
168 status = _cuda_cu_device_get_count(&device_count);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
169 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
170 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
171 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
172 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
173
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
174 if (device_count == 0) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
175 tty->print_cr("[CUDA] Found no device supporting CUDA");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
176 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
177 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
178
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
179 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
180 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
181 }
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
182
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
183 /* Get the handle to the first compute device */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
184 int device_id = 0;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
185 /* 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
186 status = _cuda_cu_device_get(&_cu_device, device_id);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
187
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
188 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
189 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
190 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
191 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
192
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
193 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
194 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
195 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
196
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
197 /* Get device attributes */
13828
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
198 int minor, major;
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
199 int unified_addressing;
13828
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
200 float version = 0.0;
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
201
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
202 /* Get the compute capability of the device found */
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
203 status = _cuda_cu_device_get_attribute(&minor, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, _cu_device);
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
204 if (status != GRAAL_CUDA_SUCCESS) {
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
205 tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device);
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
206 return false;
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
207 }
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
208 status = _cuda_cu_device_get_attribute(&major, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, _cu_device);
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
209 if (status != GRAAL_CUDA_SUCCESS) {
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
210 tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device);
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
211 return false;
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
212 }
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
213
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
214 /* Check if the device supports atleast GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION */
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
215 version = (float) major + ((float) minor)/10;
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
216
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
217 if (version < GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION) {
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
218 tty->print_cr("[CUDA] Only cuda compute capability 3.0 and later supported. Device %d supports %.1f",
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
219 _cu_device, version);
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
220 return false;
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
221 }
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
222
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
223 if (TraceGPUInteraction) {
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
224 tty->print_cr("[CUDA] Device %d supports cuda compute capability %.1f", _cu_device, version);
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
225 }
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
226
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
227 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
228
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
229 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
230 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
231 return false;
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
232 }
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
233
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
234 if (TraceGPUInteraction) {
13828
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
235 tty->print_cr("[CUDA] Device %d %s unified addressing support", _cu_device,
5c8a3c09397b Add additional device checks and compute capability checks for CUDA devices found on Linux.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13819
diff changeset
236 ((unified_addressing == 0) ? "does not have" : "has"));
11283
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
237 }
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
238
1cd1f8ff70a1 CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents: 10884
diff changeset
239
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
240 /* Get device name */
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
241 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
242 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
243
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
244 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
245 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
246 return false;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
247 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
248
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
249 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
250 tty->print_cr("[CUDA] Using %s", device_name);
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
251 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
252
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
253 gpu::initialized_gpu(device_name);
11842
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 return true;
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
256 GPU_END
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
257
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
258 GPU_ENTRY(jint, gpu::Ptx::get_total_cores, (JNIEnv *env, jobject))
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
259
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
260 int minor, major, nmp;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
261 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
262 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
263 _cu_device);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
264
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
265 if (status != GRAAL_CUDA_SUCCESS) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
266 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
267 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
268 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
269
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
270 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
271 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
272 _cu_device);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
273
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
274 if (status != GRAAL_CUDA_SUCCESS) {
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
275 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
276 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
277 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
278
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
279 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
280 GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
281 _cu_device);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
282
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
283 if (status != GRAAL_CUDA_SUCCESS) {
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
284 tty->print_cr("[CUDA] Failed to get number of MPs on device: %d", _cu_device);
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
285 return 0;
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
286 }
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
287
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
288 int total = nmp * ncores(major, minor);
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
289
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
290 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
291
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
292 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
293 GRAAL_CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
294 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
295
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
296 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
297 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
298 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
299 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
300
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
301 status = _cuda_cu_device_get_attribute(&warp_size,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
302 GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
303 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
304
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
305 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
306 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
307 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
308 }
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
309
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
310 status = _cuda_cu_device_get_attribute(&async_engines,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
311 GRAAL_CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
312 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
313
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
314 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
315 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
316 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
317 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
318
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
319 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
320 GRAAL_CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
321 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
322
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
323 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
324 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
325 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
326 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
327
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
328 status = _cuda_cu_device_get_attribute(&concurrent_kernels,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
329 GRAAL_CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS,
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
330 _cu_device);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
331
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
332 if (status != GRAAL_CUDA_SUCCESS) {
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
333 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
334 return 0;
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
335 }
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
336
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
337 if (TraceGPUInteraction) {
11894
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
338 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
339 total, async_engines, can_map_host_memory, concurrent_kernels);
c7abc8411011 Fixed BasicPTXTest and IntegerPTXTest
Morris Meyer <morris.meyer@oracle.com>
parents: 11843
diff changeset
340 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
341 }
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
342 return total;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
343 GPU_END
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
344
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
345 GPU_ENTRY(jlong, gpu::Ptx::generate_kernel, (JNIEnv *env, jclass, jbyteArray code_handle, jstring name_handle))
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
346 ResourceMark rm;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
347 jsize name_len = env->GetStringLength(name_handle);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
348 jsize code_len = env->GetArrayLength(code_handle);
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
349
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
350 char* name = NEW_RESOURCE_ARRAY(char, name_len + 1);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
351 unsigned char *code = NEW_RESOURCE_ARRAY(unsigned char, code_len + 1);
11842
8d8f63069f58 PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents: 11822
diff changeset
352
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
353 code[code_len] = 0;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
354 name[name_len] = 0;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
355
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
356 env->GetByteArrayRegion(code_handle, 0, code_len, (jbyte*) code);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
357 env->GetStringUTFRegion(name_handle, 0, name_len, name);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
358
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
359 struct CUmod_st * cu_module;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
360 // Use three JIT compiler options
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
361 const unsigned int jit_num_options = 3;
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
362 int *jit_options = NEW_RESOURCE_ARRAY(int, jit_num_options);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
363 void **jit_option_values = NEW_RESOURCE_ARRAY(void *, jit_num_options);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
364
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
365 // Set up PTX JIT compiler options
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
366 // 1. set size of compilation log buffer
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
367 int jit_log_buffer_size = 1024;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
368 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
369 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
370
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
371 // 2. set pointer to compilation log buffer
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
372 char *jit_log_buffer = NEW_RESOURCE_ARRAY(char, jit_log_buffer_size);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
373 jit_options[1] = GRAAL_CU_JIT_INFO_LOG_BUFFER;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
374 jit_option_values[1] = jit_log_buffer;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
375
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
376 // 3. set pointer to set the maximum number of registers (32) for the kernel
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
377 int jit_register_count = 32;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
378 jit_options[2] = GRAAL_CU_JIT_MAX_REGISTERS;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
379 jit_option_values[2] = (void *)(size_t)jit_register_count;
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
380
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
381 // 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
382 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
383
49bb1bc983c6 Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents: 11284
diff changeset
384 if (status != GRAAL_CUDA_SUCCESS) {
11634
bff2b88444f5 Start of PTX array passing
Morris Meyer <morris.meyer@oracle.com>
parents: 11606
diff changeset
385 tty->print_cr("[CUDA] Failed to create CUDA context for device(%d): %d", _cu_device, status);
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
386 return 0L;
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
387 }
49bb1bc983c6 Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents: 11284
diff changeset
388 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
389 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
390 }
49bb1bc983c6 Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents: 11284
diff changeset
391
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
392 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
393
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
394 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
395 tty->print_cr("[CUDA] Failed to set current context for device: %d", _cu_device);
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
396 return 0L;
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
397 }
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
398 if (TraceGPUInteraction) {
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
399 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
400 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
401 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
402 }
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
403
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
404 /* 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
405 status = _cuda_cu_module_load_data_ex(&cu_module, (void*) code, jit_num_options,
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
406 jit_options, (void **)jit_option_values);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
407 if (status != GRAAL_CUDA_SUCCESS) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
408 if (status == GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
409 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
410 }
11527
c99e65785936 Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents: 11485
diff changeset
411 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
412 status, name);
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
413 return 0L;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
414 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
415
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
416 if (TraceGPUInteraction) {
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
417 tty->print_cr("[CUDA] Loaded data for PTX Kernel");
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
418 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
419
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
420 struct CUfunc_st* cu_function;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
421 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
422
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
423 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
424 tty->print_cr("[CUDA] *** Error: Failed to get function %s", name);
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
425 return 0L;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
426 }
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
427
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
428 if (TraceGPUInteraction) {
13683
de839ec35cc7 schedule lambda method compilation and execution on GPU (PTX) when possible; fix a couple of bugs.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 13655
diff changeset
429 tty->print_cr("[CUDA] Got function handle for %s kernel address %p", name, cu_function);
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
430 }
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
431 return (jlong) cu_function;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
432 GPU_END
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
433
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
434 // A PtxCall is used to manage executing a GPU kernel. In addition to launching
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
435 // the kernel, this class releases resources allocated for the execution.
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
436 class PtxCall: StackObj {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
437 private:
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
438 JavaThread* _thread; // the thread on which this call is made
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
439 address _buffer; // buffer containing parameters and _return_value
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
440 int _buffer_size; // size (in bytes) of _buffer
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
441 oop* _pinned; // objects that have been pinned with cuMemHostRegister
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
442 int _pinned_length; // length of _pinned
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
443 gpu::Ptx::CUdeviceptr _ret_value; // pointer to slot in GPU memory holding the return value
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
444 int _ret_type_size; // size of the return type value
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
445 bool _ret_is_object; // specifies if the return type is Object
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
446 bool _gc_locked; // denotes when execution has locked GC
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
447
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
448 bool check(int status, const char *action) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
449 if (status != GRAAL_CUDA_SUCCESS) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
450 Thread* THREAD = _thread;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
451 char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, O_BUFLEN + 1);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
452 jio_snprintf(message, O_BUFLEN, "[CUDA] *** Error (status=%d): %s", status, action);
13833
fe99bfb55626 disable printing of CUDA errors unless TraceGPUInteraction is enabled
Doug Simon <doug.simon@oracle.com>
parents: 13832
diff changeset
453 if (TraceGPUInteraction) {
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
454 tty->print_cr(message);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
455 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
456 if (!HAS_PENDING_EXCEPTION) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
457 SharedRuntime::throw_and_post_jvmti_exception(_thread, vmSymbols::java_lang_RuntimeException(), message);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
458 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
459 return false;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
460 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
461 if (TraceGPUInteraction) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
462 tty->print_cr("[CUDA] Success: %s", action);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
463 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
464 return true;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
465 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
466
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
467 public:
13832
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
468 PtxCall(JavaThread* thread, address buffer, int buffer_size, oop* pinned, int encodedReturnTypeSize) : _thread(thread), _gc_locked(false),
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
469 _buffer(buffer), _buffer_size(buffer_size), _pinned(pinned), _pinned_length(0), _ret_value(0), _ret_is_object(encodedReturnTypeSize < 0) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
470 _ret_type_size = _ret_is_object ? -encodedReturnTypeSize : encodedReturnTypeSize;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
471 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
472
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
473 bool is_object_return() { return _ret_is_object; }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
474
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
475 void alloc_return_value() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
476 if (_ret_type_size != 0) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
477 if (check(gpu::Ptx::_cuda_cu_memalloc(&_ret_value, _ret_type_size), "Allocate device memory for return value")) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
478 gpu::Ptx::CUdeviceptr* retValuePtr = (gpu::Ptx::CUdeviceptr*) ((_buffer + _buffer_size) - sizeof(_ret_value));
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
479 *retValuePtr = _ret_value;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
480 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
481 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
482 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
483
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
484 void pin_objects(int count, int* objectOffsets) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
485 if (count == 0) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
486 return;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
487 }
13832
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
488 // Once we start pinning objects, no GC must occur
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
489 // until the kernel has completed. This is a big
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
490 // hammer for ensuring we can safely pass objects
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
491 // to the GPU.
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
492 GC_locker::lock_critical(_thread);
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
493 _gc_locked = true;
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
494 if (TraceGPUInteraction) {
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
495 tty->print_cr("[CUDA] Locked GC");
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
496 }
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
497
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
498 for (int i = 0; i < count; i++) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
499 int offset = objectOffsets[i];
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
500 oop* argPtr = (oop*) (_buffer + offset);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
501 oop obj = *argPtr;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
502 if (obj != NULL) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
503 // Size (in bytes) of object
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
504 int objSize = obj->size() * HeapWordSize;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
505 //tty->print_cr("Pinning object %d at offset %d: %p", i, offset, obj);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
506 if (!check(gpu::Ptx::_cuda_cu_mem_host_register(obj, objSize, GRAAL_CU_MEMHOSTREGISTER_DEVICEMAP), "Pin object")) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
507 return;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
508 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
509
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
510 // Record original oop so that its memory can be unpinned
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
511 _pinned[_pinned_length++] = obj;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
512
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
513 // Replace host pointer to object with device pointer
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
514 // to object in kernel parameters buffer
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
515 if (!check(gpu::Ptx::_cuda_cu_mem_host_get_device_pointer((gpu::Ptx::CUdeviceptr*) argPtr, obj, 0), "Get device pointer for pinned object")) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
516 return;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
517 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
518 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
519 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
520 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
521
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
522 void launch(address kernel, jint dimX, jint dimY, jint dimZ) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
523 // grid dimensionality
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
524 unsigned int gridX = 1;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
525 unsigned int gridY = 1;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
526 unsigned int gridZ = 1;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
527 void * config[] = {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
528 GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER, (char*) (address) _buffer,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
529 GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE, &_buffer_size,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
530 GRAAL_CU_LAUNCH_PARAM_END
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
531 };
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
532 if (check(gpu::Ptx::_cuda_cu_launch_kernel((struct CUfunc_st*) (address) kernel,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
533 gridX, gridY, gridZ,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
534 dimX, dimY, dimZ,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
535 0, NULL, NULL, (void**) &config), "Launch kernel")) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
536 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
537 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
538
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
539 void synchronize() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
540 check(gpu::Ptx::_cuda_cu_ctx_synchronize(), "Synchronize kernel");
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
541 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
542
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
543 void unpin_objects() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
544 while (_pinned_length > 0) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
545 oop obj = _pinned[--_pinned_length];
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
546 assert(obj != NULL, "npe");
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
547 //tty->print_cr("Unpinning object %d: %p", _pinned_length, obj);
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
548 if (!check(gpu::Ptx::_cuda_cu_mem_host_unregister(obj), "Unpin object")) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
549 return;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
550 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
551 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
552 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
553
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
554 oop get_object_return_value() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
555 oop return_val;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
556 check(gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, _ret_value, T_OBJECT_BYTE_SIZE), "Copy return value from device");
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
557 return return_val;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
558 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
559
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
560 jlong get_primitive_return_value() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
561 jlong return_val;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
562 check(gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, _ret_value, _ret_type_size), "Copy return value from device");
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
563 return return_val;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
564 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
565
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
566 void free_return_value() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
567 if (_ret_value != 0) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
568 check(gpu::Ptx::_cuda_cu_memfree(_ret_value), "Free device memory");
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
569 _ret_value = 0;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
570 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
571 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
572
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
573 void destroy_context() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
574 if (gpu::Ptx::_device_context != NULL) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
575 check(gpu::Ptx::_cuda_cu_ctx_destroy(gpu::Ptx::_device_context), "Destroy context");
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
576 gpu::Ptx::_device_context = NULL;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
577 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
578 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
579
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
580 ~PtxCall() {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
581 unpin_objects();
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
582 free_return_value();
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
583 destroy_context();
13832
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
584 if (_gc_locked) {
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
585 GC_locker::unlock_critical(_thread);
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
586 if (TraceGPUInteraction) {
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
587 tty->print_cr("[CUDA] Unlocked GC");
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
588 }
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
589 _gc_locked = false;
13832
ab370d74a8eb implemented GC locking for duration of a PTX kernel call
Doug Simon <doug.simon@oracle.com>
parents: 13819
diff changeset
590 }
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
591 }
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
592 };
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
593
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
594 // Prints values in the kernel arguments buffer
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
595 class KernelArgumentsPrinter: public SignatureIterator {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
596 Method* _method;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
597 address _buffer;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
598 size_t _bufferOffset;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
599 outputStream* _st;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
600
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
601 private:
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
602
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
603 // Get next java argument
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
604 oop next_arg(BasicType expectedType);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
605
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
606 public:
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
607 KernelArgumentsPrinter(Method* method, address buffer, outputStream* st) : SignatureIterator(method->signature()),
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
608 _method(method), _buffer(buffer), _bufferOffset(0), _st(st) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
609 if (!method->is_static()) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
610 print_oop();
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
611 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
612 iterate();
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
613 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
614
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
615 address next(size_t dataSz) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
616 if (is_return_type()) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
617 return _buffer;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
618 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
619 if (_bufferOffset != 0) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
620 _st->print(", ");
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
621 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
622 _bufferOffset = align_size_up_(_bufferOffset, dataSz);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
623 address result = _buffer + _bufferOffset;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
624 _bufferOffset += dataSz;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
625 return result;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
626 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
627
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
628 void print_oop() {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
629 oop obj = *((oop*) next(sizeof(oop)));
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
630 if (obj != NULL) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
631 char type[256];
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
632 obj->klass()->name()->as_C_string(type, 256);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
633 _st->print("oop "PTR_FORMAT" (%s)", obj, type);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
634 } else {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
635 _st->print("oop null");
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
636 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
637 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
638
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
639 bool skip() {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
640 return is_return_type();
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
641 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
642
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
643 void do_bool () { if (!skip()) _st->print("bool %d", *((jboolean*) next(sizeof(jboolean)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
644 void do_char () { if (!skip()) _st->print("char %c", *((jchar*) next(sizeof(jchar)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
645 void do_float () { if (!skip()) _st->print("float %g", *((jfloat*) next(sizeof(jfloat)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
646 void do_double() { if (!skip()) _st->print("double %g", *((jdouble*) next(sizeof(jdouble)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
647 void do_byte () { if (!skip()) _st->print("byte %d", *((jbyte*) next(sizeof(jbyte)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
648 void do_short () { if (!skip()) _st->print("short %d", *((jshort*) next(sizeof(jshort)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
649 void do_int () { if (!skip()) _st->print("int %d", *((jint*) next(sizeof(jint)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
650 void do_long () { if (!skip()) _st->print("long "JLONG_FORMAT, *((jlong*) next(sizeof(jlong)))); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
651 void do_void () { }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
652 void do_object(int begin, int end) { if (!skip()) print_oop(); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
653 void do_array (int begin, int end) { if (!skip()) print_oop(); }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
654 };
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
655
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
656 static void printKernelArguments(JavaThread* thread, address buffer) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
657 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
658 Method* m = vfst.method();
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
659 if (m != NULL) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
660 stringStream st(O_BUFLEN);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
661 st.print("[CUDA] Call: %s.%s(", m->method_holder()->name()->as_C_string(), m->name()->as_C_string());
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
662 KernelArgumentsPrinter kap(m, buffer, &st);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
663 tty->print_cr("%s)", st.as_string());
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
664 return;
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
665 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
666 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
667 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
668
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
669 GPU_VMENTRY(jlong, gpu::Ptx::get_execute_kernel_from_vm_address, (JNIEnv *env, jclass))
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
670 return (jlong) gpu::Ptx::execute_kernel_from_vm;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
671 GPU_END
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
672
13648
27acedac70b7 added support for @ParallelOver annotation in PTX kernel call wrapper
Doug Simon <doug.simon@oracle.com>
parents: 13624
diff changeset
673 JRT_ENTRY(jlong, gpu::Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ,
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
674 jlong buffer,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
675 jint bufferSize,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
676 jint objectParametersCount,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
677 jlong objectParametersOffsets,
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
678 jlong pinnedObjects,
13648
27acedac70b7 added support for @ParallelOver annotation in PTX kernel call wrapper
Doug Simon <doug.simon@oracle.com>
parents: 13624
diff changeset
679 int encodedReturnTypeSize))
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
680 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
681 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
682 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
683 }
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
684
13848
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
685 if (TraceGPUInteraction) {
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
686 printKernelArguments(thread, (address) buffer);
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
687 }
b97e2515d392 removed PTXKernelArguments; added mechanism for printing incoming kernel arguments
Doug Simon <doug.simon@oracle.com>
parents: 13834
diff changeset
688
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
689 PtxCall call(thread, (address) buffer, bufferSize, (oop*) (address) pinnedObjects, encodedReturnTypeSize);
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
690
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
691 #define TRY(action) do { \
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
692 action; \
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
693 if (HAS_PENDING_EXCEPTION) return 0L; \
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
694 } while (0)
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
695
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
696 TRY(call.alloc_return_value());
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
697
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
698 TRY(call.pin_objects(objectParametersCount, (int*) (address) objectParametersOffsets));
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
699
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
700 TRY(call.launch((address) kernel, dimX, dimY, dimZ));
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
701
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
702 TRY(call.synchronize());
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
703
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
704 if (call.is_object_return()) {
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
705 oop return_val;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
706 TRY(return_val = call.get_object_return_value());
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
707 thread->set_vm_result(return_val);
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
708 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
709 }
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
710
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
711 jlong return_val;
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
712 TRY(return_val = call.get_primitive_return_value());
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
713 return return_val;
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
714
13753
80cd5c3b8827 partially fixed passing of object parameters to PTX kernels; use a C++ object for managing resource allocation and cleanup around a PTX kernel execution
Doug Simon <doug.simon@oracle.com>
parents: 13683
diff changeset
715 #undef TRY
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
716
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
717 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
718
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
719 #if defined(LINUX)
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
720 static const char cuda_library_name[] = "libcuda.so";
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
721 #elif defined(__APPLE__)
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
722 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
723 #else
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
724 static char const cuda_library_name[] = "";
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
725 #endif
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
726
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
727 bool gpu::Ptx::link() {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
728 if (cuda_library_name == NULL) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
729 if (TraceGPUInteraction) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
730 tty->print_cr("Failed to find CUDA linkage");
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
731 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
732 return false;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
733 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
734 char ebuf[O_BUFLEN];
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
735 void *handle = os::dll_load(cuda_library_name, ebuf, O_BUFLEN);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
736 if (handle == NULL) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
737 if (TraceGPUInteraction) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
738 tty->print_cr("Unsupported CUDA platform: %s", ebuf);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
739 }
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
740 return false;
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
741 }
10882
6a2d65cb5d7d fix: gpu_ptx.cpp did not compile on windows
Christian Wirth <christian.wirth@oracle.com>
parents: 10879
diff changeset
742
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
743 LOOKUP_CUDA_FUNCTION(cuInit, cuda_cu_init);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
744 LOOKUP_CUDA_FUNCTION(cuCtxSynchronize, cuda_cu_ctx_synchronize);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
745 LOOKUP_CUDA_FUNCTION(cuCtxGetCurrent, cuda_cu_ctx_get_current);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
746 LOOKUP_CUDA_FUNCTION(cuCtxSetCurrent, cuda_cu_ctx_set_current);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
747 LOOKUP_CUDA_FUNCTION(cuDeviceGetCount, cuda_cu_device_get_count);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
748 LOOKUP_CUDA_FUNCTION(cuDeviceGetName, cuda_cu_device_get_name);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
749 LOOKUP_CUDA_FUNCTION(cuDeviceGet, cuda_cu_device_get);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
750 LOOKUP_CUDA_FUNCTION(cuDeviceComputeCapability, cuda_cu_device_compute_capability);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
751 LOOKUP_CUDA_FUNCTION(cuDeviceGetAttribute, cuda_cu_device_get_attribute);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
752 LOOKUP_CUDA_FUNCTION(cuModuleGetFunction, cuda_cu_module_get_function);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
753 LOOKUP_CUDA_FUNCTION(cuModuleLoadDataEx, cuda_cu_module_load_data_ex);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
754 LOOKUP_CUDA_FUNCTION(cuLaunchKernel, cuda_cu_launch_kernel);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
755 LOOKUP_CUDA_FUNCTION(cuMemHostRegister, cuda_cu_mem_host_register);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
756 LOOKUP_CUDA_FUNCTION(cuMemHostUnregister, cuda_cu_mem_host_unregister);
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
757 #if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
758 LOOKUP_CUDA_V2_FUNCTION(cuCtxCreate, cuda_cu_ctx_create);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
759 LOOKUP_CUDA_V2_FUNCTION(cuCtxDestroy, cuda_cu_ctx_destroy);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
760 LOOKUP_CUDA_V2_FUNCTION(cuMemAlloc, cuda_cu_memalloc);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
761 LOOKUP_CUDA_V2_FUNCTION(cuMemFree, cuda_cu_memfree);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
762 LOOKUP_CUDA_V2_FUNCTION(cuMemcpyHtoD, cuda_cu_memcpy_htod);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
763 LOOKUP_CUDA_V2_FUNCTION(cuMemcpyDtoH, cuda_cu_memcpy_dtoh);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
764 LOOKUP_CUDA_V2_FUNCTION(cuMemHostGetDevicePointer, cuda_cu_mem_host_get_device_pointer);
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
765 #else
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
766 LOOKUP_CUDA_FUNCTION(cuCtxCreate, cuda_cu_ctx_create);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
767 LOOKUP_CUDA_FUNCTION(cuCtxDestroy, cuda_cu_ctx_destroy);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
768 LOOKUP_CUDA_FUNCTION(cuMemAlloc, cuda_cu_memalloc);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
769 LOOKUP_CUDA_FUNCTION(cuMemFree, cuda_cu_memfree);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
770 LOOKUP_CUDA_FUNCTION(cuMemcpyHtoD, cuda_cu_memcpy_htod);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
771 LOOKUP_CUDA_FUNCTION(cuMemcpyDtoH, cuda_cu_memcpy_dtoh);
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
772 LOOKUP_CUDA_FUNCTION(cuMemHostGetDevicePointer, cuda_cu_mem_host_get_device_pointer);
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
773 #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
774
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
775 if (TraceGPUInteraction) {
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
776 tty->print_cr("[CUDA] Success: library linkage");
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
777 }
13819
49db2c1e3bee added support for co-existing GPU backends (JBS:GRAAL-1)
Doug Simon <doug.simon@oracle.com>
parents: 13753
diff changeset
778 return true;
10879
d55f24eac4b1 PTX support for Linux
Morris Meyer <morris.meyer@oracle.com>
parents:
diff changeset
779 }