Actual source code: vecmpicupm.hip.cpp
1: #include "../vecmpicupm.hpp" /*I <petscvec.h> I*/
3: using namespace Petsc::vec::cupm::impl;
5: static constexpr auto VecMPI_HIP = VecMPI_CUPM<::Petsc::device::cupm::DeviceType::HIP>{};
7: /*MC
8: VECHIP - VECHIP = "hip" - A VECSEQHIP on a single-process communicator, and VECMPIHIP
9: otherwise.
11: Options Database Keys:
12: . -vec_type hip - sets the vector type to VECHIP during a call to VecSetFromOptions()
14: Level: beginner
16: .seealso: VecCreate(), VecSetType(), VecSetFromOptions(), VecCreateMPIWithArray(), VECSEQHIP,
17: VECMPIHIP, VECSTANDARD, VecType, VecCreateMPI(), VecSetPinnedMemoryMin()
18: M*/
20: /*MC
21: VECMPIHIP - VECMPIHIP = "mpihip" - The basic parallel vector, modified to use HIP
23: Options Database Keys:
24: . -vec_type mpihip - sets the vector type to VECMPIHIP during a call to VecSetFromOptions()
26: Level: beginner
28: .seealso: VecCreate(), VecSetType(), VecSetFromOptions(), VecCreateMPIWithArray(), VECMPI,
29: VecType, VecCreateMPI(), VecSetPinnedMemoryMin()
30: M*/
32: PetscErrorCode VecCreate_HIP(Vec v)
33: {
34: PetscFunctionBegin;
35: PetscCall(VecMPI_HIP.Create_CUPM(v));
36: PetscFunctionReturn(PETSC_SUCCESS);
37: }
39: PetscErrorCode VecCreate_MPIHIP(Vec v)
40: {
41: PetscFunctionBegin;
42: PetscCall(VecMPI_HIP.create(v));
43: PetscFunctionReturn(PETSC_SUCCESS);
44: }
46: PetscErrorCode VecHIPGetArrays_Private(Vec v, const PetscScalar **host_array, const PetscScalar **device_array, PetscOffloadMask *mask)
47: {
48: PetscDeviceContext dctx;
50: PetscFunctionBegin;
52: PetscCall(PetscDeviceContextGetCurrentContextAssertType_Internal(&dctx, PETSC_DEVICE_HIP));
53: PetscCall(VecMPI_HIP.GetArrays_CUPMBase(v, host_array, device_array, mask, dctx));
54: PetscFunctionReturn(PETSC_SUCCESS);
55: }
57: /*@
58: VecCreateMPIHIP - Creates a standard, parallel, array-style vector for HIP devices.
60: Collective, Possibly Synchronous
62: Input Parameters:
63: + comm - the MPI communicator to use
64: . n - local vector length (or PETSC_DECIDE to have calculated if N is given)
65: - N - global vector length (or PETSC_DETERMINE to have calculated if n is given)
67: Output Parameter:
68: . v - the vector
70: Notes:
71: Use VecDuplicate() or VecDuplicateVecs() to form additional vectors of the same type as an
72: existing vector.
74: This function may initialize PetscDevice, which may incur a device synchronization.
76: Level: intermediate
78: .seealso: VecCreateMPIHIPWithArray(), VecCreateMPIHIPWithArrays(), VecCreateSeqHIP(),
79: VecCreateSeq(), VecCreateMPI(), VecCreate(), VecDuplicate(), VecDuplicateVecs(),
80: VecCreateGhost(), VecCreateMPIWithArray(), VecCreateGhostWithArray(), VecMPISetGhost()
81: @*/
82: PetscErrorCode VecCreateMPIHIP(MPI_Comm comm, PetscInt n, PetscInt N, Vec *v)
83: {
84: PetscFunctionBegin;
86: PetscCall(VecMPI_HIP.creatempicupm(comm, 0, n, N, v, PETSC_TRUE));
87: PetscFunctionReturn(PETSC_SUCCESS);
88: }
90: /*@C
91: VecCreateMPIHIPWithArrays - Creates a parallel, array-style vector using HIP, where the
92: user provides the complete array space to store the vector values.
94: Collective, Possibly Synchronous
96: Input Parameters:
97: + comm - the MPI communicator to use
98: . bs - block size, same meaning as VecSetBlockSize()
99: . n - local vector length, cannot be PETSC_DECIDE
100: . N - global vector length (or PETSC_DECIDE to have calculated)
101: . cpuarray - CPU memory where the vector elements are to be stored (or NULL)
102: - gpuarray - GPU memory where the vector elements are to be stored (or NULL)
104: Output Parameter:
105: . v - the vector
107: Notes:
108: See VecCreateSeqHIPWithArrays() for further discussion, this routine shares identical
109: semantics.
111: Level: intermediate
113: .seealso: VecCreateMPIHIP(), VecCreateSeqHIPWithArrays(), VecCreateMPIWithArray(),
114: VecCreateSeqWithArray(), VecCreate(), VecDuplicate(), VecDuplicateVecs(), VecCreateGhost(),
115: VecCreateMPI(), VecCreateGhostWithArray(), VecPlaceArray()
116: @*/
117: PetscErrorCode VecCreateMPIHIPWithArrays(MPI_Comm comm, PetscInt bs, PetscInt n, PetscInt N, const PetscScalar cpuarray[], const PetscScalar gpuarray[], Vec *v)
118: {
119: PetscFunctionBegin;
122: PetscCall(VecMPI_HIP.creatempicupmwitharrays(comm, bs, n, N, cpuarray, gpuarray, v));
123: PetscFunctionReturn(PETSC_SUCCESS);
124: }
126: /*@C
127: VecCreateMPIHIPWithArray - Creates a parallel, array-style vector using HIP, where the
128: user provides the device array space to store the vector values.
129: Collective
131: Input Parameters:
132: + comm - the MPI communicator to use
133: . bs - block size, same meaning as VecSetBlockSize()
134: . n - local vector length, cannot be PETSC_DECIDE
135: . N - global vector length (or PETSC_DECIDE to have calculated)
136: - gpuarray - the user provided GPU array to store the vector values
138: Output Parameter:
139: . v - the vector
141: Notes:
142: See VecCreateSeqHIPWithArray() for further discussion, this routine shares identical
143: semantics.
145: Level: intermediate
147: .seealso: VecCreateMPIHIP(), VecCreateSeqHIPWithArray(), VecCreateMPIWithArray(),
148: VecCreateSeqWithArray(), VecCreate(), VecDuplicate(), VecDuplicateVecs(), VecCreateGhost(),
149: VecCreateMPI(), VecCreateGhostWithArray(), VecPlaceArray()
150: @*/
151: PetscErrorCode VecCreateMPIHIPWithArray(MPI_Comm comm, PetscInt bs, PetscInt n, PetscInt N, const PetscScalar gpuarray[], Vec *v)
152: {
153: PetscFunctionBegin;
154: PetscCall(VecCreateMPIHIPWithArrays(comm, bs, n, N, nullptr, gpuarray, v));
155: PetscFunctionReturn(PETSC_SUCCESS);
156: }