OpenCL ICD Loader运行测试暨解决报错:ERROR: App log and stub log differ.

上一篇博文《OpenCL Installable Client Driver (ICD) Loader编译》详细描述了如何编译OpenCL ICD Loader。OpenCL ICD Loader自带了测试程序,成功编译后可以根据源码根目录下README.txt的说明运行测试程序来验证Loader是否可以正常工作:

== Running ICD Test ==
ICD Test can be run using ctest, which is a companion to cmake. It can also be
run directly by executing icd_loader_test(.exe) executable from the bin folder.
=== Linux ===
1. Add driver stub as an ICD
echo full/path/to/libOpenCLDriverStub.so > /etc/OpenCL/vendors/test.icd
2. Run test using ctest
make test
=== Windows ===
1. Add driver stub as an ICD by adding appropriate registry value
Key for 32-bit apps: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Khronos\OpenCL\Vendors
Key for 64-bit apps: HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors
Add a REG_DWORD value:
Name: c:/full/path/to/OpenCLDriverStub.dll
Data: 0
Note: The build_using_cmake.bat builds ICD test as a 32-bit binary.
2. Run test using ctest.exe
cd build
ctest.exe
== Cleanup ==
Manually remove the registry key or .icd files added for running the ICD test.
The “build” and “bin” folders are autogenerated by the build so those may be
safely deleted without losing any source code (on Linux “make clobber” will
delete them).

Running ICD Test

以Win7 x64系统为例,按winkey+R弹出运行对话框,执行regedit打开注册表
找到Key”HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors”(如果你没有安装过OpenCL SDK,就不存在这个Key,你可以手工建一个)
然后如下图新建一个值,名字就是编译OpenCL Installable Client Driver (ICD) Loader生成的OpenCLDriverStub.dll的全路径名
OpenCL ICD Loader运行测试暨解决报错:ERROR: App log and stub log differ._第1张图片
OpenCL ICD Loader运行测试暨解决报错:ERROR: App log and stub log differ._第2张图片

上图中HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors存在amdocl.dll,amdocl64.dll两个键是因为我的电脑中安装了AMD 显卡的OpenCL驱动。

然后可以开始执行测试,在build文件夹下运行ctest,然后程序报错了,但没提示是什么错误:
OpenCL ICD Loader运行测试暨解决报错:ERROR: App log and stub log differ._第3张图片
直接在build/bin文件夹执行icd_loader_test.exe,同样报错,但有错误提示

E:\download\Devtools\opencl\OpenCL-ICD-Loader-master.vs15\bin\Debug>icd_loader_test.exe
ERROR: App log and stub log differ.
ICD Loader Test FAILED

ERROR: App log and stub log differ.

最终发现是OpenCL ICD Loader的测试程序有bug,解决办法:
打开./test/driver_stub/cl.c文件,找到clCreateImage2D函数,在test_icd_stub_log调用参数表后最增加一个errcode_ret,详见下面代码片段中的中文注释。

CL_API_ENTRY cl_mem CL_API_CALL
clCreateImage2D(cl_context              context ,
                cl_mem_flags            flags ,
                const cl_image_format * image_format ,
                size_t                  image_width ,
                size_t                  image_height ,
                size_t                  image_row_pitch ,
                void *                  host_ptr ,
                cl_int *                errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
    cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
    obj->dispatch = dispatchTable;
    test_icd_stub_log("clCreateImage2D(%p, %x, %p, %u, %u, %u, %p, %p)\n",
                      context,
                      flags,
                      image_format,
                      image_width,
                      image_height,
                      image_row_pitch,
                      host_ptr,
                      errcode_ret);//源码中少填了一个参数,补上

    test_icd_stub_log("Value returned: %p\n", obj);
    return obj;
}

重新编译OpenCL ICD Loader的代码后再运行ctest,测试成功
OpenCL ICD Loader运行测试暨解决报错:ERROR: App log and stub log differ._第4张图片

注意:

测试工作结束后,一定要把注册表中你手工增加的那个值删除,否则会造成真正的OpenCL调用异常。

你可能感兴趣的:(opencl)