Skip to content

Commit f68f1a1

Browse files
committed
ENH: add gemv/gbsv wrappers + gemv benchmark
1 parent 998bf43 commit f68f1a1

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

benchmarks/benchmarks.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ def time_axpy(self, n, variant):
9393

9494

9595

96+
# ### BLAS level 2 ###
97+
98+
gemv_sizes = [100, 200, 400, 600, 800, 1000]
99+
100+
def run_gemv(a, x, y, func):
101+
res = func(1.0, a, x, y=y)
102+
return res
103+
104+
105+
class gemv:
106+
params = [gemv_sizes, ['s', 'd', 'c', 'z']]
107+
param_names = ["size", "variant"]
108+
109+
def setup(self, n, variant):
110+
rndm = np.random.RandomState(1234)
111+
dtyp = dtype_map[variant]
112+
113+
self.a = np.array(rndm.uniform(size=(n,n)), dtype=dtyp)
114+
self.x = np.array(rndm.uniform(size=(n,)), dtype=dtyp)
115+
self.y = np.zeros(n, dtype=dtyp)
116+
117+
self.gemv = ow.get_func('gemv', variant)
118+
119+
def time_gemv(self, n, variant):
120+
run_gemv(self.a, self.x, self.y, self.gemv)
121+
122+
96123
# ### BLAS level 3 ###
97124

98125
# gemm

openblas_wrap/blas_lapack.pyf.src

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,98 @@ function <prefix4>nrm2(n,x,offx,incx) result(n2)
112112

113113
end function <prefix4>nrm2
114114

115+
116+
!
117+
! Level 2 BLAS
118+
!
119+
120+
121+
subroutine <prefix>gemv(m,n,alpha,a,x,beta,y,offx,incx,offy,incy,trans,rows,cols,ly)
122+
! Computes a matrix-vector product using a general matrix
123+
!
124+
! y = gemv(alpha,a,x,beta=0,y=0,offx=0,incx=1,offy=0,incy=0,trans=0)
125+
! Calculate y <- alpha * op(A) * x + beta * y
126+
127+
callstatement (*f2py_func)((trans?(trans==2?"C":"T"):"N"),&m,&n,&alpha,a,&m, &
128+
x+offx,&incx,&beta,y+offy,&incy)
129+
callprotoargument char*,F_INT*,F_INT*,<ctype>*,<ctype>*,F_INT*,<ctype>*,F_INT*,<ctype>*, &
130+
<ctype>*,F_INT*
131+
132+
integer optional, intent(in), check(trans>=0 && trans <=2) :: trans = 0
133+
integer optional, intent(in), check(incx>0||incx<0) :: incx = 1
134+
integer optional, intent(in), check(incy>0||incy<0) :: incy = 1
135+
<ftype> intent(in) :: alpha
136+
<ftype> intent(in), optional :: beta = <0.0,\0,(0.0\,0.0),\2>
137+
138+
<ftype> dimension(*), intent(in) :: x
139+
<ftype> dimension(ly), intent(in,copy,out), depend(ly),optional :: y
140+
integer intent(hide), depend(incy,rows,offy) :: ly = &
141+
(y_capi==Py_None?1+offy+(rows-1)*abs(incy):-1)
142+
<ftype> dimension(m,n), intent(in) :: a
143+
integer depend(a), intent(hide):: m = shape(a,0)
144+
integer depend(a), intent(hide):: n = shape(a,1)
145+
146+
integer optional, intent(in) :: offx=0
147+
integer optional, intent(in) :: offy=0
148+
check(offx>=0 && offx<len(x)) :: x
149+
check(len(x)>offx+(cols-1)*abs(incx)) :: x
150+
depend(offx,cols,incx) :: x
151+
152+
check(offy>=0 && offy<len(y)) :: y
153+
check(len(y)>offy+(rows-1)*abs(incy)) :: y
154+
depend(offy,rows,incy) :: y
155+
156+
integer depend(m,n,trans), intent(hide) :: rows = (trans?n:m)
157+
integer depend(m,n,trans), intent(hide) :: cols = (trans?m:n)
158+
159+
end subroutine <prefix>gemv
160+
161+
162+
subroutine <prefix>gbmv(m,n,kl,ku,alpha,a,lda,x,incx,offx,beta,y,incy,offy,trans,ly)
163+
! Performs one of the matrix-vector operations
164+
!
165+
! y := alpha*A*x + beta*y, or y := alpha*A**T*x + beta*y,
166+
! or y := alpha*A**H*x + beta*y,
167+
!
168+
! where alpha and beta are scalars, x and y are vectors and A is an
169+
! m by n band matrix, with kl sub-diagonals and ku super-diagonals.
170+
171+
callstatement (*f2py_func)((trans?(trans==2?"C":"T"):"N"),&m,&n,&kl,&ku,&alpha,a,&lda,x+offx,&incx,&beta,y+offy,&incy)
172+
callprotoargument char*,F_INT*,F_INT*,F_INT*,F_INT*,<ctype>*,<ctype>*,F_INT*,<ctype>*,F_INT*,<ctype>*,<ctype>*,F_INT*
173+
174+
integer optional,intent(in),check(trans>=0 && trans <=2) :: trans = 0
175+
integer intent(in), depend(ku,kl),check(m>=ku+kl+1) :: m
176+
integer intent(in),check(n>=0&&n==shape(a,1)),depend(a) :: n
177+
integer intent(in),check(kl>=0) :: kl
178+
integer intent(in),check(ku>=0) :: ku
179+
integer intent(hide),depend(a) :: lda = MAX(shape(a,0),1)
180+
integer optional, intent(in),check(incx>0||incx<0) :: incx = 1
181+
integer optional, intent(in),check(incy>0||incy<0) :: incy = 1
182+
integer intent(hide),depend(m,n,incy,offy,trans) :: ly = &
183+
(y_capi==Py_None?1+offy+(trans==0?m-1:n-1)*abs(incy):-1)
184+
integer optional, intent(in) :: offx=0
185+
integer optional, intent(in) :: offy=0
186+
187+
<ftype> intent(in) :: alpha
188+
<ftype> intent(in),optional :: beta = <0.0,\0,(0.0\,0.0),\2>
189+
190+
<ftype> dimension(lda,n),intent(in) :: a
191+
192+
<ftype> dimension(ly), intent(in,out,copy,out=yout),depend(ly),optional :: y
193+
check(offy>=0 && offy<len(y)) :: y
194+
check(len(y)>offy+(trans==0?m-1:n-1)*abs(incy)) :: y
195+
depend(offy,n,incy) :: y
196+
197+
<ftype> dimension(*), intent(in) :: x
198+
check(offx>=0 && offx<len(x)) :: x
199+
check(len(x)>offx+(trans==0?n-1:m-1)*abs(incx)) :: x
200+
depend(offx,n,incx) :: x
201+
202+
end subroutine <prefix>gbmv
203+
204+
205+
206+
115207
!
116208
! Level 3 BLAS
117209
!

0 commit comments

Comments
 (0)