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