Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On GPU Computing with Python

You're reading from  Hands-On GPU Computing with Python

Product type Book
Published in May 2019
Publisher Packt
ISBN-13 9781789341072
Pages 452 pages
Edition 1st Edition
Languages
Author (1):
Avimanyu Bandyopadhyay Avimanyu Bandyopadhyay
Profile icon Avimanyu Bandyopadhyay

Table of Contents (17) Chapters

Preface Section 1: Computing with GPUs Introduction, Fundamental Concepts, and Hardware
Introducing GPU Computing Designing a GPU Computing Strategy Setting Up a GPU Computing Platform with NVIDIA and AMD Section 2: Hands-On Development with GPU Programming
Fundamentals of GPU Programming Setting Up Your Environment for GPU Programming Working with CUDA and PyCUDA Working with ROCm and PyOpenCL Working with Anaconda, CuPy, and Numba for GPUs Section 3: Containerization and Machine Learning with GPU-Powered Python
Containerization on GPU-Enabled Platforms Accelerated Machine Learning on GPUs GPU Acceleration for Scientific Applications Using DeepChem Other Books You May Enjoy Appendix A

Writing your first CuPy and Numba enabled accelerated programs to compute GPGPU solutions

Beginning first with CuPy, we will apply the implementations that we learned about CuPy so far, with our first CuPy program. Note that it does not use NumPy to generate the random number as well. In fact, it's a pure CuPy program. The NumPy module is not imported at all.

  1. First, open a new file on PyCharm, as shown here in the screenshot:
  1. Now use the following code that simply replaces NumPy syntax with CuPy. This is a regular and basic format in CuPy that looks exactly like NumPy, apart from the importing of the latter module:
import cupy as cp #Importing CuPy
from timeit import default_timer as timer #To record computation time

N = 500000000 #500 million elements

# Starting timer to record GPU computation time
start = timer()
# Setting two arrays all with zero values
a_cp = cp.zeros...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}