ebook img

C++ AMP: Accelerated Massive Parallelism with Microsoft Visual C++ PDF

356 Pages·2012·16.99 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C++ AMP: Accelerated Massive Parallelism with Microsoft Visual C++

www.it-ebooks.info www.it-ebooks.info C++ AMP: Accelerated Massive Parallelism with Microsoft Visual C++ ® ® Kate Gregory Ade Miller www.it-ebooks.info Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2012 by Ade Miller, Gregory Consulting Limited All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-6473-9 1 2 3 4 5 6 7 8 9 LSI 7 6 5 4 3 2 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at [email protected]. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/ Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, O’Reilly Media, Inc., Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Developmental Editor: Russell Jones Production Editor: Holly Bauer Editorial Production: nSight, Inc. Copyeditor: nSight, Inc. Indexer: nSight, Inc. Cover Design: Twist Creative • Seattle Cover Composition: Zyg Group, LLC Illustrator: Rebecca Demarest www.it-ebooks.info Dedicated to Brian, who has always been my secret weapon, and my children, now young adults who think it’s normal for your mum to write books. —Kate GreGory Dedicated to The Susan, who is so much more than I deserve. —ade Miller www.it-ebooks.info www.it-ebooks.info Contents at a Glance Foreword xv Introduction xvii ChAPter 1 Overview and C++ AMP Approach 1 ChAPter 2 NBody Case Study 21 ChAPter 3 C++ AMP Fundamentals 45 ChAPter 4 tiling 63 ChAPter 5 tiled NBody Case Study 83 ChAPter 6 Debugging 101 ChAPter 7 Optimization 127 ChAPter 8 Performance Case Study—reduction 171 ChAPter 9 Working with Multiple Accelerators 203 ChAPter 10 Cartoonizer Case Study 223 ChAPter 11 Graphics Interop 257 ChAPter 12 tips, tricks, and Best Practices 283 APPeNDIx Other resources 309 Index 313 About the Authors 327 www.it-ebooks.info www.it-ebooks.info Contents Foreword .......................................................xv Introduction ....................................................xvii Chapter 1 Overview and C++ AMP Approach 1 Why GPGPU? What Is Heterogeneous Computing? ....................1 History of Performance Improvements .........................1 Heterogeneous Platforms .....................................2 GPU Architecture ............................................4 Candidates for Performance Improvement through Parallelism ...5 Technologies for CPU Parallelism ....................................8 Vectorization ................................................8 OpenMP ...................................................10 Concurrency Runtime (ConcRT) and Parallel Patterns Library .....11 Task Parallel Library .........................................12 WARP—Windows Advanced Rasterization Platform .............12 Technologies for GPU Parallelism .............................13 Requirements for Successful Parallelism .......................14 The C++ AMP Approach ..........................................15 C++ AMP Brings GPGPU (and More) into the Mainstream .......15 C++ AMP Is C++, Not C ......................................16 C++ AMP Leverages Tools You Know ..........................16 C++ AMP Is Almost All Library ...............................17 C++ AMP Makes Portable, Future-Proof Executables ............19 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 Chapter 2 NBody Case Study 21 Prerequisites for Running the Example ..............................21 Running the NBody Sample .......................................22 Structure of the Example .........................................28 vii www.it-ebooks.info CPU Calculations .................................................29 Data Structures .............................................29 The wWinMain Function .....................................30 The OnFrameMove Callback .................................30 The OnD3D11CreateDevice Callback ..........................31 The OnGUIEvent Callback ....................................33 The OnD3D11FrameRender Callback ..........................33 The CPU NBody Classes ...........................................34 NBodySimpleInteractionEngine ...............................34 NBodySimpleSingleCore .....................................35 NBodySimpleMultiCore ......................................35 NBodySimpleInteractionEngine::BodyBodyInteraction ............35 C++ AMP Calculations ............................................36 Data Structures .............................................37 CreateTasks ................................................38 The C++ AMP NBody Classes ......................................40 NBodyAmpSimple::Integrate ..................................40 BodyBodyInteraction ........................................41 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43 Chapter 3 C++ AMP Fundamentals 45 array<T, N> .....................................................45 accelerator and accelerator_view ...................................48 index<N> .......................................................50 extent<N> ......................................................50 array_view<T, N> ................................................ 51 parallel_for_each .................................................55 Functions Marked with restrict(amp) ................................57 Copying between CPU and GPU ...................................59 Math Library Functions ...........................................61 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62 viii Contents www.it-ebooks.info

Description:
Capitalize on the faster GPU processors in today's computers with the C++ AMP code library - and bring massive parallelism to your project. With this practical book, experienced C++ developers will learn parallel programming fundamentals with C++ AMP through detailed examples, code snippets, and cas
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.