1152b3e56SJunchao Zhang #if !defined(PETSCVEC_KOKKOS_HPP) 2152b3e56SJunchao Zhang #define PETSCVEC_KOKKOS_HPP 3152b3e56SJunchao Zhang 4*11d22bbfSJunchao Zhang #include <petscconf.h> 5*11d22bbfSJunchao Zhang 6*11d22bbfSJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 7*11d22bbfSJunchao Zhang #if defined(petsccomplexlib) 8*11d22bbfSJunchao Zhang #error "Error: You must include petscvec_kokkos.hpp before other petsc headers in this C++ file to use petsc complex with Kokkos" 9*11d22bbfSJunchao Zhang #endif 10*11d22bbfSJunchao Zhang 11*11d22bbfSJunchao Zhang #define PETSC_DESIRE_KOKKOS_COMPLEX 1 /* To control the definition of petsccomplexlib in petscsystypes.h */ 12*11d22bbfSJunchao Zhang #endif 13*11d22bbfSJunchao Zhang 14152b3e56SJunchao Zhang #include <petscvec.h> 15152b3e56SJunchao Zhang 16152b3e56SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS) 17152b3e56SJunchao Zhang #include <Kokkos_Core.hpp> 18152b3e56SJunchao Zhang 19152b3e56SJunchao Zhang #if defined(PETSC_HAVE_CUDA) 20152b3e56SJunchao Zhang #define WaitForKokkos() PetscCUDASynchronize ? (Kokkos::fence(),0) : 0 21152b3e56SJunchao Zhang #elif defined(PETSC_HAVE_HIP) 22152b3e56SJunchao Zhang #define WaitForKokkos() PetscHIPSynchronize ? (Kokkos::fence(),0) : 0 23152b3e56SJunchao Zhang #else 24152b3e56SJunchao Zhang #define WaitForKokkos() 0 25152b3e56SJunchao Zhang #endif 26152b3e56SJunchao Zhang 27152b3e56SJunchao Zhang /* Routines to get/restore Kokkos Views from PETSc vectors */ 28152b3e56SJunchao Zhang 29152b3e56SJunchao Zhang /* Like VecGetArrayRead() */ 30152b3e56SJunchao Zhang template<class MemorySpace> PetscErrorCode VecGetKokkosView (Vec,Kokkos::View<const PetscScalar*,MemorySpace>*); 31152b3e56SJunchao Zhang template<class MemorySpace> PetscErrorCode VecRestoreKokkosView(Vec,Kokkos::View<const PetscScalar*,MemorySpace>*){return 0;} 32152b3e56SJunchao Zhang 33152b3e56SJunchao Zhang /* Like VecGetArray() */ 34152b3e56SJunchao Zhang template<class MemorySpace> PetscErrorCode VecGetKokkosView (Vec,Kokkos::View<PetscScalar*,MemorySpace>*); 35152b3e56SJunchao Zhang template<class MemorySpace> PetscErrorCode VecRestoreKokkosView(Vec,Kokkos::View<PetscScalar*,MemorySpace>*); 36152b3e56SJunchao Zhang 37152b3e56SJunchao Zhang /* Like VecGetArrayWrite() */ 38152b3e56SJunchao Zhang template<class MemorySpace> PetscErrorCode VecGetKokkosViewWrite (Vec,Kokkos::View<PetscScalar*,MemorySpace>*); 39152b3e56SJunchao Zhang template<class MemorySpace> PetscErrorCode VecRestoreKokkosViewWrite(Vec,Kokkos::View<PetscScalar*,MemorySpace>*); 40152b3e56SJunchao Zhang 41152b3e56SJunchao Zhang #endif 42152b3e56SJunchao Zhang 43152b3e56SJunchao Zhang #endif 44