Implementation:Alibaba MNN OpenCL CL Platform Header
| Knowledge Sources | |
|---|---|
| Domains | GPU_Computing, OpenCL |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Vendored Khronos OpenCL platform abstraction header defining fundamental data types, vector types, alignment macros, and compiler-specific portability definitions that underpin every other OpenCL header used by MNN's GPU backend.
Description
cl_platform.h is the foundational OpenCL header that establishes all platform-dependent type definitions and compiler abstraction macros. It defines the scalar types (cl_char, cl_uchar, cl_short, cl_ushort, cl_int, cl_uint, cl_long, cl_ulong, cl_half, cl_float, cl_double), vector types (cl_int2, cl_float4, cl_uchar16, etc.), GL interop types (cl_GLuint, cl_GLint, cl_GLenum), and API calling convention macros (CL_API_ENTRY, CL_API_CALL, CL_API_SUFFIX__VERSION_*, CL_CALLBACK). The header includes compiler-specific branches for MSVC, GCC, and Clang to ensure correct alignment and packing of vector types across platforms. MNN vendors this header as the base dependency for all other OpenCL headers in its GPU backend.
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_platform.h
- Lines: 1-1429
Signature
// Scalar type definitions (GCC/Clang branch)
typedef int8_t cl_char;
typedef uint8_t cl_uchar;
typedef int16_t cl_short __attribute__((aligned(2)));
typedef uint16_t cl_ushort __attribute__((aligned(2)));
typedef int32_t cl_int __attribute__((aligned(4)));
typedef uint32_t cl_uint __attribute__((aligned(4)));
typedef int64_t cl_long __attribute__((aligned(8)));
typedef uint64_t cl_ulong __attribute__((aligned(8)));
typedef uint16_t cl_half __attribute__((aligned(2)));
typedef float cl_float __attribute__((aligned(4)));
typedef double cl_double __attribute__((aligned(8)));
// GL interop types
typedef unsigned int cl_GLuint;
typedef int cl_GLint;
typedef unsigned int cl_GLenum;
// MSVC branch (alternative definitions)
typedef signed __int8 cl_char;
typedef unsigned __int8 cl_uchar;
typedef signed __int32 cl_int;
typedef unsigned __int32 cl_uint;
typedef float cl_float;
typedef double cl_double;
Import
#include "3rd_party/OpenCLHeaders/CL/cl_platform.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | Header-only; no runtime inputs |
Outputs
| Name | Type | Description |
|---|---|---|
| Type definitions | C typedefs | Portable scalar types (cl_int, cl_float, cl_ulong, etc.), vector types (cl_float4, cl_int2, etc.), GL interop types, and API calling convention macros |
Usage Examples
// MNN internal usage (not user-facing)
#include "CL/cl_platform.h"
// Use portable OpenCL types for cross-platform code
cl_int error_code = 0;
cl_uint num_platforms = 0;
cl_float scale_factor = 1.0f;
cl_ulong max_alloc_size = 0;
// Vector types for SIMD-style data
cl_float4 color = {{ 1.0f, 0.5f, 0.0f, 1.0f }};
cl_int2 dimensions = {{ 1920, 1080 }};
cl_uchar4 pixel = {{ 255, 128, 0, 255 }};
Related Pages
- Environment:Alibaba_MNN_GPU_OpenCL_Environment
- Alibaba_MNN_OpenCL_CL_Header - Core API header that depends on these type definitions
- Alibaba_MNN_OpenCL_CL_HPP_Header - C++ bindings that use these types
- Alibaba_MNN_OpenCL_CL2_HPP_Header - Modern C++ bindings that use these types
- Alibaba_MNN_OpenCL_CL_Ext_Header - Extension header that depends on these types