LCOV - code coverage report
Current view: top level - nntrainer/tensor/cpu_backend/cblas_interface - cblas_interface.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 88.5 % 26 23
Test Date: 2025-12-14 20:38:17 Functions: 87.5 % 8 7

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2024 Sungsik Kong <ss.kong@samsung.com>
       4              :  *
       5              :  * @file cblas_interface.cpp
       6              :  * @date   23 April 2024
       7              :  * @see    https://github.com/nnstreamer/nntrainer
       8              :  * @author Sungsik Kong <ss.kong@samsung.com>
       9              :  * @bug    No known bugs except for NYI items
      10              :  * @brief  Function interface to use cblas lib from cpu_backend
      11              :  *
      12              :  */
      13              : 
      14              : #include <cblas.h>
      15              : #include <cblas_interface.h>
      16              : 
      17              : namespace nntrainer {
      18        15254 : void __cblas_saxpy(const unsigned int N, const float alpha, const float *X,
      19              :                    const unsigned int incX, float *Y, const unsigned int incY) {
      20              : #ifdef BLAS_NUM_THREADS
      21              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      22              : #endif
      23        15254 :   cblas_saxpy(N, alpha, X, incX, Y, incY);
      24        15254 : }
      25              : 
      26        88188 : void __cblas_sgemv(const unsigned int TStorageOrder, bool TransA,
      27              :                    const unsigned int M, const unsigned int N,
      28              :                    const float alpha, const float *A, const unsigned int lda,
      29              :                    const float *X, const unsigned int incX, const float beta,
      30              :                    float *Y, const unsigned int incY) {
      31        88188 :   CBLAS_TRANSPOSE transA = TransA ? CblasTrans : CblasNoTrans;
      32        88188 :   CBLAS_ORDER order = TStorageOrder ? CblasColMajor : CblasRowMajor;
      33              : #ifdef BLAS_NUM_THREADS
      34              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      35              : #endif
      36        88188 :   cblas_sgemv(order, transA, M, N, alpha, A, lda, X, incX, beta, Y, incY);
      37        88188 : }
      38              : 
      39          245 : float __cblas_sdot(const unsigned int N, const float *X,
      40              :                    const unsigned int incX, const float *Y,
      41              :                    const unsigned int incY) {
      42              : #ifdef BLAS_NUM_THREADS
      43              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      44              : #endif
      45          245 :   return cblas_sdot(N, X, incX, Y, incY);
      46              : }
      47              : 
      48            0 : void __cblas_scopy(const unsigned int N, const float *X,
      49              :                    const unsigned int incX, float *Y, const unsigned int incY) {
      50              : #ifdef BLAS_NUM_THREADS
      51              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      52              : #endif
      53            0 :   cblas_scopy(N, X, incX, Y, incY);
      54            0 : }
      55              : 
      56         2609 : void __cblas_sscal(const unsigned int N, const float alpha, float *X,
      57              :                    const unsigned int incX) {
      58              : #ifdef BLAS_NUM_THREADS
      59              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      60              : #endif
      61         2609 :   cblas_sscal(N, alpha, X, incX);
      62         2609 : }
      63              : 
      64         1931 : float __cblas_snrm2(const unsigned int N, const float *X,
      65              :                     const unsigned int incX) {
      66              : #ifdef BLAS_NUM_THREADS
      67              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      68              : #endif
      69         1931 :   return cblas_snrm2(N, X, incX);
      70              : }
      71              : 
      72        16977 : void __cblas_sgemm(const unsigned int TStorageOrder, bool TransA, bool TransB,
      73              :                    const unsigned int M, const unsigned int N,
      74              :                    const unsigned int K, const float alpha, const float *A,
      75              :                    const unsigned int lda, const float *B,
      76              :                    const unsigned int ldb, const float beta, float *C,
      77              :                    const unsigned int ldc) {
      78        16977 :   CBLAS_TRANSPOSE transA = TransA ? CblasTrans : CblasNoTrans;
      79        16977 :   CBLAS_TRANSPOSE transB = TransB ? CblasTrans : CblasNoTrans;
      80        16977 :   CBLAS_ORDER order = TStorageOrder ? CblasColMajor : CblasRowMajor;
      81              : #ifdef BLAS_NUM_THREADS
      82              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      83              : #endif
      84        16977 :   cblas_sgemm(order, transA, transB, M, N, K, alpha, A, lda, B, ldb, beta, C,
      85              :               ldc);
      86        16977 : }
      87              : 
      88            3 : unsigned int __cblas_isamax(const unsigned int N, const float *X,
      89              :                             const unsigned int incX) {
      90              : #ifdef BLAS_NUM_THREADS
      91              :   openblas_set_num_threads(BLAS_NUM_THREADS);
      92              : #endif
      93            3 :   return cblas_isamax(N, X, incX);
      94              : }
      95              : } // namespace nntrainer
        

Generated by: LCOV version 2.0-1