32#ifndef SACADO_FAD_BLAS_HPP
33#define SACADO_FAD_BLAS_HPP
35#include "Teuchos_BLAS.hpp"
44 template <
typename OrdinalType,
typename FadType>
183 template <
typename OrdinalType,
typename FadType>
184 class BLAS :
public Teuchos::DefaultBLASImpl<OrdinalType,FadType> {
186 typedef typename Teuchos::ScalarTraits<FadType>::magnitudeType
MagnitudeType;
190 typedef Teuchos::DefaultBLASImpl<OrdinalType,FadType>
BLASType;
214 BLASType::ROTG(
da,
db,
c,s);
234 template <
typename alpha_type,
typename x_type>
240 typename Teuchos::ScalarTraits<FadType>::magnitudeType
243 return BLASType::ASUM(n,
x,
incx);
247 template <
typename x_type,
typename y_type>
259 return BLASType::IAMAX(n,
x,
incx);
286 template <
typename A_type>
293 template <
typename alpha_type,
typename x_type,
typename y_type>
341 template <
typename alpha_type,
typename A_type>
356 template <
typename alpha_type,
typename A_type>
372 Teuchos::BLAS<OrdinalType, ValueType>
blas;
386 template <
typename x_type,
typename y_type>
432 template <
typename alpha_type,
typename x_type,
typename y_type>
517 template <
typename alpha_type,
typename A_type>
540 template <
typename alpha_type,
typename A_type>
573#define TEUCHOS_BLAS_FAD_SPEC(FADTYPE) \
575 template <typename OrdinalType, typename ValueT> \
576 class BLAS< OrdinalType, FADTYPE<ValueT> > : \
577 public Sacado::Fad::BLAS< OrdinalType, FADTYPE<ValueT> > { \
579 BLAS(bool use_default_impl = true, bool use_dynamic = true, \
580 OrdinalType static_workspace_size = 0) : \
581 Sacado::Fad::BLAS< OrdinalType, FADTYPE<ValueT> >( \
582 use_default_impl, use_dynamic,static_workspace_size) {} \
583 BLAS(const BLAS& x) : \
584 Sacado::Fad::BLAS< OrdinalType, FADTYPE<ValueT> >(x) {} \
590 template <typename ValueT> \
591 struct ArrayValueType< FADTYPE<ValueT> > { \
592 typedef ValueT type; \
596#define TEUCHOS_BLAS_SFAD_SPEC(FADTYPE) \
598 template <typename OrdinalType, typename ValueT, int Num> \
599 class BLAS< OrdinalType, FADTYPE<ValueT,Num> > : \
600 public Sacado::Fad::BLAS< OrdinalType, FADTYPE<ValueT,Num> > { \
602 BLAS(bool use_default_impl = true, bool use_dynamic = true, \
603 OrdinalType static_workspace_size = 0) : \
604 Sacado::Fad::BLAS< OrdinalType, FADTYPE<ValueT,Num> >( \
605 use_default_impl, use_dynamic, static_workspace_size) {} \
606 BLAS(const BLAS& x) : \
607 Sacado::Fad::BLAS< OrdinalType, FADTYPE<ValueT,Num> >(x) {} \
613 template <typename ValueT, int Num> \
614 struct ArrayValueType< FADTYPE<ValueT,Num> > { \
615 typedef ValueT type; \
628#undef TEUCHOS_BLAS_FAD_SPEC
629#undef TEUCHOS_BLAS_SFAD_SPEC
#define TEUCHOS_BLAS_SFAD_SPEC(FADTYPE)
#define TEUCHOS_BLAS_FAD_SPEC(FADTYPE)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
void free_array(const ValueType *ptr, OrdinalType size) const
void free(const ValueType *a, OrdinalType n, OrdinalType n_dot, OrdinalType inc_val, OrdinalType inc_dot, const ValueType *val, const ValueType *dot) const
OrdinalType workspace_size
Size of static workspace.
void free(const ValueType *A, OrdinalType m, OrdinalType n, OrdinalType n_dot, OrdinalType lda_val, OrdinalType lda_dot, const ValueType *val, const ValueType *dot) const
void free(const ScalarType &a, OrdinalType n_dot, const ScalarType *dot) const
void unpack(const ValueType *A, OrdinalType m, OrdinalType n, OrdinalType lda, OrdinalType &n_dot, OrdinalType &lda_val, OrdinalType &lda_dot, const ValueType *&val, const ValueType *&dot) const
Sacado::ValueType< FadType >::type ValueType
Sacado::dummy< ValueType, scalar_type >::type ScalarType
ValueType * allocate_array(OrdinalType size) const
void free(const ValueType &a, OrdinalType n_dot, const ValueType *dot) const
ValueType * workspace
Workspace for holding contiguous values/derivatives.
void free(const ScalarType *a, OrdinalType n, OrdinalType n_dot, OrdinalType inc_val, OrdinalType inc_dot, const ScalarType *val, const ScalarType *dot) const
bool use_dynamic
Use dynamic memory allocation.
Sacado::ScalarType< FadType >::type scalar_type
ValueType * workspace_pointer
Pointer to current free entry in workspace.
void unpack(const ValueType *a, OrdinalType n, OrdinalType inc, OrdinalType &n_dot, OrdinalType &inc_val, OrdinalType &inc_dot, const ValueType *&val, const ValueType *&dot) const
bool is_array_contiguous(const FadType *a, OrdinalType n, OrdinalType n_dot) const
void unpack(const ValueType &a, OrdinalType &n_dot, ValueType &val, const ValueType *&dot) const
void free(const ScalarType *A, OrdinalType m, OrdinalType n, OrdinalType n_dot, OrdinalType lda_val, OrdinalType lda_dot, const ScalarType *val, const ScalarType *dot) const
ArrayTraits(bool use_dynamic=true, OrdinalType workspace_size=0)
Fad specializations for Teuchos::BLAS wrappers.
Teuchos::BLAS< OrdinalType, ValueType > blas
BLAS for values.
void TRSM(Teuchos::ESide side, Teuchos::EUplo uplo, Teuchos::ETransp transa, Teuchos::EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const A_type *A, const OrdinalType lda, FadType *B, const OrdinalType ldb) const
Solves the matrix equations: op(A)*X=alpha*B or X*op(A)=alpha*B where X and B are m by n matrices,...
void AXPY(const OrdinalType n, const alpha_type &alpha, const x_type *x, const OrdinalType incx, FadType *y, const OrdinalType incy) const
Perform the operation: y <- y+alpha*x.
std::vector< ValueType > gemv_Ax
Temporary array for GEMV.
void Fad_SYMM(Teuchos::ESide side, Teuchos::EUplo uplo, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const OrdinalType n_alpha_dot, const alpha_type *alpha_dot, const A_type *A, const OrdinalType lda, const OrdinalType n_A_dot, const A_type *A_dot, const OrdinalType lda_dot, const B_type *B, const OrdinalType ldb, const OrdinalType n_B_dot, const B_type *B_dot, const OrdinalType ldb_dot, const beta_type &beta, const OrdinalType n_beta_dot, const beta_type *beta_dot, ValueType *C, const OrdinalType ldc, const OrdinalType n_C_dot, ValueType *C_dot, const OrdinalType ldc_dot, const OrdinalType n_dot) const
Implementation of SYMM.
Sacado::dummy< ValueType, scalar_type >::type ScalarType
Teuchos::ScalarTraits< FadType >::magnitudeType MagnitudeType
BLAS(bool use_default_impl=true, bool use_dynamic=true, OrdinalType static_workspace_size=0)
Default constructor.
virtual ~BLAS()
Destructor.
ArrayTraits< OrdinalType, FadType > arrayTraits
ArrayTraits for packing/unpacking value/derivative arrays.
bool use_default_impl
Use custom or default implementation.
void Fad_GEMM(Teuchos::ETransp transa, Teuchos::ETransp transb, const OrdinalType m, const OrdinalType n, const OrdinalType k, const alpha_type &alpha, const OrdinalType n_alpha_dot, const alpha_type *alpha_dot, const A_type *A, const OrdinalType lda, const OrdinalType n_A_dot, const A_type *A_dot, const OrdinalType lda_dot, const B_type *B, const OrdinalType ldb, const OrdinalType n_B_dot, const B_type *B_dot, const OrdinalType ldb_dot, const beta_type &beta, const OrdinalType n_beta_dot, const beta_type *beta_dot, ValueType *C, const OrdinalType ldc, const OrdinalType n_C_dot, ValueType *C_dot, const OrdinalType ldc_dot, const OrdinalType n_dot) const
Implementation of GEMM.
void ROTG(FadType *da, FadType *db, MagnitudeType *c, FadType *s) const
Computes a Givens plane rotation.
void Fad_TRMM(Teuchos::ESide side, Teuchos::EUplo uplo, Teuchos::ETransp transa, Teuchos::EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const OrdinalType n_alpha_dot, const alpha_type *alpha_dot, const A_type *A, const OrdinalType lda, const OrdinalType n_A_dot, const A_type *A_dot, const OrdinalType lda_dot, ValueType *B, const OrdinalType ldb, const OrdinalType n_B_dot, ValueType *B_dot, const OrdinalType ldb_dot, const OrdinalType n_dot) const
Implementation of TRMM.
void Fad_TRSM(Teuchos::ESide side, Teuchos::EUplo uplo, Teuchos::ETransp transa, Teuchos::EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const OrdinalType n_alpha_dot, const alpha_type *alpha_dot, const A_type *A, const OrdinalType lda, const OrdinalType n_A_dot, const A_type *A_dot, const OrdinalType lda_dot, ValueType *B, const OrdinalType ldb, const OrdinalType n_B_dot, ValueType *B_dot, const OrdinalType ldb_dot, const OrdinalType n_dot) const
Implementation of TRMM.
Teuchos::ScalarTraits< FadType >::magnitudeType ASUM(const OrdinalType n, const FadType *x, const OrdinalType incx) const
Sum the absolute values of the entries of x.
void COPY(const OrdinalType n, const FadType *x, const OrdinalType incx, FadType *y, const OrdinalType incy) const
Copy the std::vector x to the std::vector y.
MagnitudeType NRM2(const OrdinalType n, const FadType *x, const OrdinalType incx) const
Compute the 2-norm of the std::vector x.
void Fad_GEMV(Teuchos::ETransp trans, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const OrdinalType n_alpha_dot, const alpha_type *alpha_dot, const A_type *A, const OrdinalType lda, const OrdinalType n_A_dot, const A_type *A_dot, const OrdinalType lda_dot, const x_type *x, const OrdinalType incx, const OrdinalType n_x_dot, const x_type *x_dot, const OrdinalType incx_dot, const beta_type &beta, const OrdinalType n_beta_dot, const beta_type *beta_dot, ValueType *y, const OrdinalType incy, const OrdinalType n_y_dot, ValueType *y_dot, const OrdinalType incy_dot, const OrdinalType n_dot) const
Implementation of GEMV.
std::vector< ValueType > gemm_AB
Temporary array for GEMM.
OrdinalType IAMAX(const OrdinalType n, const FadType *x, const OrdinalType incx) const
Return the index of the element of x with the maximum magnitude.
void Fad_GER(const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const OrdinalType n_alpha_dot, const alpha_type *alpha_dot, const x_type *x, const OrdinalType incx, const OrdinalType n_x_dot, const x_type *x_dot, const OrdinalType incx_dot, const y_type *y, const OrdinalType incy, const OrdinalType n_y_dot, const y_type *y_dot, const OrdinalType incy_dot, ValueType *A, const OrdinalType lda, const OrdinalType n_A_dot, ValueType *A_dot, const OrdinalType lda_dot, const OrdinalType n_dot) const
Implementation of GER.
void GEMV(Teuchos::ETransp trans, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const A_type *A, const OrdinalType lda, const x_type *x, const OrdinalType incx, const beta_type &beta, FadType *y, const OrdinalType incy) const
Performs the matrix-std::vector operation: y <- alpha*A*x+beta*y or y <- alpha*A'*x+beta*y where A ...
void SYMM(Teuchos::ESide side, Teuchos::EUplo uplo, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type &beta, FadType *C, const OrdinalType ldc) const
Performs the matrix-matrix operation: C <- alpha*A*B+beta*C or C <- alpha*B*A+beta*C where A is an m ...
void TRMV(Teuchos::EUplo uplo, Teuchos::ETransp trans, Teuchos::EDiag diag, const OrdinalType n, const A_type *A, const OrdinalType lda, FadType *x, const OrdinalType incx) const
Performs the matrix-std::vector operation: x <- A*x or x <- A'*x where A is a unit/non-unit n by n ...
void TRMM(Teuchos::ESide side, Teuchos::EUplo uplo, Teuchos::ETransp transa, Teuchos::EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const A_type *A, const OrdinalType lda, FadType *B, const OrdinalType ldb) const
Performs the matrix-matrix operation: C <- alpha*op(A)*B+beta*C or C <- alpha*B*op(A)+beta*C where op...
FadType DOT(const OrdinalType n, const x_type *x, const OrdinalType incx, const y_type *y, const OrdinalType incy) const
Form the dot product of the vectors x and y.
void ROT(const OrdinalType n, FadType *dx, const OrdinalType incx, FadType *dy, const OrdinalType incy, MagnitudeType *c, FadType *s) const
Applies a Givens plane rotation.
void GER(const OrdinalType m, const OrdinalType n, const alpha_type &alpha, const x_type *x, const OrdinalType incx, const y_type *y, const OrdinalType incy, FadType *A, const OrdinalType lda) const
Performs the rank 1 operation: A <- alpha*x*y'+A.
Sacado::ValueType< FadType >::type ValueType
void Fad_DOT(const OrdinalType n, const x_type *x, const OrdinalType incx, const OrdinalType n_x_dot, const x_type *x_dot, const OrdinalType incx_dot, const y_type *y, const OrdinalType incy, const OrdinalType n_y_dot, const y_type *y_dot, const OrdinalType incy_dot, ValueType &z, const OrdinalType n_z_dot, ValueType *zdot) const
Implementation of DOT.
Sacado::ScalarType< FadType >::type scalar_type
void GEMM(Teuchos::ETransp transa, Teuchos::ETransp transb, const OrdinalType m, const OrdinalType n, const OrdinalType k, const alpha_type &alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type &beta, FadType *C, const OrdinalType ldc) const
Performs the matrix-matrix operation: C <- alpha*op(A)*op(B)+beta*C where op(A) is either A or A',...
Teuchos::DefaultBLASImpl< OrdinalType, FadType > BLASType
void SCAL(const OrdinalType n, const FadType &alpha, FadType *x, const OrdinalType incx) const
Scale the std::vector x by the constant alpha.
Forward-mode AD class using dynamic memory allocation and expression templates.
Base template specification for ValueType.