* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#ifndef HCCL_BASE_H
#define HCCL_BASE_H
#include <hccl/hccl_types.h>
#include <string>
#ifdef __cplusplus
extern "C" {
#endif
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
typedef signed long long s64;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
* @brief Horovod Reduction opperation
*/
typedef enum {
HOROVOD_REDUCE_AVERAGE = 0,
HOROVOD_REDUCE_SUM = 1,
HOROVOD_REDUCE_ADASUM = 2,
HOROVOD_REDUCE_MIN = 3,
HOROVOD_REDUCE_MAX = 4,
HOROVOD_REDUCE_PROD = 5,
HOROVOD_REDUCE_RESERVED
} HorovodReduceOp;
const u32 HCCL_MAX_SEGMENT_NUM = 8;
* @brief the feature of the model
*/
struct model_feature {
const char *model_name;
u32 gradient_num;
float *gradient_size;
float *gradient_time;
};
* @brief Memory Register Address Struct for Remote Access
*/
struct MemRegisterAddr {
u64 addr;
u64 length;
};
* @brief The max number of memory register addr for remote access.
*/
const u32 HCCL_MAX_MEM_REGISTER_NUM = 32;
enum GradSplitForceMode {
FORCE_NONE,
FORCE_SIZE,
FORCE_RESERVED
};
enum OriginalGraphShapeType {
KNOWN_SHAPE,
UNKNOWN_SHAPE,
SHAPE_RESERVED
};
enum HcclEventType {
HCCL_EVENT_SEND_COMPLETION = 0,
HCCL_EVENT_RECV_REQUEST,
HCCL_EVENT_RECV_COMPLETION,
HCCL_EVENT_CONGESTION_RELIEF,
HCCL_EVENT_RESERVED
};
const u32 TAG_MAX_LEN = 191;
using TagAttr = struct TagAttrDef {
char name[TAG_MAX_LEN + 1];
uint32_t activeRecv;
uint32_t sendCredit;
uint32_t eventId;
};
using HcclEventMsg = struct HcclEventMsgDef {
HcclComm comm;
u32 peerRank;
u32 tag;
u32 hcclEventType;
union {
struct {
u32 reserver;
} sendCompletionItem;
struct {
u32 reserver;
} recvRequestItem;
struct {
u32 reserver;
} recvCompletionItem;
struct CongestionReliefItem {
u32 reserver;
} congestionReliefItem;
} desc;
};
* @brief stream handle.
*/
typedef void *rtStream_t;
* @brief model handle.
*/
typedef void *rtModel_t;
struct HcomRemoteOperation {
void *opdesc{};
void *keyAddr{};
int *tableId{};
s64 *keyNumInput{};
s32 *uniqueIndices{};
s32 *keyCount{};
void *value{};
void *indices{};
void *numUniqued{};
void *psSeg{};
void *psSegNum{};
};
struct HcomOperation {
std::string hcclType;
void *inputPtr{nullptr};
void *outputPtr{nullptr};
u64 count{0};
HcclDataType dataType{HCCL_DATA_TYPE_RESERVED};
HcclReduceOp opType{HCCL_REDUCE_RESERVED};
u32 root{0};
const char *group{nullptr};
};
struct HcomRemoteAccessAddrInfo {
u32 remotetRankID;
u64 remoteAddr;
u64 localAddr;
u64 length;
};
struct HcomRemoteOperationParams {
void *keyAddr{nullptr};
int *tableId{nullptr};
void *value{nullptr};
std::string group;
int count;
u64 keyNum{};
int valueDim;
HcclDataType keyType{HCCL_DATA_TYPE_RESERVED};
HcclDataType valueType{HCCL_DATA_TYPE_RESERVED};
int tag;
rtStream_t stream;
u64 flag;
s32 insertOption;
void *indices{};
void *numUniqued{};
void *psSeg{};
void *psSegNum{};
s64 *keyNumInput{};
s32 *uniqueIndices{};
s32 *keyCount{};
std::string hcclType;
s32 flags{};
void *globalStepAddr{ nullptr };
s32 intZerocpyFlag{};
s32 outZerocpyFlag{};
s32 maxEmbeddingDim{};
std::string uniqueTag{};
bool disableUnique{};
bool uniqued{};
};
struct HcomAllToAllVParams {
void *sendbuf{nullptr};
void *sendcounts{nullptr};
void *sdispls{nullptr};
HcclDataType sendtype{HCCL_DATA_TYPE_RESERVED};
void *recvbuf{nullptr};
void *recvcounts{nullptr};
void *rdispls{nullptr};
HcclDataType recvtype{HCCL_DATA_TYPE_RESERVED};
const char *group{nullptr};
};
struct HcomAllToAllVCParams {
void *sendbuf{nullptr};
HcclDataType sendtype{HCCL_DATA_TYPE_RESERVED};
void *recvbuf{nullptr};
HcclDataType recvtype{HCCL_DATA_TYPE_RESERVED};
void *sendcountmatrix{nullptr};
const char *group{nullptr};
};
struct HcomGatherAllToAllVParams {
void *addrInfo;
void *addrInfoCountPerRank;
void *recvbuf;
void *recvcounts;
void *rdispls;
void *gatheredbuf;
s32 addrLength;
HcclDataType recvtype;
const char *group;
};
typedef enum workMode {
HCCL_MODE_NORMAL = 0,
HCCL_MODE_ANY = 1,
HCCL_MODE_PS = 2,
HCCL_MODE_AI_CPU = 3,
HCCL_MODE_SCHED_OS = 4
} WorkMode;
typedef struct tagCommAttr {
WorkMode mode;
uint32_t deviceId = 0;
} CommAttr;
typedef void* HcclMessage;
typedef void* HcclRequest;
typedef void* ServiceHandle;
typedef struct {
int srcRank;
int tag;
int error;
int cancelled;
int count;
} HcclStatus;
using ReqStatus = struct tagReqStatus {
int tableId;
int tag;
int actualSize;
int rsvd0;
s64 globalStep;
};
using LookupReqStatus = struct tagLookupReqStatus {
int tableId;
int tag;
int actualCount;
int rsvd0;
int workerId;
};
using UpdateReqStatus = struct tagUpdateReqStatus {
int tableId;
int tag;
int actualKeyCount;
int actualValueCount;
s64 globalStep;
};
using CalcParams = struct tagCalcParams {
int uniqueCost0;
int gatherCost0;
int uniqueCost1;
int gatherCost1;
};
enum HcomSchedType {
HCOM_SCHED_TYPE_OS,
HCOM_SCHED_TYPE_NPU_TS_OFFLOAD,
HCOM_SCHED_TYPE_NPU_TS,
HCOM_SCHED_TYPE_NUM
};
enum HcomOperationType {
HCOM_OP_TYPE_SEND,
HCOM_OP_TYPE_RECV,
HCOM_OP_TYPE_BROADCAST,
HCOM_OP_TYPE_GATHER,
HCOM_OP_TYPE_NUM
};
#define HCOM_GROUP_NAME_MAX_LEN 127
typedef struct {
char group[HCOM_GROUP_NAME_MAX_LEN];
uint32_t tag;
uint32_t peerRank;
void* addr;
uint64_t count;
HcclDataType dataType;
int32_t rsv0;
int32_t rsv1;
int32_t rsv2;
} HcomP2pOpInfo;
typedef struct {
char group[HCOM_GROUP_NAME_MAX_LEN];
void* inputAddr;
void* outputAddr;
uint64_t count;
HcclDataType dataType;
uint32_t root;
HcclReduceOp reduceOp;
uint64_t strideCount;
} HcomCollOpInfo;
typedef struct {
HcomOperationType opType;
HcomSchedType schedType;
int32_t cxtId;
uint64_t flag;
union {
HcomP2pOpInfo p2p;
HcomCollOpInfo coll;
} info;
} HcomOpDesc;
typedef struct {
uint32_t status;
uint32_t rsv0;
uint32_t rsv1;
uint32_t rsv2;
} HcomStatus;
typedef struct {
uint32_t algSets;
uint32_t rankSize;
} HcclTopoDescs;
* @ingroup Hccl Address type
* @brief communication address type of HCCL
*/
enum HcclAddrType {
HCCL_ADDR_TYPE_ROCE = 0,
HCCL_ADDR_TYPE_NUM
};
* @ingroup HcclAddr
* @brief Hccl communication address
*/
typedef struct {
HcclAddrType type;
union {
struct {
uint32_t ipv4Addr;
uint16_t port;
} tcp;
uint8_t bytes[28];
} info;
} HcclAddr;
typedef void* HcomRequest;
* @brief handle to HCCL Connection
*/
typedef void* HcclConn;
#define HCCL_REQUEST_NULL nullptr
#define HCCL_TAG_ANY (1 << 30)
#ifdef __cplusplus
}
#endif
#endif