Reader small image

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

Product typeBook
Published inMay 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789341072
Edition1st Edition
Languages
Right arrow
Author (1)
Avimanyu Bandyopadhyay
Avimanyu Bandyopadhyay
author image
Avimanyu Bandyopadhyay

Avimanyu Bandyopadhyay is currently pursuing a PhD degree in Bioinformatics based on applied GPU computing in Computational Biology at Heritage Institute of Technology, Kolkata, India. Since 2014, he developed a keen interest in GPU computing, and used CUDA for his master's thesis. He has experience as a systems administrator as well, particularly on the Linux platform. Avimanyu is also a scientific writer, technology communicator, and a passionate gamer. He has published technical writing on open source computing and has actively participated in NVIDIA's GPU computing conferences since 2016. A big-time Linux fan, he strongly believes in the significance of Linux and an open source approach in scientific research. Deep learning with GPUs is his new passion!
Read more about Avimanyu Bandyopadhyay

Right arrow

Interoperability between CuPy and Numba within a single Python program

In this section, we try to test the interoperability between two different modules within the same Python program, namely, CuPy and Numba. So, we import the cuda module from numba and cupy, as well:

from numba import cuda #Using Numba
import cupy as cp #Using CuPy
from timeit import default_timer as timer

N = 500000000

@cuda.jit
def multiply(p, q):
# Thread id in a 1D block
tx = cuda.threadIdx.x
# Block id in a 1D grid
ty = cuda.blockIdx.x
# Number of threads per block
bw = cuda.blockDim.x
# Compute flattened index inside the array
index = tx + ty * bw

Like on our previous program, we compute the product based on a condition, as shown in the following code:

    if index < N: # Check array size limit
q[index]=p[index]*q[index]

def main():
a_source = cp.zeros(N, dtype=cp.double...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On GPU Computing with Python
Published in: May 2019Publisher: PacktISBN-13: 9781789341072

Author (1)

author image
Avimanyu Bandyopadhyay

Avimanyu Bandyopadhyay is currently pursuing a PhD degree in Bioinformatics based on applied GPU computing in Computational Biology at Heritage Institute of Technology, Kolkata, India. Since 2014, he developed a keen interest in GPU computing, and used CUDA for his master's thesis. He has experience as a systems administrator as well, particularly on the Linux platform. Avimanyu is also a scientific writer, technology communicator, and a passionate gamer. He has published technical writing on open source computing and has actively participated in NVIDIA's GPU computing conferences since 2016. A big-time Linux fan, he strongly believes in the significance of Linux and an open source approach in scientific research. Deep learning with GPUs is his new passion!
Read more about Avimanyu Bandyopadhyay