OpenCL 构建:stringying 内核代码的优势
OpenCL build: advantage of stringying kernel code
我目前正在分发一个OpenCL程序(在线编译)。
现在我的内核代码在一个 *.cl
文件中,该文件在内核构建期间被读取。我认为也可以将内核源代码转换为字符串文字,可以直接读取而不是出于相同目的的 *.cl
。
我的问题是:对内核代码进行字符串化有什么好处?
优点:
- 无需处理IO。如果您必须支持多个文件系统,这可能会很痛苦(Windows、Linux 等...)。
- 对用户来说更简单,可执行文件只有 1 个文件。
- 如果有人编辑 .cl 文件,您可能会遇到问题。
- 更容易编译和发布。
示例:
const char *KernelSource = "\n" \
"__kernel void square( \n" \
" __global float* input, \n" \
" __global float* output, \n" \
" const unsigned int count) \n" \
"{ \n" \
" int i = get_global_id(0); \n" \
" if(i < count) \n" \
" output[i] = input[i] * input[i]; \n" \
"} \n";
program = clCreateProgramWithSource(context, 1, (const char **) &KernelSource, NULL, &err);
我目前正在分发一个OpenCL程序(在线编译)。
现在我的内核代码在一个 *.cl
文件中,该文件在内核构建期间被读取。我认为也可以将内核源代码转换为字符串文字,可以直接读取而不是出于相同目的的 *.cl
。
我的问题是:对内核代码进行字符串化有什么好处?
优点:
- 无需处理IO。如果您必须支持多个文件系统,这可能会很痛苦(Windows、Linux 等...)。
- 对用户来说更简单,可执行文件只有 1 个文件。
- 如果有人编辑 .cl 文件,您可能会遇到问题。
- 更容易编译和发布。
示例:
const char *KernelSource = "\n" \
"__kernel void square( \n" \
" __global float* input, \n" \
" __global float* output, \n" \
" const unsigned int count) \n" \
"{ \n" \
" int i = get_global_id(0); \n" \
" if(i < count) \n" \
" output[i] = input[i] * input[i]; \n" \
"} \n";
program = clCreateProgramWithSource(context, 1, (const char **) &KernelSource, NULL, &err);