100% found this document useful (1 vote)
57 views56 pages

GPU Parallel Program Development Using CUDA 1st Edition Tolga Soyata PDF Download

The document provides information on GPU Parallel Program Development using CUDA, authored by Tolga Soyata. It includes details about the book's contents, its publication information, and various related titles in the field of computational science. The book aims to educate readers on parallel programming and the use of CUDA for enhancing performance in computing tasks.

Uploaded by

lpoecxhh1344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
57 views56 pages

GPU Parallel Program Development Using CUDA 1st Edition Tolga Soyata PDF Download

The document provides information on GPU Parallel Program Development using CUDA, authored by Tolga Soyata. It includes details about the book's contents, its publication information, and various related titles in the field of computational science. The book aims to educate readers on parallel programming and the use of CUDA for enhancing performance in computing tasks.

Uploaded by

lpoecxhh1344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

GPU Parallel Program Development Using CUDA 1st

Edition Tolga Soyata pdf download

https://textbookfull.com/product/gpu-parallel-program-
development-using-cuda-1st-edition-tolga-soyata/

Download more ebook instantly today - get yours now at textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Comprehensive Healthcare Simulation Program Center


Development 1st Edition Michael A. Seropian

https://textbookfull.com/product/comprehensive-healthcare-
simulation-program-center-development-1st-edition-michael-a-
seropian/

Cybersecurity Program Development for Business: The


Essential Planning Guide 1st Edition Chris Moschovitis

https://textbookfull.com/product/cybersecurity-program-
development-for-business-the-essential-planning-guide-1st-
edition-chris-moschovitis/

Freight transport and distribution : concepts and


optimisation models Tolga Bektas

https://textbookfull.com/product/freight-transport-and-
distribution-concepts-and-optimisation-models-tolga-bektas/

GPU Pro 360 Guide to Geometry Manipulation 1st Edition


Wolfgang Engel

https://textbookfull.com/product/gpu-pro-360-guide-to-geometry-
manipulation-1st-edition-wolfgang-engel/
GPU Pro 360 Guide to Mobile Devices 1st Edition
Wolfgang Engel

https://textbookfull.com/product/gpu-pro-360-guide-to-mobile-
devices-1st-edition-wolfgang-engel/

GPU PRO 360: Guide to GPGPU 1st Edition Wolfgang Engel


(Editor)

https://textbookfull.com/product/gpu-pro-360-guide-to-gpgpu-1st-
edition-wolfgang-engel-editor/

Data Parallel C++ Mastering DPC++ for Programming of


Heterogeneous Systems using C++ and SYCL 1st Edition
James Reinders

https://textbookfull.com/product/data-parallel-c-mastering-dpc-
for-programming-of-heterogeneous-systems-using-c-and-sycl-1st-
edition-james-reinders/

GPU Zen Advanced Rendering Techniques Wolfgang Engel


(Editor)

https://textbookfull.com/product/gpu-zen-advanced-rendering-
techniques-wolfgang-engel-editor/

GPU Pro 360 Guide to Image Space 1st Edition Wolfgang


Engel (Author)

https://textbookfull.com/product/gpu-pro-360-guide-to-image-
space-1st-edition-wolfgang-engel-author/
GPU Parallel Program
Development Using CUDA
Chapman & Hall/CRC
Computational Science Series
SERIES EDITOR

Horst Simon
Deputy Director
Lawrence Berkeley National Laboratory
Berkeley, California, U.S.A.

PUBLISHED TITLES

COMBINATORIAL SCIENTIFIC COMPUTING


Edited by Uwe Naumann and Olaf Schenk
CONTEMPORARY HIGH PERFORMANCE COMPUTING: FROM PETASCALE
TOWARD EXASCALE
Edited by Jeffrey S. Vetter
CONTEMPORARY HIGH PERFORMANCE COMPUTING: FROM PETASCALE
TOWARD EXASCALE, VOLUME TWO
Edited by Jeffrey S. Vetter
DATA-INTENSIVE SCIENCE
Edited by Terence Critchlow and Kerstin Kleese van Dam
ELEMENTS OF PARALLEL COMPUTING
Eric Aubanel
THE END OF ERROR: UNUM COMPUTING
John L. Gustafson
EXASCALE SCIENTIFIC APPLICATIONS: SCALABILITY AND
PERFORMANCE PORTABILITY
Edited by Tjerk P. Straatsma, Katerina B. Antypas, and Timothy J. Williams
FROM ACTION SYSTEMS TO DISTRIBUTED SYSTEMS: THE REFINEMENT APPROACH
Edited by Luigia Petre and Emil Sekerinski
FUNDAMENTALS OF MULTICORE SOFTWARE DEVELOPMENT
Edited by Victor Pankratius, Ali-Reza Adl-Tabatabai, and Walter Tichy
FUNDAMENTALS OF PARALLEL MULTICORE ARCHITECTURE
Yan Solihin
THE GREEN COMPUTING BOOK: TACKLING ENERGY EFFICIENCY AT LARGE SCALE
Edited by Wu-chun Feng
GRID COMPUTING: TECHNIQUES AND APPLICATIONS
Barry Wilkinson
GPU PARALLEL PROGRAM DEVELOPMENT USING CUDA
Tolga Soyata
PUBLISHED TITLES CONTINUED

HIGH PERFORMANCE COMPUTING: PROGRAMMING AND APPLICATIONS


John Levesque with Gene Wagenbreth
HIGH PERFORMANCE PARALLEL I/O
Prabhat and Quincey Koziol
HIGH PERFORMANCE VISUALIZATION:
ENABLING EXTREME-SCALE SCIENTIFIC INSIGHT
Edited by E. Wes Bethel, Hank Childs, and Charles Hansen
INDUSTRIAL APPLICATIONS OF HIGH-PERFORMANCE COMPUTING:
BEST GLOBAL PRACTICES
Edited by Anwar Osseyran and Merle Giles
INTRODUCTION TO COMPUTATIONAL MODELING USING C AND
OPEN-SOURCE TOOLS
José M Garrido
INTRODUCTION TO CONCURRENCY IN PROGRAMMING LANGUAGES
Matthew J. Sottile, Timothy G. Mattson, and Craig E Rasmussen
INTRODUCTION TO ELEMENTARY COMPUTATIONAL MODELING: ESSENTIAL
CONCEPTS, PRINCIPLES, AND PROBLEM SOLVING
José M. Garrido
INTRODUCTION TO HIGH PERFORMANCE COMPUTING FOR SCIENTISTS
AND ENGINEERS
Georg Hager and Gerhard Wellein
INTRODUCTION TO MODELING AND SIMULATION WITH MATLAB® AND PYTHON
Steven I. Gordon and Brian Guilfoos
INTRODUCTION TO REVERSIBLE COMPUTING
Kalyan S. Perumalla
INTRODUCTION TO SCHEDULING
Yves Robert and Frédéric Vivien
INTRODUCTION TO THE SIMULATION OF DYNAMICS USING SIMULINK®
Michael A. Gray
PEER-TO-PEER COMPUTING: APPLICATIONS, ARCHITECTURE, PROTOCOLS,
AND CHALLENGES
Yu-Kwong Ricky Kwok
PERFORMANCE TUNING OF SCIENTIFIC APPLICATIONS
Edited by David Bailey, Robert Lucas, and Samuel Williams
PETASCALE COMPUTING: ALGORITHMS AND APPLICATIONS
Edited by David A. Bader
PROCESS ALGEBRA FOR PARALLEL AND DISTRIBUTED PROCESSING
Edited by Michael Alexander and William Gardner
PUBLISHED TITLES CONTINUED

PROGRAMMING FOR HYBRID MULTI/MANY-CORE MPP SYSTEMS


John Levesque and Aaron Vose
SCIENTIFIC DATA MANAGEMENT: CHALLENGES, TECHNOLOGY, AND DEPLOYMENT
Edited by Arie Shoshani and Doron Rotem
SOFTWARE ENGINEERING FOR SCIENCE
Edited by Jeffrey C. Carver, Neil P. Chue Hong, and George K. Thiruvathukal
GPU Parallel Program
Development Using CUDA

Tolga Soyata
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742

© 2018 by Taylor & Francis Group, LLC


CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed on acid-free paper

