وبلاگ بلیان

راهنمای برنامه‌نویسی OpenCL

OpenCL Programming Guide

معرفی کتاب «راهنمای برنامه‌نویسی OpenCL» (با عنوان لاتین OpenCL Programming Guide) نوشتهٔ Aaftab Munshi, Benedict Gaster, Timothy G. Mattson, James Fung, Dan Ginsburg، منتشرشده توسط نشر Addison-Wesley Professional در سال 2012. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Using the new OpenCL (Open Computing Language) standard, you can write applications that access all available programming resources: CPUs, GPUs, and other processors such as DSPs and the Cell/B.E. processor. Already implemented by Apple, AMD, Intel, IBM, NVIDIA, and other leaders, OpenCL has outstanding potential for PCs, servers, handheld/embedded devices, high performance computing, and even cloud systems. This is the first comprehensive, authoritative, and practical guide to OpenCL 1.1 specifically for working developers and software architects. Written by five leading OpenCL authorities, OpenCL Programming Guide covers the entire specification. It reviews key use cases, shows how OpenCL can express a wide range of parallel algorithms, and offers complete reference material on both the API and OpenCL C programming language. Through complete case studies and downloadable code examples, the authors show how to write complex parallel programs that decompose workloads across many different devices. They also present all the essentials of OpenCL software performance optimization, including probing and adapting to hardware. Coverage includes Understanding OpenCL's architecture, concepts, terminology, goals, and rationale Programming with OpenCL C and the runtime API Using buffers, sub-buffers, images, samplers, and events Sharing and synchronizing data with OpenGL and Microsoft's Direct3D Simplifying development with the C++ Wrapper API Using OpenCL Embedded Profiles to support devices ranging from cellphones to supercomputer nodes Case studies dealing with physics simulation; image and signal processing, such as image histograms, edge detection filters, Fast Fourier Transforms, and optical flow; math libraries, such as matrix multiplication and high-performance sparse matrix multiplication; and more Source code for this book is available at https://code.google.com/p/opencl-book-samples/ Contents......Page 6 Figures......Page 16 Tables......Page 22 Listings......Page 26 Foreword......Page 30 Preface......Page 34 Acknowledgments.......Page 42 About the Authors......Page 44 Part I: The OpenCL 1.1 Language and API......Page 46 What Is OpenCL, or . . . Why You Need This Book......Page 48 Our Many-Core Future: Heterogeneous Platforms......Page 49 Software in a Many-Core World......Page 52 Conceptual Foundations of OpenCL......Page 56 OpenCL and Graphics......Page 74 The Contents of OpenCL......Page 75 The Embedded Profile......Page 80 Learning OpenCL......Page 81 2. HelloWorld: An OpenCL Example......Page 84 Building the Examples.......Page 85 HelloWorld Example......Page 90 Checking for Errors in OpenCL......Page 102 OpenCL Platforms......Page 108 OpenCL Devices......Page 113 OpenCL Contexts......Page 128 Writing a Data-Parallel Kernel Using OpenCL C......Page 142 Scalar Data Types......Page 144 Vector Data Types......Page 147 Other Data Types......Page 153 Derived Types......Page 154 Implicit Type Conversions......Page 155 Explicit Casts......Page 161 Explicit Conversions......Page 162 Reinterpreting Data as Another Type......Page 166 Vector Operators......Page 168 Qualifiers......Page 178 Preprocessor Directives and Macros......Page 186 Restrictions......Page 191 5. OpenCL C Built-In Functions......Page 194 Work-Item Functions......Page 195 Math Functions......Page 198 Integer Functions......Page 213 Common Functions......Page 217 Relational Functions......Page 220 Vector Data Load and Store Functions......Page 226 Synchronization Functions......Page 235 Async Copy and Prefetch Functions......Page 236 Atomic Functions......Page 240 Miscellaneous Vector Functions......Page 244 Image Read and Write Functions......Page 246 Program and Kernel Object Overview......Page 262 Program Objects......Page 263 Kernel Objects......Page 282 Memory Objects, Buffers, and Sub-Buffers Overview......Page 292 Creating Buffers and Sub-Buffers......Page 294 Querying Buffers and Sub-Buffers......Page 302 Reading, Writing, and Copying Buffers and Sub-Buffers......Page 304 Mapping Buffers and Sub-Buffers......Page 321 Image and Sampler Object Overview......Page 326 Creating Image Objects......Page 328 Creating Sampler Objects......Page 337 OpenCL C Functions for Working with Images......Page 340 Transferring Image Objects......Page 344 Commands, Queues, and Events Overview......Page 354 Events and Command-Queues......Page 356 Event Objects......Page 362 Generating Events on the Host......Page 366 Events Impacting Execution on the Host......Page 367 Using Events for Profiling......Page 372 Events Inside Kernels......Page 377 Events from Outside OpenCL......Page 378 OpenCL/OpenGL Sharing Overview......Page 380 Querying for the OpenGL Sharing Extension......Page 381 Initializing an OpenCL Context for OpenGL Interoperability......Page 383 Creating OpenCL Buffers from OpenGL Buffers......Page 384 Creating OpenCL Image Objects from OpenGL Textures......Page 389 Querying Information about OpenGL Objects......Page 392 Synchronization between OpenGL and OpenCL......Page 393 Direct3D/OpenCL Sharing Overview......Page 398 Initializing an OpenCL Context for Direct3D Interoperability......Page 399 Creating OpenCL Memory Objects from Direct3D Buffers and Textures......Page 402 Acquiring and Releasing Direct3D Objects in OpenCL......Page 406 Processing a Direct3D Texture in OpenCL......Page 408 Processing D3D Vertex Data in OpenCL......Page 411 C++ Wrapper API Overview......Page 414 C++ Wrapper API Exceptions......Page 416 Vector Add Example Using the C++ Wrapper API......Page 419 OpenCL Profile Overview......Page 428 64-Bit Integers......Page 430 Images......Page 431 Mandated Minimum Single-Precision Floating-Point Capabilities......Page 432 Determining the Profile Supported by a Device in an OpenCL C Program......Page 435 Part II: OpenCL 1.1 Case Studies......Page 436 Computing an Image Histogram......Page 438 Parallelizing the Image Histogram......Page 440 Additional Optimizations to the Parallel Image Histogram......Page 445 Computing Histograms with Half-Float or Float Values for Each Channel......Page 448 Implementing the Sobel Filter as an OpenCL Kernel......Page 452 16. Parallelizing Dijkstra’s Single-Source Shortest-Path Graph Algorithm......Page 456 Graph Data Structures......Page 457 Kernels......Page 459 Leveraging Multiple Compute Devices......Page 462 An Introduction to Cloth Simulation......Page 470 Simulating the Soft Body......Page 474 Executing the Simulation on the CPU......Page 476 Changes Necessary for Basic GPU Execution......Page 477 Two-Layered Batching......Page 483 Optimizing for SIMD Computation and Local Memory......Page 486 Adding OpenGL Interoperation......Page 491 18. Simulating the Ocean with Fast Fourier Transform......Page 494 An Overview of the Ocean Application......Page 495 Phillips Spectrum Generation......Page 498 An OpenCL Discrete Fourier Transform......Page 502 A Closer Look at the FFT Kernel......Page 508 A Closer Look at the Transpose Kernel......Page 512 Optical Flow Problem Overview......Page 514 Application of the Texture Cache......Page 525 Using Local Memory......Page 526 Efficient Visualization with OpenGL Interop......Page 528 Performance......Page 529 Introducing PyOpenCL......Page 532 PyImageFilter2D Code......Page 533 Context and Command-Queue Creation......Page 537 Loading to an Image Object......Page 538 Creating and Building a Program......Page 539 Setting Kernel Arguments and Executing a Kernel......Page 540 Reading the Results......Page 541 The Basic Matrix Multiplication Algorithm......Page 544 A Direct Translation into OpenCL......Page 546 Increasing the Amount of Work per Kernel......Page 551 Optimizing Memory Movement: Local Memory......Page 554 Performance Results and Optimizing the Original CPU Code......Page 556 Sparse Matrix-Vector Multiplication (SpMV) Algorithm......Page 560 Description of This Implementation......Page 563 Tiled and Packetized Sparse Matrix Representation......Page 564 Header Structure......Page 567 Tiled and Packetized Sparse Matrix Design Considerations......Page 568 Tested Hardware Devices and Results......Page 569 Additional Areas of Optimization......Page 583 Contexts......Page 586 Querying Platform Information and Devices......Page 587 Command-Queues......Page 588 Read, Write, and Copy Buffer Objects......Page 589 Query Buffer Objects......Page 590 Build Options......Page 591 Create Kernel Objects......Page 592 Execute Kernels......Page 593 Profiling Operations......Page 594 Built-In Scalar Data Types......Page 595 Reserved Data Types......Page 596 Vector Components......Page 597 Vector Addressing Equivalencies......Page 598 Function Qualifiers......Page 599 Specify Type Attributes......Page 600 Math Constants......Page 601 Integer Built-In Functions......Page 602 Common Built-In Functions......Page 604 Math Built-In Functions......Page 605 Geometric Built-In Functions......Page 608 Relational Built-In Functions......Page 609 Vector Data Load/Store Functions......Page 612 Atomic Functions......Page 613 Synchronization, Explicit Memory Fence......Page 615 Miscellaneous Vector Built-In Functions......Page 616 Image Read and Write Built-In Functions......Page 617 Create Image Objects......Page 618 Map and Unmap Image Objects......Page 619 Query Image Objects......Page 620 Sampler Objects......Page 621 OpenCL/OpenGL Sharing APIs......Page 622 Query Information......Page 623 OpenCL/Direct3D 10 Sharing APIs......Page 624 A......Page 626 B......Page 627 C......Page 628 D......Page 633 E......Page 634 F......Page 635 G......Page 636 H......Page 637 I......Page 638 K......Page 639 M......Page 640 O......Page 641 P......Page 643 R......Page 644 S......Page 645 T......Page 646 V......Page 647 Z......Page 648 Using the new OpenCL (Open Computing Language) standard, you can write applications that access all available programming resources: CPUs, GPUs, and other processors such as DSPs and the Cell/B.E. processor. Already implemented by Apple, AMD, Intel, IBM, NVIDIA, and other leaders, OpenCL has outstanding potential for PCs, servers, handheld/embedded devices, high performance computing, and even cloud systems. This is the first comprehensive, authoritative, and practical guide to OpenCL 1.1 specifically for working developers and software architects.

Written by five leading OpenCL authorities, OpenCL Programming Guide covers the entire specification. It reviews key use cases, shows how OpenCL can express a wide range of parallel algorithms, and offers complete reference material on both the API and OpenCL C programming language.

Through complete case studies and downloadable code examples, the authors show how to write complex parallel programs that decompose workloads across many different devices. They also present all the essentials of OpenCL software performance optimization, including probing and adapting to hardware. Coverage includes

  • Understanding OpenCL’s architecture, concepts, terminology, goals, and rationale
  • Programming with OpenCL C and the runtime API
  • Using buffers, sub-buffers, images, samplers, and events
  • Sharing and synchronizing data with OpenGL and Microsoft’s Direct3D
  • Simplifying development with the C++ Wrapper API
  • Using OpenCL Embedded Profiles to support devices ranging from cellphones to supercomputer nodes
  • Case studies dealing with physics simulation; image and signal processing, such as image histograms, edge detection filters, Fast Fourier Transforms, and optical flow; math libraries, such as matrix multiplication and high-performance sparse matrix multiplication; and more
دانلود کتاب راهنمای برنامه‌نویسی OpenCL