Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/cuda/CudaEvent.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_CudaEvent.h"
25
26
/**
27
* Create an event with the specified flags.
28
*
29
* Class: com.ibm.cuda.CudaEvent
30
* Method: create
31
* Signature: (II)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
* @param[in] flags the event creation flags
37
* @return a new event
38
*/
39
jlong JNICALL
40
Java_com_ibm_cuda_CudaEvent_create
41
(JNIEnv * env, jclass, jint deviceId, jint flags)
42
{
43
J9VMThread * thread = (J9VMThread *)env;
44
45
Trc_cuda_eventCreate_entry(thread, deviceId, flags);
46
47
J9CudaEvent event = NULL;
48
int32_t error = J9CUDA_ERROR_NO_DEVICE;
49
#ifdef OMR_OPT_CUDA
50
PORT_ACCESS_FROM_ENV(env);
51
error = j9cuda_eventCreate((uint32_t)deviceId, (uint32_t)flags, &event);
52
#endif /* OMR_OPT_CUDA */
53
54
if (0 != error) {
55
throwCudaException(env, error);
56
}
57
58
Trc_cuda_eventCreate_exit(thread, event);
59
60
return (jlong)event;
61
}
62
63
#ifdef OMR_OPT_CUDA
64
65
/**
66
* Destroy an event.
67
*
68
* Class: com.ibm.cuda.CudaEvent
69
* Method: destroy
70
* Signature: (IJ)V
71
*
72
* @param[in] env the JNI interface pointer
73
* @param[in] (unused) the class pointer
74
* @param[in] deviceId the device identifier
75
* @param[in] event the event
76
*/
77
void JNICALL
78
Java_com_ibm_cuda_CudaEvent_destroy
79
(JNIEnv * env, jclass, jint deviceId, jlong event)
80
{
81
J9VMThread * thread = (J9VMThread *)env;
82
83
Trc_cuda_eventDestroy_entry(thread, deviceId, (J9CudaEvent)event);
84
85
PORT_ACCESS_FROM_ENV(env);
86
87
int32_t error = j9cuda_eventDestroy((uint32_t)deviceId, (J9CudaEvent)event);
88
89
if (0 != error) {
90
throwCudaException(env, error);
91
}
92
93
Trc_cuda_eventDestroy_exit(thread, error);
94
}
95
96
/**
97
* Return the elapsed time in milliseconds between two events.
98
*
99
* Class: com.ibm.cuda.CudaEvent
100
* Method: elapsedTimeSince
101
* Signature: (JJ)F
102
*
103
* @param[in] env the JNI interface pointer
104
* @param[in] (unused) the class pointer
105
* @param[in] event the reference event
106
* @param[in] priorEvent the earlier event
107
* @return the elapsed time in milliseconds between the two events
108
*/
109
jfloat JNICALL
110
Java_com_ibm_cuda_CudaEvent_elapsedTimeSince
111
(JNIEnv * env, jclass, jlong event, jlong priorEvent)
112
{
113
J9VMThread * thread = (J9VMThread *)env;
114
115
Trc_cuda_eventElapsedTimeSince_entry(thread, (J9CudaEvent)priorEvent, (J9CudaEvent)event);
116
117
PORT_ACCESS_FROM_ENV(env);
118
119
float elapsed = 0.0f;
120
int32_t error = j9cuda_eventElapsedTime((J9CudaEvent)priorEvent, (J9CudaEvent)event, &elapsed);
121
122
if (0 != error) {
123
throwCudaException(env, error);
124
}
125
126
Trc_cuda_eventElapsedTimeSince_exit(thread, (jint)error, (jfloat)elapsed);
127
128
return (jfloat)elapsed;
129
}
130
131
/**
132
* Query the status of an event.
133
*
134
* Class: com.ibm.cuda.CudaEvent
135
* Method: query
136
* Signature: (J)I
137
*
138
* @param[in] env the JNI interface pointer
139
* @param[in] (unused) the class pointer
140
* @param[in] event the event
141
* @return 0 if the event has been recorded; else cudaErrorNotReady or another error
142
*/
143
jint JNICALL
144
Java_com_ibm_cuda_CudaEvent_query
145
(JNIEnv * env, jclass, jlong event)
146
{
147
J9VMThread * thread = (J9VMThread *)env;
148
149
Trc_cuda_eventQuery_entry(thread, (J9CudaEvent)event);
150
151
PORT_ACCESS_FROM_ENV(env);
152
153
int32_t error = j9cuda_eventQuery((J9CudaEvent)event);
154
155
Trc_cuda_eventQuery_exit(thread, error);
156
157
return (jint)error;
158
}
159
160
/**
161
* Record an event on a stream or the default stream.
162
*
163
* Class: com.ibm.cuda.CudaEvent
164
* Method: record
165
* Signature: (IJJ)V
166
*
167
* @param[in] env the JNI interface pointer
168
* @param[in] (unused) the class pointer
169
* @param[in] deviceId the device identifier
170
* @param[in] stream the stream, or null for the default stream
171
* @param[in] event the event to be recorded
172
*/
173
void JNICALL
174
Java_com_ibm_cuda_CudaEvent_record
175
(JNIEnv * env, jclass, jint deviceId, jlong stream, jlong event)
176
{
177
J9VMThread * thread = (J9VMThread *)env;
178
179
Trc_cuda_eventRecord_entry(thread, deviceId, (J9CudaStream)stream, (J9CudaEvent)event);
180
181
PORT_ACCESS_FROM_ENV(env);
182
183
int32_t error = j9cuda_eventRecord((uint32_t)deviceId, (J9CudaEvent)event, (J9CudaStream)stream);
184
185
if (0 != error) {
186
throwCudaException(env, error);
187
}
188
189
Trc_cuda_eventRecord_exit(thread);
190
}
191
192
/**
193
* Synchronize with an event.
194
*
195
* Class: com.ibm.cuda.CudaEvent
196
* Method: synchronize
197
* Signature: (J)V
198
*
199
* @param[in] env the JNI interface pointer
200
* @param[in] (unused) the class pointer
201
* @param[in] event the event to be recorded
202
*/
203
void JNICALL
204
Java_com_ibm_cuda_CudaEvent_synchronize
205
(JNIEnv * env, jclass, jlong event)
206
{
207
J9VMThread * thread = (J9VMThread *)env;
208
209
Trc_cuda_eventSynchronize_entry(thread, (J9CudaEvent)event);
210
211
PORT_ACCESS_FROM_ENV(env);
212
213
int32_t error = j9cuda_eventSynchronize((J9CudaEvent)event);
214
215
if (0 != error) {
216
throwCudaException(env, error);
217
}
218
219
Trc_cuda_eventSynchronize_exit(thread, (jint)error);
220
}
221
222
#endif /* OMR_OPT_CUDA */
223
224