Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Adept II

Hide/Encrypt/Load Kernel code ?



I just would like to know how you store your OpenCL kernel in your C++ software ?

Some peoples use external files, but I don't want that my 'code' will be available to my customers !

Currently I use simple strings like this :

string code =

"void function() \n"
"{ \n"
" ..."
"} \n";

 But really it is not always easy to write some OpenCL code like this !

Thanks for your suggestions

4 Replies


this might help

Journeyman III

Originally posted by: viewon01


Some peoples use external files, but I don't want that my 'code' will be available to my customers !


If you really have so little trust in your customers - why do you sell them binaries and not a webservice? It's something to think about, because introducing a dummy OpenCL.dll that would filter out all the code you pass to clBuild is dead easy as is reverse engineering your binary to get at the inner loops in your code.

Pre-building binaries will mean endless support cycles as new devices come to market. It will be annoying to both you and the customers.

The proper approach here, IMO is to take a deep breath and consider very carefully if your code really is so special that it needs to be protected beyond what a free code obfuscator could do. In most cases, you should conclude that you're providing your customers with a service which includes a lot more than just the application you're selling them. Such as future development, bug fixing and the like.

Either way, there's no advantage whatsoever to code OpenCL as strings in your application. Embed the source files as resources, place them in a .zip file, or something if you want that kind of minimal security.

If you really have reason to think that your customers might steal your work, either don't sell to them at all(a webservice can be an alternative in some cases), or make sure the license agreement is worded in a way that lets you sue them if they do.



Not a web service, because it is not mandatory to have an internet connection for this kind of soft 😛

Pre-building is not really a good idea... due to maintenance !

a "dummy OpenCL.dll" ... how can we do this ? is it possible ?

So, how can I embed my .cl files in my binary ?


you just need create dummy OpenCL.dll which will have exported all OpenCL functions which will pass all data to original OpenCL.dll

then you just need dump source code in your dummy clCreateProgramWithSource(). it is easy and i myself have done it. (not exactly dump OpenCL source code) just google "hijack OR preload dll"

best what you can is use binary kernel or just run some obfuscator to your code.

get to code which is in form of char string in source file is even easier. you just open exe file and you can see all strings constant as plain text.