c++vexcl

working with VexCL "compiling binaries"


I want to make a program "which will be distributed to customers" , so I wanna protect my kernels code from hackers "some one told me that AMD driver some-how puts the kernel source inside the binary , so hacker can log the kernel with AMD device"

as I'm not experienced yet with VexCL , what is the proper compile line to just distribute binaries

for example with CUDA I can type : nvcc -gencode arch=compute_10,code=sm_10 myfile.cu -o myexec

what is the equivilent in VexCL?

also does VexCL work on Mac OS?which IDE? (this is a future task as I didn't have experience on Mac OS before)

my previous experience with OpenCL was by using STDCL library "but it is buggy on windows, no Mac support"


Solution

  • I am the developer of VexCL, and I have also replied to your question here.

    VexCL generates OpenCL/CUDA kernels for the expressions you use in your code at runtime. Moreover, it allows the user to dump the generated kernel sources to the standard output stream. For example, if you save the following to a hello.cpp file:

    #include <vexcl/vexcl.hpp>
    int main() {
        vex::Context ctx(vex::Filter::Env);
        vex::vector<double> x(ctx, 1024);
        vex::vector<double> y(ctx, 1024);
        y = 2 * sin(M_PI * x) + 1;
    }
    

    then compile it with

    g++ -o hello hello.cpp -std=c++11 -I/path/to/vexcl -lOpenCL -lboost_system
    

    then set VEXCL_SHOW_KERNELS=1 and run the compiled binary:

    $ export VEXCL_SHOW_KERNELS=1
    $ ./hello
    

    you will see the kernel that was generated for the expression y = 2 * sin(M_PI * x) + 1:

    #if defined(cl_khr_fp64)
    #  pragma OPENCL EXTENSION cl_khr_fp64: enable
    #elif defined(cl_amd_fp64)
    #  pragma OPENCL EXTENSION cl_amd_fp64: enable
    #endif
    
    kernel void vexcl_vector_kernel
    (
      ulong n,
      global double * prm_1,
      int prm_2,
      double prm_3,
      global double * prm_4,
      int prm_5
    )
    {
      for(size_t idx = get_global_id(0); idx < n; idx += get_global_size(0))
      {
        prm_1[idx] = ( ( prm_2 * sin( ( prm_3 * prm_4[idx] ) ) ) + prm_5 );
      }
    }
    

    VexCL also allows to cache the compiled binary sources (in the $HOME/.vexcl folder by default), and it saves the source code with the cache.

    From the one hand, the sources that you see are, being automatically generated, not very human-friendly. On the other hand, those are still more convenient to read than, e.g., disassembled binary. I am afraid there is nothing you can do to keep the sources away from 'hackers' except may be modify VexCL source code to suite your needs. The MIT license allows you to do that, and, if you are ready to do this, I could provide you with some guidance.

    Mind you, NVIDIA OpenCL driver does it's own caching, and it also stores the kernel sources together with the cached binaries (in the $HOME/.nv/ComputeCache folder). I don't know if it is possible to alter this behavior, so 'hackers' could still get the kernel sources from there. I don't know if AMD does similar thing, but may be that is what your source meant by "log the kernel with AMD device".

    Regarding the MacOS compatibility, I don't have a MacOS machine to do my own testing, but I had reports that VexCL does work there. I am not sure what IDE was used.