International Standard Book Number-13: 978-1-4987-5075-2 (Hardback)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts
have been made to publish reliable data and information, but the author and publisher cannot assume
responsibility for the validity of all materials or the consequences of their use. The authors and publishers
have attempted to trace the copyright holders of all material reproduced in this publication and apologize
to copyright holders if permission to publish in this form has not been obtained. If any copyright material
has not been acknowledged please write and let us know so we may rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, trans-
mitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter
invented, including photocopying, microfilming, and recording, or in any information storage or retrieval
system, without written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com
(http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive,
Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and regis-
tration for a variety of users. For organizations that have been granted a photocopy license by the CCC,
a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are
used only for identification and explanation without intent to infringe.
——————————————————————————————————————————————–
Library of Congress Cataloging-in-Publication Data
——————————————————————————————————————————————–
Names: Soyata, Tolga, 1967- author.
Title: GPU parallel program development using CUDA
/ by Tolga Soyata.
Description: Boca Raton, Florida : CRC Press, [2018] | Includes bibliographical
references and index.
Identifiers: LCCN 2017043292 | ISBN 9781498750752 (hardback) |
ISBN 9781315368290 (e-book)
Subjects: LCSH: Parallel programming (Computer science) | CUDA (Computer architecture) |
Graphics processing units–Programming.
Classification: LCC QA76.642.S67 2018 | DDC 005.2/75–dc23
LC record available at https://lccn.loc.gov/2017043292
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com

and the CRC Press Web site at


http://www.crcpress.com
To my wife Eileen
and my step-children Katherine, Andrew, and Eric.
Contents

List of Figures xxiii


List of Tables xxix
Preface xxxiii
About the Author xxxv

Part I Understanding CPU Parallelism


Chapter 1  Introduction to CPU Parallel Programming 3

1.1 EVOLUTION OF PARALLEL PROGRAMMING 3


1.2 MORE CORES, MORE PARALLELISM 4
1.3 CORES VERSUS THREADS 5
1.3.1 More Threads or More Cores to Parallelize? 5
1.3.2 Influence of Core Resource Sharing 7
1.3.3 Influence of Memory Resource Sharing 7
1.4 OUR FIRST SERIAL PROGRAM 8
1.4.1 Understanding Data Transfer Speeds 8
1.4.2 The main() Function in imflip.c 10
1.4.3 Flipping Rows Vertically: FlipImageV() 11
1.4.4 Flipping Columns Horizontally: FlipImageH() 12
1.5 WRITING, COMPILING, RUNNING OUR PROGRAMS 13
1.5.1 Choosing an Editor and a Compiler 13
1.5.2 Developing in Windows 7, 8, and Windows 10
Platforms 13
1.5.3 Developing in a Mac Platform 15
1.5.4 Developing in a Unix Platform 15
1.6 CRASH COURSE ON UNIX 15
1.6.1 Unix Directory-Related Commands 15
1.6.2 Unix File-Related Commands 16
1.7 DEBUGGING YOUR PROGRAMS 19
1.7.1 gdb 20
1.7.2 Old School Debugging 21
1.7.3 valgrind 22

ix
x  Contents

1.8 PERFORMANCE OF OUR FIRST SERIAL PROGRAM 23


1.8.1 Can We Estimate the Execution Time? 24
1.8.2 What Does the OS Do When Our Code Is
Executing? 24
1.8.3 How Do We Parallelize It? 25
1.8.4 Thinking About the Resources 25

Chapter 2  Developing Our First Parallel CPU Program 27

2.1 OUR FIRST PARALLEL PROGRAM 27


2.1.1 The main() Function in imflipP.c 28
2.1.2 Timing the Execution 29
2.1.3 Split Code Listing for main() in imflipP.c 29
2.1.4 Thread Initialization 32
2.1.5 Thread Creation 32
2.1.6 Thread Launch/Execution 34
2.1.7 Thread Termination (Join) 35
2.1.8 Thread Task and Data Splitting 35
2.2 WORKING WITH BITMAP (BMP) FILES 37
2.2.1 BMP is a Non-Lossy/Uncompressed File
Format 37
2.2.2 BMP Image File Format 38
2.2.3 Header File ImageStuff.h 39
2.2.4 Image Manipulation Routines in ImageStuff.c 40
2.3 TASK EXECUTION BY THREADS 42
2.3.1 Launching a Thread 43
2.3.2 Multithreaded Vertical Flip: MTFlipV() 45
2.3.3 Comparing FlipImageV() and MTFlipV() 48
2.3.4 Multithreaded Horizontal Flip: MTFlipH() 50
2.4 TESTING/TIMING THE MULTITHREADED CODE 51

Chapter 3  Improving Our First Parallel CPU Program 53

3.1 EFFECT OF THE “PROGRAMMER” ON PERFORMANCE 53


3.2 EFFECT OF THE “CPU” ON PERFORMANCE 54
3.2.1 In-Order versus Out-Of-Order Cores 55
3.2.2 Thin versus Thick Threads 57
3.3 PERFORMANCE OF IMFLIPP 57
3.4 EFFECT OF THE “OS” ON PERFORMANCE 58
3.4.1 Thread Creation 59
3.4.2 Thread Launch and Execution 59
3.4.3 Thread Status 60
Contents  xi

3.4.4 Mapping Software Threads to Hardware Threads 61


3.4.5 Program Performance versus Launched Pthreads 62
3.5 IMPROVING IMFLIPP 63
3.5.1 Analyzing Memory Access Patterns in MTFlipH() 64
3.5.2 Multithreaded Memory Access of MTFlipH() 64
3.5.3 DRAM Access Rules of Thumb 66
3.6 IMFLIPPM: OBEYING DRAM RULES OF THUMB 67
3.6.1 Chaotic Memory Access Patterns of imflipP 67
3.6.2 Improving Memory Access Patterns of imflipP 68
3.6.3 MTFlipHM(): The Memory Friendly MTFlipH() 69
3.6.4 MTFlipVM(): The Memory Friendly MTFlipV() 71
3.7 PERFORMANCE OF IMFLIPPM.C 72
3.7.1 Comparing Performances of imflipP.c and imflipPM.c 72
3.7.2 Speed Improvement: MTFlipV() versus MTFlipVM() 73
3.7.3 Speed Improvement: MTFlipH() versus MTFlipHM() 73
3.7.4 Understanding the Speedup: MTFlipH() versus MTFlipHM() 73
3.8 PROCESS MEMORY MAP 74
3.9 INTEL MIC ARCHITECTURE: XEON PHI 76
3.10 WHAT ABOUT THE GPU? 77
3.11 CHAPTER SUMMARY 78

Chapter 4  Understanding the Cores and Memory 79

4.1 ONCE UPON A TIME ... INTEL ... 79


4.2 CPU AND MEMORY MANUFACTURERS 80
4.3 DYNAMIC (DRAM) VERSUS STATIC (SRAM) MEMORY 81
4.3.1 Static Random Access Memory (SRAM) 81
4.3.2 Dynamic Random Access Memory (DRAM) 81
4.3.3 DRAM Interface Standards 81
4.3.4 Influence of DRAM on our Program Performance 82
4.3.5 Influence of SRAM (Cache) on our Program
Performance 83
4.4 IMAGE ROTATION PROGRAM: IMROTATE.C 83
4.4.1 Description of the imrotate.c 84
4.4.2 imrotate.c: Parametric Restrictions and
Simplifications 84
4.4.3 imrotate.c: Theory of Operation 85
4.5 PERFORMANCE OF IMROTATE 89
4.5.1 Qualitative Analysis of Threading Efficiency 89
4.5.2 Quantitative Analysis: Defining Threading
Efficiency 89
xii  Contents

4.6 THE ARCHITECTURE OF THE COMPUTER 91


4.6.1 The Cores, L1$ and L2$ 91
4.6.2 Internal Core Resources 92
4.6.3 The Shared L3 Cache Memory (L3$) 94
4.6.4 The Memory Controller 94
4.6.5 The Main Memory 95
4.6.6 Queue, Uncore, and I/O 96
4.7 IMROTATEMC: MAKING IMROTATE MORE EFFICIENT 97
4.7.1 Rotate2(): How Bad is Square Root and FP Division? 99
4.7.2 Rotate3() and Rotate4(): How Bad Is sin() and cos()? 100
4.7.3 Rotate5(): How Bad Is Integer Division/Multiplication? 102
4.7.4 Rotate6(): Consolidating Computations 102
4.7.5 Rotate7(): Consolidating More Computations 104
4.7.6 Overall Performance of imrotateMC 104
4.8 CHAPTER SUMMARY 106

Chapter 5  Thread Management and Synchronization 107

5.1 EDGE DETECTION PROGRAM: IMEDGE.C 107


5.1.1 Description of the imedge.c 108
5.1.2 imedge.c: Parametric Restrictions and
Simplifications 108
5.1.3 imedge.c: Theory of Operation 109
5.2 IMEDGE.C : IMPLEMENTATION 111
5.2.1 Initialization and Time-Stamping 112
5.2.2 Initialization Functions for Different Image
Representations 113
5.2.3 Launching and Terminating Threads 114
5.2.4 Gaussian Filter 115
5.2.5 Sobel 116
5.2.6 Threshold 117
5.3 PERFORMANCE OF IMEDGE 118
5.4 IMEDGEMC: MAKING IMEDGE MORE EFFICIENT 118
5.4.1 Using Precomputation to Reduce Bandwidth 119
5.4.2 Storing the Precomputed Pixel Values 120
5.4.3 Precomputing Pixel Values 121
5.4.4 Reading the Image and Precomputing Pixel
Values 122
5.4.5 PrGaussianFilter 123
5.4.6 PrSobel 124
5.4.7 PrThreshold 125
5.5 PERFORMANCE OF IMEDGEMC 126
Contents  xiii

5.6 IMEDGEMCT: SYNCHRONIZING THREADS EFFICIENTLY 127


5.6.1 Barrier Synchronization 128
5.6.2 MUTEX Structure for Data Sharing 129
5.7 IMEDGEMCT: IMPLEMENTATION 130
5.7.1 Using a MUTEX: Read Image, Precompute 132
5.7.2 Precomputing One Row at a Time 133
5.8 PERFORMANCE OF IMEDGEMCT 134

Part II GPU Programming Using CUDA


Chapter 6  Introduction to GPU Parallelism and CUDA 137

6.1 ONCE UPON A TIME ... NVIDIA ... 137


6.1.1 The Birth of the GPU 137
6.1.2 Early GPU Architectures 138
6.1.3 The Birth of the GPGPU 140
6.1.4 Nvidia, ATI Technologies, and Intel 141
6.2 COMPUTE-UNIFIED DEVICE ARCHITECTURE (CUDA) 143
6.2.1 CUDA, OpenCL, and Other GPU Languages 143
6.2.2 Device Side versus Host Side Code 143
6.3 UNDERSTANDING GPU PARALLELISM 144
6.3.1 How Does the GPU Achieve High Performance? 145
6.3.2 CPU versus GPU Architectural Differences 146
6.4 CUDA VERSION OF THE IMAGE FLIPPER: IMFLIPG.CU 147
6.4.1 imflipG.cu: Read the Image into a CPU-Side Array 149
6.4.2 Initialize and Query the GPUs 151
6.4.3 GPU-Side Time-Stamping 153
6.4.4 GPU-Side Memory Allocation 155
6.4.5 GPU Drivers and Nvidia Runtime Engine 155
6.4.6 CPU→GPU Data Transfer 156
6.4.7 Error Reporting Using Wrapper Functions 157
6.4.8 GPU Kernel Execution 157
6.4.9 Finish Executing the GPU Kernel 160
6.4.10 Transfer GPU Results Back to the CPU 161
6.4.11 Complete Time-Stamping 161
6.4.12 Report the Results and Cleanup 162
6.4.13 Reading and Writing the BMP File 163
6.4.14 Vflip(): The GPU Kernel for Vertical Flipping 164
6.4.15 What Is My Thread ID, Block ID, and Block Dimension? 166
6.4.16 Hflip(): The GPU Kernel for Horizontal Flipping 169
xiv  Contents

6.4.17 Hardware Parameters: threadIDx.x, blockIdx.x,


blockDim.x 169
6.4.18 PixCopy(): The GPU Kernel for Copying an Image 169
6.4.19 CUDA Keywords 170
6.5 CUDA PROGRAM DEVELOPMENT IN WINDOWS 170
6.5.1 Installing MS Visual Studio 2015 and CUDA Toolkit 8.0 171
6.5.2 Creating Project imflipG.cu in Visual Studio 2015 172
6.5.3 Compiling Project imflipG.cu in Visual Studio 2015 174
6.5.4 Running Our First CUDA Application: imflipG.exe 177
6.5.5 Ensuring Your Program’s Correctness 178
6.6 CUDA PROGRAM DEVELOPMENT ON A MAC PLATFORM 179
6.6.1 Installing XCode on Your Mac 179
6.6.2 Installing the CUDA Driver and CUDA Toolkit 180
6.6.3 Compiling and Running CUDA Applications on a Mac 180
6.7 CUDA PROGRAM DEVELOPMENT IN A UNIX PLATFORM 181
6.7.1 Installing Eclipse and CUDA Toolkit 181
6.7.2 ssh into a Cluster 182
6.7.3 Compiling and Executing Your CUDA Code 182

Chapter 7  CUDA Host/Device Programming Model 185

7.1 DESIGNING YOUR PROGRAM’S PARALLELISM 185


7.1.1 Conceptually Parallelizing a Task 186
7.1.2 What Is a Good Block Size for Vflip()? 187
7.1.3 imflipG.cu: Interpreting the Program Output 187
7.1.4 imflipG.cu: Performance Impact of Block and
Image Size 188
7.2 KERNEL LAUNCH COMPONENTS 189
7.2.1 Grids 189
7.2.2 Blocks 190
7.2.3 Threads 191
7.2.4 Warps and Lanes 192
7.3 IMFLIPG.CU: UNDERSTANDING THE KERNEL DETAILS 193
7.3.1 Launching Kernels in main() and Passing Arguments
to Them 193
7.3.2 Thread Execution Steps 194
7.3.3 Vflip() Kernel Details 195
7.3.4 Comparing Vflip() and MTFlipV() 196
7.3.5 Hflip() Kernel Details 197
7.3.6 PixCopy() Kernel Details 197
7.4 DEPENDENCE OF PCI EXPRESS SPEED ON THE CPU 199
Contents  xv

7.5 PERFORMANCE IMPACT OF PCI EXPRESS BUS 200


7.5.1 Data Transfer Time, Speed, Latency, Throughput, and
Bandwidth 200
7.5.2 PCIe Throughput Achieved with imflipG.cu 201
7.6 PERFORMANCE IMPACT OF GLOBAL MEMORY BUS 204
7.7 PERFORMANCE IMPACT OF COMPUTE CAPABILITY 206
7.7.1 Fermi, Kepler, Maxwell, Pascal, and Volta Families 207
7.7.2 Relative Bandwidth Achieved in Different Families 207
7.7.3 imflipG2.cu: Compute Capability 2.0 Version of imflipG.cu 208
7.7.4 imflipG2.cu: Changes in main() 210
7.7.5 The PxCC20() Kernel 211
7.7.6 The VfCC20() Kernel 212
7.8 PERFORMANCE OF IMFLIPG2.CU 214
7.9 OLD-SCHOOL CUDA DEBUGGING 214
7.9.1 Common CUDA Bugs 216
7.9.2 return Debugging 218
7.9.3 Comment-Based Debugging 220
7.9.4 printf() Debugging 220
7.10 BIOLOGICAL REASONS FOR SOFTWARE BUGS 221
7.10.1 How Is Our Brain Involved in Writing/Debugging Code? 222
7.10.2 Do We Write Buggy Code When We Are Tired? 222
7.10.2.1 Attention 223
7.10.2.2 Physical Tiredness 223
7.10.2.3 Tiredness Due to Heavy Physical Activity 223
7.10.2.4 Tiredness Due to Needing Sleep 223
7.10.2.5 Mental Tiredness 224

Chapter 8  Understanding GPU Hardware Architecture 225

8.1 GPU HARDWARE ARCHITECTURE 226


8.2 GPU HARDWARE COMPONENTS 226
8.2.1 SM: Streaming Multiprocessor 226
8.2.2 GPU Cores 227
8.2.3 Giga-Thread Scheduler 227
8.2.4 Memory Controllers 229
8.2.5 Shared Cache Memory (L2$) 229
8.2.6 Host Interface 229
8.3 NVIDIA GPU ARCHITECTURES 230
8.3.1 Fermi Architecture 231
8.3.2 GT, GTX, and Compute Accelerators 231
8.3.3 Kepler Architecture 232
xvi  Contents

8.3.4 Maxwell Architecture 232


8.3.5 Pascal Architecture and NVLink 233
8.4 CUDA EDGE DETECTION: IMEDGEG.CU 233
8.4.1 Variables to Store the Image in CPU, GPU Memory 233
8.4.1.1 TheImage and CopyImage 233
8.4.1.2 GPUImg 234
8.4.1.3 GPUBWImg 234
8.4.1.4 GPUGaussImg 234
8.4.1.5 GPUGradient and GPUTheta 234
8.4.1.6 GPUResultImg 235
8.4.2 Allocating Memory for the GPU Variables 235
8.4.3 Calling the Kernels and Time-Stamping Their Execution 238
8.4.4 Computing the Kernel Performance 239
8.4.5 Computing the Amount of Kernel Data Movement 239
8.4.6 Reporting the Kernel Performance 242
8.5 IMEDGEG: KERNELS 242
8.5.1 BWKernel() 242
8.5.2 GaussKernel() 244
8.5.3 SobelKernel() 246
8.5.4 ThresholdKernel() 249
8.6 PERFORMANCE OF IMEDGEG.CU 249
8.6.1 imedgeG.cu: PCIe Bus Utilization 250
8.6.2 imedgeG.cu: Runtime Results 250
8.6.3 imedgeG.cu: Kernel Performance Comparison 252
8.7 GPU CODE: COMPILE TIME 253
8.7.1 Designing CUDA Code 253
8.7.2 Compiling CUDA Code 255
8.7.3 GPU Assembly: PTX, CUBIN 255
8.8 GPU CODE: LAUNCH 255
8.8.1 OS Involvement and CUDA DLL File 255
8.8.2 GPU Graphics Driver 256
8.8.3 CPU←→GPU Memory Transfers 256
8.9 GPU CODE: EXECUTION (RUN TIME) 257
8.9.1 Getting the Data 257
8.9.2 Getting the Code and Parameters 257
8.9.3 Launching Grids of Blocks 258
8.9.4 Giga Thread Scheduler (GTS) 258
8.9.5 Scheduling Blocks 259
8.9.6 Executing Blocks 260
8.9.7 Transparent Scalability 261
Contents  xvii

Chapter 9  Understanding GPU Cores 263

9.1 GPU ARCHITECTURE FAMILIES 263


9.1.1 Fermi Architecture 263
9.1.2 Fermi SM Structure 264
9.1.3 Kepler Architecture 266
9.1.4 Kepler SMX Structure 267
9.1.5 Maxwell Architecture 268
9.1.6 Maxwell SMM Structure 268
9.1.7 Pascal GP100 Architecture 270
9.1.8 Pascal GP100 SM Structure 271
9.1.9 Family Comparison: Peak GFLOPS and Peak DGFLOPS 272
9.1.10 GPU Boost 273
9.1.11 GPU Power Consumption 274
9.1.12 Computer Power Supply 274
9.2 STREAMING MULTIPROCESSOR (SM) BUILDING BLOCKS 275
9.2.1 GPU Cores 275
9.2.2 Double Precision Units (DPU) 276
9.2.3 Special Function Units (SFU) 276
9.2.4 Register File (RF) 276
9.2.5 Load/Store Queues (LDST) 277
9.2.6 L1$ and Texture Cache 277
9.2.7 Shared Memory 278
9.2.8 Constant Cache 278
9.2.9 Instruction Cache 278
9.2.10 Instruction Buffer 278
9.2.11 Warp Schedulers 278
9.2.12 Dispatch Units 279
9.3 PARALLEL THREAD EXECUTION (PTX) DATA TYPES 279
9.3.1 INT8 : 8-bit Integer 280
9.3.2 INT16 : 16-bit Integer 280
9.3.3 24-bit Integer 280
9.3.4 INT32 : 32-bit Integer 281
9.3.5 Predicate Registers (32-bit) 281
9.3.6 INT64 : 64-bit Integer 282
9.3.7 128-bit Integer 282
9.3.8 FP32: Single Precision Floating Point (float) 282
9.3.9 FP64: Double Precision Floating Point (double) 283
9.3.10 FP16: Half Precision Floating Point (half) 284
9.3.11 What is a FLOP? 284
xviii  Contents

9.3.12 Fused Multiply-Accumulate (FMA) versus Multiply-Add


(MAD) 285
9.3.13 Quad and Octo Precision Floating Point 285
9.3.14 Pascal GP104 Engine SM Structure 285
9.4 IMFLIPGC.CU: CORE-FRIENDLY IMFLIPG 286
9.4.1 Hflip2(): Precomputing Kernel Parameters 288
9.4.2 Vflip2(): Precomputing Kernel Parameters 290
9.4.3 Computing Image Coordinates by a Thread 290
9.4.4 Block ID versus Image Row Mapping 291
9.4.5 Hflip3(): Using a 2D Launch Grid 292
9.4.6 Vflip3(): Using a 2D Launch Grid 293
9.4.7 Hflip4(): Computing Two Consecutive Pixels 294
9.4.8 Vflip4(): Computing Two Consecutive Pixels 295
9.4.9 Hflip5(): Computing Four Consecutive Pixels 296
9.4.10 Vflip5(): Computing Four Consecutive Pixels 297
9.4.11 PixCopy2(), PixCopy3(): Copying 2,4 Consecutive Pixels at
a Time 298
9.5 IMEDGEGC.CU: CORE-FRIENDLY IMEDGEG 299
9.5.1 BWKernel2(): Using Precomputed Values and 2D Blocks 299
9.5.2 GaussKernel2(): Using Precomputed Values and 2D Blocks 300

Chapter 10  Understanding GPU Memory 303

10.1 GLOBAL MEMORY 303


10.2 L2 CACHE 304
10.3 TEXTURE/L1 CACHE 304
10.4 SHARED MEMORY 305
10.4.1 Split versus Dedicated Shared Memory 305
10.4.2 Memory Resources Available Per Core 306
10.4.3 Using Shared Memory as Software Cache 306
10.4.4 Allocating Shared Memory in an SM 307
10.5 INSTRUCTION CACHE 307
10.6 CONSTANT MEMORY 307
10.7 IMFLIPGCM.CU: CORE AND MEMORY FRIENDLY IMFLIPG 308
10.7.1 Hflip6(),Vflip6(): Using Shared Memory as Buffer 308
10.7.2 Hflip7(): Consecutive Swap Operations in Shared Memory 310
10.7.3 Hflip8(): Using Registers to Swap Four Pixels 312
10.7.4 Vflip7(): Copying 4 Bytes (int) at a Time 314
10.7.5 Aligned versus Unaligned Data Access in Memory 314
10.7.6 Vflip8(): Copying 8 Bytes at a Time 315
10.7.7 Vflip9(): Using Only Global Memory, 8 Bytes at a Time 316
List of Figures

1.1 Harvesting each coconut requires two consecutive 30-second tasks (threads).
Thread 1: get a coconut. Thread 2: crack (process) that coconut using the
hammer. 4
1.2 Simultaneously executing Thread 1 (“1”) and Thread 2 (“2”). Accessing
shared resources will cause a thread to wait (“-”). 6
1.3 Serial (single-threaded) program imflip.c flips a 640×480 dog picture (left)
horizontally (middle) or vertically (right). 8
1.4 Running gdb to catch a segmentation fault. 20
1.5 Running valgrind to catch a memory access error. 23

2.1 Windows Task Manager, showing 1499 threads, however, there is 0% CPU
utilization. 33

3.1 The life cycle of a thread. From the creation to its termination, a thread is
cycled through many different statuses, assigned by the OS. 60
3.2 Memory access patterns of MTFlipH() in Code 2.8. A total of 3200 pixels’
RGB values (9600 Bytes) are flipped for each row. 65
3.3 The memory map of a process when only a single thread is running within
the process (left) or multiple threads are running in it (right). 75

4.1 Inside a computer containing an i7-5930K CPU [10] (CPU5 in Table 3.1),
and 64 GB of DDR4 memory. This PC has a GTX Titan Z GPU that will
be used to test a lot of the programs in Part II. 80
4.2 The imrotate.c program rotates a picture by a specified angle. Original dog
(top left), rotated +10◦ (top right), +45◦ (bottom left), and −75◦ (bottom
right) clockwise. Scaling is done to avoid cropping of the original image area. 84
4.3 The architecture of one core of the i7-5930K CPU (the PC in Figure 4.1).
This core is capable of executing two threads (hyper-threading, as defined
by Intel). These two threads share most of the core resources, but have their
own register files. 92
4.4 Architecture of the i7-5930K CPU (6C/12T). This CPU connects to the
GPUs through an external PCI express bus and memory through the mem-
ory bus. 94

5.1 The imedge.c program is used to detect edges in the original image
astronaut.bmp (top left). Intermediate processing steps are: GaussianFilter()
(top right), Sobel() (bottom left), and finally Threshold() (bottom right). 108

xxiii
Contents  xix

10.7.8 PixCopy4(), PixCopy5(): Copying One versus 4 Bytes Using


Shared Memory 317
10.7.9 PixCopy6(), PixCopy7(): Copying One/Two Integers Using
Global Memory 318
10.8 IMEDGEGCM.CU: CORE- & MEMORY-FRIENDLY IMEDGEG 319
10.8.1 BWKernel3(): Using Byte Manipulation to Extract RGB 319
10.8.2 GaussKernel3(): Using Constant Memory 321
10.8.3 Ways to Handle Constant Values 321
10.8.4 GaussKernel4(): Buffering Neighbors of 1 Pixel in Shared
Memory 323
10.8.5 GaussKernel5(): Buffering Neighbors of 4 Pixels in Shared
Memory 325
10.8.6 GaussKernel6(): Reading 5 Vertical Pixels into Shared
Memory 327
10.8.7 GaussKernel7(): Eliminating the Need to Account for Edge
Pixels 329
10.8.8 GaussKernel8(): Computing 8 Vertical Pixels 331
10.9 CUDA OCCUPANCY CALCULATOR 333
10.9.1 Choosing the Optimum Threads/Block 334
10.9.2 SM-Level Resource Limitations 335
10.9.3 What is “Occupancy”? 336
10.9.4 CUDA Occupancy Calculator: Resource
Computation 336
10.9.5 Case Study: GaussKernel7() 340
10.9.6 Case Study: GaussKernel8() 343

Chapter 11  CUDA Streams 345

11.1 WHAT IS PIPELINING? 347


11.1.1 Execution Overlapping 347
11.1.2 Exposed versus Coalesced Runtime 348
11.2 MEMORY ALLOCATION 349
11.2.1 Physical versus Virtual Memory 349
11.2.2 Physical to Virtual Address Translation 350
11.2.3 Pinned Memory 350
11.2.4 Allocating Pinned Memory with cudaMallocHost() 351
11.3 FAST CPU←→GPU DATA TRANSFERS 351
11.3.1 Synchronous Data Transfers 351
11.3.2 Asynchronous Data Transfers 351
11.4 CUDA STREAMS 352
11.4.1 CPU→GPU Transfer, Kernel Exec, GPU→CPUTransfer 352
11.4.2 Implementing Streaming in CUDA 353
xx  Contents

11.4.3 Copy Engine 353


11.4.4 Kernel Execution Engine 353
11.4.5 Concurrent Upstream and Downstream PCIe
Transfers 354
11.4.6 Creating CUDA Streams 355
11.4.7 Destroying CUDA Streams 355
11.4.8 Synchronizing CUDA Streams 355
11.5 IMGSTR.CU: STREAMING IMAGE PROCESSING 356
11.5.1 Reading the Image into Pinned Memory 356
11.5.2 Synchronous versus Single Stream 358
11.5.3 Multiple Streams 359
11.5.4 Data Dependence Across Multiple Streams 361
11.5.4.1 Horizontal Flip: No Data Dependence 362
11.5.4.2 Edge Detection: Data Dependence 363
11.5.4.3 Preprocessing Overlapping Rows Synchronously 363
11.5.4.4 Asynchronous Processing the Non-Overlapping
Rows 364
11.6 STREAMING HORIZONTAL FLIP KERNEL 366
11.7 IMGSTR.CU: STREAMING EDGE DETECTION 367
11.8 PERFORMANCE COMPARISON: IMGSTR.CU 371
11.8.1 Synchronous versus Asynchronous Results 371
11.8.2 Randomness in the Results 372
11.8.3 Optimum Queuing 372
11.8.4 Best Case Streaming Results 373
11.8.5 Worst Case Streaming Results 374
11.9 NVIDIA VISUAL PROFILER: NVVP 375
11.9.1 Installing nvvp and nvprof 375
11.9.2 Using nvvp 376
11.9.3 Using nvprof 377
11.9.4 imGStr Synchronous and Single-Stream Results 377
11.9.5 imGStr 2- and 4-Stream Results 378

Part III More To Know


Chapter 12  CUDA Libraries 383
Mohamadhadi Habibzadeh, Omid Rajabi Shishvan, and Tolga Soyata
12.1 cuBLAS 383
12.1.1 BLAS Levels 383
12.1.2 cuBLAS Datatypes 384
12.1.3 Installing cuBLAS 385
12.1.4 Variable Declaration and Initialization 385
Contents  xxi

12.1.5 Device Memory Allocation 386


12.1.6 Creating Context 386
12.1.7 Transferring Data to the Device 386
12.1.8 Calling cuBLAS Functions 387
12.1.9 Transfer Data Back to the Host 388
12.1.10 Deallocating Memory 388
12.1.11 Example cuBLAS Program: Matrix Scalar 388
12.2 CUFFT 390
12.2.1 cuFFT Library Characteristics 390
12.2.2 A Sample Complex-to-Complex Transform 390
12.2.3 A Sample Real-to-Complex Transform 391
12.3 NVIDIA PERFORMANCE PRIMITIVES (NPP) 392
12.4 THRUST LIBRARY 393

Chapter 13  Introduction to OpenCL 397


Chase Conklin and Tolga Soyata
13.1 WHAT IS OpenCL? 397
13.1.1 Multiplatform 397
13.1.2 Queue-Based 397
13.2 IMAGE FLIP KERNEL IN OPENCL 398
13.3 RUNNING OUR KERNEL 399
13.3.1 Selecting a Device 400
13.3.2 Running the Kernel 401
13.3.2.1 Creating a Compute Context 401
13.3.2.2 Creating a Command Queue 401
13.3.2.3 Loading Kernel File 402
13.3.2.4 Setting Up Kernel Invocation 403
13.3.3 Runtimes of Our OpenCL Program 405
13.4 EDGE DETECTION IN OpenCL 406

Chapter 14  Other GPU Programming Languages 413


Sam Miller, Andrew Boggio-Dandry, and Tolga Soyata
14.1 GPU PROGRAMMING WITH PYTHON 413
14.1.1 PyOpenCL Version of imflip 414
14.1.2 PyOpenCL Element-Wise Kernel 418
14.2 OPENGL 420
14.3 OPENGL ES: OPENGL FOR EMBEDDED SYSTEMS 420
14.4 VULKAN 421
14.5 MICROSOFT’S HIGH-LEVEL SHADING LANGUAGE (HLSL) 421
14.5.1 Shading 421
14.5.2 Microsoft HLSL 422
xxii  Contents

14.6 APPLE’S METAL API 422


14.7 APPLE’S SWIFT PROGRAMMING LANGUAGE 423
14.8 OPENCV 423
14.8.1 Installing OpenCV and Face Recognition 423
14.8.2 Mobile-Cloudlet-Cloud Real-Time Face Recognition 423
14.8.3 Acceleration as a Service (AXaas) 423

Chapter 15  Deep Learning Using CUDA 425


Omid Rajabi Shishvan and Tolga Soyata
15.1 ARTIFICIAL NEURAL NETWORKS (ANNS) 425
15.1.1 Neurons 425
15.1.2 Activation Functions 425
15.2 FULLY CONNECTED NEURAL NETWORKS 425
15.3 DEEP NETWORKS/CONVOLUTIONAL NEURAL NETWORKS 427
15.4 TRAINING A NETWORK 428
15.5 CUDNN LIBRARY FOR DEEP LEARNING 428
15.5.1 Creating a Layer 429
15.5.2 Creating a Network 430
15.5.3 Forward Propagation 431
15.5.4 Backpropagation 431
15.5.5 Using cuBLAS in the Network 431
15.6 KERAS 432

Bibliography 435

Index 439
xxiv  List of Figures

5.2 Example barrier synchronization for 4 threads. Serial runtime is 7281 ms


and the 4-threaded runtime is 2246 ms. The speedup of 3.24× is close to
the best-expected 4×, but not equal due to the imbalance of each thread’s
runtime. 128
5.3 Using a MUTEXdata structure to access shared variables. 129

6.1 Turning the dog picture into a 3D wire frame. Triangles are used to represent
the object, rather than pixels. This representation allows us to map a texture
to each triangle. When the object moves, so does each triangle, along with
their associated textures. To increase the resolution of this kind of an object
representation, we can divide triangles into smaller triangles in a process
called tesselation. 139
6.2 Steps to move triangulated 3D objects. Triangles contain two attributes:
their location and their texture. Objects are moved by performing mathe-
matical operations only on their coordinates. A final texture mapping places
the texture back on the moved object coordinates, while a 3D-to-2D transfor-
mation allows the resulting image to be displayed on a regular 2D computer
monitor. 140
6.3 Three farmer teams compete in Analogy 6.1: (1) Arnold competes alone
with his 2× bigger tractor and “the strongest farmer” reputation, (2) Fred
and Jim compete together in a much smaller tractor than Arnold. (3) Tolga,
along with 32 boy and girl scouts, compete together using a bus. Who wins? 145
6.4 Nvidia Runtime Engine is built into your GPU drivers, shown in your Win-
dows 10 Pro SysTray. When you click the Nvidia symbol, you can open the
Nvidia control panel to see the driver version as well as the parameters of
your GPU(s). 156
6.5 Creating a Visual Studio 2015 CUDA project named imflipG.cu. Assume
that the code will be in a directory named Z:\code\imflipG in this example. 172
6.6 Visual Studio 2015 source files are in the Z:\code\imflipG\imflipG direc-
tory. In this specific example, we will remove the default file, kernel.cu, that
VS 2015 creates. After this, we will add an existing file, imflipG.cu, to the
project. 173
6.7 The default CPU platform is x86. We will change it to x64. We will also
remove the GPU debugging option. 174
6.8 The default Compute Capability is 2.0. This is too old. We will change it to
Compute Capability 3.0, which is done by editing Code Generation under
Device and changing it to compute 30, sm 30. 175
6.9 Compiling imflipG.cu to get the executable file imflipG.exe in the
Z:\code\imflipG\x64\Debug directory. 176
6.10 Running imflipG.exe from a CMD command line window. 177
6.11 The /usr/local directory in Unix contains your CUDA directories. 181
6.12 Creating a new CUDA project using the Eclipse IDE in Unix. 183

7.1 The PCIe bus connects for the host (CPU) and the device(s) (GPUs).
The host and each device have their own I/O controllers to allow transfers
through the PCIe bus, while both the host and the device have their own
memory, with a dedicated bus to it; in the GPU this memory is called global
memory. 205
List of Figures  xxv

8.1 Analogy 8.1 for executing a massively parallel program using a significant
number of GPU cores, which receive their instructions and data from differ-
ent sources. Melissa (Memory controller ) is solely responsible for bringing
the coconuts from the jungle and dumping them into the big barrel (L2$).
Larry (L2$ controller ) is responsible for distributing these coconuts into the
smaller barrels (L1$) of Laura, Linda, Lilly, and Libby; eventually, these four
folks distribute the coconuts (data) to the scouts (GPU cores). On the right
side, Gina (Giga-Thread Scheduler ) has the big list of tasks (list of blocks to
be executed ); she assigns each block to a school bus (SM or streaming mul-
tiprocessor ). Inside the bus, one person — Tolga, Tony, Tom, and Tim —
is responsible to assign them to the scouts (instruction schedulers). 228
8.2 The internal architecture of the GTX550Ti GPU. A total of 192 GPU cores
are organized into six streaming multiprocessor (SM) groups of 32 GPU
cores. A single L2$ is shared among all 192 cores, while each SM has its
own L1$. A dedicated memory controller is responsible for bringing data in
and out of the GDDR5 global memory and dumping it into the shared L2$,
while a dedicated host interface is responsible for shuttling data (and code)
between the CPU and GPU over the PCIe bus. 230
8.3 A sample output of the imedgeG.cu program executed on the astronaut.bmp
image using a GTX Titan Z GPU. Kernel execution times and the amount
of data movement for each kernel is clearly shown. 242

9.1 GF110 Fermi architecture with 16 SMs, where each SM houses 32 cores, 16
LD/ST units, and 4 Special Function Units (SFUs). The highest end Fermi
GPU contains 512 cores (e.g., GTX 580). 264
9.2 GF110 Fermi SM structure. Each SM has a 128 KB register file that contains
32,768 (32 K) registers, where each register is 32-bits. This register file feeds
operands to the 32 cores and 4 Special Function Units (SFU). 16 Load/Store
(LD/ST) units are used to queue memory load/store requests. A 64 KB total
cache memory is used for L1$ and shared memory. 265
9.3 GK110 Kepler architecture with 15 SMXs, where each SMX houses 192
cores, 48 double precision units (DPU), 32 LD/ST units, and 32 Special
Function Units (SFU). The highest end Kepler GPU contains 2880 cores
(e.g., GTX Titan Black); its “double” version GTX Titan Z contains 5760
cores. 266
9.4 GK110 Kepler SMX structure. A 256 KB (64 K-register) register file feeds
192 cores, 64 Double-Precision Units (DPU), 32 Load/Store units, and 32
SFUs. Four warp schedulers can schedule four warps, which are dispatched
as 8 half-warps. Read-only cache is used to hold constants. 267
9.5 GM200 Maxwell architecture with 24 SMMs, housed inside 6 larger GPC
units; each SMM houses 128 cores, 32 LD/ST units, and 32 Special Function
Units (SFU), does not contain double-precision units (DPUs). The highest
end Maxwell GPU contains 3072 cores (e.g., GTX Titan X). 268
9.6 GM200 Maxwell SMM structure consists of 4 identical sub-structures with
32 cores, 8 LD/ST units, 8 SFUs, and 16 K registers. Two of these sub-
structures share an L1$, while four of them share a 96 KB shared memory. 269
9.7 GP100 Pascal architecture with 60 SMs, housed inside 6 larger GPC units,
each containing 10 SMs. The highest end Pascal GPU contains 3840 cores
(e.g., P100 compute accelerator). NVLink and High Bandwidth Memory
Exploring the Variety of Random
Documents with Different Content
— 150 — nur ein einzelner Mann, aber er hatte mindestens
ein halbes Dutzend Flinten — während Hunter und ich neue Ladung
aus dem Boote holten. So arbeiteten wir ohne Unterbrechung und
ohne auch nur Atem zu schöpfen, bis die ganze Ladung verstaut war.
Die beiden Diener blieben zur Bewachung des Blockhauses zurück,
während ich mit allen Kräften zur „Hispaniola" zurückruderte. Es
klingt verwegener, als es wirklich war, daß wir noch ein zweites Mal
die Fahrt unternahmen. Die Feinde waren uns freilich an Zahl
überlegen, aber wir ihnen an Waffen. Keiner der Leute an Land hatte
ein Gewehr bei sich, und bis sie auf Pistolenschußweite an uns
herangekommen wären, hätten wir, wie wir uns schmeichelten,
mindestens schon ein halbes Dutzend erledigt. Der Squire erwartete
mich am Achterfenster. Seine Schwäche hatte er völlig überwunden.
Er machte das Fangtau fest, und wir beluden nunmehr das Boot mit
unseren eigentlichen Lebensnotwendigkeiten. Schweinefleisch,
Pulver und Zwieback war die Ladung, außerdem je eine Flinte und
ein Entermesser für den Squire, mich, Redruth und den Kapitän. Den
Rest an Munition und Waffen versenkten wir zweieinhalb Faden tief
ins Wasser, wo wir unten auf dem klaren Sandboden das
schimmernde Eisen blinken sahen. Um diese Zeit setzte die Ebbe ein,
und das Schiff schaukelte an dem Anker. In weiter Entfernung hörten
wir schwache Rufe aus der Richtung der Boote, und obgleich uns
dies bezüglich Hunters und Joyces be 
— 151 — ruhigte, war es uns doch eine Warnung zu
baldigem Aufbruch. Redruth zog sich von seinem Standplatz auf dem
Gang zurück und sprang ins Boot, das wir dann an die Heckgillung
des Schiffes heranbrachten, um es Kapitän Smollett bequemer zu
machen. „Hallo, Leute," sagte der Kapitän, „hört ihr mich ?" Keine
Antwort aus dem Vorderschiff. „Zu ihnen, Abraham Gray, spreche
ich!" Noch immer keine Antwort. „Gray," wiederholte der Kapitän
etwas lauter, „ich verlasse das Schiff und befehle Ihnen, Ihrem
Kapitän zu folgen. Ich weiß, daß Sie im Grunde genommen ein guter
Kerl sind, ja ich meine sogar, keiner von euch ist ganz so schlecht,
als er sich stellt. Ich nehme meine Uhr zur Hand und gebe Ihnen
dreißig Sekunden Bedenkzeit." Pause. „Komm, mein Junge," fuhr der
Kapitän fort, „überleg's dir nicht so lang. Jede Sekunde gefährdet
mein Leben und das Leben dieser guten Herren." Plötzlich hörte man
eine Balgerei und Schläge, dann stürzte Abraham Gray mit einer
Messerwunde auf der Wange heraus und lief auf den Kapitän zu, wie
ein Hund, dem sein Herr gepfiffen hat. „Ich gehe mit Ihnen, Sir",
sagte er. Im nächsten Augenblick sprangen der Kapitän und Gray ins
Boot und wir stießen ab und fuhren los. Aus dem Schiff waren wir,
aber noch waren wir nicht an Land in unserem Blockhaus.
SIEBZEHNTES KAPITEL (Fortsetzung der Erzählung durch
den Doktor) Die letzte Fahrt der Jolle Unsere zweite Fahrt verlief
ganz anders als die früheren. Erstens war unsere kleine Nußschale
von Boot viel zu schwer geladen. Fünf erwachsene Männer, davon
drei — Trelawney, Redruth und der Kapitän — über sechs Fuß hoch,
waren schon das äußerste, was es zu leisten vermochte. Dazu
kamen aber noch Munition, Fleisch und ßrotsäcke. Das Schanzdeck
tauchte tief ins Wasser, auch bekamen wir mehrere Male Wasser ins
Boot, so daß meine Beinkleider und Rockschöße gänzlich
durchweicht waren, ehe wir ein paar hundert Meter zurückgelegt
hatten. Der Kapitän ließ uns das Gewicht des Bootes ausbalancieren,
so daß wir etwas gerader zu liegen kamen, aber trotzdem wagten
wir kaum zu atmen. Zweitens war jetzt Ebbe, eine starke Strömung
lief westlich durch die Bucht und zog dann südlich und seewärts die
Straße entlang, durch die wir heute morgen eingefahren waren.
Schon die Wellen waren eine Gefahr für unser überlastetes Boot,
aber das schlimmste war, daß uns die Strömung von unserem
Landungsplatz hinter der Biegung abtrieb. Wären wir der Strömung
gefolgt, so hätte sie uns geradeswegs zu den Boo 
— i53 — ten am Ufer hingeführt, wo jeden Augenblick die
Seeräuber auftauchen konnten. „Ich kann die Richtung auf das
Blockhaus nicht halten", sagte ich zum Kapitän. Ich saß nämlich am
Steuer, während er und Redruth, die noch ausgeruht waren,
ruderten. „Die Strömung zieht mich ab. Könnten Sie nicht etwas
stärker rudern?" „Nicht ohne das Boot voll Wasser zu bekommen",
antwortete er. „Sie müssen abfallen, Sir, unbedingt, bis Sie sehen,
daß Sie Raum bekommen." Ich versuchte es und fand heraus, daß
die Strömung uns westwärts abzog, wenn ich nicht die Spitze ganz
östlich richtete, also genau rechtwinklig zu dem Kurs, den wir
zurückzulegen hatten. „Auf diese Weise kommen wir nie ans Ufer!"
sagte ich. „Wenn wir keinen anderen Kurs nehmen können, so
müssen wir eben diesen halten", entgegnete der Kapitän. „Wir
müssen uns gegen die Strömung halten; denn Sie sehen, Sir, wenn
wir einmal leewärts vom Landungsplatz abtreiben, können wir nicht
voraussehen, wo wir an Land kommen, abgesehen von der Gefahr,
daß wir von den Booten geentert werden. Halten wir aber den Kurs,
so muß die Strömung nachlassen und dann können wir längs der
Küste zurücklavieren." „Die Strömung läßt schon nach, Sir", sagte
der Matrose Gray, der vorne saß. „Sie können schon etwas
nachgeben." „Danke schön, mein Freund", sagte ich ruhig, als ob
nichts vorgefallen wäre; denn wir waren alle still 
— 154 — schweigend übereingekommen, ihn wie einen der
Unseren zu behandeln. Plötzlich nahm der Kapitän wieder das Wort,
und seine Stimme schien mir etwas verändert. „Die Kanone!" sagte
er. „Ich habe schon dran gedacht", antwortete ich, in dem Glauben,
er denke an ein Bombardement der Festung. „Sie können aber die
Kanone nicht an Land bringen, und selbst wenn ihnen dies gelänge,
könnten sie sie niemals durch die Wälder schleppen." „Drehen Sie
sich um, Doktor", sagte der Kapitän. Wir hatten den langen
Neunpfünder glatt vergessen und sahen jetzt zu unserem Entsetzen
die Schufte emsig damit beschäftigt, ihm den Rock auszuziehen, wie
sie seine dicke Teertuchhülle nannten. Nicht allein das, uns fiel auch
ein, daß wir die Kugeln und das Pulver für die Kanone
zurückgelassen hatten, und ein Axthieb würde sie in den Besitz der
Teufel an Bord bringen. „Israel war Flints Kanonier", sagte Gray
heiser. Jeder Gefahr zum Trotz hielten wir mit dem Boot direkt auf
den Landungsplatz zu. Nun waren wir bereits so weit aus der
Strömung heraus, daß wir selbst bei dem notwendigerweise
langsamen Rudern ziemlich rasch auf unser Ziel lossteuerten.
Schlimm war's nur, daß wir bei unserem jetzigen Kurs der
„Hispaniola" statt des Hecks unsere Breitseite zukehrten, die eine
Zielscheibe bot wie ein Scheunentor. Ich sah und hörte, wie der
versoffene Schurke Israel Hands eine Kanonenkugel auf das Deck
plumpsen ließ. -*'?* im**'* Ltuteaais£aB** sagte der £*?*■■■
Lw*m Trebuff*^ lung (•• Wt-V tan, J* >■■" Balance, wiarcDer $:- '
rudern und kgta • * * *▼ um das Gkidfewk ■ kfe * geordnet, daß w
baa ajM ■«■ ■ kamen. iibbb» i»-Lue Haft*«»--* der Mündung aai n-
tt^Q m
rw "•*• ;d — 155 — „Wer ist der beste Schütze?" fragte der
Kapitän. „Unbedingt Squire Trelawney !" sagte ich. „Wollen Sie so
gut sein, Mr. Trelawney, einen der Leute aufs Korn zu nehmen?
Wenn möglich, Hands!" sagte der Kapitän. Trelawney blieb ganz
kaltblütig. Er prüfte die Zündung seines Gewehrs. „Vorsichtig mit
dem Gewehr, Sir," rief der Kapitän, „sonst kentert das Boot! Alle
Mann halten die Balance, während er zielt!" Der Squire hob das
Gewehr, wir hörten auf zu rudern und legten uns auf der Gegenseite
hintenüber, um das Gleichgewicht zu halten. Alles war so gut
angeordnet, daß wir keinen Tropfen Wasser ins Boot bekamen.
Unterdessen hatten sie die Kanone auf der Drehbasse umgedreht,
und Hands, der mit dem Ladestock an der Mündung stand, war
folglich am exponiertesten. Wir hatten aber kein Glück- denn gerade
als Trelawney feuerte, bückte jener sich, die Kugel pfiff über ihn
hinweg und traf einen der vier anderen. Der Schrei, den dieser
ausstieß, wurde nicht bloß von seinen Gefährten an Bord wiederholt,
sondern noch von zahlreichen anderen Stimmen vom Ufer her. Und
als ich hinblickte, sah ich die übrigen Piraten zwischen den Bäumen
herauskommen und auf die Boote stürzen. „Hier kommen die Boote,
Sir", sagte ich. „Vorwärts dann!" rief der Kapitän. „Jetzt können wir
uns nicht mehr darum kümmern, ob wir Wasser i I 1 i I
— 154 — schweigend übereingekommen, ihn wie einen der
Unseren zu behandeln. Plötzlich nahm der Kapitän wieder das Wort,
und seine Stimme schien mir etwas verändert. „Die Kanone!" sagte
er. „Ich habe schon dran gedacht", antwortete ich, in dem Glauben,
er denke an ein Bombardement der Festung. „Sie können aber die
Kanone nicht an Land bringen, und selbst wenn ihnen dies gelänge,
könnten sie sie niemals durch die Wälder schleppen." „Drehen Sie
sich um, Doktor", sagte der Kapitän. Wir hatten den langen
Neunpfünder glatt vergessen und sahen jetzt zu unserem Entsetzen
die Schufte emsig damit beschäftigt, ihm den Rock auszuziehen, wie
sie seine dicke Teertuchhülle nannten. Nicht allein das, uns fiel auch
ein, daß wir die Kugeln und das Pulver für die Kanone
zurückgelassen hatten, und ein Axthieb würde sie in den Besitz der
Teufel an Bord bringen. „Israel war Flints Kanonier", sagte Gray
heiser. Jeder Gefahr zum Trotz hielten wir mit dem Boot direkt auf
den Landungsplatz zu. Nun waren wir bereits so weit aus der
Strömung heraus, daß wir selbst bei dem notwendigerweise
langsamen Rudern ziemlich rasch auf unser Ziel lossteuerten.
Schlimm war's nur, daß wir bei unserem jetzigen Kurs der
„Hispaniola" statt des Hecks unsere Breitseite zukehrten, die eine
Zielscheibe bot wie ein Scheunentor. Ich sah und hörte, wie der
versoffene Schurke Israel Hands eine Kanonenkugel auf das Deck
plumpsen ließ.
— 155 — „Wer ist der beste Schütze?" fragte der Kapitän.
„Unbedingt Squire Trelawney!" sagte ich. „Wollen Sie so gut sein, Mr.
Trelawney, einen der Leute aufs Korn zu nehmen? Wenn möglich,
Hands!" sagte der Kapitän. Trelawney blieb ganz kaltblütig. Er prüfte
die Zündung seines Gewehrs. „Vorsichtig mit dem Gewehr, Sir," rief
der Kapitän, „sonst kentert das Boot! Alle Mann halten die Balance,
während er zielt!" Der Squire hob das Gewehr, wir hörten auf zu
rudern und legten uns auf der Gegenseite hintenüber, um das
Gleichgewicht zu halten. Alles war so gut angeordnet, daß wir keinen
Tropfen Wasser ins Boot bekamen. Unterdessen hatten sie die
Kanone auf der Drehbasse umgedreht, und Hands, der mit dem
Ladestock an der Mündung stand, war folglich am exponiertesten.
Wir hatten aber kein Glück; denn gerade als Trelawney feuerte,
bückte jener sich, die Kugel pfiff über ihn hinweg und traf einen der
vier anderen. Der Schrei, den dieser ausstieß, wurde nicht bloß von
seinen Gefährten an Bord wiederholt, sondern noch von zahlreichen
anderen Stimmen vom Ufer her. Und als ich hinblickte, sah ich die
übrigen Piraten zwischen den Bäumen herauskommen und auf die
Boote stürzen. „Hier kommen die Boote, Sir", sagte ich. „Vorwärts
dann!" rief der Kapitän. „Jetzt können wir uns nicht mehr darum
kümmern, ob wir Wasser
The text on this page is estimated to be only 11.95%
accurate

Kapkta wieder das Wort, und 1 ■* **» »etindert » pfadH*,


antwortete ich, in e M ein Bombardement der *e Kanone nicht an
Land *■» dies gelänge, könnten -e Wilder ichleppen." Oibor", sagte
der Kapitän, t ^afca Neunptunder glatt vergessen ■ mmm Entsetzen
die Schufte af-, ifia den Rock auszuziehen, 7t*mcüälJe nannten.
Nicht allein ^ iii wu die Kugeln und das Pulnatten, und ein Axtirr
Teufel an Bord bringen. ', tagte Gray heiser, wir mit dem Boot viren
wir bedaß wir selbst Rudern ziemlich war's nur, :ne »•* <4L * . I —
itaift H( l --■—
igte der Kapitän, sagte ich. relawney, einen der n möglich,
Hands!" Er prüfte die Züniir," rief der Kapie Mann halten die wir
hörten auf zu r Gegenseite hintenüber, bJ Alles war so gut anam
Wasser ins Boot beknone auf der Drehemit dem Ladestock an lgih
am exponiertesten. d|n gerade als Trelaw, d Kugel pfiff über ihn ;r
pderen. M§ß, wurde nicht bloß Um wiederholt, sondern _n vom Ufer
her. I die übrigen Piraten •nen und auf die Boote
The text on this page is estimated to be only 8.20%
accurate

a«, ihn wie einen der UnKl N ^«fcr das Woi H»« etWM
»erändert ■K«*»ke *■ pMt1 antwortete ich, in «a Bombardement
der MI dies lone nicht an Land 4 I 4 * Wilder schleppen. ßclänge,
könnten * aa «. Doktor«, »gto der Kapitän, .att Entsetzen die
Schufte der Teufel an Bord bringei tagte Gray rIhm haha ni mit i «**
tl. Nun wäre ■HM) dal] j baguoen Rudern Schlimm w «rrta Wtnjea
Kurs der „H rukehr : ■§ qjj Scktiatator . pji *r an Ane ■I da ■■ W,
und ,+>* f in des Rock auszuziehen, «*kWk nannten. Nicht allein i»
ki mit die Kugeln und das Pulhatten, und ein Axt\
The text on this page is estimated to be only 15.11%
accurate

*\ — ■*
- i56 schöpfen. Wenn wir nicht ans Ufer kommen, ist alles
verloren!" „Sie haben nur eines der Boote bemannt," fügte ich hinzu,
„die Leute vom zweiten Boot gehen offenbar längs des Ufers, um
uns abzuschneiden." „Dann müssen sie tüchtig laufen, Sir",
entgegnete der Kapitän. „Sie wissen ja — eine Teerjacke zu Lande!
Die fürchte ich nicht, aber die Kanonenkugel. Zimmerkrocket! Eine
Kammerzofe könnte uns nicht verfehlen! Sagen Sie uns, Squire,
wann das Spiel beginnt, und wir werden Stich halten." Wir waren
unterdessen für ein so überladenes Boot gut vorwärtsgekommen
und das Boot hatte nur wenig Wasser gesackt. Jetzt waren wir schon
ganz nahe; noch dreißig oder vierzig Ruderschläge und wir konnten
landen, denn die Ebbe hatte einen schmalen Sandgürtel unter den
dichten Bäumen freigelegt. Das Boot bedrohte uns nicht mehr, da
die Biegung es unseren Blicken entzogen hatte. Die Ebbe, die uns
erst so grausam aufgehalten hatte, machte ihre Schuld jetzt wett,
indem sie unsere Verfolger hemmte. Die einzige Gefahr war die
Kanone. „Wenn ich's wagte," sagte der Kapitän, „würde ich
aufstehen und einen zweiten Mann herunterholen." Aber sie ließen
sich offenbar durch nichts vom Abfeuern des Schusses abhalten.
Kaum gönnten sie ihrem gefallenen Kameraden einen Blick, trotzdem
er nicht tot war. Ich sah, wie er fortzukriechen versuchte. „Fertig!"
rief der Squire.
— 157 — „Festhalten!" schrie der Kapitän, schnell wie ein
Echo. Und er und Redruth legten sich mit aller Kraft nach rückwärts,
so daß das Hinterteil der Jolle unter Wasser kam. Im selben Moment
ertönte der Schuß, der erste, den Jim hörte, denn den Schuß des
Squires hatte er nicht vernommen. Wohin die Kugel geflogen war,
wußte keiner von uns genau, aber vermutlich wohl über unsere
Köpfe hinweg, so daß der Wind, den sie erzeugte, zu unserem
Mißgeschick beigetragen haben mag. Jedenfalls sank das Boot
langsam achtern drei Fuß unter Wasser. Der Kapitän und ich, die
einander gegenüber aufgesprungen waren, blieben ganz trocken,
aber die anderen hatten eine vollständige Dusche abbekommen und
kamen naß und triefend wieder nach oben. Das wäre an sich nicht
so schlimm gewesen. Wir hatten kein Menschenleben eingebüßt und
konnten in Sicherheit an das Ufer waten. Aber alle unsere Vorräte
lagen unter Wasser, und obendrein waren von den fünf Schußwaffen
nur zwei gebrauchsfähig geblieben. Ich hatte mein Gewehr im
Augenblick der Gefahr instinktiv gepackt und hoch über den Kopf
gehalten, der Kapitän trug das seine an einem Riemen über der
Schulter, als kluger Mann das Schloß nach oben. Die drei anderen
Gewehre waren mit dem Boot untergegangen. Unsere Bestürzung
wurde noch vermehrt, da wir schon Stimmen vernahmen, die längs
des Ufers näher kamen. Wir schwebten nicht bloß in Gefahr, in
unserem halb wehrlosen Zustande vom Blockhaus abgeschnitten zu
werden, sondern sorgten uns auch, ob Hunter und Joyce, wenn sie
von einem halben Dutzend Leuten angegrif 
- i58 fen würden, klug und standhaft genug Widerstand
leisten würden. Hunter war standhaft, das wußten wir, aber Joyce
war ein zweifelhafter Fall, ein angenehmer, höflicher Mann, ein guter
Diener, der die Kleider zu putzen versteht, aber ganz und gar nicht
zum Krieger geboren. In dieser Gemütsverfassung wateten wir, so
schnell wir konnten, ans Ufer und ließen unsere arme Jolle sowie
den größten Teil unserer Munition und unseres Proviants im Stich.
ACHTZEHNTES KAPITEL (Fortsetzung der Erzählung durch
den Doktor) Das Ende des ersten Kampftages Wir eilten so rasch wir
konnten durch den Streifen Wald, der uns vom Blockhaus trennte,
und mit jedem Schritt hörten wir die Stimmen der Piraten aus
größerer Nähe. Bald vernahmen wir auch ihre Schritte und das
Knacken der Zweige, wie sie durch das Gebüsch brachen. Ich begriff,
daß wir um einen ernsthaften Kampf nicht herumkommen würden,
und prüfte die Zündung meines Gewehrs. „Kapitän," sagte ich,
„Trelawney ist ein Meisterschütze; geben Sie ihm Ihr Gewehr, das
seinige ist verdorben." Sie tauschten die Gewehre, und Trelawney,
schweigend und kühl, wie er seit Beginn des Kampfes gewesen war,
blieb einen Augenblick stehen, um zu sehen, ob alles parat sei. Ich
bemerkte gleichzeitig, daß Gray unbewaffnet war, und reichte ihm
mein Entermesser. Es tat uns allen wohl, zu sehen, wie er in die
Hand spuckte und dann mit drohend zusammengezogenen Brauen
die Klinge durch die Luft sausen ließ. Jede seiner Gebärden bewies
uns, daß unsere neue Hilfskraft ihr Essen wert war.
- i58 fen würden, h : und standhaft genug Widerstand
leisten würden, [unter war standhaft, das wußten wir, aber J
^felhafter Fall, ein angenehmer, höflicher Mann, ir er Diener, der die
Kleider zu putzen versteht, aberjanz und gar nicht zum Krieger
geboren. In dieser < itsverfassung wateten wir, so schnell wir
konnten, ms Ufer und ließen unsere arme Jolle sowie den graten Teil
unserer Munition und unseres Proviant* ir. '«*»• -!-•**••*
Ä *L I I Ä ■ •> »v ^»*a ACHTZEHNTES VP I T E L
(Fortsetzung der Erzählung durch d Das Ende des ersten Ka* 'ftages
Wir eilten so rasch wir konnten d c den Streifen Wald, der uns vom
Blockhaus trennte, jid mit jedem Schritt hörten wir die Stimmen der
Pii ius größerer Nähe. Bald vernahmen wir auch 1! ir Schritte und
das Knacken der Zweige, wie sie duizjdas Gebüsch brachen. Ich
begriff, daß wir um einen e staften Kampf nicht herumkommen
würden, und pri :t«die Zündung meines Gewehrs. „Kapitän," sagte
ich, „Trelawnev is ein Meisterschütze; geben Sie ihm Ihr Gewel . e ist
verdorben." Sie tauschten die Gewehre, und Tr< gend und kühl, wie
er seit Beginn <. wesen="" war="" blieb="" einen="" augenblick=""
s="" um="" zu="" sehen="" ob="" alles="" parat="" sei.="" ich=""
bemerkte="" gleich="" da="" gray="" unbewaffnet="" und=""
reichte="" ihm="" j="" es="" tat="" uns="" allen="" wohl=""
sehei="" spuckte="" n="" mit="" brauen="" die="" di="" seiner=""
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like