简体   繁体   English

使用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" 我想制作一个“将分发给客户”的程序,所以我想保护我的内核代码免受黑客攻击“有人告诉我,AMD驱动程序有些如何将内核源代码放入二进制文件中,因此黑客可以使用AMD设备“

as I'm not experienced yet with VexCL , what is the proper compile line to just distribute binaries 因为我对VexCL没有经验,只需分发二进制文件的正确编译行是什么

for example with CUDA I can type : nvcc -gencode arch=compute_10,code=sm_10 myfile.cu -o myexec 例如使用CUDA我可以输入:nvcc -gencode arch = compute_10,code = sm_10 myfile.cu -o myexec

what is the equivilent in VexCL? VexCL中的等价物是什么?

also does VexCL work on Mac OS?which IDE? VexCL也适用于Mac OS?哪个IDE? (this is a future task as I didn't have experience on Mac OS before) (这是未来的任务,因为我之前没有Mac OS的经验)

my previous experience with OpenCL was by using STDCL library "but it is buggy on windows, no Mac support" 我之前使用OpenCL的经验是使用STDCL库“但它在Windows上有问题,没有Mac支持”

I am the developer of VexCL, and I have also replied to your question here . 我是VexCL的开发者,我也在这里回复了你的问题。

VexCL generates OpenCL/CUDA kernels for the expressions you use in your code at runtime. VexCL为运行时代码中使用的表达式生成OpenCL / CUDA内核。 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: 例如,如果将以下内容保存到hello.cpp文件中:

#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: 然后设置VEXCL_SHOW_KERNELS = 1并运行已编译的二进制文件:

$ export VEXCL_SHOW_KERNELS=1
$ ./hello

you will see the kernel that was generated for the expression y = 2 * sin(M_PI * x) + 1: 你会看到为表达式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. VexCL还允许缓存已编译的二进制源(默认情况下位于$ HOME / .vexcl文件夹中),并使用缓存保存源代码。

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, eg, 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. 我担心除了可能修改VexCL源代码以满足您的需求之外,您无法阻止源代码远离“黑客”。 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). 请注意,NVIDIA OpenCL驱动程序执行自己的缓存,它还将内核源与缓存的二进制文件一起存储(在$ HOME / .nv / ComputeCache文件夹中)。 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". 我不知道AMD是否做了类似的事情,但可能是你的“使用AMD设备记录内核”所指的内容。

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. 关于MacOS兼容性,我没有MacOS机器来进行我自己的测试,但我有报告称VexCL在那里工作。 I am not sure what IDE was used. 我不确定使用了什么IDE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM