Reputation: 3130
I would like to create an OpenCL kernel without giving access to it to the end user.
Therefore, I can't use a regular external .cl
text file. What are the alternatives, regarding that I would like to avoid creating a huge text string with the kernel?
And yet another question, if I put this code in an hardcoded string, won't it be possible to access that code from some disassembler?
Upvotes: 1
Views: 548
Reputation: 6343
Use SPIR 1.2 for OpenCL 1.2 or SPIR 2.0 for OpenCL 2.0 until SPIR-V for OpenCL 2.1 is available.
Upvotes: 1
Reputation: 8410
Here you have 2 scenarios:
In the first scenario, there is a possibility to embed the binary data into your executable (using a string). And load it when you run the program. There would be no reverse engineering possible (unless the already known ones, like assembly), since the program will have compiled code and not the original code you wrote.
The way of doing that would be:
uchar binary_dev1[binarySize] = "..."
uchar * binary = &binary_dev1;
program = clCreateProgramWithBinary(context, 1, &device,
&binarySize,
(const unsigned char**)&binary,
&binaryStatus,
&errNum);
The second alternative involves protecting the source code in the kernel by some sort of "mangling". Since the mangler code is going to be compiled, reverse engineer it could be complicated.
You can do any mangling you can think of that is reversible, and even combine them. Some ideas:
Compress the code it using a compression format, but hardcode some parameters of the decompresion, to make it less straightforward.
Use an XOR operator on the code. Better if it varies over time, and better if it varies using a non-obvious rule.
char seq = 0x1A; for(int i=0; i<len; i++){ out[i] = in[i] ^ seq; seq = ((seq ^ i) * 78965213) >> 4 + ((seq * i) * 56987) << 4; }
Encode it using encoding methods that require a key, and are reversible
Upvotes: 1