For the final example of this book, we will now make a standard array summation kernel for a given array of doubles, except this time we will use every trick that we've learned in this chapter to make it as fast as possible. We will check the output of our summing kernel against NumPy's sum function, and then we will run some tests with the standard Python timeit function to compare how our function compares to PyCUDA's own sum function for gpuarray objects.
Let's get started by importing all of the necessary libraries, and then start with a laneid function, similar to the one we used in the previous section:
from __future__ import division
import numpy as np
from pycuda.compiler import SourceModule
import pycuda.autoinit
from pycuda import gpuarray
import pycuda.driver as drv
from timeit import timeit
SumCode='''
__device__...