Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/cuda/CudaStream.cpp
5985 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_CudaStream.h"
25
26
/**
27
* Create a stream with the default priority and flags.
28
*
29
* Class: com.ibm.cuda.CudaStream
30
* Method: create
31
* Signature: (I)J
32
*
33
* @param[in] env the JNI interface pointer
34
* @param[in] (unused) the class pointer
35
* @param[in] deviceId the device identifier
36
* @return a new stream
37
*/
38
jlong JNICALL
39
Java_com_ibm_cuda_CudaStream_create
40
(JNIEnv * env, jclass, jint deviceId)
41
{
42
J9VMThread * thread = (J9VMThread *)env;
43
44
Trc_cuda_streamCreate_entry(thread, deviceId);
45
46
J9CudaStream stream = NULL;
47
int32_t error = J9CUDA_ERROR_NO_DEVICE;
48
#ifdef OMR_OPT_CUDA
49
PORT_ACCESS_FROM_ENV(env);
50
error = j9cuda_streamCreate((uint32_t)deviceId, &stream);
51
#endif /* OMR_OPT_CUDA */
52
53
if (0 != error) {
54
throwCudaException(env, error);
55
}
56
57
Trc_cuda_streamCreate_exit(thread, stream);
58
59
return (jlong)stream;
60
}
61
62
/**
63
* Create a stream with the specified flags and priority.
64
*
65
* Class: com.ibm.cuda.CudaStream
66
* Method: createWithPriority
67
* Signature: (III)J
68
*
69
* @param[in] env the JNI interface pointer
70
* @param[in] (unused) the class pointer
71
* @param[in] deviceId the device identifier
72
* @param[in] flags the stream creation flags
73
* @param[in] priority the requested stream priority
74
* @return a new stream
75
*/
76
jlong JNICALL
77
Java_com_ibm_cuda_CudaStream_createWithPriority
78
(JNIEnv * env, jclass, jint deviceId, jint flags, jint priority)
79
{
80
J9VMThread * thread = (J9VMThread *)env;
81
82
Trc_cuda_streamCreateWithPriority_entry(thread, deviceId, flags, priority);
83
84
J9CudaStream stream = NULL;
85
int32_t error = J9CUDA_ERROR_NO_DEVICE;
86
#ifdef OMR_OPT_CUDA
87
PORT_ACCESS_FROM_ENV(env);
88
error = j9cuda_streamCreateWithPriority(
89
(uint32_t)deviceId,
90
priority,
91
(uint32_t)flags,
92
&stream);
93
#endif /* OMR_OPT_CUDA */
94
95
if (0 != error) {
96
throwCudaException(env, error);
97
}
98
99
Trc_cuda_streamCreateWithPriority_exit(thread, stream);
100
101
return (jlong)stream;
102
}
103
104
#ifdef OMR_OPT_CUDA
105
106
/**
107
* Destroy a stream.
108
*
109
* Class: com.ibm.cuda.CudaStream
110
* Method: destroy
111
* Signature: (IJ)V
112
*
113
* @param[in] env the JNI interface pointer
114
* @param[in] (unused) the class pointer
115
* @param[in] deviceId the device identifier
116
* @param[in] stream the stream to be destroyed
117
*/
118
void JNICALL
119
Java_com_ibm_cuda_CudaStream_destroy
120
(JNIEnv * env, jclass, jint deviceId, jlong stream)
121
{
122
J9VMThread * thread = (J9VMThread *)env;
123
124
Trc_cuda_streamDestroy_entry(thread, deviceId, (J9CudaStream)stream);
125
126
PORT_ACCESS_FROM_ENV(env);
127
128
int32_t error = j9cuda_streamDestroy((uint32_t)deviceId, (J9CudaStream)stream);
129
130
if (0 != error) {
131
throwCudaException(env, error);
132
}
133
134
Trc_cuda_streamDestroy_exit(thread, error);
135
}
136
137
/**
138
* Query the flags of a stream.
139
*
140
* Class: com.ibm.cuda.CudaStream
141
* Method: getFlags
142
* Signature: (IJ)I
143
*
144
* @param[in] env the JNI interface pointer
145
* @param[in] (unused) the class pointer
146
* @param[in] deviceId the device identifier
147
* @param[in] stream the stream
148
* @return the flags of the stream
149
*/
150
jint JNICALL
151
Java_com_ibm_cuda_CudaStream_getFlags
152
(JNIEnv * env, jclass, jint deviceId, jlong stream)
153
{
154
J9VMThread * thread = (J9VMThread *)env;
155
156
Trc_cuda_streamGetFlags_entry(thread, deviceId, (J9CudaStream)stream);
157
158
PORT_ACCESS_FROM_ENV(env);
159
160
uint32_t flags = 0;
161
int32_t error = j9cuda_streamGetFlags((uint32_t)deviceId, (J9CudaStream)stream, &flags);
162
163
if (0 != error) {
164
throwCudaException(env, error);
165
}
166
167
Trc_cuda_streamGetFlags_exit(thread, error, flags);
168
169
return (jint)flags;
170
}
171
172
/**
173
* Query the priority of a stream.
174
*
175
* Class: com.ibm.cuda.CudaStream
176
* Method: getPriority
177
* Signature: (IJ)I
178
*
179
* @param[in] env the JNI interface pointer
180
* @param[in] (unused) the class pointer
181
* @param[in] deviceId the device identifier
182
* @param[in] stream the stream
183
* @return the priority of the stream
184
*/
185
jint JNICALL
186
Java_com_ibm_cuda_CudaStream_getPriority
187
(JNIEnv * env, jclass, jint deviceId, jlong stream)
188
{
189
J9VMThread * thread = (J9VMThread *)env;
190
191
Trc_cuda_streamGetPriority_entry(thread, deviceId, (J9CudaStream)stream);
192
193
PORT_ACCESS_FROM_ENV(env);
194
195
int32_t priority = 0;
196
int32_t error = j9cuda_streamGetPriority((uint32_t)deviceId, (J9CudaStream)stream, &priority);
197
198
if (0 != error) {
199
throwCudaException(env, error);
200
}
201
202
Trc_cuda_streamGetPriority_exit(thread, error, priority);
203
204
return priority;
205
}
206
207
/**
208
* Query the completion status of a stream.
209
*
210
* Class: com.ibm.cuda.CudaStream
211
* Method: query
212
* Signature: (IJ)I
213
*
214
* @param[in] env the JNI interface pointer
215
* @param[in] (unused) the class pointer
216
* @param[in] deviceId the device identifier
217
* @param[in] stream the stream
218
* @return 0 if the stream is complete; else cudaErrorNotReady or another error
219
*/
220
jint JNICALL
221
Java_com_ibm_cuda_CudaStream_query
222
(JNIEnv * env, jclass, jint deviceId, jlong stream)
223
{
224
J9VMThread * thread = (J9VMThread *)env;
225
226
Trc_cuda_streamQuery_entry(thread, deviceId, (J9CudaStream)stream);
227
228
PORT_ACCESS_FROM_ENV(env);
229
230
int32_t error = j9cuda_streamQuery((uint32_t)deviceId, (J9CudaStream)stream);
231
232
Trc_cuda_streamQuery_exit(thread, error);
233
234
return error;
235
}
236
237
/**
238
* Synchronize with a stream.
239
*
240
* Class: com.ibm.cuda.CudaStream
241
* Method: synchronize
242
* Signature: (IJ)V
243
*
244
* @param[in] env the JNI interface pointer
245
* @param[in] (unused) the class pointer
246
* @param[in] deviceId the device identifier
247
* @param[in] stream the stream
248
*/
249
void JNICALL
250
Java_com_ibm_cuda_CudaStream_synchronize
251
(JNIEnv * env, jclass, jint deviceId, jlong stream)
252
{
253
J9VMThread * thread = (J9VMThread *)env;
254
255
Trc_cuda_streamSynchronize_entry(thread, deviceId, (J9CudaStream)stream);
256
257
PORT_ACCESS_FROM_ENV(env);
258
259
int32_t error = j9cuda_streamSynchronize((uint32_t)deviceId, (J9CudaStream)stream);
260
261
if (0 != error) {
262
throwCudaException(env, error);
263
}
264
265
Trc_cuda_streamSynchronize_exit(thread, error);
266
}
267
268
/**
269
* Cause a stream to wait for an event.
270
*
271
* Class: com.ibm.cuda.CudaStream
272
* Method: waitFor
273
* Signature: (IJJ)V
274
*
275
* @param[in] env the JNI interface pointer
276
* @param[in] (unused) the class pointer
277
* @param[in] deviceId the device identifier
278
* @param[in] stream the stream
279
* @param[in] event the event to wait for
280
*/
281
void JNICALL
282
Java_com_ibm_cuda_CudaStream_waitFor
283
(JNIEnv * env, jclass, jint deviceId, jlong stream, jlong event)
284
{
285
J9VMThread * thread = (J9VMThread *)env;
286
287
Trc_cuda_streamWaitFor_entry(thread, deviceId, (J9CudaStream)stream, (J9CudaEvent)event);
288
289
PORT_ACCESS_FROM_ENV(env);
290
291
int32_t error = j9cuda_streamWaitEvent((uint32_t)deviceId, (J9CudaStream)stream, (J9CudaEvent)event);
292
293
if (0 != error) {
294
throwCudaException(env, error);
295
}
296
297
Trc_cuda_streamWaitFor_exit(thread, error);
298
}
299
300
#endif /* OMR_OPT_CUDA */
301
302