Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Listings

Listings

Listing 2.1HelloWorld OpenCL Kernel and Main Function46
Listing 2.2Choosing a Platform and Creating a Context49
Listing 2.3Choosing the First Available Device and Creating a Command-Queue51
Listing 2.4Loading a Kernel Source File from Disk and Creating and Building a Program Object53
Listing 2.5Creating a Kernel54
Listing 2.6Creating Memory Objects55
Listing 2.7Setting the Kernel Arguments, Executing the Kernel, and Reading Back the Results56
Listing 3.1Enumerating the List of Platforms66
Listing 3.2Querying and Displaying Platform-Specific Information67
Listing 3.3Example of Querying and Displaying Platform-Specific Information79
Listing 3.4Using Platform, Devices, and Contexts—Simple Convolution Kernel90
Listing 3.5Example of Using Platform, Devices, and Contexts—Simple Convolution91
Listing 6.1Creating and Building a Program Object221
Listing 6.2Caching the Program Binary on First Run229
Listing 6.3Querying for and Storing the Program Binary230
Listing 6.4Example Program Binary for HelloWorld.cl (NVIDIA)233
Listing 6.5Creating a Program from Binary235
Listing 7.1Creating, Writing, and Reading Buffers and Sub-Buffers Example Kernel Code262
Listing 7.2Creating, Writing, and Reading Buffers and Sub-Buffers Example Host Code262
Listing 8.1Creating a 2D Image Object from a File284
Listing 8.2Creating a 2D Image Object for Output285
Listing 8.3Query for Device Image Support291
Listing 8.4Creating a Sampler Object293
Listing 8.5Gaussian Filter Kernel295
Listing 8.6Queue Gaussian Kernel for Execution297
Listing 8.7Read Image Back to Host Memory300
Listing 8.8Mapping Image Results to a Host Memory Pointer307
Listing 12.1Vector Add Example Program Using the C++ Wrapper API379
Listing 13.1Querying Platform and Device Profiles384
Listing 14.1Sequential Implementation of RGB Histogram393
Listing 14.2A Parallel Version of the RGB Histogram—Compute Partial Histograms395
Listing 14.3A Parallel Version of the RGB Histogram—Sum Partial Histograms397
Listing 14.4Host Code of CL API Calls to Enqueue Histogram Kernels398
Listing 14.5A Parallel Version of the RGB Histogram—Optimized Version400
Listing 14.6A Parallel Version of the RGB Histogram for Half-Float and Float Channels403
Listing 15.1An OpenCL Sobel Filter408
Listing 15.2An OpenCL Sobel Filter Producing a Grayscale Image410
Listing 16.1Data Structure and Interface for Dijkstra’s Algorithm413
Listing 16.2Pseudo Code for High-Level Loop That Executes Dijkstra’s Algorithm414
Listing 16.3Kernel to Initialize Buffers before Each Run of Dijkstra’s Algorithm415
Listing 16.4Two Kernel Phases That Compute Dijkstra’s Algorithm416
Listing 20.1ImageFilter2D.py489
Listing 20.2Creating a Context492
Listing 20.3Loading an Image494
Listing 20.4Creating and Building a Program495
Listing 20.5Executing the Kernel496
Listing 20.6Reading the Image into a Numpy Array496
Listing 21.1A C Function Implementing Sequential Matrix Multiplication500
Listing 21.2A kernel to compute the matrix product of A and B summing the result into a third matrix, C. Each work-item is responsible for a single element of the C matrix. The matrices are stored in global memory.501
Listing 21.3The Host Program for the Matrix Multiplication Program503
Listing 21.4Each work-item updates a full row of C. The kernel code is shown as well as changes to the host code from the base host program in Listing 21.3. The only change required in the host code was to the dimensions of the NDRange.507
Listing 21.5Each work-item manages the update to a full row of C, but before doing so the relevant row of the A matrix is copied into private memory from global memory.508
Listing 21.6Each work-item manages the update to a full row of C. Private memory is used for the row of A and local memory (Bwrk) is used by all work-items in a work-group to hold a column of B. The host code is the same as before other than the addition of a new argument for the B-column local memory.510
Listing 21.7Different Versions of the Matrix Multiplication Functions Showing the Permutations of the Loop Orderings513
Listing 22.1Sparse Matrix-Vector Multiplication OpenCL Kernels530


  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint