Geogram  Version 1.9.1
A programming library of geometric algorithms
nl_blas.h File Reference

Abstract interface to the basic linear algebra routines used by OpenNL internally. More...

#include "nl_private.h"

Go to the source code of this file.

Classes

struct  NLBlas
 

Macros

#define NL_NEW_VECTOR(blas, memtype, dim)    (double*)blas->Malloc(blas,memtype,(size_t)(dim)*sizeof(double))
 Allocates a vector of doubles;. More...
 
#define NL_DELETE_VECTOR(blas, memtype, dim, ptr)    blas->Free(blas,memtype,(size_t)(dim)*sizeof(double),ptr)
 Deletes a vector of doubles;. More...
 

Typedefs

typedef struct NLBlasNLBlas_t
 A handle to a BLAS abstraction layer.
 
typedef void *(* FUNPTR_malloc) (NLBlas_t blas, NLmemoryType type, size_t size)
 Allocates memory in host or in device. More...
 
typedef void(* FUNPTR_free) (NLBlas_t blas, NLmemoryType type, size_t size, void *ptr)
 Frees memory from host or from device. More...
 
typedef void(* FUNPTR_memcpy) (NLBlas_t blas, void *to, NLmemoryType to_type, void *from, NLmemoryType from_type, size_t size)
 Copies a bloc of memory. More...
 
typedef void(* FUNPTR_memset) (NLBlas_t blas, void *to, NLmemoryType to_type, int c, size_t size)
 Sets a bloc of memory. More...
 
typedef void(* FUNPTR_dcopy) (NLBlas_t blas, int n, const double *x, int incx, double *y, int incy)
 Copies a vector. More...
 
typedef void(* FUNPTR_dscal) (NLBlas_t blas, int n, double a, double *x, int incx)
 Scales a vector. More...
 
typedef double(* FUNPTR_ddot) (NLBlas_t blas, int n, const double *x, int incx, const double *y, int incy)
 Computes the dot product between two vectors. More...
 
typedef double(* FUNPTR_dnrm2) (NLBlas_t blas, int n, const double *x, int incx)
 Computes the norm of a vector. More...
 
typedef void(* FUNPTR_daxpy) (NLBlas_t blas, int n, double a, const double *x, int incx, double *y, int incy)
 Computes a linear combination of two vectors. More...
 
typedef void(* FUNPTR_dmul) (NLBlas_t blas, int n, const double *x, const double *y, double *z)
 Component-wise multiplication. More...
 
typedef void(* FUNPTR_dgemv) (NLBlas_t blas, MatrixTranspose trans, int m, int n, double alpha, const double *A, int ldA, const double *x, int incx, double beta, double *y, int incy)
 Computes a matrix-vector product. More...
 
typedef void(* FUNPTR_dtpsv) (NLBlas_t blas, MatrixTriangle uplo, MatrixTranspose trans, MatrixUnitTriangular diag, int n, const double *AP, double *x, int incx)
 Solves a linear system. More...
 
typedef void(* FUNPTR_show_stats) (NLBlas_t blas)
 Displays the statistics associated with a BLAS context. More...
 
typedef void(* FUNPTR_reset_stats) (NLBlas_t blas)
 Resets the statistics associated with a BLAS context. More...
 

Enumerations

enum  MatrixTranspose { NoTranspose =0 , Transpose =1 , ConjugateTranspose =2 }
 Specifies whether matrix should be transposed. More...
 
enum  MatrixTriangle { UpperTriangle =0 , LowerTriangle =1 }
 Specifies which triangular part of a matrix should be used. More...
 
enum  MatrixUnitTriangular { UnitTriangular =0 , NotUnitTriangular =1 }
 Specifies which triangular part of a matrix should be used. More...
 
enum  NLmemoryType { NL_HOST_MEMORY , NL_DEVICE_MEMORY }
 Specifies on which type of memory a function should be applied. More...
 

Functions

NLAPI NLboolean NLAPIENTRY nlBlasHasUnifiedMemory (NLBlas_t blas)
 Tests whether BLAS device uses the same address space as the CPU. More...
 
NLAPI void NLAPIENTRY nlBlasResetStats (NLBlas_t blas)
 Resets the statistics associated with a BLAS context. More...
 
NLAPI void NLAPIENTRY nlBlasShowStats (NLBlas_t blas)
 Displays the statistics associated with a BLAS context. More...
 
NLAPI double NLAPIENTRY nlBlasGFlops (NLBlas_t blas)
 Gets the number of floating point operations per seconds computed since creation of the BLAS abstaction layer or since the latest call to nlBlasResetStats(). More...
 
NLAPI NLulong NLAPIENTRY nlBlasUsedRam (NLBlas_t blas, NLmemoryType type)
 Gets the currently used amount of memory computed since creation of the BLAS abstaction layer or since the latest call to nlBlasResetStats(). More...
 
NLAPI NLulong NLAPIENTRY nlBlasMaxUsedRam (NLBlas_t blas, NLmemoryType type)
 Gets the high mark of used amount of memory computed since creation of the BLAS abstaction layer or since the latest call to nlBlasResetStats(). More...
 
NLAPI NLBlas_t NLAPIENTRY nlHostBlas (void)
 Gets a pointer to the BLAS abstraction layer for BLAS operation on the host CPU. More...
 

Detailed Description

Abstract interface to the basic linear algebra routines used by OpenNL internally.

Definition in file nl_blas.h.

Macro Definition Documentation

◆ NL_DELETE_VECTOR

#define NL_DELETE_VECTOR (   blas,
  memtype,
  dim,
  ptr 
)     blas->Free(blas,memtype,(size_t)(dim)*sizeof(double),ptr)

Deletes a vector of doubles;.

Parameters
[in]blasa pointer to the BLAS abstraction layer.
[in]memtypeone of NL_HOST_MEMORY, NL_DEVICE_MEMORY.
[in]dimnumber of components in the vector.
[in]ptra pointer to the vector to be deleted.

Definition at line 460 of file nl_blas.h.

◆ NL_NEW_VECTOR

#define NL_NEW_VECTOR (   blas,
  memtype,
  dim 
)     (double*)blas->Malloc(blas,memtype,(size_t)(dim)*sizeof(double))

Allocates a vector of doubles;.

Parameters
[in]blasa pointer to the BLAS abstraction layer.
[in]memtypeone of NL_HOST_MEMORY, NL_DEVICE_MEMORY.
[in]dimnumber of components in the vector.

Definition at line 450 of file nl_blas.h.

Typedef Documentation

◆ FUNPTR_daxpy

typedef void(* FUNPTR_daxpy) (NLBlas_t blas, int n, double a, const double *x, int incx, double *y, int incy)

Computes a linear combination of two vectors.

In formula: \( y \leftarrow a x + y \)

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]ndimension of the vectors
[in]ascaling coefficient
[in]xsource vector to be scaled and added
[in]incxstraddle between two consecutive coefficients of the source vector
[in,out]ythe vector that a x should be added to
[in]incystraddle between two consecutive coefficients of the destination vector

Definition at line 230 of file nl_blas.h.

◆ FUNPTR_dcopy

typedef void(* FUNPTR_dcopy) (NLBlas_t blas, int n, const double *x, int incx, double *y, int incy)

Copies a vector.

In formula: \( y \leftarrow x \)

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]ndimension of the vector
[in]xsource vector
[in]incxstraddle between two consecutive coefficients of the source vector
[out]ydestination vector
[in]incystraddle between two consecutive coefficients of the destination vector

Definition at line 169 of file nl_blas.h.

◆ FUNPTR_ddot

typedef double(* FUNPTR_ddot) (NLBlas_t blas, int n, const double *x, int incx, const double *y, int incy)

Computes the dot product between two vectors.

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]ndimension of the vectors
[in]xfirst vector
[in]incxstraddle between two consecutive coefficients of the first vector
[in]ysecond vector
[in]incystraddle between two consecutive coefficients of the second vector
Returns
the dot product between x and y

Definition at line 199 of file nl_blas.h.

◆ FUNPTR_dgemv

typedef void(* FUNPTR_dgemv) (NLBlas_t blas, MatrixTranspose trans, int m, int n, double alpha, const double *A, int ldA, const double *x, int incx, double beta, double *y, int incy)

Computes a matrix-vector product.

performs one of the matrix-vector operations \( y = \alpha A x + \beta y \) or \( y = \alpha A^t x + \beta y \), where \( \alpha \) and \( \beta \) are scalars, x and y are vectors and A is an m by n matrix.

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]transone of (NoTranspose, Transpose, ConjugateTranspose), specifies the operation to be performed as follows:
  • NoTranspose: \( y = \alpha A x + \beta y \)
  • Transpose: \( y = \alpha A^t x + \beta y \)
  • ConjugateTranspose: \( y = \alpha A^t x + \beta y \)
[in]mnumber of rows of the matrix A
[in]nnumber of columns of the matrix A
[in]alphathe scalar \( \alpha \)
[in]Aan array of dimension (ldA,n). On entry, the leading m by n part of the array A must contain the array of coefficients.
[in]ldAspecifies the first dimension of A as declared by the caller. ldA must be at least max(1,m).
[in]xarray of dimension at least ( 1 + ( n - 1 )*abs( incx ) ) when trans = NoTranspose and at least ( 1 + ( m - 1 )*abs( incx ) ) otherwise. Before entry, the incremented array X must contain the vector x.
[in]incxthe increment for the elements of x
[in]betathe scalar \( \beta \)
[in,out]yan array of dimension ( 1 + ( m - 1 )*abs( incy ) ) when trans = NoTranspose and at least ( 1 + ( n - 1 )*abs( incy ) ) otherwise. Before entry with beta non-zero, the incremented array y must contain the vector y. On exit, y is overwritten by the updated vector y.
[in]incythe increment for the elements of y

Definition at line 285 of file nl_blas.h.

◆ FUNPTR_dmul

typedef void(* FUNPTR_dmul) (NLBlas_t blas, int n, const double *x, const double *y, double *z)

Component-wise multiplication.

In formula: \( z \leftarrow x ** y \)

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]ndimension of the vectors
[in]x,ysource vectors
[in]zdestination vector

Definition at line 244 of file nl_blas.h.

◆ FUNPTR_dnrm2

typedef double(* FUNPTR_dnrm2) (NLBlas_t blas, int n, const double *x, int incx)

Computes the norm of a vector.

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]ndimension of the vector
[in]xthe vector
[in]incxstraddle between two consecutive coefficients of the vector
Returns
the norm of x

Definition at line 213 of file nl_blas.h.

◆ FUNPTR_dscal

typedef void(* FUNPTR_dscal) (NLBlas_t blas, int n, double a, double *x, int incx)

Scales a vector.

In formula: \( x \leftarrow a x \)

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]ndimension of the vector
[in]ascaling coefficient
[in,out]xvector to be scaled
[in]incxstraddle between two consecutive coefficients

Definition at line 182 of file nl_blas.h.

◆ FUNPTR_dtpsv

typedef void(* FUNPTR_dtpsv) (NLBlas_t blas, MatrixTriangle uplo, MatrixTranspose trans, MatrixUnitTriangular diag, int n, const double *AP, double *x, int incx)

Solves a linear system.

Solves one of the systems of equations \( A x = b \) or \( A^t x = b \) where b and x are n element vectors and A is an n by n unit, or non-unit, upper or lower triangular matrix, supplied in packed form. No test for singularity or near-singularity is included in this routine. Such tests must be performed before calling this routine.

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]uploone of (UpperTriangle, LowerTriangle), specifies whether A is an upper or lower triangular matrix as follows:
  • UpperTriangle: A is an upper triangular matrix
  • LowerTriangle: A is a lower triangular matrix
[in]transone of (NoTranspose, Transpose, ConjugateTranspose), specifies the equations to be solved as follows:
  • NoTranspose: \( A x = b \)
  • Transpose: \( A^t x = b \)
  • ConjugateTranspose: \( A^t x = b \)
[in]diagone of (UnitTriangular, NotUnitTriangular), specifies whether or not A is unit triangular as follows:
  • UnitTriangular: A is assumed to be unit triangular
  • NotUnitTriangular: A is not assumed to be unit triangular
[in]nthe order of the matrix
[in]APan array of dimension at least ( ( n*( n + 1))/2).
  • if uplo = UpperTriangular, the array AP must contain the upper triangular matrix packed sequentially, column by column, so that AP[0] contains a(1,1), AP[1] and AP[2] contain a(1,2) and a(2,2) respectively, and so on.
  • if uplo = LowerTriangular, the array AP must contain the lower triangular matrix packed sequentially, column by column, so that AP[0] contains a(1,1 ), AP[1] and AP[2] contain a(2,1) and a(3,1) respectively, and so on. Note that when diag = UnitTriangular, the diagonal elements of A are not referenced, but are assumed to be unity.
[in,out]xarray of dimension at least (1 + (n-1)*abs( incx )). Before entry, the incremented array x must contain the n element right-hand side vector b. On exit, x is overwritten with the solution vector x.
[in]incxspecifies the increment for the elements of x. Must not be zero.

Definition at line 333 of file nl_blas.h.

◆ FUNPTR_free

typedef void(* FUNPTR_free) (NLBlas_t blas, NLmemoryType type, size_t size, void *ptr)

Frees memory from host or from device.

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]typewhether RAM should be allocated on the CPU (NL_HOST_MEMORY) or the GPU (NL_DEVICE_MEMORY)
[in]sizethe number of bytes of the memory bloc to be allocated.
[in]ptra pointer to the memory to be freed.

Definition at line 120 of file nl_blas.h.

◆ FUNPTR_malloc

typedef void*(* FUNPTR_malloc) (NLBlas_t blas, NLmemoryType type, size_t size)

Allocates memory in host or in device.

Parameters
[in]blasa handle to the BLAS abstraction layer
[in]typewhether RAM should be allocated on the CPU (NL_HOST_MEMORY) or the GPU (NL_DEVICE_MEMORY)
[in]sizethe number of bytes of the memory bloc to be allocated.
Returns
a pointer to the allocated memory.

Definition at line 107 of file nl_blas.h.

◆ FUNPTR_memcpy

typedef void(* FUNPTR_memcpy) (NLBlas_t blas, void *to, NLmemoryType to_type, void *from, NLmemoryType from_type, size_t size)

Copies a bloc of memory.

Parameters
[in]blasa handle to the BLAS abstraction layer.
[in]to,to_typea pointer to the destination and indication of whether the destination is on CPU RAM (NL_HOST_MEMORY) or GPU RAM (NL_DEVICE_MEMORY).
[in]from,frm_typea pointer to the source and indication of whether the source is on CPU RAM (NL_HOST_MEMORY) or GPU RAM (NL_DEVICE_MEMORY).
[in]sizenumber of bytes to be copied.

Definition at line 135 of file nl_blas.h.

◆ FUNPTR_memset

typedef void(* FUNPTR_memset) (NLBlas_t blas, void *to, NLmemoryType to_type, int c, size_t size)

Sets a bloc of memory.

Parameters
[in]blasa handle to the BLAS abstraction layer.
[in]to,to_typea pointer to the destination and indication of whether the destination is on CPU RAM (NL_HOST_MEMORY) or GPU RAM (NL_DEVICE_MEMORY).
[in]cvalue of each byte to be set.
[in]sizenumber of bytes to set.

Definition at line 151 of file nl_blas.h.

◆ FUNPTR_reset_stats

typedef void(* FUNPTR_reset_stats) (NLBlas_t blas)

Resets the statistics associated with a BLAS context.

Parameters
[in]blasa pointer to the BLAS abstraction layer.

Definition at line 351 of file nl_blas.h.

◆ FUNPTR_show_stats

typedef void(* FUNPTR_show_stats) (NLBlas_t blas)

Displays the statistics associated with a BLAS context.

Parameters
[in]blasa pointer to the BLAS abstraction layer.

Definition at line 345 of file nl_blas.h.

Enumeration Type Documentation

◆ MatrixTranspose

Specifies whether matrix should be transposed.

Used by dtpsv() and dgemv()

Definition at line 69 of file nl_blas.h.

◆ MatrixTriangle

Specifies which triangular part of a matrix should be used.

Used by dtpsv()

Definition at line 77 of file nl_blas.h.

◆ MatrixUnitTriangular

Specifies which triangular part of a matrix should be used.

Used by dtpsv()

Definition at line 85 of file nl_blas.h.

◆ NLmemoryType

Specifies on which type of memory a function should be applied.

NL_HOST_MEMORY refers to CPU RAM and NL_DEVICE_MEMORY to GPU RAM.

Definition at line 94 of file nl_blas.h.

Function Documentation

◆ nlBlasGFlops()

NLAPI double NLAPIENTRY nlBlasGFlops ( NLBlas_t  blas)

Gets the number of floating point operations per seconds computed since creation of the BLAS abstaction layer or since the latest call to nlBlasResetStats().

Returns
the number of GFlops.

◆ nlBlasHasUnifiedMemory()

NLAPI NLboolean NLAPIENTRY nlBlasHasUnifiedMemory ( NLBlas_t  blas)

Tests whether BLAS device uses the same address space as the CPU.

Parameters
[in]blasa pointer to the BLAS abstraction layer.
Returns
NL_TRUE if device and CPU use the same address space.
Return values
NL_FALSEotherwise.

◆ nlBlasMaxUsedRam()

NLAPI NLulong NLAPIENTRY nlBlasMaxUsedRam ( NLBlas_t  blas,
NLmemoryType  type 
)

Gets the high mark of used amount of memory computed since creation of the BLAS abstaction layer or since the latest call to nlBlasResetStats().

Parameters
[in]blasa pointer to the BLAS abstraction layer.
[in]typeone of NL_HOST_MEMORY, NL_DEVICE_MEMORY.
Returns
the high mark of the used memory, in bytes.

◆ nlBlasResetStats()

NLAPI void NLAPIENTRY nlBlasResetStats ( NLBlas_t  blas)

Resets the statistics associated with a BLAS context.

Parameters
[in]blasa pointer to the BLAS abstraction layer.

◆ nlBlasShowStats()

NLAPI void NLAPIENTRY nlBlasShowStats ( NLBlas_t  blas)

Displays the statistics associated with a BLAS context.

Parameters
[in]blasa pointer to the BLAS abstraction layer.

◆ nlBlasUsedRam()

NLAPI NLulong NLAPIENTRY nlBlasUsedRam ( NLBlas_t  blas,
NLmemoryType  type 
)

Gets the currently used amount of memory computed since creation of the BLAS abstaction layer or since the latest call to nlBlasResetStats().

Parameters
[in]blasa pointer to the BLAS abstraction layer.
[in]typeone of NL_HOST_MEMORY, NL_DEVICE_MEMORY.
Returns
the amount of used memory, in bytes.

◆ nlHostBlas()

NLAPI NLBlas_t NLAPIENTRY nlHostBlas ( void  )

Gets a pointer to the BLAS abstraction layer for BLAS operation on the host CPU.

Returns
a pointer to the BLAS abstraction layer.