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-08-12 11:05:02 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              : 
      28              : public:
      29              :     FWKKernelTfImpl();
      30              : 
      31              :     ~FWKKernelTfImpl();
      32              : 
      33              : public:
      34              :     // Init Interface
      35              :     aeStatus_t Init();
      36              :     // Implement call a tensorflow op kernel interface
      37              :     int32_t CallKernelApi(const uint64_t fwkKernelParam);
      38              : 
      39              :     // Implement load tensorflow so
      40              :     aeStatus_t LoadTfSo();
      41              : 
      42              :     // get thread mode so path
      43              :     void GetThreadModelSoPath(std::string& soPath);
      44              : 
      45              :     aeStatus_t GetTfThreadModeSoPath(std::string& soPath);
      46              : 
      47              :     void GetTensorflowThreadModeSoPath(std::string soPath);
      48              : 
      49              :     void GetTfKernelThreadModeSoPath(std::string& soPath) const;
      50              : 
      51              : private:
      52              :     const std::string& GetKernelName() const;
      53              : 
      54              :     const std::string& GetSoFile() const;
      55              : 
      56              :     // Transform kernel error code
      57              :     static aeStatus_t TransformKernelErrorCode(const uint32_t errCode, const uint64_t fwkKernelParam);
      58              : 
      59              : private:
      60              :     // The tf-kernel lib file
      61              :     std::string soFile_;
      62              :     // The tensorflow lib file
      63              :     std::string tensorflowSoFile_;
      64              :     // The tensorflow lib api name
      65              :     std::string kernelName_;
      66              :     // Store the tensorflow lib api addr
      67              :     void* funcAddr_;
      68              :     // Store the handle of  tensorflow lib open by dlopen
      69              :     void* soHandle_;
      70              :     // Store the hadle of libtensorflow.so open by dlopen
      71              :     void* soTensorflowHandle_;
      72              :     // A Read Write lock to protect apiCacher_
      73              :     tAERwLock rwLock_ = PTHREAD_RWLOCK_INITIALIZER;
      74              : };
      75              : 
      76              : class AIKernelsLibFWK : public AIKernelsLibBase {
      77              : public:
      78            8 :     ~AIKernelsLibFWK() override = default;
      79              : 
      80              :     // SINGLETON object get interface
      81              :     static AIKernelsLibFWK* GetInstance();
      82              : 
      83              :     // Init interface
      84              :     aeStatus_t Init() override;
      85              : 
      86              :     // Close so
      87              :     aeStatus_t CloseSo(const char_t* const soName) override;
      88              : 
      89              :     // SINGLETON object destroy interface
      90              :     static void DestroyInstance();
      91              : 
      92              :     // Call a framework op kernel interface
      93              :     int32_t CallKernelApi(const aicpu::KernelType kernelType, const void* const kernelBase) override;
      94              : 
      95              :     // Batch load kernel so
      96              :     aeStatus_t BatchLoadKernelSo(const aicpu::KernelType kernelType, 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              : } // namespace cce
     111              : #endif
        

Generated by: LCOV version 2.0-1