You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose of this repository is to both showcase the performance of the Ginkgo accessor and to serve as an integration example.
Including the Ginkgo's accessor into your project
Integration into the build system
To use Ginkgo's accessor, you need to:
Use C++14 or higher in your own project
use ${GINKGO_DIR} as an include directory (you only need ${GINKGO_DIR}/accessor from Ginkgo)
In this repository, we use CMake, which makes the integration straight forward.
We give users the option to either specify a local copy of the Ginkgo repository, or automatically clone the repository into the build directory, followed by using it.
We achieve both with these few lines in CMake:
Now, we only need to call this function for every target where we use the accessor.
Creating a range with an accessor
In this repository, we only use the reduced_row_major accessor, but all others work accordingly.
For the reduced_row_major accessor, you need to specify:
the dimensionality of the range (we specify 2D, even for vectors, so we can access vectors with a stride)
the arithmetic and storage type
Now, this type can be used to create the range<reduced_row_major<...>> by specifying the size, stride and storage pointer.
We showcase the creation of both constant and non-constant ranges with reduced_row_major accessors here:
using c_range = gko::acc::range<typename accessor::const_accessor>;
auto m_acc = c_range(m_info.size, mtx, m_stride);
auto x_acc = c_range(x_info.size, x, x_stride);
auto res_acc = range(res_info.size, res, res_stride);
We utilize the constant accessors for the matrix and the x vector since both storage pointers are also constant.
Utilizing the range/accessor in a CUDA kernel
Utilizing the range in a kernel (works the same for CPUs) is straight forward:
Use a templated kernel argument in order to accept all kind of ranges
Read and write operations utilize the bracket operator()
To know which arithmetic type is used, we can either use the accessor::arithmetic_type property, or detect what type arithmetic operations result in. In this example, we use the second option: