Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Aparapi Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
We are moving to Forgejo!
You are on a read-only GitLab instance.
Show more breadcrumbs
Aparapi
Aparapi Examples
Commits
5fb5df24
Commit
5fb5df24
authored
13 years ago
by
Gary Frost
Browse files
Options
Downloads
Patches
Plain Diff
Tidy JNI code (added some helpers)
parent
35d5e1a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.amd.aparapi.jni/src/cpp/aparapi.cpp
+73
-101
73 additions, 101 deletions
com.amd.aparapi.jni/src/cpp/aparapi.cpp
with
73 additions
and
101 deletions
com.amd.aparapi.jni/src/cpp/aparapi.cpp
+
73
−
101
View file @
5fb5df24
...
@@ -288,6 +288,8 @@ jfieldID Range::localIsDerivedFieldID=0;
...
@@ -288,6 +288,8 @@ jfieldID Range::localIsDerivedFieldID=0;
class
ProfileInfo
{
class
ProfileInfo
{
public:
public:
jint
type
;
//0 write, 1 execute, 2 read
char
*
name
;
cl_ulong
queued
;
cl_ulong
queued
;
cl_ulong
submit
;
cl_ulong
submit
;
cl_ulong
start
;
cl_ulong
start
;
...
@@ -880,7 +882,7 @@ jint writeProfileInfo(JNIContext* jniContext){
...
@@ -880,7 +882,7 @@ jint writeProfileInfo(JNIContext* jniContext){
}
}
// Should failed profiling abort the run and return early?
// Should failed profiling abort the run and return early?
cl_int
profile
(
ProfileInfo
*
profileInfo
,
cl_event
*
event
){
cl_int
profile
(
ProfileInfo
*
profileInfo
,
cl_event
*
event
,
jint
type
,
char
*
name
){
cl_int
status
=
CL_SUCCESS
;
cl_int
status
=
CL_SUCCESS
;
status
=
clGetEventProfilingInfo
(
*
event
,
CL_PROFILING_COMMAND_QUEUED
,
sizeof
(
profileInfo
->
queued
),
&
(
profileInfo
->
queued
),
NULL
);
status
=
clGetEventProfilingInfo
(
*
event
,
CL_PROFILING_COMMAND_QUEUED
,
sizeof
(
profileInfo
->
queued
),
&
(
profileInfo
->
queued
),
NULL
);
ASSERT_CL
(
"clGetEventProfiliningInfo() QUEUED"
);
ASSERT_CL
(
"clGetEventProfiliningInfo() QUEUED"
);
...
@@ -890,6 +892,8 @@ cl_int profile(ProfileInfo *profileInfo, cl_event *event){
...
@@ -890,6 +892,8 @@ cl_int profile(ProfileInfo *profileInfo, cl_event *event){
ASSERT_CL
(
"clGetEventProfiliningInfo() START"
);
ASSERT_CL
(
"clGetEventProfiliningInfo() START"
);
status
=
clGetEventProfilingInfo
(
*
event
,
CL_PROFILING_COMMAND_END
,
sizeof
(
profileInfo
->
end
),
&
(
profileInfo
->
end
),
NULL
);
status
=
clGetEventProfilingInfo
(
*
event
,
CL_PROFILING_COMMAND_END
,
sizeof
(
profileInfo
->
end
),
&
(
profileInfo
->
end
),
NULL
);
ASSERT_CL
(
"clGetEventProfiliningInfo() END"
);
ASSERT_CL
(
"clGetEventProfiliningInfo() END"
);
profileInfo
->
type
=
type
;
profileInfo
->
name
=
name
;
return
status
;
return
status
;
}
}
...
@@ -1357,7 +1361,7 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_runKernelJNI(JNIEnv *je
...
@@ -1357,7 +1361,7 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_runKernelJNI(JNIEnv *je
for
(
int
i
=
0
;
i
<
readEventCount
;
i
++
){
for
(
int
i
=
0
;
i
<
readEventCount
;
i
++
){
if
(
jniContext
->
isProfilingEnabled
())
{
if
(
jniContext
->
isProfilingEnabled
())
{
status
=
profile
(
&
jniContext
->
args
[
jniContext
->
readEventArgs
[
i
]]
->
value
.
ref
.
read
,
&
jniContext
->
readEvents
[
i
]);
status
=
profile
(
&
jniContext
->
args
[
jniContext
->
readEventArgs
[
i
]]
->
value
.
ref
.
read
,
&
jniContext
->
readEvents
[
i
]
,
0
,
jniContext
->
args
[
jniContext
->
readEventArgs
[
i
]]
->
name
);
if
(
status
!=
CL_SUCCESS
)
{
if
(
status
!=
CL_SUCCESS
)
{
jniContext
->
unpinAll
(
jenv
);
jniContext
->
unpinAll
(
jenv
);
return
status
;
return
status
;
...
@@ -1381,7 +1385,7 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_runKernelJNI(JNIEnv *je
...
@@ -1381,7 +1385,7 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_runKernelJNI(JNIEnv *je
}
}
if
(
jniContext
->
isProfilingEnabled
())
{
if
(
jniContext
->
isProfilingEnabled
())
{
status
=
profile
(
&
jniContext
->
exec
,
&
jniContext
->
executeEvents
[
0
]);
status
=
profile
(
&
jniContext
->
exec
,
&
jniContext
->
executeEvents
[
0
]
,
1
,
NULL
);
if
(
status
!=
CL_SUCCESS
)
{
if
(
status
!=
CL_SUCCESS
)
{
jniContext
->
unpinAll
(
jenv
);
jniContext
->
unpinAll
(
jenv
);
return
status
;
return
status
;
...
@@ -1415,7 +1419,7 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_runKernelJNI(JNIEnv *je
...
@@ -1415,7 +1419,7 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_runKernelJNI(JNIEnv *je
for
(
int
i
=
0
;
i
<
writeEventCount
;
i
++
){
for
(
int
i
=
0
;
i
<
writeEventCount
;
i
++
){
if
(
jniContext
->
isProfilingEnabled
())
{
if
(
jniContext
->
isProfilingEnabled
())
{
profile
(
&
jniContext
->
args
[
jniContext
->
writeEventArgs
[
i
]]
->
value
.
ref
.
write
,
&
jniContext
->
writeEvents
[
i
]);
profile
(
&
jniContext
->
args
[
jniContext
->
writeEventArgs
[
i
]]
->
value
.
ref
.
write
,
&
jniContext
->
writeEvents
[
i
]
,
2
,
jniContext
->
args
[
jniContext
->
writeEventArgs
[
i
]]
->
name
);
}
}
status
=
clReleaseEvent
(
jniContext
->
writeEvents
[
i
]);
status
=
clReleaseEvent
(
jniContext
->
writeEvents
[
i
]);
if
(
status
!=
CL_SUCCESS
)
{
if
(
status
!=
CL_SUCCESS
)
{
...
@@ -1743,135 +1747,103 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_getJNI(JNIEnv *jenv, jo
...
@@ -1743,135 +1747,103 @@ JNIEXPORT jint JNICALL Java_com_amd_aparapi_KernelRunner_getJNI(JNIEnv *jenv, jo
return
0
;
return
0
;
}
}
jobject
create
List
(
JNIEnv
*
jenv
,
JNIContext
*
jniContext
){
jobject
create
Instance
(
JNIEnv
*
jenv
,
char
*
className
,
char
*
signature
,
...
){
jclass
list
Class
=
jenv
->
FindClass
(
"java/util/ArrayList"
);
jclass
the
Class
=
jenv
->
FindClass
(
className
);
if
(
list
Class
==
NULL
||
jenv
->
ExceptionCheck
())
{
if
(
the
Class
==
NULL
||
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionDescribe
();
jenv
->
ExceptionClear
();
\
jenv
->
ExceptionClear
();
fprintf
(
stderr
,
"bummer! class
\n
"
);
fprintf
(
stderr
,
"bummer!
getting '%s'
\n
"
,
class
Name
);
return
(
NULL
);
return
(
NULL
);
}
}
jmethodID
constructor
=
jenv
->
GetMethodID
(
list
Class
,
"<init>"
,
"()V"
);
jmethodID
constructor
=
jenv
->
GetMethodID
(
the
Class
,
"<init>"
,
signature
);
if
(
constructor
==
NULL
||
jenv
->
ExceptionCheck
())
{
if
(
constructor
==
NULL
||
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionDescribe
();
jenv
->
ExceptionClear
();
\
jenv
->
ExceptionClear
();
fprintf
(
stderr
,
"bummer getting constructor
!
\n
"
);
fprintf
(
stderr
,
"bummer getting constructor
from '%s' with signature! '%s'
\n
"
,
className
,
signature
);
return
(
NULL
);
return
(
NULL
);
}
}
jobject
listInstance
=
jenv
->
NewObject
(
listClass
,
constructor
);
va_list
argp
;
if
(
listInstance
==
NULL
||
jenv
->
ExceptionCheck
())
{
va_start
(
argp
,
signature
);
jenv
->
ExceptionDescribe
();
/* write to console */
\
jobject
instance
=
jenv
->
NewObjectV
(
theClass
,
constructor
,
argp
);
jenv
->
ExceptionClear
();
\
if
(
instance
==
NULL
||
jenv
->
ExceptionCheck
())
{
fprintf
(
stderr
,
"bummer invoking constructor!
\n
"
);
jenv
->
ExceptionDescribe
();
return
(
NULL
);
jenv
->
ExceptionClear
();
fprintf
(
stderr
,
"bummer invoking constructor from '%s' with signature! '%s'
\n
"
,
className
,
signature
);
}
}
return
(
listInstance
);
va_end
(
argp
);
return
(
instance
);
}
}
void
ad
d
(
JNIEnv
*
jenv
,
JNIContext
*
jniContext
,
jobject
list
,
jobject
profileItem
){
void
callVoi
d
(
JNIEnv
*
jenv
,
jobject
instance
,
char
*
methodName
,
char
*
methodSignature
,
...
){
jclass
list
Class
=
jenv
->
FindClass
(
"java/util/ArrayList"
);
jclass
the
Class
=
jenv
->
GetObjectClass
(
instance
);
if
(
list
Class
==
NULL
||
jenv
->
ExceptionCheck
())
{
if
(
the
Class
==
NULL
||
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionDescribe
();
jenv
->
ExceptionClear
();
\
jenv
->
ExceptionClear
();
fprintf
(
stderr
,
"bummer!
list class
\n
"
);
fprintf
(
stderr
,
"bummer!
getting class from instance
\n
"
);
return
;
return
;
}
}
jmethodID
methodId
=
jenv
->
GetMethodID
(
list
Class
,
"add"
,
"(Ljava/lang/Object;)Z"
);
jmethodID
methodId
=
jenv
->
GetMethodID
(
the
Class
,
methodName
,
methodSignature
);
if
(
methodId
==
NULL
||
jenv
->
ExceptionCheck
())
{
if
(
methodId
==
NULL
||
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionDescribe
();
jenv
->
ExceptionClear
();
\
jenv
->
ExceptionClear
();
fprintf
(
stderr
,
"bummer getting
add method!
\n
"
);
fprintf
(
stderr
,
"bummer getting
method '%s %s' from instance
\n
"
,
methodName
,
methodSignature
);
return
;
return
;
}
}
jenv
->
CallVoidMethod
(
list
,
methodId
,
profileItem
);
va_list
argp
;
va_start
(
argp
,
methodSignature
);
jenv
->
CallVoidMethodV
(
instance
,
methodId
,
argp
);
if
(
jenv
->
ExceptionCheck
())
{
if
(
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionDescribe
();
/* write to console */
jenv
->
ExceptionClear
();
\
jenv
->
ExceptionClear
();
fprintf
(
stderr
,
"bummer callin add
\n
"
);
fprintf
(
stderr
,
"bummer calling '%s %s'
\n
"
,
methodName
,
methodSignature
);
return
;
}
}
va_end
(
argp
);
return
;
}
}
jobject
createProfileInfo
(
JNIEnv
*
jenv
,
jstring
label
,
ProfileInfo
&
profileInfo
,
jint
type
){
jobject
createProfileInfo
(
JNIEnv
*
jenv
,
ProfileInfo
&
profileInfo
){
jclass
profileInfoClass
=
jenv
->
FindClass
(
"com/amd/aparapi/ProfileInfo"
);
jobject
profileInstance
=
createInstance
(
jenv
,
"com/amd/aparapi/ProfileInfo"
,
"(Ljava/lang/String;IJJJJ)V"
,
if
(
profileInfoClass
==
NULL
||
jenv
->
ExceptionCheck
())
{
((
jstring
)(
profileInfo
.
name
==
NULL
?
NULL
:
jenv
->
NewStringUTF
(
profileInfo
.
name
))),
jenv
->
ExceptionDescribe
();
/* write to console */
\
((
jint
)
profileInfo
.
type
),
jenv
->
ExceptionClear
();
\
((
jlong
)
profileInfo
.
start
),
fprintf
(
stderr
,
"bummer! class
\n
"
);
((
jlong
)
profileInfo
.
end
),
return
(
NULL
);
((
jlong
)
profileInfo
.
queued
),
}
((
jlong
)
profileInfo
.
submit
));
jmethodID
constructor
=
jenv
->
GetMethodID
(
profileInfoClass
,
"<init>"
,
"(Ljava/lang/String;IJJJJ)V"
);
if
(
constructor
==
NULL
||
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionClear
();
\
fprintf
(
stderr
,
"bummer getting constructor!
\n
"
);
return
(
NULL
);
}
jlong
start
=
profileInfo
.
start
;
jlong
end
=
profileInfo
.
end
;
jlong
queued
=
profileInfo
.
queued
;
jlong
submit
=
profileInfo
.
submit
;
jobject
profileInstance
=
jenv
->
NewObject
(
profileInfoClass
,
constructor
,
label
,
type
,
start
,
end
,
queued
,
submit
);
if
(
profileInstance
==
NULL
||
jenv
->
ExceptionCheck
())
{
jenv
->
ExceptionDescribe
();
/* write to console */
\
jenv
->
ExceptionClear
();
\
fprintf
(
stderr
,
"bummer invoking constructor!
\n
"
);
return
(
NULL
);
}
return
(
profileInstance
);
return
(
profileInstance
);
}
}
JNIEXPORT
jobject
JNICALL
Java_com_amd_aparapi_KernelRunner_getProfileInfoJNI
(
JNIEnv
*
jenv
,
jobject
jobj
,
jlong
jniContextHandle
)
{
JNIEXPORT
jobject
JNICALL
Java_com_amd_aparapi_KernelRunner_getProfileInfoJNI
(
JNIEnv
*
jenv
,
jobject
jobj
,
jlong
jniContextHandle
)
{
cl_int
status
=
CL_SUCCESS
;
cl_int
status
=
CL_SUCCESS
;
JNIContext
*
jniContext
=
JNIContext
::
getJNIContext
(
jniContextHandle
);
JNIContext
*
jniContext
=
JNIContext
::
getJNIContext
(
jniContextHandle
);
jobject
returnList
=
NULL
;
jobject
returnList
=
NULL
;
if
(
jniContext
!=
NULL
&&
jniContext
->
isProfilingEnabled
()){
if
(
jniContext
!=
NULL
){
returnList
=
createList
(
jenv
,
jniContext
);
returnList
=
createInstance
(
jenv
,
"java/util/ArrayList"
,
"()V"
);
if
(
jniContext
->
isProfilingEnabled
()){
for
(
jint
i
=
0
;
i
<
jniContext
->
argc
;
i
++
){
KernelArg
*
arg
=
jniContext
->
args
[
i
];
for
(
jint
i
=
0
;
i
<
jniContext
->
argc
;
i
++
){
if
(
arg
->
isArray
()){
KernelArg
*
arg
=
jniContext
->
args
[
i
];
if
(
arg
->
isRead
()){
if
(
arg
->
isArray
()){
jobject
writeProfileInfo
=
createProfileInfo
(
jenv
,
jenv
->
NewStringUTF
(
arg
->
name
),
arg
->
value
.
ref
.
write
,
0
);
if
(
arg
->
isRead
()){
add
(
jenv
,
jniContext
,
returnList
,
writeProfileInfo
);
jobject
writeProfileInfo
=
createProfileInfo
(
jenv
,
arg
->
value
.
ref
.
write
);
callVoid
(
jenv
,
returnList
,
"add"
,
"(Ljava/lang/Object;)Z"
,
writeProfileInfo
);
}
}
}
}
}
}
jobject
executeProfileInfo
=
createProfileInfo
(
jenv
,
NULL
,
jniContext
->
exec
,
1
);
jobject
executeProfileInfo
=
createProfileInfo
(
jenv
,
jniContext
->
exec
);
add
(
jenv
,
jniContext
,
returnList
,
executeProfileInfo
);
callVoid
(
jenv
,
returnList
,
"add"
,
"(Ljava/lang/Object;)Z"
,
executeProfileInfo
);
for
(
jint
i
=
0
;
i
<
jniContext
->
argc
;
i
++
){
for
(
jint
i
=
0
;
i
<
jniContext
->
argc
;
i
++
){
KernelArg
*
arg
=
jniContext
->
args
[
i
];
KernelArg
*
arg
=
jniContext
->
args
[
i
];
if
(
arg
->
isArray
()){
if
(
arg
->
isArray
()){
if
(
arg
->
isWrite
()){
if
(
arg
->
isWrite
()){
jobject
readProfileInfo
=
createProfileInfo
(
jenv
,
jenv
->
NewStringUTF
(
arg
->
name
),
arg
->
value
.
ref
.
read
,
2
);
jobject
readProfileInfo
=
createProfileInfo
(
jenv
,
arg
->
value
.
ref
.
read
);
add
(
jenv
,
jniContext
,
returnList
,
readProfileInfo
);
callVoid
(
jenv
,
returnList
,
"add"
,
"(Ljava/lang/Object;)Z"
,
readProfileInfo
);
}
}
}
}
}
}
}
/*
fprintf(stderr, " write end =%lu\n", arg->value.ref.write.end);
fprintf(stderr, " write start =%lu\n", arg->value.ref.write.start);
fprintf(stderr, " write submit=%lu\n", arg->value.ref.write.submit);
fprintf(stderr, " write queued=%lu\n", arg->value.ref.write.queued);
fprintf(stderr, " write =======%lu\n", arg->value.ref.write.end-arg->value.ref.write.start);
fprintf(stderr, " exec end =%lu\n", jniContext->exec.end);
fprintf(stderr, " exec start =%lu\n", jniContext->exec.start);
fprintf(stderr, " exec submit=%lu\n", jniContext->exec.submit);
fprintf(stderr, " exec queued=%lu\n", jniContext->exec.queued);
fprintf(stderr, " exec =======%lu\n", jniContext->exec.end-jniContext->exec.start);
fprintf(stderr, " read end =%lu\n", arg->value.ref.read.end);
fprintf(stderr, " read start =%lu\n", arg->value.ref.read.start);
fprintf(stderr, " read submit=%lu\n", arg->value.ref.read.submit);
fprintf(stderr, " read queued=%lu\n", arg->value.ref.read.queued);
fprintf(stderr, " read =======%lu\n", arg->value.ref.read.end-arg->value.ref.read.start);
*/
}
}
return
returnList
;
return
returnList
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment