15 USE iso_c_binding,
ONLY: c_char,&
29 #include "./base/base_uses.f90"
34 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'parallel_gemm_api'
36 PUBLIC :: parallel_gemm
38 INTERFACE parallel_gemm
39 MODULE PROCEDURE parallel_gemm_fm
40 MODULE PROCEDURE parallel_gemm_cfm
41 END INTERFACE parallel_gemm
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
72 TYPE(cp_fm_type),
INTENT(IN) :: matrix_c
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, handle1, my_multi
80 CALL timeset(routinen, handle)
84 SELECT CASE (my_multi)
86 CALL timeset(routinen//
"_gemm", handle1)
87 CALL cp_fm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
88 a_first_col=a_first_col, &
89 a_first_row=a_first_row, &
90 b_first_col=b_first_col, &
91 b_first_row=b_first_row, &
92 c_first_col=c_first_col, &
93 c_first_row=c_first_row)
94 CALL timestop(handle1)
97 CALL timeset(routinen//
"_cosma", handle1)
99 CALL cosma_pdgemm(transa=transa, transb=transb, m=m, n=n, k=k, alpha=alpha, &
100 matrix_a=matrix_a, matrix_b=matrix_b, beta=beta, matrix_c=matrix_c, &
101 a_first_col=a_first_col, &
102 a_first_row=a_first_row, &
103 b_first_col=b_first_col, &
104 b_first_row=b_first_row, &
105 c_first_col=c_first_col, &
106 c_first_row=c_first_row)
107 CALL timestop(handle1)
109 cpabort(
"CP2K compiled without the COSMA library.")
112 CALL timestop(handle)
114 END SUBROUTINE parallel_gemm_fm
135 SUBROUTINE parallel_gemm_cfm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, &
136 matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, &
137 c_first_col, c_first_row)
138 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
139 INTEGER,
INTENT(IN) :: m, n, k
140 COMPLEX(KIND=dp),
INTENT(IN) :: alpha
141 TYPE(cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b
142 COMPLEX(KIND=dp),
INTENT(IN) :: beta
143 TYPE(cp_cfm_type),
INTENT(IN) :: matrix_c
144 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
145 b_first_row, c_first_col, c_first_row
147 CHARACTER(len=*),
PARAMETER :: routineN =
'parallel_gemm_cfm'
149 INTEGER :: handle, handle1, my_multi
151 CALL timeset(routinen, handle)
155 SELECT CASE (my_multi)
157 CALL timeset(routinen//
"_gemm", handle1)
158 CALL cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
159 a_first_col=a_first_col, &
160 a_first_row=a_first_row, &
161 b_first_col=b_first_col, &
162 b_first_row=b_first_row, &
163 c_first_col=c_first_col, &
164 c_first_row=c_first_row)
165 CALL timestop(handle1)
168 CALL timeset(routinen//
"_cosma", handle1)
170 CALL cosma_pzgemm(transa=transa, transb=transb, m=m, n=n, k=k, alpha=alpha, &
171 matrix_a=matrix_a, matrix_b=matrix_b, beta=beta, matrix_c=matrix_c, &
172 a_first_col=a_first_col, &
173 a_first_row=a_first_row, &
174 b_first_col=b_first_col, &
175 b_first_row=b_first_row, &
176 c_first_col=c_first_col, &
177 c_first_row=c_first_row)
178 CALL timestop(handle1)
180 cpabort(
"CP2K compiled without the COSMA library.")
183 CALL timestop(handle)
185 END SUBROUTINE parallel_gemm_cfm
208 SUBROUTINE cosma_pdgemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
209 a_first_col, a_first_row, b_first_col, b_first_row, &
210 c_first_col, c_first_row)
211 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
212 INTEGER,
INTENT(IN) :: m, n, k
213 REAL(KIND=
dp),
INTENT(IN) :: alpha
214 TYPE(cp_fm_type),
INTENT(IN) :: matrix_a, matrix_b
215 REAL(KIND=
dp),
INTENT(IN) :: beta
216 TYPE(cp_fm_type),
INTENT(IN) :: matrix_c
217 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
218 b_first_row, c_first_col, c_first_row
220 INTEGER :: i_a, i_b, i_c, j_a, j_b, j_c
222 SUBROUTINE cosma_pdgemm_c(transa, transb, m, n, k, alpha, a, ia, ja, desca, &
223 b, ib, jb, descb, beta, c, ic, jc, descc) &
224 BIND(C, name="cosma_pdgemm")
225 IMPORT :: c_ptr, c_int, c_double, c_char
226 CHARACTER(KIND=C_CHAR) :: transa
227 CHARACTER(KIND=C_CHAR) :: transb
228 INTEGER(KIND=C_INT) :: m
229 INTEGER(KIND=C_INT) :: n
230 INTEGER(KIND=C_INT) :: k
231 REAL(KIND=c_double) :: alpha
232 TYPE(C_PTR),
VALUE :: a
233 INTEGER(KIND=C_INT) :: ia
234 INTEGER(KIND=C_INT) :: ja
235 TYPE(C_PTR),
VALUE :: desca
236 TYPE(C_PTR),
VALUE :: b
237 INTEGER(KIND=C_INT) :: ib
238 INTEGER(KIND=C_INT) :: jb
239 TYPE(C_PTR),
VALUE :: descb
240 REAL(KIND=c_double) :: beta
241 TYPE(C_PTR),
VALUE :: c
242 INTEGER(KIND=C_INT) :: ic
243 INTEGER(KIND=C_INT) :: jc
244 TYPE(C_PTR),
VALUE :: descc
245 END SUBROUTINE cosma_pdgemm_c
248 IF (
PRESENT(a_first_row))
THEN
253 IF (
PRESENT(a_first_col))
THEN
258 IF (
PRESENT(b_first_row))
THEN
263 IF (
PRESENT(b_first_col))
THEN
268 IF (
PRESENT(c_first_row))
THEN
273 IF (
PRESENT(c_first_col))
THEN
279 CALL cosma_pdgemm_c(transa=transa, transb=transb, m=m, n=n, k=k, &
281 a=c_loc(matrix_a%local_data(1, 1)), ia=i_a, ja=j_a, &
282 desca=c_loc(matrix_a%matrix_struct%descriptor(1)), &
283 b=c_loc(matrix_b%local_data(1, 1)), ib=i_b, jb=j_b, &
284 descb=c_loc(matrix_b%matrix_struct%descriptor(1)), &
286 c=c_loc(matrix_c%local_data(1, 1)), ic=i_c, jc=j_c, &
287 descc=c_loc(matrix_c%matrix_struct%descriptor(1)))
289 END SUBROUTINE cosma_pdgemm
311 SUBROUTINE cosma_pzgemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, &
312 a_first_col, a_first_row, b_first_col, b_first_row, &
313 c_first_col, c_first_row)
314 CHARACTER(LEN=1),
INTENT(IN) :: transa, transb
315 INTEGER,
INTENT(IN) :: m, n, k
316 COMPLEX(KIND=dp),
INTENT(IN) :: alpha
317 TYPE(cp_cfm_type),
INTENT(IN) :: matrix_a, matrix_b
318 COMPLEX(KIND=dp),
INTENT(IN) :: beta
319 TYPE(cp_cfm_type),
INTENT(IN) :: matrix_c
320 INTEGER,
INTENT(IN),
OPTIONAL :: a_first_col, a_first_row, b_first_col, &
321 b_first_row, c_first_col, c_first_row
323 INTEGER :: i_a, i_b, i_c, j_a, j_b, j_c
324 REAL(KIND=
dp),
DIMENSION(2),
TARGET :: alpha_t, beta_t
326 SUBROUTINE cosma_pzgemm_c(transa, transb, m, n, k, alpha, a, ia, ja, desca, &
327 b, ib, jb, descb, beta, c, ic, jc, descc) &
328 BIND(C, name="cosma_pzgemm")
329 IMPORT :: c_ptr, c_int, c_char
330 CHARACTER(KIND=C_CHAR) :: transa
331 CHARACTER(KIND=C_CHAR) :: transb
332 INTEGER(KIND=C_INT) :: m
333 INTEGER(KIND=C_INT) :: n
334 INTEGER(KIND=C_INT) :: k
335 TYPE(C_PTR),
VALUE :: alpha
336 TYPE(C_PTR),
VALUE :: a
337 INTEGER(KIND=C_INT) :: ia
338 INTEGER(KIND=C_INT) :: ja
339 TYPE(C_PTR),
VALUE :: desca
340 TYPE(C_PTR),
VALUE :: b
341 INTEGER(KIND=C_INT) :: ib
342 INTEGER(KIND=C_INT) :: jb
343 TYPE(C_PTR),
VALUE :: descb
344 TYPE(C_PTR),
VALUE :: beta
345 TYPE(C_PTR),
VALUE :: c
346 INTEGER(KIND=C_INT) :: ic
347 INTEGER(KIND=C_INT) :: jc
348 TYPE(C_PTR),
VALUE :: descc
349 END SUBROUTINE cosma_pzgemm_c
352 IF (
PRESENT(a_first_row))
THEN
357 IF (
PRESENT(a_first_col))
THEN
362 IF (
PRESENT(b_first_row))
THEN
367 IF (
PRESENT(b_first_col))
THEN
372 IF (
PRESENT(c_first_row))
THEN
377 IF (
PRESENT(c_first_col))
THEN
383 alpha_t(1) = real(alpha, kind=
dp)
384 alpha_t(2) = real(aimag(alpha), kind=
dp)
385 beta_t(1) = real(beta, kind=
dp)
386 beta_t(2) = real(aimag(beta), kind=
dp)
388 CALL cosma_pzgemm_c(transa=transa, transb=transb, m=m, n=n, k=k, &
389 alpha=c_loc(alpha_t), &
390 a=c_loc(matrix_a%local_data(1, 1)), ia=i_a, ja=j_a, &
391 desca=c_loc(matrix_a%matrix_struct%descriptor(1)), &
392 b=c_loc(matrix_b%local_data(1, 1)), ib=i_b, jb=j_b, &
393 descb=c_loc(matrix_b%matrix_struct%descriptor(1)), &
394 beta=c_loc(beta_t), &
395 c=c_loc(matrix_c%local_data(1, 1)), ic=i_c, jc=j_c, &
396 descc=c_loc(matrix_c%matrix_struct%descriptor(1)))
398 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