[ Mixed ] fix apply using casted function
[platform/core/ml/nntrainer.git] / nntrainer / tensor / blas_interface.h
1 // SPDX-License-Identifier: Apache-2.0
2 /**
3  * Copyright (C) 2020 Jijoong Moon <jijoong.moon@samsung.com>
4  *
5  * @file   blas_interface.h
6  * @date   28 Aug 2020
7  * @see    https://github.com/nnstreamer/nntrainer
8  * @author Jijoong Moon <jijoong.moon@samsung.com>
9  * @bug    No known bugs except for NYI items
10  * @brief  This is dummy header for blas support
11  *
12  */
13
14 #ifndef __BLAS_INTERFACE_H_
15 #define __BLAS_INTERFACE_H_
16 #ifdef __cplusplus
17
18 #ifdef USE_BLAS
19 extern "C" {
20 #include <cblas.h>
21 }
22 #else
23 enum CBLAS_ORDER { CblasRowMajor = 101, CblasColMajor = 102 };
24
25 enum CBLAS_TRANSPOSE {
26   CblasNoTrans = 111,
27   CblasTrans = 112,
28   CblasConjTrans = 113
29 };
30
31 #endif
32
33 #ifdef USE_CUBLAS
34 #include <helper_cuda.h>
35 #include <helper_functions.h>
36 #endif
37
38 #include <tensor_dim.h>
39
40 namespace nntrainer {
41
42 #ifdef ENABLE_FP16
43 void sscal(const unsigned int N, const float alpha, _FP16 *X, const int incX);
44 _FP16 snrm2(const int N, const _FP16 *X, const int incX);
45 void scopy(const unsigned int N, const _FP16 *X, const int incX, _FP16 *Y,
46            const int intY);
47 _FP16 sdot(const unsigned int N, const _FP16 *X, const unsigned int incX,
48             const _FP16 *Y, const unsigned int incY);
49 void saxpy(const unsigned int N, const float alpha, const _FP16 *X,
50            const int incX, _FP16 *Y, const int incY);
51 void sgemm(CBLAS_ORDER order, CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB,
52            const unsigned int M, const unsigned int N, const unsigned int K,
53            const float alpha, const _FP16 *A, const unsigned int lda,
54            const _FP16 *B, const unsigned int ldb, const float beta, _FP16 *C,
55            const unsigned int ldc);
56 void sgemv(CBLAS_ORDER order, CBLAS_TRANSPOSE TransA, const unsigned int M,
57            const unsigned int N, const float alpha, const _FP16 *A,
58            const unsigned int lda, const _FP16 *X, const int incX,
59            const float beta, _FP16 *Y, const int incY);
60 unsigned int isamax(const unsigned int N, const _FP16 *X, const int incX);
61 #endif
62
63 void sscal(const unsigned int N, const float alpha, void *X, const int incX,
64            ml::train::TensorDim::DataType d_type);
65
66 void sscal(const unsigned int N, const float alpha, float *X, const int incX);
67
68 float snrm2(const int N, const float *X, const int incX);
69
70 void scopy(const unsigned int N, const void *X, const int incX, void *Y,
71            const int incY, ml::train::TensorDim::DataType d_type);
72 void scopy(const unsigned int N, const float *X, const int incX, float *Y,
73            const int intY);
74
75 float sdot(const unsigned int N, const float *X, const unsigned int incX,
76            const float *Y, const unsigned int incY);
77
78 void saxpy(const unsigned int N, const float alpha, const void *X,
79            const int incX, void *Y, const int incY,
80            ml::train::TensorDim::DataType d_type);
81 void saxpy(const unsigned int N, const float alpha, const float *X,
82            const int incX, float *Y, const int incY);
83
84 void sgemm(CBLAS_ORDER order, CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB,
85            const unsigned int M, const unsigned int N, const unsigned int K,
86            const float alpha, const void *A, const unsigned int lda,
87            const void *B, const unsigned int ldb, const float beta, void *C,
88            const unsigned int ldc, ml::train::TensorDim::DataType d_type);
89
90 void sgemm(CBLAS_ORDER order, CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB,
91            const unsigned int M, const unsigned int N, const unsigned int K,
92            const float alpha, const float *A, const unsigned int lda,
93            const float *B, const unsigned int ldb, const float beta, float *C,
94            const unsigned int ldc);
95
96 void sgemv(CBLAS_ORDER order, CBLAS_TRANSPOSE TransA, const unsigned int M,
97            const unsigned int N, const float alpha, const void *A,
98            const unsigned int lda, const void *X, const int incX,
99            const float beta, void *Y, const int incY,
100            ml::train::TensorDim::DataType d_type);
101
102 void sgemv(CBLAS_ORDER order, CBLAS_TRANSPOSE TransA, const unsigned int M,
103            const unsigned int N, const float alpha, const float *A,
104            const unsigned int lda, const float *X, const int incX,
105            const float beta, float *Y, const int incY);
106
107 unsigned int isamax(const unsigned int N, const float *X, const int incX);
108
109 } /* namespace nntrainer */
110 #endif /* __cplusplus */
111 #endif /* __BLAS_INTERFACE_H__ */