xref: /petsc/include/petscvec_kokkos.hpp (revision 21bad809f40e818c1322b1ab0473215d46c527d1)
1152b3e56SJunchao Zhang #if !defined(PETSCVEC_KOKKOS_HPP)
2152b3e56SJunchao Zhang #define PETSCVEC_KOKKOS_HPP
3152b3e56SJunchao Zhang 
411d22bbfSJunchao Zhang #include <petscconf.h>
511d22bbfSJunchao Zhang 
611d22bbfSJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
711d22bbfSJunchao Zhang   #if defined(petsccomplexlib)
811d22bbfSJunchao Zhang     #error "Error: You must include petscvec_kokkos.hpp before other petsc headers in this C++ file to use petsc complex with Kokkos"
911d22bbfSJunchao Zhang   #endif
1011d22bbfSJunchao Zhang 
1111d22bbfSJunchao Zhang   #define PETSC_DESIRE_KOKKOS_COMPLEX   1   /* To control the definition of petsccomplexlib in petscsystypes.h */
1211d22bbfSJunchao Zhang #endif
1311d22bbfSJunchao Zhang 
14152b3e56SJunchao Zhang #include <petscvec.h>
15152b3e56SJunchao Zhang 
16152b3e56SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
17152b3e56SJunchao Zhang   #include <Kokkos_Core.hpp>
18152b3e56SJunchao Zhang 
19*21bad809SJunchao Zhang /*@C
20*21bad809SJunchao Zhang      VecGetKokkosView - Returns a constant Kokkos View that contains up-to-date data of a vector in the specified memory space.
21152b3e56SJunchao Zhang 
22*21bad809SJunchao Zhang    Synopsis:
23*21bad809SJunchao Zhang    #include <petscvec_kokkos.hpp>
24*21bad809SJunchao Zhang    PetscErrorCode VecGetKokkosView  (Vec v,Kokkos::View<const PetscScalar*,MemorySpace>* kv);
25*21bad809SJunchao Zhang    PetscErrorCode VecGetKokkosView  (Vec v,Kokkos::View<PetscScalar*,MemorySpace>* kv);
26*21bad809SJunchao Zhang 
27*21bad809SJunchao Zhang    Logically Collective on Vec
28*21bad809SJunchao Zhang 
29*21bad809SJunchao Zhang    Input Parameter:
30*21bad809SJunchao Zhang .  v - the vector in type of VECKOKKOS
31*21bad809SJunchao Zhang 
32*21bad809SJunchao Zhang    Output Parameter:
33*21bad809SJunchao Zhang .  kv - the Kokkos View with a user-specified template parameter MemorySpace
34*21bad809SJunchao Zhang 
35*21bad809SJunchao Zhang    Notes:
36*21bad809SJunchao Zhang    If the vector is not of type VECKOKKOS, an error will be raised.
37*21bad809SJunchao Zhang    The functions are similar to VecGetArrayRead() and VecGetArray() respectively. One can read-only or read/write the returned Kokkos View.
38*21bad809SJunchao Zhang    Note that passing in a const View enables read-only access.
39*21bad809SJunchao Zhang    One must return the View by a matching VecRestoreKokkosView() after finishing using the View. Currently, only two memory
40*21bad809SJunchao Zhang    spaces are supported: Kokkos::HostSpace and Kokkos::DefaultExecutionSpace::memory_space.
41*21bad809SJunchao Zhang    If needed, a memory copy will be internally called to copy the latest vector data to the specified memory space.
42*21bad809SJunchao Zhang 
43*21bad809SJunchao Zhang    Level: beginner
44*21bad809SJunchao Zhang 
45*21bad809SJunchao Zhang .seealso: VecRestoreKokkosView(), VecRestoreArray(), VecGetKokkosViewWrite(), VecGetArrayRead(), VecGetArrays(), VecGetArrayF90(), VecGetArrayReadF90(), VecPlaceArray(), VecGetArray2d(),
46*21bad809SJunchao Zhang           VecGetArrayPair(), VecRestoreArrayPair(), VecGetArrayWrite(), VecRestoreArrayWrite()
47*21bad809SJunchao Zhang @*/
48152b3e56SJunchao Zhang   template<class MemorySpace> PetscErrorCode VecGetKokkosView (Vec,Kokkos::View<const PetscScalar*,MemorySpace>*);
49152b3e56SJunchao Zhang   template<class MemorySpace> PetscErrorCode VecGetKokkosView (Vec,Kokkos::View<PetscScalar*,MemorySpace>*);
50*21bad809SJunchao Zhang 
51*21bad809SJunchao Zhang /*@C
52*21bad809SJunchao Zhang        VecRestoreKokkosView - Returns a Kokkos View gotten by VecGetKokkosView().
53*21bad809SJunchao Zhang 
54*21bad809SJunchao Zhang    Synopsis:
55*21bad809SJunchao Zhang    #include <petscvec_kokkos.hpp>
56*21bad809SJunchao Zhang    PetscErrorCode VecRestoreKokkosView  (Vec v,Kokkos::View<const PetscScalar*,MemorySpace>* kv);
57*21bad809SJunchao Zhang    PetscErrorCode VecRestoreKokkosView  (Vec v,Kokkos::View<PetscScalar*,MemorySpace>* kv);
58*21bad809SJunchao Zhang 
59*21bad809SJunchao Zhang    Logically Collective on Vec
60*21bad809SJunchao Zhang 
61*21bad809SJunchao Zhang    Input Parameter:
62*21bad809SJunchao Zhang +  v  - the vector in type of VECKOKKOS
63*21bad809SJunchao Zhang -  kv - the Kokkos View with a user-specified template parameter MemorySpace
64*21bad809SJunchao Zhang 
65*21bad809SJunchao Zhang    Notes:
66*21bad809SJunchao Zhang    If the vector is not of type VECKOKKOS, an error will be raised.
67*21bad809SJunchao Zhang    The functions are similar to VecRestoreArrayRead() and VecRestoreArray() respectively. They are the counterpart of VecGetKokkosView().
68*21bad809SJunchao Zhang 
69*21bad809SJunchao Zhang    Level: beginner
70*21bad809SJunchao Zhang 
71*21bad809SJunchao Zhang .seealso: VecGetKokkosView(), VecRestoreKokkosViewWrite(), VecRestoreArray(), VecGetArrayRead(), VecGetArrays(), VecGetArrayF90(), VecGetArrayReadF90(), VecPlaceArray(), VecGetArray2d(),
72*21bad809SJunchao Zhang           VecGetArrayPair(), VecRestoreArrayPair(), VecGetArrayWrite(), VecRestoreArrayWrite()
73*21bad809SJunchao Zhang @*/
74*21bad809SJunchao Zhang   template<class MemorySpace> PetscErrorCode VecRestoreKokkosView(Vec,Kokkos::View<const PetscScalar*,MemorySpace>*){return 0;}
75152b3e56SJunchao Zhang   template<class MemorySpace> PetscErrorCode VecRestoreKokkosView(Vec,Kokkos::View<PetscScalar*,MemorySpace>*);
76152b3e56SJunchao Zhang 
77*21bad809SJunchao Zhang 
78*21bad809SJunchao Zhang /*@C
79*21bad809SJunchao Zhang      VecGetKokkosViewWrite - Returns a Kokkos View that contains the array of a vector in the specified memory space.
80*21bad809SJunchao Zhang 
81*21bad809SJunchao Zhang    Synopsis:
82*21bad809SJunchao Zhang    #include <petscvec_kokkos.hpp>
83*21bad809SJunchao Zhang    PetscErrorCode VecGetKokkosViewWrite  (Vec v,Kokkos::View<PetscScalar*,MemorySpace>* kv);
84*21bad809SJunchao Zhang 
85*21bad809SJunchao Zhang    Logically Collective on Vec
86*21bad809SJunchao Zhang 
87*21bad809SJunchao Zhang    Input Parameter:
88*21bad809SJunchao Zhang .  v - the vector in type of VECKOKKOS
89*21bad809SJunchao Zhang 
90*21bad809SJunchao Zhang    Output Parameter:
91*21bad809SJunchao Zhang .  kv - the Kokkos View with a user-specified template parameter MemorySpace
92*21bad809SJunchao Zhang 
93*21bad809SJunchao Zhang    Notes:
94*21bad809SJunchao Zhang    If the vector is not of type VECKOKKOS, an error will be raised.
95*21bad809SJunchao Zhang    The functions is similar to VecGetArrayWrite(). The returned view might contain garbage data or stale data and one is not
96*21bad809SJunchao Zhang    expected to read data from the View. Instead, one is expected to overwrite all data in the View.
97*21bad809SJunchao Zhang    One must return the View by a matching VecRestoreKokkosViewWrite() after finishing using the View.
98*21bad809SJunchao Zhang   Currently, only two memory spaces are supported: Kokkos::HostSpace and Kokkos::DefaultExecutionSpace::memory_space.
99*21bad809SJunchao Zhang 
100*21bad809SJunchao Zhang    Level: beginner
101*21bad809SJunchao Zhang 
102*21bad809SJunchao Zhang .seealso: VecRestoreKokkosViewWrite(), VecRestoreKokkosView(), VecGetKokkosView(), VecRestoreArray(), VecGetArrayRead(), VecGetArrays(), VecGetArrayF90(), VecGetArrayReadF90(), VecPlaceArray(), VecGetArray2d(),
103*21bad809SJunchao Zhang           VecGetArrayPair(), VecRestoreArrayPair(), VecGetArrayWrite(), VecRestoreArrayWrite()
104*21bad809SJunchao Zhang @*/
105152b3e56SJunchao Zhang   template<class MemorySpace> PetscErrorCode VecGetKokkosViewWrite    (Vec,Kokkos::View<PetscScalar*,MemorySpace>*);
106*21bad809SJunchao Zhang 
107*21bad809SJunchao Zhang /*@C
108*21bad809SJunchao Zhang      VecRestoreKokkosViewWrite - Returns a Kokkos View gotten by VecGetKokkosViewWrite().
109*21bad809SJunchao Zhang 
110*21bad809SJunchao Zhang    Synopsis:
111*21bad809SJunchao Zhang    #include <petscvec_kokkos.hpp>
112*21bad809SJunchao Zhang    PetscErrorCode VecRestoreKokkosViewWrite  (Vec v,Kokkos::View<PetscScalar*,MemorySpace>* kv);
113*21bad809SJunchao Zhang 
114*21bad809SJunchao Zhang    Logically Collective on Vec
115*21bad809SJunchao Zhang 
116*21bad809SJunchao Zhang    Input Parameter:
117*21bad809SJunchao Zhang +  v  - the vector in type of VECKOKKOS
118*21bad809SJunchao Zhang -  kv - the Kokkos View with a user-specified template parameter MemorySpace
119*21bad809SJunchao Zhang 
120*21bad809SJunchao Zhang    Notes:
121*21bad809SJunchao Zhang    If the vector is not of type VECKOKKOS, an error will be raised.
122*21bad809SJunchao Zhang    The function is similar to VecRestoreArrayWrite(). It is the counterpart of VecGetKokkosViewWrite().
123*21bad809SJunchao Zhang 
124*21bad809SJunchao Zhang    Level: beginner
125*21bad809SJunchao Zhang 
126*21bad809SJunchao Zhang .seealso: VecGetKokkosViewWrite(), VecGetKokkosView(), VecGetKokkosView(), VecRestoreArray(), VecGetArrayRead(), VecGetArrays(), VecGetArrayF90(), VecGetArrayReadF90(), VecPlaceArray(), VecGetArray2d(),
127*21bad809SJunchao Zhang           VecGetArrayPair(), VecRestoreArrayPair(), VecGetArrayWrite(), VecRestoreArrayWrite()
128*21bad809SJunchao Zhang @*/
129152b3e56SJunchao Zhang   template<class MemorySpace> PetscErrorCode VecRestoreKokkosViewWrite(Vec,Kokkos::View<PetscScalar*,MemorySpace>*);
130152b3e56SJunchao Zhang 
131152b3e56SJunchao Zhang #endif
132152b3e56SJunchao Zhang 
133152b3e56SJunchao Zhang #endif
134