Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/cuda/CudaFunction.cpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2013, 2016 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#include "CudaCommon.hpp"
24
#include "java/com_ibm_cuda_CudaFunction.h"
25
26
#ifdef OMR_OPT_CUDA
27
28
/**
29
* Query a function attribute.
30
*
31
* Class: com.ibm.cuda.CudaFunction
32
* Method: getAttribute
33
* Signature: (IJI)I
34
*
35
* @param[in] env the JNI interface pointer
36
* @param[in] (unused) the class pointer
37
* @param[in] deviceId the device identifier
38
* @param[in] function the function pointer
39
* @param[in] attribute the attribute to query
40
* @return the value of the requested attribute
41
*/
42
jint JNICALL
43
Java_com_ibm_cuda_CudaFunction_getAttribute
44
(JNIEnv * env, jclass, jint deviceId, jlong function, jint attribute)
45
{
46
J9VMThread * thread = (J9VMThread *)env;
47
48
Trc_cuda_functionGetAttribute_entry(thread, deviceId, (J9CudaFunction)function, attribute);
49
50
PORT_ACCESS_FROM_ENV(env);
51
52
int32_t value = 0;
53
int32_t error = j9cuda_funcGetAttribute(
54
(uint32_t)deviceId,
55
(J9CudaFunction)function,
56
(J9CudaFunctionAttribute)attribute,
57
&value);
58
59
if (0 != error) {
60
throwCudaException(env, error);
61
}
62
63
Trc_cuda_functionGetAttribute_exit(thread, value);
64
65
return (jint)value;
66
}
67
68
/**
69
* Launch a grid of threads executing a kernel function.
70
*
71
* Class: com.ibm.cuda.CudaFunction
72
* Method: launch
73
* Signature: (IJIIIIIIIJ[J)V
74
*
75
* @param[in] env the JNI interface pointer
76
* @param[in] (unused) the class pointer
77
* @param[in] deviceId the device identifier
78
* @param[in] function the function pointer
79
* @param[in] grdDimX the grid size in the X dimension
80
* @param[in] grdDimY the grid size in the Y dimension
81
* @param[in] grdDimZ the grid size in the Z dimension
82
* @param[in] blkDimX the block size in the X dimension
83
* @param[in] blkDimY the block size in the Y dimension
84
* @param[in] blkDimZ the block size in the Z dimension
85
* @param[in] sharedMemBytes the number of bytes of dynamic shared memory required
86
* @param[in] stream the stream, or null for the default stream
87
* @param[in] argValues the array of argument values
88
*/
89
void JNICALL
90
Java_com_ibm_cuda_CudaFunction_launch
91
(JNIEnv * env, jclass,
92
jint deviceId, jlong function,
93
jint grdDimX, jint grdDimY, jint grdDimZ,
94
jint blkDimX, jint blkDimY, jint blkDimZ,
95
jint sharedMemBytes, jlong stream,
96
jlongArray argValues)
97
{
98
J9VMThread * thread = (J9VMThread *)env;
99
100
Trc_cuda_functionLaunch_entry(
101
thread,
102
deviceId,
103
(J9CudaFunction)function,
104
grdDimX, grdDimY, grdDimZ,
105
blkDimX, blkDimY, blkDimZ,
106
sharedMemBytes,
107
(J9CudaStream)stream,
108
argValues);
109
110
int32_t error = J9CUDA_ERROR_OPERATING_SYSTEM;
111
jlong * values = env->GetLongArrayElements(argValues, NULL);
112
113
if (NULL == values) {
114
Trc_cuda_functionLaunch_getFail(thread);
115
} else {
116
PORT_ACCESS_FROM_ENV(env);
117
118
jsize argCount = env->GetArrayLength(argValues);
119
void ** args = (void **)J9CUDA_ALLOCATE_MEMORY(argCount * sizeof(void *));
120
121
if (NULL == args) {
122
Trc_cuda_functionLaunch_allocFail(thread);
123
error = J9CUDA_ERROR_MEMORY_ALLOCATION;
124
} else {
125
// gather addresses of parameters
126
for (jsize i = 0; i < argCount; ++i) {
127
args[i] = &values[i];
128
}
129
130
error = j9cuda_launchKernel(
131
(uint32_t)deviceId,
132
(J9CudaFunction)function,
133
(uint32_t)grdDimX, (uint32_t)grdDimY, (uint32_t)grdDimZ,
134
(uint32_t)blkDimX, (uint32_t)blkDimY, (uint32_t)blkDimZ,
135
(uint32_t)sharedMemBytes,
136
(J9CudaStream)stream,
137
(void **)args);
138
139
J9CUDA_FREE_MEMORY(args);
140
}
141
142
env->ReleaseLongArrayElements(argValues, values, JNI_ABORT);
143
}
144
145
if (0 != error) {
146
throwCudaException(env, error);
147
}
148
149
Trc_cuda_functionLaunch_exit(thread);
150
}
151
152
/**
153
* Set the cache configuration of a kernel function.
154
*
155
* Class: com.ibm.cuda.CudaFunction
156
* Method: setCacheConfig
157
* Signature: (IJI)V
158
*
159
* @param[in] env the JNI interface pointer
160
* @param[in] (unused) the class pointer
161
* @param[in] deviceId the device identifier
162
* @param[in] function the function pointer
163
* @param[in] config the requested cache configuration
164
*/
165
void JNICALL
166
Java_com_ibm_cuda_CudaFunction_setCacheConfig
167
(JNIEnv * env, jclass, jint deviceId, jlong function, jint config)
168
{
169
J9VMThread * thread = (J9VMThread *)env;
170
171
Trc_cuda_functionSetCacheConfig_entry(thread, deviceId, (J9CudaFunction)function, config);
172
173
PORT_ACCESS_FROM_ENV(env);
174
175
int32_t error = j9cuda_funcSetCacheConfig(
176
(uint32_t)deviceId,
177
(J9CudaFunction)function,
178
(J9CudaCacheConfig)config);
179
180
if (0 != error) {
181
throwCudaException(env, error);
182
}
183
184
Trc_cuda_functionSetCacheConfig_exit(thread);
185
}
186
187
/**
188
* Set the shared memory configuration of a kernel function.
189
*
190
* Class: com.ibm.cuda.CudaFunction
191
* Method: setSharedMemConfig
192
* Signature: (IJI)V
193
*
194
* @param[in] env the JNI interface pointer
195
* @param[in] (unused) the class pointer
196
* @param[in] deviceId the device identifier
197
* @param[in] function the function pointer
198
* @param[in] config the requested shared memory configuration
199
*/
200
void JNICALL
201
Java_com_ibm_cuda_CudaFunction_setSharedMemConfig
202
(JNIEnv * env, jclass, jint deviceId, jlong function, jint config)
203
{
204
J9VMThread * thread = (J9VMThread *)env;
205
206
Trc_cuda_functionSetSharedMemConfig_entry(thread, deviceId, (J9CudaFunction)function, config);
207
208
PORT_ACCESS_FROM_ENV(env);
209
210
int32_t error = j9cuda_funcSetSharedMemConfig(
211
(uint32_t)deviceId,
212
(J9CudaFunction)function,
213
(J9CudaSharedMemConfig)config);
214
215
if (0 != error) {
216
throwCudaException(env, error);
217
}
218
219
Trc_cuda_functionSetSharedMemConfig_exit(thread);
220
}
221
222
#endif /* OMR_OPT_CUDA */
223
224