LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/resource/notify - notify_base.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 61.1 % 36 22
Test Date: 2026-08-18 17:47:01 Functions: 64.3 % 14 9

            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 NOTIFY_BASE_H
      12              : #define NOTIFY_BASE_H
      13              : 
      14              : #include "adapter_rts.h"
      15              : #include "adapter_hal.h"
      16              : #include "hccl/base.h"
      17              : 
      18              : #include "mem_name_repository_pub.h"
      19              : #include "dispatcher_pub.h"
      20              : 
      21              : namespace hccl {
      22              : 
      23              : enum class NotifyType { RUNTIME_NOTIFY = 0, RUNTIME_NOTIFY_MC2, BARE_NOTIFY, ESCHED_EVENT, NOTIFY_TYPE_RESERVED };
      24              : 
      25              : constexpr s32 IPC_NOTIFY_PID_ARRAY_SIZE = 1;
      26              : 
      27              : using HcclIpcRtsNotify = struct TagHcclIpcRtsNotify {
      28              :     u8 ipcName[HCCL_IPC_MEM_NAME_LEN] = {0};
      29              :     bool withIpc;
      30              :     HcclRtNotify ptr;
      31              :     u32 id;
      32              :     u64 offset;
      33              : 
      34         5396 :     TagHcclIpcRtsNotify() : withIpc(false), ptr(nullptr), id(INVALID_UINT), offset(INVALID_U64) {}
      35              : };
      36              : 
      37              : using HcclNotifyInfo = struct TagHcclNotifyInfo {
      38              :     u32 type;
      39              :     HcclIpcRtsNotify ipcNotify;
      40              : 
      41         5395 :     TagHcclNotifyInfo() : type(INVALID_UINT) {}
      42              : 
      43            3 :     TagHcclNotifyInfo(const TagHcclNotifyInfo& that) : type(that.type), ipcNotify(that.ipcNotify) {}
      44              : 
      45              :     TagHcclNotifyInfo(const TagHcclNotifyInfo&& that) : type(that.type), ipcNotify(that.ipcNotify) {}
      46              : 
      47              :     TagHcclNotifyInfo& operator=(const TagHcclNotifyInfo& that)
      48              :     {
      49              :         if (&that != this) {
      50              :             type = that.type;
      51              :             ipcNotify = that.ipcNotify;
      52              :         }
      53              :         return *this;
      54              :     }
      55              : };
      56              : 
      57              : class NotifyBase {
      58              : public:
      59         5393 :     explicit NotifyBase(NotifyType notifyType) : notifyType(notifyType)
      60              :     {
      61         5394 :         notifyInfo_.type = static_cast<u32>(notifyType);
      62         5394 :     }
      63              : 
      64            1 :     NotifyBase(NotifyType notifyType, HcclNotifyInfo notifyInfo) : notifyType(notifyType), notifyInfo_(notifyInfo) {}
      65              : 
      66              :     NotifyBase(NotifyType notifyType, [[maybe_unused]] HcclSignalInfo notifyInfo) : notifyType(notifyType)
      67              :     {
      68              :         HCCL_ERROR("[NotifyConstructor]Does not support this interface.");
      69              :     }
      70              : 
      71         5398 :     virtual ~NotifyBase() {}
      72              : 
      73            1 :     HcclResult Serialize(std::vector<u8>& byteVector)
      74              :     {
      75            1 :         std::vector<u8> data = CustomTypeToVectorByte<HcclNotifyInfo>(notifyInfo_);
      76            1 :         if (data.empty() || data.size() > NOTIFY_INFO_LENGTH) {
      77            0 :             HCCL_ERROR("serialize msgSize[%u] > NOTIFY_INFO_LENGTH[%u]", data.size(), NOTIFY_INFO_LENGTH);
      78            0 :             return HCCL_E_INTERNAL;
      79              :         }
      80              : 
      81            1 :         std::vector<u8> paddingData(NOTIFY_INFO_LENGTH - data.size(), 0);
      82            1 :         HCCL_DEBUG("[Serialize]data size[%u], paddingData[%u].", data.size(), paddingData.size());
      83            1 :         data.insert(data.end(), paddingData.begin(), paddingData.end());
      84              : 
      85            1 :         byteVector = data;
      86              : 
      87            1 :         return HCCL_SUCCESS;
      88            1 :     }
      89              : 
      90            1 :     static HcclResult Deserialize(const std::vector<u8>& byteVector, HcclNotifyInfo& notifyInfo)
      91              :     {
      92            1 :         CHK_PRT_RET(
      93              :             byteVector.size() < sizeof(HcclNotifyInfo),
      94              :             HCCL_ERROR(
      95              :                 "[Deserialize]expected byteVector size[%zu] < sizeof(HcclNotifyInfo)[%zu]", byteVector.size(),
      96              :                 sizeof(HcclNotifyInfo)),
      97              :             HCCL_E_PARA);
      98            1 :         CHK_SAFETY_FUNC_RET(memcpy_s((u8*)&notifyInfo, sizeof(HcclNotifyInfo), &byteVector[0], sizeof(HcclNotifyInfo)));
      99            1 :         return HCCL_SUCCESS;
     100              :     }
     101              : 
     102              :     virtual HcclResult Alloc() = 0;
     103              :     virtual HcclResult Destroy() = 0;
     104              : 
     105              :     virtual HcclResult Open() = 0;
     106              :     virtual HcclResult Close() = 0;
     107              : 
     108              :     virtual HcclResult Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut) = 0;
     109              :     virtual HcclResult Post(Stream& stream, HcclDispatcher dispatcher, s32 stage) = 0;
     110              : 
     111              :     virtual HcclResult
     112              :     Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut, u32 userRank, u32 remoteUserRank)
     113              :         = 0;
     114              :     virtual HcclResult Wait(Stream& stream, u32 timeOut) = 0;
     115              :     virtual HcclResult Post(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 remoteUserRank) = 0;
     116              :     virtual HcclResult Post(Stream& stream) = 0;
     117              :     virtual HcclResult SetIpc() = 0;
     118              :     virtual HcclResult Grant(s64 recvId) = 0;
     119            0 :     virtual void Break()
     120              :     {
     121            0 :         HCCL_ERROR("[Break]Does not support this interface.");
     122            0 :         return;
     123              :     }
     124              : 
     125            0 :     virtual HcclResult GetNotifyData([[maybe_unused]] HcclSignalInfo& notifyInfo)
     126              :     {
     127            0 :         HCCL_ERROR("[GetNotifyData]Does not support this interface.");
     128            0 :         return HCCL_E_NOT_SUPPORT;
     129              :     }
     130              : 
     131            0 :     virtual HcclResult SetNotifyData([[maybe_unused]] const HcclSignalInfo& notifyInfo)
     132              :     {
     133            0 :         HCCL_ERROR("[SetNotifyData]Does not support this interface.");
     134            0 :         return HCCL_E_NOT_SUPPORT;
     135              :     }
     136              : 
     137            0 :     virtual HcclResult GetNotifyOffset([[maybe_unused]] u64& offset)
     138              :     {
     139            0 :         HCCL_ERROR("[GetNotifyOffset]Does not support this interface.");
     140            0 :         return HCCL_E_NOT_SUPPORT;
     141              :     }
     142              : 
     143         5390 :     inline HcclRtNotify ptr() { return notifyPtr; }
     144              : 
     145              : protected:
     146              :     NotifyType notifyType;
     147              :     HcclNotifyInfo notifyInfo_;
     148              :     HcclRtNotify notifyPtr{nullptr};
     149              : };
     150              : } // namespace hccl
     151              : 
     152              : #endif // NOTIFY_BASE_H
        

Generated by: LCOV version 2.0-1