xref: /petsc/src/ksp/ksp/utils/lmvm/blas_cyclic/cupm/blas_cyclic_cupm.cxx (revision 017deb10d530c1b6d9744fcd772cd96c5fcd74f2)
1 #include "blas_cyclic_cupm.h"
2 #include "blas_cyclic_cupm_impl.hpp"
3 
4 namespace Petsc
5 {
6 
7 namespace device
8 {
9 
10 namespace cupm
11 {
12 
13 namespace impl
14 {
15 #if PetscDefined(HAVE_CUDA)
16 template struct BLASCyclic<DeviceType::CUDA>;
17 #endif
18 
19 #if PetscDefined(HAVE_HIP)
20 template struct BLASCyclic<DeviceType::HIP>;
21 #endif
22 } // namespace impl
23 
24 } // namespace cupm
25 
26 } // namespace device
27 
28 } // namespace Petsc
29 
AXPBYCyclic_CUPM_Private(PetscInt m,PetscInt oldest,PetscInt next,PetscScalar alpha,const PetscScalar x[],PetscScalar beta,PetscScalar y[],PetscInt y_stride)30 PETSC_INTERN PetscErrorCode AXPBYCyclic_CUPM_Private(PetscInt m, PetscInt oldest, PetscInt next, PetscScalar alpha, const PetscScalar x[], PetscScalar beta, PetscScalar y[], PetscInt y_stride)
31 {
32   PetscDeviceContext dctx;
33   PetscDeviceType    device_type;
34 
35   PetscFunctionBegin;
36   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
37   PetscCall(PetscDeviceContextGetDeviceType(dctx, &device_type));
38   switch (device_type) {
39 #if PetscDefined(HAVE_CUDA)
40   case PETSC_DEVICE_CUDA:
41     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::CUDA>::axpby(dctx, m, oldest, next, alpha, x, beta, y, y_stride));
42     break;
43 #endif
44 #if PetscDefined(HAVE_HIP)
45   case PETSC_DEVICE_HIP:
46     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::HIP>::axpby(dctx, m, oldest, next, alpha, x, beta, y, y_stride));
47     break;
48 #endif
49   default:
50     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Unsupported device type %s", PetscDeviceTypes[device_type]);
51   }
52   PetscFunctionReturn(PETSC_SUCCESS);
53 }
54 
DMVCyclic_CUPM_Private(PetscBool hermitian_transpose,PetscInt m,PetscInt oldest,PetscInt next,PetscScalar alpha,const PetscScalar A[],const PetscScalar x[],PetscScalar beta,PetscScalar y[])55 PETSC_INTERN PetscErrorCode DMVCyclic_CUPM_Private(PetscBool hermitian_transpose, PetscInt m, PetscInt oldest, PetscInt next, PetscScalar alpha, const PetscScalar A[], const PetscScalar x[], PetscScalar beta, PetscScalar y[])
56 {
57   PetscDeviceContext dctx;
58   PetscDeviceType    device_type;
59 
60   PetscFunctionBegin;
61   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
62   PetscCall(PetscDeviceContextGetDeviceType(dctx, &device_type));
63   switch (device_type) {
64 #if PetscDefined(HAVE_CUDA)
65   case PETSC_DEVICE_CUDA:
66     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::CUDA>::dmv(dctx, hermitian_transpose, m, oldest, next, alpha, A, x, beta, y));
67     break;
68 #endif
69 #if PetscDefined(HAVE_HIP)
70   case PETSC_DEVICE_HIP:
71     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::HIP>::dmv(dctx, hermitian_transpose, m, oldest, next, alpha, A, x, beta, y));
72     break;
73 #endif
74   default:
75     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Unsupported device type %s", PetscDeviceTypes[device_type]);
76   }
77   PetscFunctionReturn(PETSC_SUCCESS);
78 }
79 
DSVCyclic_CUPM_Private(PetscBool hermitian_transpose,PetscInt m,PetscInt oldest,PetscInt next,const PetscScalar A[],const PetscScalar x[],PetscScalar y[])80 PETSC_INTERN PetscErrorCode DSVCyclic_CUPM_Private(PetscBool hermitian_transpose, PetscInt m, PetscInt oldest, PetscInt next, const PetscScalar A[], const PetscScalar x[], PetscScalar y[])
81 {
82   PetscDeviceContext dctx;
83   PetscDeviceType    device_type;
84 
85   PetscFunctionBegin;
86   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
87   PetscCall(PetscDeviceContextGetDeviceType(dctx, &device_type));
88   switch (device_type) {
89 #if PetscDefined(HAVE_CUDA)
90   case PETSC_DEVICE_CUDA:
91     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::CUDA>::dsv(dctx, hermitian_transpose, m, oldest, next, A, x, y));
92     break;
93 #endif
94 #if PetscDefined(HAVE_HIP)
95   case PETSC_DEVICE_HIP:
96     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::HIP>::dsv(dctx, hermitian_transpose, m, oldest, next, A, x, y));
97     break;
98 #endif
99   default:
100     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Unsupported device type %s", PetscDeviceTypes[device_type]);
101   }
102   PetscFunctionReturn(PETSC_SUCCESS);
103 }
104 
TRSVCyclic_CUPM_Private(PetscBool hermitian_transpose,PetscInt m,PetscInt oldest,PetscInt next,const PetscScalar A[],PetscInt lda,const PetscScalar x[],PetscScalar y[])105 PETSC_INTERN PetscErrorCode TRSVCyclic_CUPM_Private(PetscBool hermitian_transpose, PetscInt m, PetscInt oldest, PetscInt next, const PetscScalar A[], PetscInt lda, const PetscScalar x[], PetscScalar y[])
106 {
107   PetscDeviceContext dctx;
108   PetscDeviceType    device_type;
109 
110   PetscFunctionBegin;
111   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
112   PetscCall(PetscDeviceContextGetDeviceType(dctx, &device_type));
113   switch (device_type) {
114 #if PetscDefined(HAVE_CUDA)
115   case PETSC_DEVICE_CUDA:
116     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::CUDA>::trsv(dctx, hermitian_transpose, m, oldest, next, A, lda, x, y));
117     break;
118 #endif
119 #if PetscDefined(HAVE_HIP)
120   case PETSC_DEVICE_HIP:
121     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::HIP>::trsv(dctx, hermitian_transpose, m, oldest, next, A, lda, x, y));
122     break;
123 #endif
124   default:
125     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Unsupported device type %s", PetscDeviceTypes[device_type]);
126   }
127   PetscFunctionReturn(PETSC_SUCCESS);
128 }
129 
HEMVCyclic_CUPM_Private(PetscInt m,PetscInt oldest,PetscInt next,PetscScalar alpha,const PetscScalar A[],PetscInt lda,const PetscScalar x[],PetscScalar beta,PetscScalar y[])130 PETSC_INTERN PetscErrorCode HEMVCyclic_CUPM_Private(PetscInt m, PetscInt oldest, PetscInt next, PetscScalar alpha, const PetscScalar A[], PetscInt lda, const PetscScalar x[], PetscScalar beta, PetscScalar y[])
131 {
132   PetscDeviceContext dctx;
133   PetscDeviceType    device_type;
134 
135   PetscFunctionBegin;
136   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
137   PetscCall(PetscDeviceContextGetDeviceType(dctx, &device_type));
138   switch (device_type) {
139 #if PetscDefined(HAVE_CUDA)
140   case PETSC_DEVICE_CUDA:
141     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::CUDA>::hemv(dctx, m, oldest, next, alpha, A, lda, x, beta, y));
142     break;
143 #endif
144 #if PetscDefined(HAVE_HIP)
145   case PETSC_DEVICE_HIP:
146     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::HIP>::hemv(dctx, m, oldest, next, alpha, A, lda, x, beta, y));
147     break;
148 #endif
149   default:
150     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Unsupported device type %s", PetscDeviceTypes[device_type]);
151   }
152   PetscFunctionReturn(PETSC_SUCCESS);
153 }
154 
GEMVCyclic_CUPM_Private(PetscBool hermitian_transpose,PetscInt m,PetscInt oldest,PetscInt next,PetscScalar alpha,const PetscScalar A[],PetscInt lda,const PetscScalar x[],PetscScalar beta,PetscScalar y[])155 PETSC_INTERN PetscErrorCode GEMVCyclic_CUPM_Private(PetscBool hermitian_transpose, PetscInt m, PetscInt oldest, PetscInt next, PetscScalar alpha, const PetscScalar A[], PetscInt lda, const PetscScalar x[], PetscScalar beta, PetscScalar y[])
156 {
157   PetscDeviceContext dctx;
158   PetscDeviceType    device_type;
159 
160   PetscFunctionBegin;
161   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
162   PetscCall(PetscDeviceContextGetDeviceType(dctx, &device_type));
163   switch (device_type) {
164 #if PetscDefined(HAVE_CUDA)
165   case PETSC_DEVICE_CUDA:
166     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::CUDA>::gemv(dctx, hermitian_transpose, m, oldest, next, alpha, A, lda, x, beta, y));
167     break;
168 #endif
169 #if PetscDefined(HAVE_HIP)
170   case PETSC_DEVICE_HIP:
171     PetscCall(::Petsc::device::cupm::impl::BLASCyclic<::Petsc::device::cupm::DeviceType::HIP>::gemv(dctx, hermitian_transpose, m, oldest, next, alpha, A, lda, x, beta, y));
172     break;
173 #endif
174   default:
175     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Unsupported device type %s", PetscDeviceTypes[device_type]);
176   }
177   PetscFunctionReturn(PETSC_SUCCESS);
178 }
179