1. Trang chủ
  2. » Công Nghệ Thông Tin

1620 OpenCL in action

458 70 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 458
Dung lượng 9,65 MB

Nội dung

How to accelerate graphics and computation IN ACTION Matthew Scarpino MANNING www.it-ebooks.info OpenCL in Action www.it-ebooks.info www.it-ebooks.info OpenCL in Action HOW TO ACCELERATE GRAPHICS AND COMPUTATION MATTHEW SCARPINO MANNING SHELTER ISLAND www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact Special Sales Department Manning Publications Co 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2012 by Manning Publications Co All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine Manning Publications Co 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Development editor: Copyeditor: Proofreader: Typesetter: Cover designer: Maria Townsley Andy Carroll Maureen Spencer Gordan Salinovic Marija Tudor ISBN 9781617290176 Printed in the United States of America 10 – MAL – 16 15 14 13 12 11 www.it-ebooks.info brief contents PART PART FOUNDATIONS OF OPENCL PROGRAMMING 1 ■ Introducing OpenCL ■ Host programming: fundamental data structures ■ Host programming: data transfer and partitioning ■ Kernel programming: data types and device memory ■ Kernel programming: operators and functions 94 ■ Image processing ■ Events, profiling, and synchronization ■ Development with C++ ■ Development with Java and Python 10 ■ General coding principles 16 43 68 123 140 167 196 221 CODING PRACTICAL ALGORITHMS IN OPENCL 235 11 ■ Reduction and sorting 237 12 ■ Matrices and QR decomposition 258 13 ■ Sparse matrices 14 ■ Signal processing and the fast Fourier transform 278 v www.it-ebooks.info 295 vi PART BRIEF CONTENTS ACCELERATING OPENGL WITH OPENCL 319 15 ■ Combining OpenCL and OpenGL 16 ■ Textures and renderbuffers www.it-ebooks.info 340 321 contents preface xv acknowledgments xvii about this book xix PART FOUNDATIONS OF OPENCL PROGRAMMING 1 Introducing OpenCL 1.1 1.2 The dawn of OpenCL Why OpenCL? Portability Standardized vector processing programming ■ 1.3 1.4 1.5 1.6 1.7 ■ Parallel Analogy: OpenCL processing and a game of cards A first look at an OpenCL application 10 The OpenCL standard and extensions 13 Frameworks and software development kits (SDKs) 14 Summary 14 vii www.it-ebooks.info viii CONTENTS Host programming: fundamental data structures 2.1 2.2 16 Primitive data types 17 Accessing platforms 18 Creating platform structures 18 Obtaining platform information 19 Code example: testing platform extensions 20 ■ ■ 2.3 Accessing installed devices 22 Creating device structures 22 Obtaining device information 23 Code example: testing device extensions ■ ■ 2.4 Managing devices with contexts 24 25 Creating contexts 26 Obtaining context information 28 Contexts and the reference count 28 Code example: checking a context’s reference count 29 ■ ■ 2.5 Storing device code in programs 30 Creating programs 30 Building programs 31 Obtaining program information 33 Code example: building a program from multiple source files 35 ■ ■ ■ 2.6 Packaging functions in kernels 36 Creating kernels 36 Obtaining kernel information Code example: obtaining kernel information 38 ■ 2.7 Collecting kernels in a command queue 39 Creating command queues commands 40 2.8 37 Summary 40 ■ Enqueuing kernel execution 41 Host programming: data transfer and partitioning 43 3.1 3.2 Setting kernel arguments Buffer objects 45 Allocating buffer objects 3.3 Image objects 45 Creating subbuffer objects 47 ■ 48 Creating image objects objects 51 3.4 3.5 44 48 ■ Obtaining information about image Obtaining information about buffer objects Memory object transfer commands 54 52 Read/write data transfer 54 Mapping memory objects 58 Copying data between memory objects 59 ■ www.it-ebooks.info ix CONTENTS 3.6 Data partitioning 62 Loops and work-items 63 Work sizes and offsets 64 A simple one-dimensional example 65 Work-groups and compute units 65 ■ ■ ■ 3.7 Summary 67 Kernel programming: data types and device memory 4.1 4.2 Introducing kernel coding Scalar data types 70 69 Accessing the double data type 71 4.3 68 Floating-point computing ■ Byte order 72 73 The float data type 73 The double data type 74 The half data type 75 Checking IEEE-754 compliance 76 ■ ■ ■ 4.4 Vector data types 77 Preferred vector widths 79 Initializing vectors 80 Reading and modifying vector components 80 Endianness and memory access 84 ■ ■ ■ 4.5 The OpenCL device model 85 Device model analogy part 1: math students in school 85 Device model analogy part 2: work-items in a device 87 Address spaces in code 88 Memory alignment 90 ■ ■ ■ 4.6 Local and private kernel arguments Local arguments 4.7 Summary 91 ■ 90 Private arguments 91 93 Kernel programming: operators and functions 5.1 5.2 Operators 95 Work-item and work-group functions Dimensions and work-items example application 100 5.3 Data transfer operations 98 ■ 94 97 Work-groups 99 ■ An 101 Loading and storing data of the same type 101 Loading vectors from a scalar array 101 Storing vectors to a scalar array 102 ■ ■ 5.4 Floating-point functions 103 Arithmetic and rounding functions 103 Comparison functions 105 Exponential and logarithmic functions 106 Trigonometric functions 106 Miscellaneous floating-point functions 108 ■ ■ ■ www.it-ebooks.info .. .OpenCL in Action www.it-ebooks.info www.it-ebooks.info OpenCL in Action HOW TO ACCELERATE GRAPHICS AND COMPUTATION MATTHEW SCARPINO MANNING SHELTER ISLAND www.it-ebooks.info For online information... www.it-ebooks.info www.it-ebooks.info Introducing OpenCL This chapter covers ■ Understanding the purpose and benefits of OpenCL ■ Introducing OpenCL operation: hosts and kernels ■ Implementing an OpenCL. .. texture information information about the OpenGL context 330 15.3 Basic interoperability example 329 ■ Obtaining 331 Initializing OpenGL operation 331 Initializing OpenCL operation 331 Creating data

Ngày đăng: 06/03/2019, 16:10

w