LCOV - code coverage report
Current view: top level - coll_communicator_mgr/team/hcomm - hcomm_team.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.8 % 65 61
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 HCOMM_TEAM_H
      12              : #define HCOMM_TEAM_H
      13              : #include <stdint.h>
      14              : #include <stddef.h>
      15              : #include <stdbool.h>
      16              : #include "hcomm_res_defs.h"
      17              : #include "hcomm_team_defs.h"
      18              : 
      19              : #ifdef __cplusplus
      20              : extern "C" {
      21              : #endif // __cplusplus
      22              : 
      23              : typedef enum {
      24              :     HCOMM_TEAM_WINDOW_FLAG_INVALID = -1,
      25              :     HCOMM_TEAM_WINDOW_FLAG_SYMMETRIC = 0, // 当前仅支持配置为0
      26              : } HcommTeamWindowFlag;
      27              : 
      28              : typedef struct {
      29              :     CommAbiHeader header;
      30              :     uint32_t memberNum;
      31              :     uint32_t selfMemberId;
      32              :     const uint32_t*
      33              :         worldMemberIds; /*worldMemberIds在创建worldteam的时候是nullptr,创建subteam的时候是subteam的成员在worldteam中的memberId数组,长度是memberNum*/
      34              :     uint32_t netLayer;  /* 用户希望使用的网络层,0表示默认选择 */
      35              :     CommProtocol protocol; /* 用户希望使用的通信协议,-1表示保留协议类型, 1个team仅支持一个协议 */
      36              :     HcommTeamSyncMemRequirement requirement;
      37              :     uint32_t reserved[6];
      38              : } HcommTeamCreateDesc;
      39              : 
      40              : typedef struct {
      41              :     CommAbiHeader header;
      42              :     uint32_t* channelNumPerMember; /* 长度为memberNum,表示每个成员的channel数量 */
      43              :     ChannelHandle** channelsByMemberId;
      44              :     uint32_t memberNum;
      45              :     uint32_t reserved[8];
      46              : } HcommTeamBindChannelsDesc;
      47              : 
      48              : typedef struct {
      49              :     CommAbiHeader header;
      50              :     CommMem* mems; // 下标是成员id,长度是memberNum,如果是selfMemberId,则是本地内存,否则是远端内存
      51              :     uint32_t memberNum;
      52              :     uint32_t reserved[5];
      53              : } HcommTeamWindowDesc;
      54              : 
      55              : typedef struct {
      56              :     CommAbiHeader header;
      57              :     CommMem* remoteMems;
      58              :     uint32_t remoteMemNum;
      59              :     uint32_t reserved[5];
      60              : } HcommTeamBindSyncMemDesc;
      61              : 
      62              : static const uint32_t HCOMM_TEAM_CREATE_DESC_MAGIC_WORD = 0x0f0f0f10U;
      63              : static const uint32_t HCOMM_TEAM_CREATE_DESC_VERSION = 1U;
      64              : 
      65              : static const uint32_t HCOMM_TEAM_BIND_CHANNELS_DESC_MAGIC_WORD = 0x0f0f0f11U;
      66              : static const uint32_t HCOMM_TEAM_BIND_CHANNELS_DESC_VERSION = 1U;
      67              : 
      68              : static const uint32_t HCOMM_TEAM_WINDOW_DESC_MAGIC_WORD = 0x0f0f0f12U;
      69              : static const uint32_t HCOMM_TEAM_WINDOW_DESC_VERSION = 1U;
      70              : 
      71              : static const uint32_t HCOMM_TEAM_BIND_SYNCMEM_DESC_MAGIC_WORD = 0x0f0f0f13U;
      72              : static const uint32_t HCOMM_TEAM_BIND_SYNCMEM_DESC_VERSION = 1U;
      73              : 
      74           40 : static inline HcommResult HcommTeamCreateDescInit(HcommTeamCreateDesc* desc)
      75              : {
      76           40 :     const HcommResult hcommEPointer = (HcommResult)2;
      77              : 
      78           40 :     if (desc == NULL) {
      79            0 :         return hcommEPointer;
      80              :     }
      81              : 
      82           40 :     (void)memset_s(desc, sizeof(HcommTeamCreateDesc), 0xFF, sizeof(HcommTeamCreateDesc));
      83           40 :     desc->header.version = HCOMM_TEAM_CREATE_DESC_VERSION;
      84           40 :     desc->header.magicWord = HCOMM_TEAM_CREATE_DESC_MAGIC_WORD;
      85           40 :     desc->header.size = sizeof(HcommTeamCreateDesc);
      86           40 :     desc->header.reserved = 0;
      87           40 :     desc->memberNum = 0;
      88           40 :     desc->selfMemberId = 0;
      89           40 :     desc->worldMemberIds = NULL;
      90           40 :     desc->netLayer = 0;
      91           40 :     desc->protocol = COMM_PROTOCOL_RESERVED;
      92           40 :     desc->requirement.signalCount = 0;
      93           40 :     desc->requirement.counterCount = 0;
      94           40 :     desc->requirement.barrierCount = 0;
      95          240 :     for (uint32_t i = 0; i < 5; ++i) {
      96          200 :         desc->requirement.reserved[i] = 0;
      97              :     }
      98          240 :     for (uint32_t i = 0; i < 5; ++i) {
      99          200 :         desc->reserved[i] = 0;
     100              :     }
     101              : 
     102           40 :     return 0;
     103              : }
     104              : 
     105            8 : static inline HcommResult HcommTeamBindChannelsDescInit(HcommTeamBindChannelsDesc* desc)
     106              : {
     107            8 :     const HcommResult hcommEPointer = (HcommResult)2;
     108              : 
     109            8 :     if (desc == NULL) {
     110            0 :         return hcommEPointer;
     111              :     }
     112              : 
     113            8 :     (void)memset_s(desc, sizeof(HcommTeamBindChannelsDesc), 0xFF, sizeof(HcommTeamBindChannelsDesc));
     114            8 :     desc->header.version = HCOMM_TEAM_BIND_CHANNELS_DESC_VERSION;
     115            8 :     desc->header.magicWord = HCOMM_TEAM_BIND_CHANNELS_DESC_MAGIC_WORD;
     116            8 :     desc->header.size = sizeof(HcommTeamBindChannelsDesc);
     117            8 :     desc->header.reserved = 0;
     118            8 :     desc->memberNum = 0;
     119            8 :     desc->channelNumPerMember = NULL;
     120            8 :     desc->channelsByMemberId = NULL;
     121           72 :     for (uint32_t i = 0; i < 8; ++i) {
     122           64 :         desc->reserved[i] = 0;
     123              :     }
     124              : 
     125            8 :     return 0;
     126              : }
     127              : 
     128            6 : static inline HcommResult HcommTeamWindowDescInit(HcommTeamWindowDesc* desc)
     129              : {
     130            6 :     const HcommResult hcommEPointer = (HcommResult)2;
     131              : 
     132            6 :     if (desc == NULL) {
     133            0 :         return hcommEPointer;
     134              :     }
     135              : 
     136            6 :     (void)memset_s(desc, sizeof(HcommTeamWindowDesc), 0xFF, sizeof(HcommTeamWindowDesc));
     137            6 :     desc->header.version = HCOMM_TEAM_WINDOW_DESC_VERSION;
     138            6 :     desc->header.magicWord = HCOMM_TEAM_WINDOW_DESC_MAGIC_WORD;
     139            6 :     desc->header.size = sizeof(HcommTeamWindowDesc);
     140            6 :     desc->header.reserved = 0;
     141            6 :     desc->mems = NULL;
     142            6 :     desc->memberNum = 0;
     143           36 :     for (uint32_t i = 0; i < 5; ++i) {
     144           30 :         desc->reserved[i] = 0;
     145              :     }
     146              : 
     147            6 :     return 0;
     148              : }
     149              : 
     150            5 : static inline HcommResult HcommTeamBindSyncMemDescInit(HcommTeamBindSyncMemDesc* desc)
     151              : {
     152            5 :     const HcommResult hcommEPointer = (HcommResult)2;
     153              : 
     154            5 :     if (desc == NULL) {
     155            0 :         return hcommEPointer;
     156              :     }
     157              : 
     158            5 :     (void)memset_s(desc, sizeof(HcommTeamBindSyncMemDesc), 0xFF, sizeof(HcommTeamBindSyncMemDesc));
     159            5 :     desc->header.version = HCOMM_TEAM_BIND_SYNCMEM_DESC_VERSION;
     160            5 :     desc->header.magicWord = HCOMM_TEAM_BIND_SYNCMEM_DESC_MAGIC_WORD;
     161            5 :     desc->header.size = sizeof(HcommTeamBindSyncMemDesc);
     162            5 :     desc->header.reserved = 0;
     163            5 :     desc->remoteMems = NULL;
     164            5 :     desc->remoteMemNum = 0;
     165           30 :     for (uint32_t i = 0; i < 5; ++i) {
     166           25 :         desc->reserved[i] = 0;
     167              :     }
     168              : 
     169            5 :     return 0;
     170              : }
     171              : 
     172              : /* ===== team 生命周期 ===== */
     173              : HcommResult HcommTeamCreate(
     174              :     HcommTeamHandle worldTeam, const HcommTeamCreateDesc* desc, HcommTeamHandle* team, uint64_t* syncMemSize);
     175              : HcommResult HcommTeamDestroy(HcommTeamHandle team);
     176              : 
     177              : /* ===== team 窗口操作 ===== */
     178              : HcommResult HcommTeamWindowRegister(
     179              :     HcommTeamHandle worldTeam, const HcommTeamWindowDesc* desc, HcommWindowHandle* handle, HcommTeamWindowFlag flag);
     180              : HcommResult HcommTeamWindowDeregister(HcommTeamHandle worldTeam, HcommWindowHandle handle);
     181              : 
     182              : /* ===== team 资源绑定 ===== */
     183              : HcommResult HcommTeamBindChannels(HcommTeamHandle team, const HcommTeamBindChannelsDesc* desc);
     184              : HcommResult HcommTeamBindRemoteSyncMem(HcommTeamHandle team, const HcommTeamBindSyncMemDesc* remoteDesc);
     185              : HcommResult
     186              : HcommTeamWindowBindRemoteMems(HcommTeamHandle team, HcommWindowHandle handle, const HcommTeamWindowDesc* remoteDesc);
     187              : 
     188              : /* ===== team 工具函数 ===== */
     189              : HcommResult HcommTeamIsSubBelongToWorld(HcommTeamHandle worldTeam, HcommTeamHandle subTeam, bool* isBelong);
     190              : 
     191              : #ifdef __cplusplus
     192              : }
     193              : #endif // __cplusplus
     194              : #endif // HCOMM_TEAM_H
        

Generated by: LCOV version 2.0-1