LCOV - code coverage report
Current view: top level - aicpu_processer - ae_kernel_lib_fwk.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef __AE_KERNEL_LIB_FWK_H_
      12              : #define __AE_KERNEL_LIB_FWK_H_
      13              : 
      14              : #include "aicpu_engine.h"
      15              : #include "ae_def.hpp"
      16              : #include "ae_kernel_lib_base.hpp"
      17              : #include "ae_so_manager.hpp"
      18              : #include <mutex>
      19              : #include <string>
      20              : #include <vector>
      21              : #include <sys/types.h>
      22              : 
      23              : namespace cce {
      24              : 
      25              :     class FWKKernelTfImpl {
      26              :         using FwkTfOpFuncPtr = uint32_t (*)(uint64_t paramBase);
      27              :     public:
      28              :         FWKKernelTfImpl();
      29              : 
      30              :         ~FWKKernelTfImpl();
      31              : 
      32              :     public:
      33              :         // Init Interface
      34              :         aeStatus_t Init();
      35              :         // Implement call a tensorflow op kernel interface
      36              :         int32_t CallKernelApi(const uint64_t fwkKernelParam);
      37              : 
      38              :         // Implement load tensorflow so
      39              :         aeStatus_t LoadTfSo();
      40              : 
      41              :         // get thread mode so path
      42              :         void GetThreadModelSoPath(std::string &soPath);
      43              : 
      44              :         aeStatus_t GetTfThreadModeSoPath(std::string &soPath);
      45              : 
      46              :         void GetTensorflowThreadModeSoPath(std::string soPath);
      47              : 
      48              :         void GetTfKernelThreadModeSoPath(std::string &soPath) const;
      49              : 
      50              :     private:
      51              :         const std::string &GetKernelName() const;
      52              : 
      53              :         const std::string &GetSoFile() const;
      54              : 
      55              :         // Transform kernel error code
      56              :         static aeStatus_t TransformKernelErrorCode(const uint32_t errCode, const uint64_t fwkKernelParam);
      57              : 
      58              :     private:
      59              :         // The tf-kernel lib file
      60              :         std::string soFile_;
      61              :         // The tensorflow lib file
      62              :         std::string tensorflowSoFile_;
      63              :         // The tensorflow lib api name
      64              :         std::string kernelName_;
      65              :         // Store the tensorflow lib api addr
      66              :         void *funcAddr_;
      67              :         // Store the handle of  tensorflow lib open by dlopen
      68              :         void *soHandle_;
      69              :         // Store the hadle of libtensorflow.so open by dlopen
      70              :         void *soTensorflowHandle_;
      71              :         // A Read Write lock to protect apiCacher_
      72              :         tAERwLock rwLock_ = PTHREAD_RWLOCK_INITIALIZER;
      73              :     };
      74              : 
      75              :     class AIKernelsLibFWK : public AIKernelsLibBase {
      76              :     public:
      77            8 :         ~AIKernelsLibFWK() override = default;
      78              : 
      79              :         // SINGLETON object get interface
      80              :         static AIKernelsLibFWK *GetInstance();
      81              : 
      82              :         // Init interface
      83              :         aeStatus_t Init() override;
      84              : 
      85              :         // Close so
      86              :         aeStatus_t CloseSo(const char_t * const soName) override;
      87              : 
      88              :         // SINGLETON object destroy interface
      89              :         static void DestroyInstance();
      90              : 
      91              :         // Call a framework op kernel interface
      92              :         int32_t CallKernelApi(const aicpu::KernelType kernelType, const void * const kernelBase) override;
      93              : 
      94              :         // Batch load kernel so
      95              :         aeStatus_t BatchLoadKernelSo(const aicpu::KernelType kernelType,
      96              :                                      std::vector<std::string> &soVec) override;
      97              : 
      98              :     private:
      99              :         //SINGLETON object
     100              :         static AIKernelsLibFWK *instance_;
     101              : 
     102            4 :         AIKernelsLibFWK() = default;
     103              : 
     104              :     private:
     105              :         // Tensorflow implement.
     106              :         FWKKernelTfImpl tfImpl_;
     107              :         // Mutex lock to protect SINGLETON object create or destroy
     108              :         static std::mutex mtx_;
     109              :     };
     110              : }
     111              : #endif
     112              : 
        

Generated by: LCOV version 2.0-1