Error in API Hook on PGCL by the way of wrapper DLL.

Hi.

Now, I’m trying to hook OpenCLAPI of PGCL.
I chose how to call from libOpenCL.so wrapped to alias original libOpenCL.so.

However, when I run the PGCL sample’s NDKOclImageInverse, the program return an error (CL_INVALID_BINARY) in clCreateWithBinary().
I think the problem is not in the binary when I use the original OpenCLAPI Since program can be performed by the same binary.

When I use the original PGCL Library, similar errors occured when not calling setDriverDirectory() and setTmpDirPath() in OpenCLActivitiy class in PGCL sample’s JavaLibOpenCL project.

If there is a function that needs to be called or a variable that needs to be rewritten, please let me know.
Also, might be the cause of something else, please let me know if come up with. For example, the configuration of make.

I do not know the cause, I need your help.
Thank you for your attention.

My system and code are as follows:

/* Envirionment */
Target Device : Xperia P
My system’s description of “/proc/cpuinfo” is as follows:

Processor : ARMv7 Processor rev 1 (v7l)
processor : 0
BogoMIPS : 4.80

processor : 1
BogoMIPS : 4.80

Features : swp half thumb fastmult vfp edsp neon vfpv3
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x2
CPU part : 0xc09
CPU revision : 1

Hardware : riogrande
Revision : 0000
Serial : 0000000000000000

/* my code */

//---call dlopen,dlsym------
dl_handle = dlopen("[app_path]/lib/libOpenCLo.so", RTLD_NOW);
if(!dl_handle)
{
    //error
}
LOGD("NDK:LC: [%s]", "Load:libOpenCLo.so");
dlerror();
p_clCreateContextFromType = (func_clCreateContextFromType)dlsym(dl_handle, "clCreateContextFromType");
LOGD("NDK:LC: [%s]", dlerror()); // no error

//---call function------
cl_program clCreateProgramWithBinary(
		cl_context context,
		cl_uint num_devices,
		const cl_device_id *device_list,
		const size_t *lengths,
		const unsigned char **binaries,
		cl_int *binary_status,
		cl_int *errcode_ret)
{
	  cl_program ret = p_clCreateProgramWithBinary(
			  context,
			  num_devices,
			  device_list,
			  lengths,
			  binaries,
			  binary_status,
			  errcode_ret
	  );

	  return ret;
}

Hi ckit,

Sorry but I don’t understand what you’re trying to do.
Can you give more information ?

In the code sample you’ve given, you redefine clCreateProgramWithBinary to call to p_clCreateProgramWithBinary. I guess this routine is part of your OpenCL lib right ?

My understanding is that you would like a PGCL produced binary to be loaded/executed by your own lib that would replace our current libOpenCL.so, is this correct ?

I need first your answer to better understand your problem and eventually reply to your request.

Best Regards
Seb

Sorry for my bad English and less information.

What I want to do is that I call a function of libOpenCL.so from own lib. After changing the value of the argument of function of OpenCL called in own lib, I want to call a function of libOpenCL.so in own lib.

p_clCreateProgramWithBinary have called the function of the original libOpenCL. Because I changed the name of the original libOpenCL.so libOpenCLo.so.
I’m sorry for confusing you.

Thank you.

Hi ckit,

One more question for you, are you trying to call your own lib from Java ?

Seb

That’s right.
I call the code below in Java.
Since I use JavaLibOpenCL of PGCL sample, the statement was written already.

System.loadLibrary (“OpenCL”);

I have confirmed similar code using JNI on Ubuntu that will work with other SDK. So, I believe that there is no big mistake in this code.

Hello ckit,

Try adding an explicit load of OpenCLo library in JavalibOpenCL to see if it solves the issue:

System.loadLibrary (“OpenCLo”);
System.loadLibrary (“OpenCL”);

Best Regards
Seb

Hi.

Words were not enough int the previous post.
I wrote it.

I can hook other functions such as clCreateContext and clCreateCommandQueue and so on.
my program return an error (CL_INVALID_BINARY) when it reaches the clCreateWithBinary.
For this reason I think my program can load the library.

ckit

Hi ckit,

Can you share your source code with me, to see if I can help ?

Seb

Hi.

Sorry for late reply.
I’m really glad your help.

Too long to post all the code.
https://github.com/chikat/OclHookPGCL
I push jni directory in github.
Please put libOpenCLo.so was renamed from libOpenCL.so in this directory.

I’ve created a libOpenCL.so from these files by ndk-build.
Place the libOpenCL.so JavaLibOpenCL project that was created, I’m running NDKOclImageInverse.
However, an error occurs.

Thank you.

ckit

Hi ckit,

Sorry for the late reply, but I can’t use git with outside site. Can you provide me your source base as a .tgz archive for instance ?

Thanks
Seb

Hi ckit,

I’ve got a quick look at your sources, I still need more information. Is your Java Application using JavaLibOpenCL ? If yes did you try to add System.loadLibrary(“OpenCLo”); in JavaLibOpenCL ?
JavaLibOpenCL is designed to garanty that an activity that extends OpenCLActivity get libOpenCL loaded at the correct time. Android activities have less right that adb shell, thus we should explicitly set up from Java driver directory and access to a temporary path where is is allowed to write data. If those are not set correctly then clCreateProgramWithBinary or clCreateProgramWithSources will fail.
In conclusion, make sure your Activity uses JavaLibOpenCL and extends OpenCLActivity. If you can not do it that way, then try to explicitly call routine setTmpDirPath from your C++ code. Prototype is
Java_com_pgroup_lib_OpenCLActivity_setTmpDirPath(JNIEnv *env, jobject openclActivity, jstring path).
I can not garanty it will work that way, sorry.

sorry,
Since I said in a previous post, I did’nt explain…

Application use JavaLibOpenCL, and I add System.loadLibrary (“OpenCLo”); in OpenCLActivity.


I mail jni directory.
Please put libOpenCLo.so was renamed from libOpenCL.so in this directory.

I created libOpenCL.so from these files by ndk-build, and place the libOpenCL.so JavaLibOpenCL project.
I add System.loadLibrary (“OpenCLo”); in OpenCLActivity.
The other has not been edited in OpenCLActivity.

I’m running NDKOclImageInverse.
If NDKOclImageInverse don’t use the libOpenCLo.so, it can successfully run.
However,

when I run the PGCL sample’s NDKOclImageInverse, the program return an error (CL_INVALID_BINARY) in clCreateWithBinary ().
I can hook other functions such as clCreateContext() and clCreateCommandQueue() and so on.

ckit

Hi ckit,

Please provide me your full project. I don’t need your new lib sources, just need .so.
I’ll see what I can do but I’m not optimistic.

Sebastien

Hi,

I fail to send to your e-mail address that I was able to send before.

How do you send full project files to you?

ckit