Creating the C++ Library
We started this chapter talking about integrating a C++ library with Python, but up until now we’ve only created C++ programs that use the GPU – and all of them were executable programs, not libraries. So let’s see how we can turn our code into a library! We will use as our example a very simple vector addition kernel that receives two input arrays, one output array, and their size to perform addition of the input arrays’ elements and store the results on the output array. Note that we pass a single value for the size because the arrays must be of the same size.
A C++ library, in simple terms, is a collection of precompiled code that can be linked to multiple applications, saving time and leveraging code reuse. For our purpose of integrating with Python we’ll need to create a shared library (dynamically loaded), and CMake provides everything we need to accomplish that.
Static versus shared libraries
Although...