15 USE iso_c_binding,
ONLY: c_char,&
29#include "./base/base_uses.f90"
34 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'parallel_gemm_api'
39 MODULE PROCEDURE parallel_gemm_fm
40 MODULE PROCEDURE parallel_gemm_cfm
64 SUBROUTINE parallel_gemm_fm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, &
65 matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, &
66 c_first_col, c_first_row)
67 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
68 INTEGER,
INTENT(IN) :: m, n, k
69 REAL(KIND=
dp),
INTENT(IN) :: alpha
70 TYPE(
cp_fm_type),
INTENT(IN) :: matrix_a, matrix_b
71 REAL(kind=
dp),
INTENT(IN) :: beta
73 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
74 b_first_row, c_first_col, c_first_row
76 CHARACTER(len=*),
PARAMETER :: routinen =
'parallel_gemm_fm'
78 INTEGER :: handle, my_multi
82 SELECT CASE (my_multi)
84 CALL timeset(routinen//
"_gemm", handle)
85 CALL cp_fm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
86 a_first_col=a_first_col, &
87 a_first_row=a_first_row, &
88 b_first_col=b_first_col, &
89 b_first_row=b_first_row, &
90 c_first_col=c_first_col, &
91 c_first_row=c_first_row)
94 CALL timeset(routinen//
"_cosma", handle)
96 CALL cosma_pdgemm(transa=transa, transb=transb, m=m, n=n, k=k, alpha=alpha, &
97 matrix_a=matrix_a, matrix_b=matrix_b, beta=beta, matrix_c=matrix_c, &
98 a_first_col=a_first_col, &
99 a_first_row=a_first_row, &
100 b_first_col=b_first_col, &
101 b_first_row=b_first_row, &
102 c_first_col=c_first_col, &
103 c_first_row=c_first_row)
105 cpabort(
"CP2K compiled without the COSMA library.")
108 CALL timestop(handle)
110 END SUBROUTINE parallel_gemm_fm
131 SUBROUTINE parallel_gemm_cfm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, &
132 matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, &
133 c_first_col, c_first_row)
134 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
135 INTEGER,
INTENT(IN) :: m, n, k
136 COMPLEX(KIND=dp),
INTENT(IN) :: alpha
137 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b
138 COMPLEX(KIND=dp),
INTENT(IN) :: beta
140 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
141 b_first_row, c_first_col, c_first_row
143 CHARACTER(len=*),
PARAMETER :: routineN =
'parallel_gemm_cfm'
145 INTEGER :: handle, handle1, my_multi
147 CALL timeset(routinen, handle)
151 SELECT CASE (my_multi)
153 CALL timeset(routinen//
"_gemm", handle1)
154 CALL cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
155 a_first_col=a_first_col, &
156 a_first_row=a_first_row, &
157 b_first_col=b_first_col, &
158 b_first_row=b_first_row, &
159 c_first_col=c_first_col, &
160 c_first_row=c_first_row)
161 CALL timestop(handle1)
164 CALL timeset(routinen//
"_cosma", handle1)
166 CALL cosma_pzgemm(transa=transa, transb=transb, m=m, n=n, k=k, alpha=alpha, &
167 matrix_a=matrix_a, matrix_b=matrix_b, beta=beta, matrix_c=matrix_c, &
168 a_first_col=a_first_col, &
169 a_first_row=a_first_row, &
170 b_first_col=b_first_col, &
171 b_first_row=b_first_row, &
172 c_first_col=c_first_col, &
173 c_first_row=c_first_row)
174 CALL timestop(handle1)
176 cpabort(
"CP2K compiled without the COSMA library.")
179 CALL timestop(handle)
181 END SUBROUTINE parallel_gemm_cfm
204 SUBROUTINE cosma_pdgemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
205 a_first_col, a_first_row, b_first_col, b_first_row, &
206 c_first_col, c_first_row)
207 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
208 INTEGER,
INTENT(IN) :: m, n, k
209 REAL(KIND=
dp),
INTENT(IN) :: alpha
210 TYPE(
cp_fm_type),
INTENT(IN) :: matrix_a, matrix_b
211 REAL(kind=
dp),
INTENT(IN) :: beta
213 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
214 b_first_row, c_first_col, c_first_row
216 INTEGER :: i_a, i_b, i_c, j_a, j_b, j_c
218 SUBROUTINE cosma_pdgemm_c(transa, transb, m, n, k, alpha, a, ia, ja, desca, &
219 b, ib, jb, descb, beta, c, ic, jc, descc) &
220 BIND(C, name="cosma_pdgemm")
221 IMPORT :: c_ptr, c_int, c_double, c_char
222 CHARACTER(KIND=C_CHAR) :: transa
223 CHARACTER(KIND=C_CHAR) :: transb
224 INTEGER(KIND=C_INT) :: m
225 INTEGER(KIND=C_INT) :: n
226 INTEGER(KIND=C_INT) :: k
227 REAL(kind=c_double) :: alpha
228 TYPE(c_ptr),
VALUE :: a
229 INTEGER(KIND=C_INT) :: ia
230 INTEGER(KIND=C_INT) :: ja
231 TYPE(c_ptr),
VALUE :: desca
232 TYPE(c_ptr),
VALUE :: b
233 INTEGER(KIND=C_INT) :: ib
234 INTEGER(KIND=C_INT) :: jb
235 TYPE(c_ptr),
VALUE :: descb
236 REAL(KIND=c_double) :: beta
237 TYPE(c_ptr),
VALUE :: c
238 INTEGER(KIND=C_INT) :: ic
239 INTEGER(KIND=C_INT) :: jc
240 TYPE(c_ptr),
VALUE :: descc
241 END SUBROUTINE cosma_pdgemm_c
244 IF (
PRESENT(a_first_row))
THEN
249 IF (
PRESENT(a_first_col))
THEN
254 IF (
PRESENT(b_first_row))
THEN
259 IF (
PRESENT(b_first_col))
THEN
264 IF (
PRESENT(c_first_row))
THEN
269 IF (
PRESENT(c_first_col))
THEN
275 CALL cosma_pdgemm_c(transa=transa, transb=transb, m=m, n=n, k=k, &
277 a=c_loc(matrix_a%local_data(1, 1)), ia=i_a, ja=j_a, &
278 desca=c_loc(matrix_a%matrix_struct%descriptor(1)), &
279 b=c_loc(matrix_b%local_data(1, 1)), ib=i_b, jb=j_b, &
280 descb=c_loc(matrix_b%matrix_struct%descriptor(1)), &
282 c=c_loc(matrix_c%local_data(1, 1)), ic=i_c, jc=j_c, &
283 descc=c_loc(matrix_c%matrix_struct%descriptor(1)))
285 END SUBROUTINE cosma_pdgemm
307 SUBROUTINE cosma_pzgemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
308 a_first_col, a_first_row, b_first_col, b_first_row, &
309 c_first_col, c_first_row)
310 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
311 INTEGER,
INTENT(IN) :: m, n, k
312 COMPLEX(KIND=dp),
INTENT(IN) :: alpha
313 TYPE(
cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b
314 COMPLEX(KIND=dp),
INTENT(IN) :: beta
316 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
317 b_first_row, c_first_col, c_first_row
319 INTEGER :: i_a, i_b, i_c, j_a, j_b, j_c
320 REAL(KIND=
dp),
DIMENSION(2),
TARGET :: alpha_t, beta_t
322 SUBROUTINE cosma_pzgemm_c(transa, transb, m, n, k, alpha, a, ia, ja, desca, &
323 b, ib, jb, descb, beta, c, ic, jc, descc) &
324 BIND(C, name="cosma_pzgemm")
325 IMPORT :: c_ptr, c_int, c_char
326 CHARACTER(KIND=C_CHAR) :: transa
327 CHARACTER(KIND=C_CHAR) :: transb
328 INTEGER(KIND=C_INT) :: m
329 INTEGER(KIND=C_INT) :: n
330 INTEGER(KIND=C_INT) :: k
331 TYPE(c_ptr),
VALUE :: alpha
332 TYPE(c_ptr),
VALUE :: a
333 INTEGER(KIND=C_INT) :: ia
334 INTEGER(KIND=C_INT) :: ja
335 TYPE(c_ptr),
VALUE :: desca
336 TYPE(c_ptr),
VALUE :: b
337 INTEGER(KIND=C_INT) :: ib
338 INTEGER(KIND=C_INT) :: jb
339 TYPE(c_ptr),
VALUE :: descb
340 TYPE(c_ptr),
VALUE :: beta
341 TYPE(c_ptr),
VALUE :: c
342 INTEGER(KIND=C_INT) :: ic
343 INTEGER(KIND=C_INT) :: jc
344 TYPE(c_ptr),
VALUE :: descc
345 END SUBROUTINE cosma_pzgemm_c
348 IF (
PRESENT(a_first_row))
THEN
353 IF (
PRESENT(a_first_col))
THEN
358 IF (
PRESENT(b_first_row))
THEN
363 IF (
PRESENT(b_first_col))
THEN
368 IF (
PRESENT(c_first_row))
THEN
373 IF (
PRESENT(c_first_col))
THEN
379 alpha_t(1) = real(alpha, kind=
dp)
380 alpha_t(2) = real(aimag(alpha), kind=
dp)
381 beta_t(1) = real(beta, kind=
dp)
382 beta_t(2) = real(aimag(beta), kind=
dp)
384 CALL cosma_pzgemm_c(transa=transa, transb=transb, m=m, n=n, k=k, &
385 alpha=c_loc(alpha_t), &
386 a=c_loc(matrix_a%local_data(1, 1)), ia=i_a, ja=j_a, &
387 desca=c_loc(matrix_a%matrix_struct%descriptor(1)), &
388 b=c_loc(matrix_b%local_data(1, 1)), ib=i_b, jb=j_b, &
389 descb=c_loc(matrix_b%matrix_struct%descriptor(1)), &
390 beta=c_loc(beta_t), &
391 c=c_loc(matrix_c%local_data(1, 1)), ic=i_c, jc=j_c, &
392 descc=c_loc(matrix_c%matrix_struct%descriptor(1)))
394 END SUBROUTINE cosma_pzgemm
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, c_first_row)
Performs one of the matrix-matrix operations: matrix_c = alpha * op1( matrix_a ) * op2( matrix_b ) + ...
Represents a complex full matrix distributed on many processors.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, c_first_row)
computes matrix_c = beta * matrix_c + alpha * ( matrix_a ** transa ) * ( matrix_b ** transb )
represent a full matrix distributed on many processors
integer function, public cp_fm_get_mm_type()
...
Defines the basic variable types.
integer, parameter, public dp
Fortran API for the offload package, which is written in C.
subroutine, public offload_activate_chosen_device()
Activates the device selected via offload_set_chosen_device()
basic linear algebra operations for full matrixes
Represent a complex full matrix.