-
Notifications
You must be signed in to change notification settings - Fork 35
ECP Milestone 1.7: Kokkos contribution
In this report we develop and port two QMCPACK kernels of the miniqmc miniapp (spline and Jastrow evaluations) to the Kokkos C++ programming model, and at least one CPU and one GPU based architecture. We make an initial assessment of:
- Capability (expressiveness, ability to achieve required levels of parallelization)
- Performance (achieved time to solution on multiple architectures)
- Portability (extent of modification required for performance on multiple architectures)
- Suitability (deviation from desired application abstractions required to port or to obtain performance, complexity, difficulty of learning curve)
- Support (compiler, tools, documentation)
Desired improvements and extensions to improve the objective (1-3) and subjective (4,5) measures will be identified and communicated with the Kokkos team.
We implement the Kokkos C++ programming model in the spline and Jastrow kernels in order to achieve portability on multiple architectures.
Each Monte Carlo step requires the evaluation of single particle orbitals (SPOs). The miniqmc miniapp uses a 3D tricubic B-spline based orbital representation for the evaluation of the SPOs. The 3D tricubic B-spline basis is a highly efficient representation for SPOs requiring only 64 elements at any given point in space. The Kokkos implementation of the spline kernel requires modifications to the data structures and expression of parallelism in the mini-app.
The spline kernel evaluates the wavefunction, its gradient (a 3D vector containing the first derivative with respect to particle positions) and its hessian (a 3D tensor containing the second derivative with respect to particle positions). We convert several data structures related to these into Views which is the Kokkos abstraction for multidimensional arrays with template parameters controlling in which memory space (host or device) the data resides and which data layout is imposed.
-
In src/einspline/multi_bspline_create.cpp (renamed src/einspline/multi_bspline_create.c):
Old
void set_multi_UBspline_3d_s_d(multi_UBspline_3d_s *spline, int num, double *data) { ... double *spline_tmp = malloc(sizeof(double) * Nx * Ny * Nz); ... }
New
void set_multi_UBspline_3d_s_d(multi_UBspline_3d_s *spline, int num, double *data) { ... double *spline_tmp = (double*) malloc(sizeof(double) * Nx * Ny * Nz); ... }
- In src/einspline/multi_bspline_structs.h:
-
Add Kokkos header file
New... #include <Kokkos_Core.hpp> ...
-
Create Kokkos views
Oldtypedef struct { spline_code spcode; type_code tcode; double *restrict coefs; intptr_t x_stride, y_stride, z_stride; Ugrid x_grid, y_grid, z_grid; BCtype_d xBC, yBC, zBC; int num_splines; size_t coefs_size; } multi_UBspline_3d_d;
New
typedef struct { typedef Kokkos::View<double****, Kokkos::LayoutRight> coefs_view_t; spline_code spcode; type_code tcode; double *restrict coefs; coefs_view_t coefs_view; intptr_t x_stride, y_stride, z_stride; Ugrid x_grid, y_grid, z_grid; BCtype_d xBC, yBC, zBC; int num_splines; size_t coefs_size; } multi_UBspline_3d_d;
-
- In src/spline2/bspline_allocator.cpp:
- Remove functions.
OldNewextern "C" { void set_multi_UBspline_3d_d(multi_UBspline_3d_d *spline, int spline_num, double *data); void set_multi_UBspline_3d_s(multi_UBspline_3d_s *spline, int spline_num, float *data); multi_UBspline_3d_s * einspline_create_multi_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, int num_splines); UBspline_3d_s *einspline_create_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, float *data); multi_UBspline_3d_d * einspline_create_multi_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, int num_splines); UBspline_3d_d *einspline_create_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, double *data); }
extern "C" { void set_multi_UBspline_3d_d(multi_UBspline_3d_d *spline, int spline_num, double *data); void set_multi_UBspline_3d_s(multi_UBspline_3d_s *spline, int spline_num, float *data); }
- Changes in deallocation
OldNewvoid Allocator::set(double *indata, multi_UBspline_3d_s *spline, int i) { ... einspline_free(singleS->coefs); ... }
void Allocator::set(double *indata, multi_UBspline_3d_s *spline, int i) { ... einspline_free((void*)singleS->coefs); ... }
- Remove functions.
- In src/spline2/bspline_allocator.hpp:
Delete Kokkos view by setting it to an empty view and relying on reference counting of views.
OldNewclass Allocator { ... template <typename SplineType> void destroy(SplineType *spline) { einspline_free(spline->coefs); free(spline); } ... }
class Allocator { ... template <typename SplineType> void destroy(SplineType *spline) { // Delete View by setting it to an empty view and rely on reference counting of views. spline->coefs_view = typename SplineType::coefs_view_t(); free(spline); } ... }
- In src/spline2/einspline_allocator.cpp (Renamed src/spline2/einspline_allocator.c):
- Add Kokkos header file
New#include <Kokkos_Core.hpp>
- Remove inline specifier for all einspline_alloc and einspline_free.
- Modify multi_Bspline creation:
OldNewmulti_UBspline_3d_s * einspline_create_multi_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, int num_splines) { // Create new spline multi_UBspline_3d_s *restrict spline = malloc(sizeof(multi_UBspline_3d_s)); ... } ... multi_UBspline_3d_d * einspline_create_multi_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, int num_splines) { // Create new spline multi_UBspline_3d_d *restrict spline = malloc(sizeof(multi_UBspline_3d_d)); ... }
multi_UBspline_3d_s * einspline_create_multi_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, int num_splines) { // Create new spline multi_UBspline_3d_s *restrict spline = (multi_UBspline_3d_s *)malloc(sizeof(multi_UBspline_3d_s)); ... } ... multi_UBspline_3d_d * einspline_create_multi_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, int num_splines) { // Create new spline multi_UBspline_3d_d *restrict spline = new multi_UBspline_3d_d;//(multi_UBspline_3d_d *)malloc(sizeof(multi_UBspline_3d_d)); ... } ...
- Create Kokkos view
OldNewspline->coefs_size = (size_t)Nx * spline->x_stride; spline->coefs = (double *)einspline_alloc(sizeof(double) * spline->coefs_size, QMC_CLINE);
// Create KokkosView spline->coefs_view = multi_UBspline_3d_d::coefs_view_t("Multi_UBspline_3d_d",Nx,Ny,Nz,N); // Check data layout is as expected int strides[4]; spline->coefs_view.stride(strides); if(spline->x_stride!=strides[0] || spline->y_stride!=strides[1] || spline->z_stride!=strides[2] || 1!=strides[3]) fprintf(stderr, "Kokkos View has non-compatible strides %i %i | %i %i | %i %i\n", spline->x_stride,strides[0], spline->y_stride,strides[1], spline->z_stride,strides[2] ); spline->coefs = spline->coefs_view.data();
- Modify Bspline creation
OldNewUBspline_3d_d *einspline_create_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, double *data) { // Create new spline UBspline_3d_d *restrict spline = malloc(sizeof(UBspline_3d_d)); ... } ... UBspline_3d_s *einspline_create_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, float *data) { // Create new spline UBspline_3d_s *spline = malloc(sizeof(UBspline_3d_s)); ... } ...
UBspline_3d_d *einspline_create_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, double *data) { // Create new spline UBspline_3d_d *restrict spline = (UBspline_3d_d *)malloc(sizeof(UBspline_3d_d)); ... } ... UBspline_3d_s *einspline_create_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, float *data) { // Create new spline UBspline_3d_s *spline = (UBspline_3d_s *)malloc(sizeof(UBspline_3d_s)); ... } ...
- Add Kokkos header file
- In
- Add multi_Bspline and Bspline functions
Old
Newextern "C" { #endif void *einspline_alloc(size_t size, size_t alignment); void einspline_free(void *ptr); #ifdef __cplusplus }
extern "C" { void *einspline_alloc(size_t size, size_t alignment); void einspline_free(void *ptr); multi_UBspline_3d_s * einspline_create_multi_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, int num_splines); multi_UBspline_3d_d * einspline_create_multi_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, int num_splines); UBspline_3d_s *einspline_create_UBspline_3d_s(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_s xBC, BCtype_s yBC, BCtype_s zBC, float *data); UBspline_3d_d *einspline_create_UBspline_3d_d(Ugrid x_grid, Ugrid y_grid, Ugrid z_grid, BCtype_d xBC, BCtype_d yBC, BCtype_d zBC, double *data); }
- Add multi_Bspline and Bspline functions
We assess our Kokkos implementation of the spline and Jastrow kernels on the following architectures.
- Many-core architecture: Intel Xeon Phi (KNL)
- GPU: Nvidia K40
This research was supported by the Exascale Computing Project (ECP), Project Number: 17-SC-20-SC, a collaborative effort of two DOE organizations—the Office of Science and the National Nuclear Security Administration—responsible for the planning and preparation of a capable exascale ecosystem—including software, applications, hardware, advanced system engineering, and early testbed platforms—to support the nation’s exascale computing imperative.|