forked from certik/fastGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linalg_c.f90
42 lines (35 loc) · 1.13 KB
/
linalg_c.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module linalg
! C implementation of the matmul routines
use iso_c_binding, only: c_int, c_float
implicit none
integer, parameter :: sp = kind(0.0)
interface
subroutine acc_sgemm(m, n, k, A, B, C) bind(c)
import :: c_int, c_float
implicit none
integer(c_int), value, intent(in) :: m, n, k
real(c_float), intent(in) :: A(m,k), B(k,n)
real(c_float), intent(out) :: C(m,n)
end subroutine
subroutine acc_sgemm_t(m, n, k, A, B, C) bind(c)
import :: c_int, c_float
implicit none
integer(c_int), value, intent(in) :: m, n, k
real(c_float), intent(in) :: A(k,m), B(k,n)
real(c_float), intent(out) :: C(m,n)
end subroutine
end interface
contains
subroutine matmul_2d(A, B, C)
! C = matmul(A, B)
real(sp), intent(in) :: A(:,:), B(:,:)
real(sp), intent(out) :: C(:,:)
call acc_sgemm(size(A,1), size(B,2), size(A,2), A, B, C)
end subroutine
subroutine matmul_2d_t(A, B, C)
! C = matmul(transpose(A), B)
real(sp), intent(in) :: A(:,:), B(:,:)
real(sp), intent(out) :: C(:,:)
call acc_sgemm_t(size(A,2), size(B,2), size(A,1), A, B, C)
end subroutine
end module