函数 clGetExtensionFunctionAddress 的使用

Usage of function clGetExtensionFunctionAddress

我是 OpenCL 扩展的新手,我尝试使用扩展函数 clImportMemoryARM with code blow:

cl_mem buffer = NULL;
clImportMemoryARM = (clImportMemoryARMFunc)clGetExtensionFunctionAddressForPlatform(plt->platforms[0], "clImportMemoryARM");
buffer = clImportMemoryARM(plt->context[0], 0, NULL, NULL, 0, &ret);

但是我在构建中收到错误 'clImportMemoryARMFunc' was not declared in this scope,我更改了 clImportMemoryARMFunc 和 clImportMemoryARM 也收到错误消息 error: assignment of function '_cl_mem clImportMemoryARM(cl_context, cl_mem_flags, const cl_import_properties_arm, void, size_t, cl_int)。就是不知道怎么用这个功能,有高手能解决吗?

非常感谢!

因为驱动没有向用户公开clImportMemoryARM所以你必须自己定义一个函数指针:

typedef cl_mem(clImportMemoryARM_func)
(cl_context                     psContext,
cl_mem_flags                    bfFlags,
const cl_import_properties_arm *properties,
void *                          pvMemory,
size_t                          uiSize,
cl_int *                        piErrorCodeRet);

然后你可以使用指向这个 API 的函数指针,像这样:

clImportMemoryARM_func *clImportMemoryARM = NULL;

clImportMemoryARM = (clImportMemoryARM_func *)clGetExtensionFunctionAddressForPlatform(plt->platforms[0], "clImportMemoryARM");

您需要包括 cl_ext.h:

#include <CL/cl_ext.h>

此文件是 OpenCL headers 的一部分。这个 header 应该有所有没有“外部依赖”的扩展(比如 OpenGL),它还有 clImportMemoryARM 和一堆其他的 ARM 函数和声明。