Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/cuda/CudaLinker.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_CudaLinker.h"
25
26
#ifdef OMR_OPT_CUDA
27
28
/**
29
* Add a module fragment to the set of linker inputs.
30
*
31
* Class: com.ibm.cuda.CudaLinker
32
* Method: add
33
* Signature: (IJI[BLjava/lang/String;J)V
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] linker the linker state pointer
39
* @param[in] type the type of input in image
40
* @param[in] image the input content
41
* @param[in] name an optional name for use in log messages
42
* @param[in] options an optional options pointer
43
*/
44
void JNICALL
45
Java_com_ibm_cuda_CudaLinker_add
46
(JNIEnv * env, jclass, jint deviceId, jlong linker, jint type, jbyteArray image, jstring name, jlong options)
47
{
48
J9VMThread * thread = (J9VMThread *)env;
49
50
Trc_cuda_linkerAdd_entry(thread, deviceId, (J9CudaLinker)linker, type, image, name, (J9CudaJitOptions *)options);
51
52
int32_t error = J9CUDA_ERROR_OPERATING_SYSTEM;
53
jbyte * imageData = env->GetByteArrayElements(image, NULL);
54
const char * nameData = NULL;
55
56
if (NULL != name) {
57
nameData = env->GetStringUTFChars(name, NULL);
58
}
59
60
if ((NULL == imageData) || ((NULL != name) && (NULL == nameData))) {
61
Trc_cuda_linkerAdd_fail(thread);
62
} else {
63
PORT_ACCESS_FROM_ENV(env);
64
65
error = j9cuda_linkerAddData(
66
(uint32_t)deviceId,
67
(J9CudaLinker)linker,
68
(J9CudaJitInputType)type,
69
imageData,
70
(uintptr_t)env->GetArrayLength(image),
71
nameData,
72
(J9CudaJitOptions *)options);
73
}
74
75
if (NULL != nameData) {
76
env->ReleaseStringUTFChars(name, nameData);
77
}
78
79
if (NULL != imageData) {
80
env->ReleaseByteArrayElements(image, imageData, JNI_ABORT);
81
}
82
83
if (0 != error) {
84
throwCudaException(env, error);
85
}
86
87
Trc_cuda_linkerAdd_exit(thread);
88
}
89
90
/**
91
* Complete linking the module.
92
*
93
* Class: com.ibm.cuda.CudaLinker
94
* Method: complete
95
* Signature: (IJ)[B
96
*
97
* @param[in] env the JNI interface pointer
98
* @param[in] (unused) the class pointer
99
* @param[in] deviceId the device identifier
100
* @param[in] linker the linker state pointer
101
* @return the completed module ready for loading
102
*/
103
jbyteArray JNICALL
104
Java_com_ibm_cuda_CudaLinker_complete
105
(JNIEnv * env, jclass, jint deviceId, jlong linker)
106
{
107
J9VMThread * thread = (J9VMThread *)env;
108
109
Trc_cuda_linkerComplete_entry(thread, deviceId, (J9CudaLinker)linker);
110
111
PORT_ACCESS_FROM_ENV(env);
112
113
void * data = NULL;
114
uintptr_t size = 0;
115
int32_t error = j9cuda_linkerComplete((uint32_t)deviceId, (J9CudaLinker)linker, &data, &size);
116
jbyteArray result = NULL;
117
118
if (0 != error) {
119
throwCudaException(env, error);
120
} else {
121
result = env->NewByteArray((jsize)size);
122
123
if (env->ExceptionCheck()) {
124
Trc_cuda_linkerComplete_exception(thread);
125
result = NULL;
126
} else if (NULL == result) {
127
Trc_cuda_linkerComplete_fail(thread);
128
} else {
129
env->SetByteArrayRegion(result, 0, (jsize)size, (jbyte *)data);
130
}
131
}
132
133
Trc_cuda_linkerComplete_exit(thread, result);
134
135
return result;
136
}
137
138
#endif /* OMR_OPT_CUDA */
139
140
/**
141
* Create a new linker session.
142
*
143
* Class: com.ibm.cuda.CudaLinker
144
* Method: create
145
* Signature: (IJ)J
146
*
147
* @param[in] env the JNI interface pointer
148
* @param[in] (unused) the class pointer
149
* @param[in] deviceId the device identifier
150
* @param[in] options an optional options pointer
151
* @return the linker state pointer
152
*/
153
jlong JNICALL
154
Java_com_ibm_cuda_CudaLinker_create
155
(JNIEnv * env, jclass, jint deviceId, jlong options)
156
{
157
J9VMThread * thread = (J9VMThread *)env;
158
159
Trc_cuda_linkerCreate_entry(thread, deviceId, (J9CudaJitOptions *)options);
160
161
J9CudaLinker linker = NULL;
162
int32_t error = J9CUDA_ERROR_NO_DEVICE;
163
#ifdef OMR_OPT_CUDA
164
PORT_ACCESS_FROM_ENV(env);
165
error = j9cuda_linkerCreate((uint32_t)deviceId, (J9CudaJitOptions *)options, &linker);
166
#endif /* OMR_OPT_CUDA */
167
168
if (0 != error) {
169
throwCudaException(env, error);
170
}
171
172
Trc_cuda_linkerCreate_exit(thread, linker);
173
174
return (jlong)linker;
175
}
176
177
#ifdef OMR_OPT_CUDA
178
179
/**
180
* Destroy a linker session.
181
*
182
* Class: com.ibm.cuda.CudaLinker
183
* Method: destroy
184
* Signature: (IJ)V
185
*
186
* @param[in] env the JNI interface pointer
187
* @param[in] (unused) the class pointer
188
* @param[in] deviceId the device identifier
189
* @param[in] linker the linker state pointer
190
*/
191
void JNICALL
192
Java_com_ibm_cuda_CudaLinker_destroy
193
(JNIEnv * env, jclass, jint deviceId, jlong linker)
194
{
195
J9VMThread * thread = (J9VMThread *)env;
196
197
Trc_cuda_linkerDestroy_entry(thread, deviceId, (J9CudaLinker)linker);
198
199
PORT_ACCESS_FROM_ENV(env);
200
201
int32_t error = j9cuda_linkerDestroy((uint32_t)deviceId, (J9CudaLinker)linker);
202
203
if (0 != error) {
204
throwCudaException(env, error);
205
}
206
207
Trc_cuda_linkerDestroy_exit(thread);
208
}
209
210
#endif /* OMR_OPT_CUDA */
211
212