Actual source code: pcbjkokkosimpl.h

  1: #pragma once

  3: #include <petscvec_kokkos.hpp>
  4: #include <petscpkg_version.h>
  5: #include <petsc/private/pcimpl.h>
  6: #include <petsc/private/deviceimpl.h>
  7: #include <petsc/private/kspimpl.h>

  9: #include "Kokkos_Core.hpp"

 11: #if PetscDefined(HAVE_CUDA)
 12:   #include <nvtx3/nvToolsExt.h>
 13: #endif

 15: #define PCBJKOKKOS_SHARED_LEVEL 1 // 0 is shared, 1 is global
 16: #define PCBJKOKKOS_VEC_SIZE     16
 17: #define PCBJKOKKOS_TEAM_SIZE    16

 19: #define PCBJKOKKOS_VERBOSE_LEVEL 1

 21: typedef enum {
 22:   BATCH_KSP_BICG_IDX,
 23:   BATCH_KSP_TFQMR_IDX,
 24:   BATCH_KSP_GMRESKK_IDX,
 25:   BATCH_KSP_PREONLY_IDX,
 26:   NUM_BATCH_TYPES
 27: } KSPIndex;

 29: typedef Kokkos::DefaultExecutionSpace exec_space;
 30: using layout           = Kokkos::LayoutRight;
 31: using IntView          = Kokkos::View<PetscInt **, layout, exec_space>;
 32: using AMatrixValueView = const Kokkos::View<PetscScalar **, layout, exec_space>;
 33: using XYType           = const Kokkos::View<PetscScalar **, layout, exec_space>;

 35: typedef struct {
 36:   Vec                                               vec_diag;
 37:   PetscInt                                          nBlocks; /* total number of blocks */
 38:   PetscInt                                          n;       // cache host version of d_bid_eqOffset_k[nBlocks]
 39:   KSP                                               ksp;     // Used just for options. Should have one for each block
 40:   Kokkos::View<PetscInt *, Kokkos::LayoutRight>    *d_bid_eqOffset_k;
 41:   Kokkos::View<PetscScalar *, Kokkos::LayoutRight> *d_idiag_k;
 42:   Kokkos::View<PetscInt *>                         *d_isrow_k;
 43:   Kokkos::View<PetscInt *>                         *d_isicol_k;
 44:   KSPIndex                                          ksp_type_idx;
 45:   PetscInt                                          nwork;
 46:   PetscInt                                          const_block_size; // used to decide to use shared memory for work vectors
 47:   PetscInt                                         *dm_Nf;            // Number of fields in each DM
 48:   PetscInt                                          num_dms;
 49:   // diagnostics
 50:   PetscBool reason;
 51:   PetscBool monitor;
 52:   PetscInt  batch_target;
 53:   PetscInt  rank_target;
 54:   PetscInt  nsolves_team;
 55:   PetscInt  max_nits;
 56:   // caches
 57:   IntView          *rowOffsets;
 58:   IntView          *colIndices;
 59:   XYType           *batch_b;
 60:   XYType           *batch_x;
 61:   AMatrixValueView *batch_values;
 62: } PC_PCBJKOKKOS;

 64: typedef Kokkos::TeamPolicy<>::member_type team_member;
 65: #if PetscDefined(HAVE_KOKKOS_KERNELS_BATCH)
 66: PETSC_INTERN PetscErrorCode PCApply_BJKOKKOSKERNELS(PC, const PetscScalar *, PetscScalar *, const PetscInt *glb_Aai, const PetscInt *glb_Aaj, const PetscScalar *glb_Aaa, const PetscInt, MatInfo, const PetscInt, PCFailedReason *);
 67: #endif