Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
nl_blas.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#include "nl_private.h"
41
48#ifndef OPENNL_BLAS_H
49#define OPENNL_BLAS_H
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
58struct NLBlas;
59
63typedef struct NLBlas* NLBlas_t;
64
69typedef enum {
70 NoTranspose=0, Transpose=1, ConjugateTranspose=2
72
77typedef enum {
78 UpperTriangle=0, LowerTriangle=1
80
85typedef enum {
86 UnitTriangular=0, NotUnitTriangular=1
88
94typedef enum {
95 NL_HOST_MEMORY, NL_DEVICE_MEMORY
97
107typedef void* (*FUNPTR_malloc)(
108 NLBlas_t blas, NLmemoryType type, size_t size
109);
110
120typedef void (*FUNPTR_free)(
121 NLBlas_t blas, NLmemoryType type, size_t size, void* ptr
122);
123
135typedef void (*FUNPTR_memcpy)(
136 NLBlas_t blas,
137 void* to, NLmemoryType to_type,
138 void* from, NLmemoryType from_type,
139 size_t size
140);
141
154typedef void (*FUNPTR_dcopy)(
155 NLBlas_t blas, int n, const double *x, int incx, double *y, int incy
156);
157
167typedef void (*FUNPTR_dscal)(
168 NLBlas_t blas, int n, double a, double *x, int incx
169);
170
171
184typedef double (*FUNPTR_ddot)(
185 NLBlas_t blas, int n, const double *x, int incx, const double *y, int incy
186);
187
197typedef double (*FUNPTR_dnrm2)(NLBlas_t blas, int n, const double *x, int incx);
198
212typedef void (*FUNPTR_daxpy)(
213 NLBlas_t blas, int n,
214 double a, const double *x, int incx, double *y, int incy
215);
216
217
254typedef void (*FUNPTR_dgemv)(
255 NLBlas_t blas, MatrixTranspose trans, int m, int n, double alpha,
256 const double *A, int ldA, const double *x, int incx,
257 double beta, double *y, int incy
258);
259
260
302typedef void (*FUNPTR_dtpsv)(
303 NLBlas_t blas, MatrixTriangle uplo, MatrixTranspose trans,
304 MatrixUnitTriangular diag, int n, const double *AP,
305 double *x, int incx
306);
307
308struct NLBlas {
309 FUNPTR_malloc Malloc;
310 FUNPTR_free Free;
311 FUNPTR_memcpy Memcpy;
312
313 FUNPTR_dcopy Dcopy;
314 FUNPTR_dscal Dscal;
315 FUNPTR_ddot Ddot;
316 FUNPTR_dnrm2 Dnrm2;
317 FUNPTR_daxpy Daxpy;
318 FUNPTR_dgemv Dgemv;
319 FUNPTR_dtpsv Dtpsv;
320
321 NLboolean has_unified_memory;
322 double start_time;
323 NLulong flops;
324 NLulong used_ram[2];
325 NLulong max_used_ram[2];
326
327 /*
328 * Used for stats of the linear solver
329 * (a bit ugly, should not be here, but
330 * more convenient for now...)
331 */
332 double sq_rnorm;
333 double sq_bnorm;
334};
335
344
349NLAPI void NLAPIENTRY nlBlasResetStats(NLBlas_t blas);
350
357NLAPI double NLAPIENTRY nlBlasGFlops(NLBlas_t blas);
358
367NLAPI NLulong NLAPIENTRY nlBlasUsedRam(NLBlas_t blas, NLmemoryType type);
368
377NLAPI NLulong NLAPIENTRY nlBlasMaxUsedRam(NLBlas_t blas, NLmemoryType type);
378
384NLAPI NLBlas_t NLAPIENTRY nlHostBlas(void);
385
392#define NL_NEW_VECTOR(blas, memtype, dim) \
393 (double*)blas->Malloc(blas,memtype,(size_t)(dim)*sizeof(double))
394
402#define NL_DELETE_VECTOR(blas, memtype, dim, ptr) \
403 blas->Free(blas,memtype,(size_t)(dim)*sizeof(double),ptr)
404
405/******************************************************************************/
406
407#ifdef __cplusplus
408}
409#endif
410
411#endif
uint64_t NLulong
A 8-bytes unsigned integer.
Definition nl.h:273
unsigned char NLboolean
A truth value (NL_TRUE or NL_FALSE).
Definition nl.h:221
void(* FUNPTR_dscal)(NLBlas_t blas, int n, double a, double *x, int incx)
Scales a vector.
Definition nl_blas.h:167
MatrixTriangle
Specifies which triangular part of a matrix should be used.
Definition nl_blas.h:77
MatrixTranspose
Specifies whether matrix should be transposed.
Definition nl_blas.h:69
NLAPI void NLAPIENTRY nlBlasResetStats(NLBlas_t blas)
Restes the flops and memory used statistics.
void(* FUNPTR_memcpy)(NLBlas_t blas, void *to, NLmemoryType to_type, void *from, NLmemoryType from_type, size_t size)
Copies a bloc of memory.
Definition nl_blas.h:135
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.
Definition nl_blas.h:212
MatrixUnitTriangular
Specifies which triangular part of a matrix should be used.
Definition nl_blas.h:85
void *(* FUNPTR_malloc)(NLBlas_t blas, NLmemoryType type, size_t size)
Allocates memory in host or in device.
Definition nl_blas.h:107
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 s...
struct NLBlas * NLBlas_t
A handle to a BLAS abstraction layer.
Definition nl_blas.h:63
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.
Definition nl_blas.h:302
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 sinc...
void(* FUNPTR_dcopy)(NLBlas_t blas, int n, const double *x, int incx, double *y, int incy)
Copies a vector.
Definition nl_blas.h:154
double(* FUNPTR_dnrm2)(NLBlas_t blas, int n, const double *x, int incx)
Computes the norm of a vector.
Definition nl_blas.h:197
void(* FUNPTR_free)(NLBlas_t blas, NLmemoryType type, size_t size, void *ptr)
Frees memory from host or from device.
Definition nl_blas.h:120
NLmemoryType
Specifies on which type of memory a function should be applied.
Definition nl_blas.h:94
NLAPI NLboolean NLAPIENTRY nlBlasHasUnifiedMemory(NLBlas_t blas)
Tests whether BLAS device uses the same address space as the CPU.
NLAPI NLBlas_t NLAPIENTRY nlHostBlas(void)
Gets a pointer to the BLAS abstraction layer for BLAS operation on the host CPU.
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.
Definition nl_blas.h:184
NLAPI double NLAPIENTRY nlBlasGFlops(NLBlas_t blas)
Gets the number of floating point operations per seconds computed since creation of the BLAS abstacti...
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.
Definition nl_blas.h:254
Some macros and functions used internally by OpenNL.