Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/gpu.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2014, 2018 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 "jni.h"
24
#include "j9.h"
25
#include "rommeth.h"
26
#include "jclprots.h"
27
28
static void**
29
extractArguments(JNIEnv *env, jintArray argSizes, jlongArray argValues) {
30
PORT_ACCESS_FROM_VMC( ((J9VMThread *) env) );
31
32
#if !defined(J9VM_ENV_LITTLE_ENDIAN)
33
jint * sizes = (*env)->GetIntArrayElements (env, argSizes, (jboolean *)0);
34
#endif
35
jlong * values = (*env)->GetLongArrayElements(env, argValues, (jboolean *)0);
36
37
if (
38
#if !defined(J9VM_ENV_LITTLE_ENDIAN)
39
(NULL == sizes) ||
40
#endif
41
(NULL == values)
42
) {
43
/* TODO throwCudaException(env, cudaErrorOperatingSystem); */
44
return NULL;
45
} else {
46
jsize argCount = (*env)->GetArrayLength(env, argSizes);
47
void ** args = (void **)j9mem_allocate_memory(argCount * sizeof(void**), J9MEM_CATEGORY_VM_JCL);
48
jsize i = 0;
49
50
if (NULL == args) {
51
((J9VMThread *)env)->javaVM->internalVMFunctions->throwNativeOOMError(env, 0, 0);
52
return NULL;
53
}
54
/* gather addresses of parameters */
55
for (i = 0; i < argCount; ++i) {
56
char * value = (char *)&values[i];
57
58
#if !defined(J9VM_ENV_LITTLE_ENDIAN)
59
size_t size = (size_t)sizes[i];
60
61
if (size != 0) {
62
value += sizeof(jlong) - size;
63
} else {
64
value += sizeof(jlong) - sizeof(void *);
65
}
66
#endif
67
args[i] = value;
68
}
69
return args;
70
}
71
}
72
73
74
jint JNICALL
75
Java_com_ibm_gpu_Kernel_launch(JNIEnv *env,
76
jobject thisObject, /* Kernel object */
77
jobject invokeObject, /* object on which the method will be invoked */
78
jobject mymethod, jint deviceId,
79
jint gridDimX, jint gridDimY, jint gridDimZ,
80
jint blockDimX, jint blockDimY, jint blockDimZ,
81
jintArray argSizes, jlongArray argValues)
82
{
83
J9VMThread *vmThread = (J9VMThread *)env;
84
J9JavaVM *jvm = vmThread->javaVM;
85
IDATA result = 1; /* launchGPU() returns 1 if it fails */
86
87
if (NULL != jvm->jitConfig) {
88
jmethodID methodID = 0;
89
J9Method *ramMethod = NULL;
90
void **args = NULL;
91
92
PORT_ACCESS_FROM_JAVAVM(jvm);
93
94
if (argSizes != NULL && argValues != NULL) {
95
args = extractArguments(env, argSizes, argValues);
96
if (NULL == args) {
97
goto done;
98
}
99
}
100
101
jvm->internalVMFunctions->internalEnterVMFromJNI(vmThread);
102
methodID = jvm->reflectFunctions.reflectMethodToID(vmThread, mymethod);
103
ramMethod = ((J9JNIMethodID *) methodID)->method;
104
105
result = jvm->jitConfig->launchGPU(vmThread, invokeObject,
106
ramMethod, deviceId,
107
gridDimX, gridDimY, gridDimZ,
108
blockDimX, blockDimY, blockDimZ,
109
args);
110
111
jvm->internalVMFunctions->internalExitVMToJNI(vmThread);
112
113
if (NULL != args) {
114
j9mem_free_memory(args);
115
}
116
}
117
118
done:
119
return (jint) result;
120
}
121
122
123
void JNICALL
124
Java_java_util_stream_IntPipeline_promoteGPUCompile(JNIEnv *env, jclass clazz)
125
{
126
J9VMThread *vmThread = (J9VMThread *)env;
127
J9JavaVM *vm = vmThread->javaVM;
128
129
if (NULL != vm->jitConfig) {
130
J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
131
132
vmFuncs->internalEnterVMFromJNI(vmThread);
133
vm->jitConfig->promoteGPUCompile(vmThread);
134
vmFuncs->internalExitVMToJNI(vmThread);
135
}
136
}
137
138
139