The Opencl Specification
Total Page:16
File Type:pdf, Size:1020Kb
The OpenCL Specification Version: 2.0 Document Revision: 22 Khronos OpenCL Working Group Editor: Aaftab Munshi Last Revision Date: 3/18/14 Page 1 1. INTRODUCTION ............................................................................................................... 10 2. GLOSSARY ......................................................................................................................... 12 3. THE OPENCL ARCHITECTURE .................................................................................... 23 3.1 Platform Model ................................................................................................................................ 23 3.2 Execution Model .............................................................................................................................. 25 3.2.1 Execution Model: Mapping work-items onto an NDRange ........................................................................28 3.2.2 Execution Model: Execution of kernel-instances ........................................................................................30 3.2.3 Execution Model: Device-side enqueue ......................................................................................................31 3.2.4 Execution Model: Synchronization .............................................................................................................32 3.2.5 Execution Model: Categories of Kernels ....................................................................................................33 3.3 Memory Model ................................................................................................................................. 34 3.3.1 Memory Model: Fundamental Memory Regions .......................................................................................34 3.3.2 Memory Model: Memory Objects ...............................................................................................................37 3.3.3 Memory Model: Shared Virtual Memory ...................................................................................................39 3.3.4 Memory Model: Memory Consistency Model ...........................................................................................40 3.3.5 Memory Model: Overview of atomic and fence operations ......................................................................43 3.3.6 Memory Model: Memory Ordering Rules .................................................................................................44 3.3.6.1 Memory Ordering Rules: Atomic Operations ....................................................................................................... 47 3.3.6.2 Memory Ordering Rules: Fence Operations ......................................................................................................... 50 3.3.6.3 Memory Ordering Rules: Work-group Functions ................................................................................................. 51 3.3.6.4 Memory Ordering Rules: Host-side and Device-side Commands ......................................................................... 52 3.4 The OpenCL Framework ................................................................................................................ 54 3.4.1 OpenCL Framework: Mixed Version Support ............................................................................................55 4. THE OPENCL PLATFORM LAYER .............................................................................. 56 4.1 Querying Platform Info ................................................................................................................... 56 4.2 Querying Devices ............................................................................................................................. 58 4.3 Partitioning a Device ....................................................................................................................... 77 4.4 Contexts ............................................................................................................................................ 82 5. THE OPENCL RUNTIME ................................................................................................. 89 5.1 Command Queues ............................................................................................................................ 89 5.2 Buffer Objects .................................................................................................................................. 95 5.2.1 Creating Buffer Objects ..............................................................................................................................95 5.2.2 Reading, Writing and Copying Buffer Objects .........................................................................................101 5.2.3 Filling Buffer Objects ................................................................................................................................113 5.2.4 Mapping Buffer Objects ............................................................................................................................115 Last Revision Date: 3/18/14 Page 2 5.3 Image Objects ................................................................................................................................. 119 5.3.1 Creating Image Objects .............................................................................................................................119 5.3.1.1 Image Format Descriptor ..................................................................................................................................... 122 5.3.1.2 Image Descriptor .................................................................................................................................................. 124 5.3.2 Querying List of Supported Image Formats ..............................................................................................126 5.3.2.1 Minimum List of Supported Image Formats ....................................................................................................... 128 5.3.3 Reading, Writing and Copying Image Objects .........................................................................................130 5.3.4 Filling Image Objects ................................................................................................................................137 5.3.5 Copying between Image and Buffer Objects ............................................................................................139 5.3.6 Mapping Image Objects ............................................................................................................................144 5.3.7 Image Object Queries ................................................................................................................................147 5.4 Pipes ................................................................................................................................................ 150 5.4.1 Creating Pipe Objects ................................................................................................................................150 5.4.2 Pipe Object Queries ...................................................................................................................................151 5.5 Querying, Unmapping, Migrating, Retaining and Releasing Memory Objects ...................... 153 5.5.1 Retaining and Releasing Memory Objects ................................................................................................153 5.5.2 Unmapping Mapped Memory Objects ......................................................................................................155 5.5.3 Accessing mapped regions of a memory object ........................................................................................157 5.5.4 Migrating Memory Objects .......................................................................................................................158 5.5.5 Memory Object Queries ............................................................................................................................160 5.6 Shared Virtual Memory ................................................................................................................ 164 5.6.1 SVM sharing granularity: coarse- and fine- grained sharing ...................................................................164 5.6.2 Memory consistency for SVM allocations ................................................................................................177 5.7 Sampler Objects ............................................................................................................................. 179 5.7.1 Creating Sampler Objects ..........................................................................................................................179 5.7.2 Sampler Object Queries ............................................................................................................................181 5.8 Program Objects ............................................................................................................................ 183 5.8.1 Creating Program Objects .........................................................................................................................183 5.8.2 Building Program Executables ..................................................................................................................188