Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/cuda/CudaJitOptions.cpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2013, 2015 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_CudaJitOptions.h"
25
26
namespace
27
{
28
29
/**
30
* Destroy a JIT options instance.
31
*/
32
void
33
destroyOptions(JNIEnv * env, J9CudaJitOptions * options)
34
{
35
J9VMThread * thread = (J9VMThread *)env;
36
37
Trc_cuda_jitOptionsDestroy0_entry(thread, options);
38
39
PORT_ACCESS_FROM_ENV(env);
40
41
void * errorLog = options->errorLogBuffer;
42
43
if (NULL != errorLog) {
44
J9CUDA_FREE_MEMORY(errorLog);
45
}
46
47
void * infoLog = options->infoLogBuffer;
48
49
if (NULL != infoLog) {
50
J9CUDA_FREE_MEMORY(infoLog);
51
}
52
53
J9CUDA_FREE_MEMORY(options);
54
55
Trc_cuda_jitOptionsDestroy0_exit(thread);
56
}
57
58
} // namespace
59
60
/**
61
* Create and initialize a JIT options object.
62
*
63
* Class: com.ibm.cuda.CudaJitOptions
64
* Method: create
65
* Signature: ([I)J
66
*
67
* @param[in] env the JNI interface pointer
68
* @param[in] (unused) the class pointer
69
* @param[in] pairs an array of option/value pairs
70
* @return a pointer to a new JIT options object
71
*/
72
jlong JNICALL
73
Java_com_ibm_cuda_CudaJitOptions_create
74
(JNIEnv * env, jclass, jintArray pairs)
75
{
76
J9VMThread * thread = (J9VMThread *)env;
77
78
Trc_cuda_jitOptionsCreate_entry(thread, pairs);
79
80
jsize const pairLength = env->GetArrayLength(pairs) & ~1;
81
jint * pairData = NULL;
82
83
if (0 != pairLength) {
84
pairData = env->GetIntArrayElements(pairs, NULL);
85
86
if (NULL == pairData) {
87
Trc_cuda_jitOptionsCreate_getFail(thread);
88
throwCudaException(env, J9CUDA_ERROR_OPERATING_SYSTEM);
89
Trc_cuda_jitOptionsCreate_exit(thread, NULL);
90
return 0;
91
}
92
}
93
94
PORT_ACCESS_FROM_ENV(env);
95
96
int32_t error = 0;
97
J9CudaJitOptions * options = (J9CudaJitOptions *)J9CUDA_ALLOCATE_MEMORY(sizeof(J9CudaJitOptions));
98
99
if (NULL == options) {
100
Trc_cuda_jitOptionsCreate_allocFail(thread);
101
error = J9CUDA_ERROR_MEMORY_ALLOCATION;
102
} else {
103
memset(options, 0, sizeof(J9CudaJitOptions));
104
105
for (jint index = 0; (0 == error) && (index < pairLength); index += 2) {
106
jint key = pairData[index];
107
jint value = pairData[index + 1];
108
109
switch (key) {
110
case com_ibm_cuda_CudaJitOptions_OPT_CACHE_MODE:
111
options->cacheMode = (J9CudaJitCacheMode)value;
112
break;
113
114
case com_ibm_cuda_CudaJitOptions_OPT_ERROR_LOG_BUFFER_SIZE_BYTES:
115
if (NULL != options->errorLogBuffer) {
116
J9CUDA_FREE_MEMORY(options->errorLogBuffer);
117
}
118
119
options->errorLogBuffer = (char *)J9CUDA_ALLOCATE_MEMORY((size_t)value);
120
options->errorLogBufferSize = (uintptr_t)value;
121
122
if (NULL == options->errorLogBuffer) {
123
Trc_cuda_jitOptionsCreate_allocFail(thread);
124
options->errorLogBufferSize = 0;
125
error = J9CUDA_ERROR_MEMORY_ALLOCATION;
126
}
127
break;
128
129
case com_ibm_cuda_CudaJitOptions_OPT_FALLBACK_STRATEGY:
130
options->fallbackStrategy = (J9CudaJitFallbackStrategy)value;
131
break;
132
133
case com_ibm_cuda_CudaJitOptions_OPT_GENERATE_DEBUG_INFO:
134
options->generateDebugInfo = value ? J9CUDA_JIT_FLAG_ENABLED : J9CUDA_JIT_FLAG_DISABLED;
135
break;
136
137
case com_ibm_cuda_CudaJitOptions_OPT_GENERATE_LINE_INFO:
138
options->generateLineInfo = value ? J9CUDA_JIT_FLAG_ENABLED : J9CUDA_JIT_FLAG_DISABLED;
139
break;
140
141
case com_ibm_cuda_CudaJitOptions_OPT_INFO_LOG_BUFFER_SIZE_BYTES:
142
if (NULL != options->infoLogBuffer) {
143
J9CUDA_FREE_MEMORY(options->infoLogBuffer);
144
}
145
146
options->infoLogBuffer = (char *)J9CUDA_ALLOCATE_MEMORY((size_t)value);
147
options->infoLogBufferSize = (uintptr_t)value;
148
149
if (NULL == options->infoLogBuffer) {
150
Trc_cuda_jitOptionsCreate_allocFail(thread);
151
options->infoLogBufferSize = 0;
152
error = J9CUDA_ERROR_MEMORY_ALLOCATION;
153
}
154
break;
155
156
case com_ibm_cuda_CudaJitOptions_OPT_LOG_VERBOSE:
157
options->verboseLogging = value ? J9CUDA_JIT_FLAG_ENABLED : J9CUDA_JIT_FLAG_DISABLED;
158
break;
159
160
case com_ibm_cuda_CudaJitOptions_OPT_MAX_REGISTERS:
161
options->maxRegisters = (uint32_t)value;
162
break;
163
164
case com_ibm_cuda_CudaJitOptions_OPT_OPTIMIZATION_LEVEL:
165
switch (value) {
166
case 0:
167
options->optimizationLevel = J9CUDA_JIT_OPTIMIZATION_LEVEL_0;
168
break;
169
case 1:
170
options->optimizationLevel = J9CUDA_JIT_OPTIMIZATION_LEVEL_1;
171
break;
172
case 2:
173
options->optimizationLevel = J9CUDA_JIT_OPTIMIZATION_LEVEL_2;
174
break;
175
case 3:
176
options->optimizationLevel = J9CUDA_JIT_OPTIMIZATION_LEVEL_3;
177
break;
178
case 4:
179
options->optimizationLevel = J9CUDA_JIT_OPTIMIZATION_LEVEL_4;
180
break;
181
default:
182
error = J9CUDA_ERROR_INVALID_VALUE;
183
break;
184
}
185
break;
186
187
case com_ibm_cuda_CudaJitOptions_OPT_TARGET:
188
options->target = (uint32_t)value;
189
break;
190
191
case com_ibm_cuda_CudaJitOptions_OPT_TARGET_FROM_CUCONTEXT:
192
options->targetFromContext = value ? J9CUDA_JIT_FLAG_ENABLED : J9CUDA_JIT_FLAG_DISABLED;
193
break;
194
195
case com_ibm_cuda_CudaJitOptions_OPT_THREADS_PER_BLOCK:
196
if (0 != value) {
197
options->threadsPerBlock = (uint32_t)value;
198
} else {
199
error = J9CUDA_ERROR_INVALID_VALUE;
200
}
201
break;
202
203
case com_ibm_cuda_CudaJitOptions_OPT_WALL_TIME:
204
options->recordWallTime = value ? J9CUDA_JIT_FLAG_ENABLED : J9CUDA_JIT_FLAG_DISABLED;
205
break;
206
207
default:
208
Trc_cuda_jitOptionsCreate_badOption(thread, key);
209
error = J9CUDA_ERROR_INVALID_VALUE;
210
break;
211
}
212
}
213
}
214
215
if (NULL != pairData) {
216
env->ReleaseIntArrayElements(pairs, pairData, JNI_ABORT);
217
}
218
219
if (0 != error) {
220
throwCudaException(env, error);
221
}
222
223
if (env->ExceptionCheck() && (NULL != options)) {
224
destroyOptions(env, options);
225
options = NULL;
226
}
227
228
Trc_cuda_jitOptionsCreate_exit(thread, options);
229
230
return (jlong)options;
231
}
232
233
/**
234
* Destroy a JIT options object.
235
*
236
* Class: com.ibm.cuda.CudaJitOptions
237
* Method: destroy
238
* Signature: (J)V
239
*
240
* @param[in] env the JNI interface pointer
241
* @param[in] (unused) the class pointer
242
* @param[in] handle the options pointer
243
*/
244
void JNICALL
245
Java_com_ibm_cuda_CudaJitOptions_destroy
246
(JNIEnv * env, jclass, jlong handle)
247
{
248
J9VMThread * thread = (J9VMThread *)env;
249
J9CudaJitOptions * options = (J9CudaJitOptions *)handle;
250
251
Trc_cuda_jitOptionsDestroy_entry(thread, options);
252
253
destroyOptions(env, options);
254
255
Trc_cuda_jitOptionsDestroy_exit(thread);
256
}
257
258
/**
259
* Return the contents of the error log.
260
*
261
* Class: com.ibm.cuda.CudaJitOptions
262
* Method: getErrorLogBuffer
263
* Signature: (J)Ljava/lang/String;
264
*
265
* @param[in] env the JNI interface pointer
266
* @param[in] (unused) the class pointer
267
* @param[in] handle the options pointer
268
* @return a string containing the error log
269
*/
270
jstring JNICALL
271
Java_com_ibm_cuda_CudaJitOptions_getErrorLogBuffer
272
(JNIEnv * env, jclass, jlong handle)
273
{
274
J9VMThread * thread = (J9VMThread *)env;
275
J9CudaJitOptions * options = (J9CudaJitOptions *)handle;
276
277
Trc_cuda_jitOptionsGetErrorLogBuffer_entry(thread, options);
278
279
const char * buffer = ((J9CudaJitOptions *)handle)->errorLogBuffer;
280
jstring result = env->NewStringUTF((NULL == buffer) ? "" : buffer);
281
282
Trc_cuda_jitOptionsGetErrorLogBuffer_exit(thread, result);
283
284
return result;
285
}
286
287
/**
288
* Return the contents of the information log.
289
*
290
* Class: com.ibm.cuda.CudaJitOptions
291
* Method: getInfoLogBuffer
292
* Signature: (J)Ljava/lang/String;
293
*
294
* @param[in] env the JNI interface pointer
295
* @param[in] (unused) the class pointer
296
* @param[in] handle the options pointer
297
* @return a string containing the information log
298
*/
299
jstring JNICALL
300
Java_com_ibm_cuda_CudaJitOptions_getInfoLogBuffer
301
(JNIEnv * env, jclass, jlong handle)
302
{
303
J9VMThread * thread = (J9VMThread *)env;
304
J9CudaJitOptions * options = (J9CudaJitOptions *)handle;
305
306
Trc_cuda_jitOptionsGetInfoLogBuffer_entry(thread, options);
307
308
const char * buffer = options->infoLogBuffer;
309
jstring result = env->NewStringUTF((NULL == buffer) ? "" : buffer);
310
311
Trc_cuda_jitOptionsGetInfoLogBuffer_exit(thread, result);
312
313
return result;
314
}
315
316
/**
317
* Return the number of threads the compiler actually targeted per block.
318
*
319
* Class: com.ibm.cuda.CudaJitOptions
320
* Method: getThreadsPerBlock
321
* Signature: (J)I
322
*
323
* @param[in] env the JNI interface pointer
324
* @param[in] (unused) the class pointer
325
* @param[in] handle the options pointer
326
* @return the number of threads per block
327
*/
328
jint JNICALL
329
Java_com_ibm_cuda_CudaJitOptions_getThreadsPerBlock
330
(JNIEnv * env, jclass, jlong handle)
331
{
332
J9VMThread * thread = (J9VMThread *)env;
333
J9CudaJitOptions * options = (J9CudaJitOptions *)handle;
334
335
Trc_cuda_jitOptionsGetThreadsPerBlock_entry(thread, options);
336
337
jint result = (jint)options->threadsPerBlock;
338
339
Trc_cuda_jitOptionsGetThreadsPerBlock_exit(thread, result);
340
341
return result;
342
}
343
344
/**
345
* Return the elapsed compile or link time in milliseconds.
346
*
347
* Class: com.ibm.cuda.CudaJitOptions
348
* Method: getWallTime
349
* Signature: (J)F
350
*
351
* @param[in] env the JNI interface pointer
352
* @param[in] (unused) the class pointer
353
* @param[in] handle the options pointer
354
* @return the elapsed compile/link time
355
*/
356
jfloat JNICALL
357
Java_com_ibm_cuda_CudaJitOptions_getWallTime
358
(JNIEnv * env, jclass, jlong handle)
359
{
360
J9VMThread * thread = (J9VMThread *)env;
361
J9CudaJitOptions * options = (J9CudaJitOptions *)handle;
362
363
Trc_cuda_jitOptionsGetWallTime_entry(thread, options);
364
365
jfloat result = (jfloat)options->wallTime;
366
367
Trc_cuda_jitOptionsGetWallTime_exit(thread, result);
368
369
return result;
370
}
371
372