The CUDA Device Function Libraries and Thrust

In the last chapter, looking at a fairly broad overview of the libraries that are available in CUDA through the Scikit-CUDA wrapper module. We will now look at a few other libraries that we will have to use directly from within CUDA C proper, without the assistance of wrappers like those in Scikit-CUDA. We will start by looking at two standard libraries that consist of device functions that we may invoke from any CUDA C kernel cuRAND and the CUDA Math API. By the end of learning how to use these libraries, we will know how to use these libraries in the context of Monte Carlo integration. Monte Carlo integration is a well-known randomized method that provides estimates for the values of definite integrals from calculus. We will first look at a basic example of how to implement a simple Monte Carlo method with cuRAND to do a basic estimate of the value of Pi (as in the well-known constant, π=3.14159...), and then we'll embark on a more ambitious project where we will construct a Python class that can perform definite integration on any arbitrary mathematical function, and use the Math API for creating such functions. We'll also look at how to effectively use some ideas from metaprogramming in our design of this class.

 We will then take another look at writing some pure CUDA programs with the help of the Thrust C++ library. Thrust is a library that provides C++ template containers, similar to those in the C++ Standard Template Library (STL). This will enable us to manipulate CUDA C arrays from C++ in a more natural way that is closer to PyCUDA's gpuarray and the STL's vector container. This will save us from having to constantly use pointers, such as mallocs and frees, that plagued us before in CUDA C.

In this chapter, we will look at the following topics:

  • Understanding the purpose that a seed has in generating lists of pseudo-random numbers
  • Using cuRAND device functions for generating random numbers in a CUDA kernel
  • Understanding the concept of Monte Carlo integration
  • Using dictionary-based string formatting in Python for metaprogramming
  • Using the CUDA Math API device function library
  • Understanding what a functor is
  • Using the Thrust vector container when programming in pure CUDA C
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.36