0

I just started with OpenCL and I want to port an app I have in CUDA. The problem I'm facing now is the kernel stuff. In CUDA I have all my kernel functions in the same file, on the contrary, OpenCL asks to read the file with the kernel source code and then do some other stuff.

My question is: Can I have one single file with all my kernel functions and then build the program in OpenCL OR I have to have one file for each of my kernel functions?

It would be nice if you give a little example.

4

1 に答える 1

1

OpenCL と CUDA の唯一の違い (この点に関して) は、CUDA ではデバイスとホスト コードを同じソース ファイルに混在させることができるのに対し、OpenCL ではプログラム ソースを外部文字列として読み込んで実行時にコンパイルする必要があることです。

しかし、多くのカーネル関数を 1 つの OpenCL プログラムに入れても、1 つの OpenCL プログラム ソース文字列に入れてもまったく問題ありません。カーネル (たとえば、C API カーネル オブジェクト) 自体は、それぞれの関数名を使用してプログラム オブジェクトから抽出されます。

OpenCL の醜い C インターフェイスを簡素化する疑似コード:

単一の OpenCL ファイル:

__kernel void a(...) {}
__kernel void b(...) {}

C ファイル:

source = read_cl_file();
program = clCreateProgramWithSource(source);
clBuildProgram(program);
kernel_a = clCreateKernel(program, "a");
kernel_b = clCreateKernel(program, "b");
于 2013-05-14T14:11:21.447 に答える