ように私は静的ライブラリの両方以下のコードをコンパイルすると、オブジェクトファイルをしようとしない。ハロゲン化物AOTは、静的ライブラリとして正常に動作しますが、共有オブジェクト
静的の場合Halide::Func f("f");
Halide::Var x("x");
f(x) = x;
f.gpu_tile(x, 4);
f.bound(x, 0, 16);
Halide::Target target = Halide::get_target_from_environment();
target.set_feature(Halide::Target::OpenCL);
target.set_feature(Halide::Target::Debug);
// f.compile_to_static_library("mylib", {}, "f", target);
// f.compile_to_file("mylib", {}, "f", target);
すべての罰金と出力作品リンク
Halide::Buffer<int> output(16);
f(output.raw_buffer());
output.copy_to_host();
std::cout << output(10) << std::endl;
しかし、私は、共有オブジェクトへのリンクオブジェクトファイルをしようとすると、
gcc -shared -pthread mylib.o -o mylib.so
そして:結果が正確です私はCL_INVALID_MEM_OBJECT
エラーが表示さ
void* handle = dlopen("mylib.so", RTLD_NOW);
int (*func)(halide_buffer_t*);
*(void**)(&func) = dlsym(handle, "f");
func(output.raw_buffer());
、コード(Ubuntuの16.04)から開きます。デバッグログは次のとおりです。
CL: halide_opencl_init_kernels (user_context: 0x0, state_ptr: 0x7f1266b5a4e0, program: 0x7f1266957480, size: 1577
load_libopencl (user_context: 0x0)
Loaded OpenCL runtime library: libOpenCL.so
create_opencl_context (user_context: 0x0)
Got platform 'Intel(R) OpenCL', about to create context (t=6249430)
Multiple CL devices detected. Selecting the one with the most cores.
Device 0 has 20 cores
Device 1 has 4 cores
Selected device 0
device name: Intel(R) HD Graphics
device vendor: Intel(R) Corporation
device profile: FULL_PROFILE
global mem size: 1630 MB
max mem alloc size: 815 MB
local mem size: 65536
max compute units: 20
max workgroup size: 256
max work item dimensions: 3
max work item sizes: 256x256x256x0
clCreateContext -> 0x1899af0
clCreateCommandQueue 0x1a26a80
clCreateProgramWithSource -> 0x1a26ab0
clBuildProgram 0x1a26ab0 -D MAX_CONSTANT_BUFFER_SIZE=854799155 -D MAX_CONSTANT_ARGS=8
Time: 1.015832e+02 ms
CL: halide_opencl_run (user_context: 0x0, entry: kernel_f_s0_x___deprecated_block_id_x___block_id_x, blocks: 4x1x1, threads: 4x1x1, shmem: 0
clCreateKernel kernel_f_s0_x___deprecated_block_id_x___block_id_x -> Time: 1.361700e-02 ms
clSetKernelArg 0 4 [0x2e00010000000000 ...] 0
clSetKernelArg 1 8 [0x2149040 ...] 1
Mapped dev handle is: 0x2149040
Error: CL: clSetKernelArg failed: CL_INVALID_MEM_OBJECT
Aborted (core dumped)
ありがとうございました!コミット状態c7375fa。必要があれば余分な情報を提供することを嬉しく思います。
更新: 'halide_opencl_init_kernels'と' halide_opencl_device_malloc':clCreateContext'は二回呼び出したときに '' halide_opencl_init_kernels'が、動的リンクのために静的に 'リンクの場合にはclCreateContext'が一度呼び出すことがわかっhalide_set_custom_print'助け'と。作成されるコンテキストは異なります。 –
問題が見つかりました。私のサンプルはHalideの依存性も持っています。 Halide依存関係のない単一のファイルを使用すると、ダイナミックリンク作業が可能になります。前述のように 'clCreateContext'シンボルが重複していて、' libOpenCL.so'から2つの読み込みが必要なようです。 –