Implementation:Alibaba MNN OpenCL CL Ext Header
| Knowledge Sources | |
|---|---|
| Domains | GPU_Computing, OpenCL |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Vendored Khronos OpenCL extension declarations header defining cross-vendor and vendor-specific extension constants, function typedefs, and API entry points for advanced GPU features used by MNN's OpenCL backend.
Description
cl_ext.h declares OpenCL extensions that supplement the core API defined in cl.h. These include Khronos-ratified extensions (prefixed cl_khr_) such as ICD platform discovery, IL program creation (SPIR/SPIR-V), image2D-from-buffer, context termination, and sub-group operations, as well as vendor-specific extensions for ARM (cl_arm_), Qualcomm (cl_qcom_), and IMG (cl_img_) GPUs. MNN vendors this header to enable compile-time detection and runtime use of hardware-specific optimizations such as shared virtual memory, import/export of DMA buffers, and specialized image formats across different mobile and desktop GPU vendors.
Usage
This header is included internally by MNN's OpenCL backend. It is not directly imported by end users.
Code Reference
Source Location
- Repository: Alibaba_MNN
- File: 3rd_party/OpenCLHeaders/CL/cl_ext.h
- Lines: 1-745
Signature
// ICD extension - platform discovery
typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)(
cl_uint num_entries,
cl_platform_id * platforms,
cl_uint * num_platforms);
// IL program creation (SPIR-V support)
typedef CL_API_ENTRY cl_program
(CL_API_CALL *clCreateProgramWithILKHR_fn)(
cl_context context,
const void * il,
size_t length,
cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2;
// Context termination
typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(
cl_context context) CL_EXT_SUFFIX__VERSION_1_2;
// Sub-group queries
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetKernelSubGroupInfoKHR_fn)(
cl_kernel kernel,
cl_device_id device,
cl_kernel_sub_group_info param_name,
size_t input_value_size,
const void * input_value,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret);
Import
#include "3rd_party/OpenCLHeaders/CL/cl_ext.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | Header-only; no runtime inputs |
Outputs
| Name | Type | Description |
|---|---|---|
| API declarations | C functions/typedefs | OpenCL extension function typedefs, constant definitions, and API entry points for KHR, ARM, Qualcomm, and IMG extensions |
Usage Examples
// MNN internal usage (not user-facing)
#include "CL/cl_ext.h"
// Check for ICD extension support
cl_int err;
clIcdGetPlatformIDsKHR_fn pIcdGetPlatformIDs;
pIcdGetPlatformIDs = (clIcdGetPlatformIDsKHR_fn)
clGetExtensionFunctionAddressForPlatform(platform, "clIcdGetPlatformIDsKHR");
// Create program from SPIR-V IL
clCreateProgramWithILKHR_fn pCreateProgramWithIL;
pCreateProgramWithIL = (clCreateProgramWithILKHR_fn)
clGetExtensionFunctionAddressForPlatform(platform, "clCreateProgramWithILKHR");
cl_program prog = pCreateProgramWithIL(context, spirv_data, spirv_size, &err);
Related Pages
- Environment:Alibaba_MNN_GPU_OpenCL_Environment
- Alibaba_MNN_OpenCL_CL_Header - Core OpenCL API that extensions supplement
- Alibaba_MNN_OpenCL_CL_Ext_Intel_Header - Intel-specific extensions (included separately)
- Alibaba_MNN_OpenCL_CL_Ext_Qcom_Header - Qualcomm-specific extensions (included separately)
- Alibaba_MNN_OpenCL_CL_Platform_Header - Platform type definitions