module magma2
use iso_c_binding
use magma2_common
implicit none
type(c_ptr), private :: magma_queue
integer(c_int), private :: magma_device
interface
subroutine magma_dgetrf_batchedF( &
m, n, dA_array, lda, ipiv_array, info_array, batchcount, queue) &
bind(C, name="magma_dgetrf_batched")
use iso_c_binding
integer(c_int), value :: m, n, lda, batchcount
type(c_ptr), value :: dA_array !! double_complex**
type(c_ptr), value :: ipiv_array !! int**
type(c_ptr), value :: info_array !! int*
type(c_ptr), value :: queue
end subroutine
subroutine magma_dgeqrf_batchedF( &
m, n, dA_array, lda, dtau_array, info_array, batchcount, queue) &
bind(C, name="magma_dgeqrf_batched")
use iso_c_binding
integer(c_int), value :: m, n, lda, batchcount
type(c_ptr), value :: dA_array !! double_complex**
type(c_ptr), value :: dtau_array !! int**
type(c_ptr), value :: info_array !! int*
type(c_ptr), value :: queue
end subroutine
!! -------------------------------------------------------------------------
!! initialize
subroutine magma_init() &
bind(C, name="magma_init")
use iso_c_binding
end subroutine
subroutine magma_finalize() &
bind(C, name="magma_finalize")
use iso_c_binding
end subroutine
subroutine magma_get_device(dev) &
bind(C, name="magma_getdevice")
use iso_c_binding
integer(c_int), target :: dev
end subroutine
subroutine magma_set_device(dev) &
bind(C, name="magma_setdevice")
use iso_c_binding
integer(c_int), value :: dev
end subroutine
integer(c_size_t) function magma_mem_size(queue) &
bind(C, name="magma_mem_size")
use iso_c_binding
type(c_ptr), value :: queue
end function
subroutine magma_queue_create_internal(dev, queue_ptr, func, file, line) &
bind(C, name="magma_queue_create_internal")
use iso_c_binding
integer(c_int), value :: dev
type(c_ptr), target :: queue_ptr !! queue_t*
character(c_char) :: func, file
integer(c_int), value :: line
end subroutine
subroutine magma_queue_destroy_internal(queue, func, file, line) &
bind(C, name="magma_queue_destroy_internal")
use iso_c_binding
type(c_ptr), value :: queue !! queue_t
character(c_char) :: func, file
integer(c_int), value :: line
end subroutine
subroutine magma_queue_sync_internal(queue, func, file, line) &
bind(C, name="magma_queue_sync_internal")
use iso_c_binding
type(c_ptr), value :: queue !! queue_t
character(c_char) :: func, file
integer(c_int), value :: line
end subroutine
integer(c_int) function magma_queue_get_device(queue) &
bind(C, name="magma_queue_get_device")
use iso_c_binding
type(c_ptr), value :: queue !! queue_t
end function
end interface
contains
subroutine magma_queue_create(dev, queue_ptr)
use iso_c_binding
integer(c_int), value :: dev
type(c_ptr), target :: queue_ptr !! queue_t*
call magma_queue_create_internal( &
dev, queue_ptr, &
"magma_queue_create"//c_null_char, &
__FILE__//c_null_char, &
__LINE__)
end subroutine
subroutine magma_queue_destroy(queue)
use iso_c_binding
type(c_ptr), value :: queue !! queue_t
call magma_queue_destroy_internal( &
queue, &
"magma_queue_destroy"//c_null_char, &
__FILE__//c_null_char, &
__LINE__)
end subroutine
subroutine magma_queue_sync(queue)
use iso_c_binding
type(c_ptr), value :: queue !! queue_t
call magma_queue_sync_internal( &
queue, &
"magma_queue_sync"//c_null_char, &
__FILE__//c_null_char, &
__LINE__)
end subroutine
subroutine init_magma()
implicit none
call magma_init()
call magma_get_device(magma_device)
call magma_queue_create(magma_device,magma_queue)
end subroutine init_magma
subroutine finalize_magma()
call magma_finalize()
end subroutine finalize_magma
subroutine magma_dgetrf_batched( batch_size, n, A, ld1, ipvt,info)
use iso_c_binding
use magma2_common
implicit none
integer :: n, ld1, batch_size, i, istat
integer(c_int), target :: cn, cld1, cbatch_size
double precision(c_double), target :: A(0:ld1 - 1, 0:n - 1, 1:batch_size)
integer(c_int), target :: info(1:batch_size)
integer(c_int), target :: ipvt(0:n - 1,1:batch_size)
type(c_ptr), dimension(batch_size) :: dptr_A, iptr_ipvt
type(c_ptr) :: iptr_info
cn = n
cld1 = ld1
cbatch_size = batch_size
!$acc data present(ipvt, info, A) pcreate(dptr_A,iptr_ipvt,iptr_info)
!$acc host_data use_device(A,ipvt,info)
!$acc kernels loop private(i)
do i = 1, batch_size
dptr_A(i) = c_loc(A(0,0, i))
iptr_ipvt(i) = c_loc(ipvt(0,i))
enddo
!$acc end kernels
!$acc serial
iptr_info = c_loc(info(LBOUND(info,1)))
!$acc end serial
!$acc end host_data
!$acc host_data use_device(A,ipvt,info,dptr_A,iptr_ipvt,iptr_info)
call magma_dgetrf_batchedF(cn,cn,c_loc(dptr_A),cld1,c_loc(iptr_ipvt),c_loc(iptr_info),cbatch_size,magma_queue)
call magma_queue_sync(magma_queue)
!$acc end host_data
!$acc end data
end subroutine magma_dgetrf_batched
subroutine magma2_dgeqrf_batched( batch_size, m,n, A, ld1, Tau,info)
use iso_c_binding
use magma2_common
implicit none
integer :: m,n, ld1, batch_size, i, istat
integer(c_int) :: cm, cn, cld1, cbatch_size
double precision(c_double), target :: A(0:ld1-1,0: n-1, 1:batch_size)
double precision(c_double), target :: Tau(0:m-1,1:batch_size)
integer(c_int), target :: info(1:batch_size)
type(c_ptr), dimension(1:batch_size) :: dptr_A, dptr_Tau
type(c_ptr) :: iptr_info
cm = m
cn = n
cld1 = ld1
cbatch_size = batch_size
!$acc data present(Tau,A,info) pcreate(dptr_A,dptr_Tau,iptr_info)
!$acc host_data use_device(A,Tau,info)
!$acc kernels loop private(i)
do i = 1, batch_size
dptr_A(i) = c_loc(A(LBOUND(A,1),LBOUND(A,2), i))
dptr_Tau(i) = c_loc(Tau(LBOUND(Tau,1),i))
enddo
!$acc end kernels
!$acc serial
iptr_info = c_loc(info(LBOUND(info,1)))
!$acc end serial
!$acc end host_data
!$acc host_data use_device(A,Tau,info,dptr_A,dptr_Tau,iptr_info)
call magma_dgeqrf_batchedF(cm,cn,c_loc(dptr_A),cld1,c_loc(dptr_tau),c_loc(iptr_info),cbatch_size,magma_queue)
call magma_queue_sync(magma_queue)
!$acc end host_data
!$acc end data
end subroutine magma2_dgeqrf_batched
end module