* 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_TESTER_H__
#define __HCCL_TESTER_H__
typedef enum tag_hccl_excute_type /* 动作类型枚举 */
{
EXCUTE_TYPE_BROADCAST = 0,
EXCUTE_TYPE_REDUCE = 1,
EXCUTE_TYPE_ALL_GATHER = 2,
EXCUTE_TYPE_REDUCE_SCATTER = 3,
EXCUTE_TYPE_ALL_REDUCE = 4,
EXCUTE_TYPE_SEND_RECEIVE = 5,
EXCUTE_TYPE_RESERVED ,
} hccl_excute_t;
typedef enum tag_hccl_sendbuf_init_type
{
HCCL_SENDBUF_INIT_TYPE_INC = 0,
HCCL_SENDBUF_INIT_TYPE_ALL0 = 1,
HCCL_SENDBUF_INIT_TYPE_ALL1 = 2,
HCCL_SENDBUF_INIT_TYPE_INC_S8 = 3,
HCCL_SENDBUF_INIT_TYPE_DEVID = 4,
HCCL_SENDBUF_INIT_TYPE_OFFSET = 5,
HCCL_SENDBUF_INIT_TYPE_RESERVED ,
} hccl_sendbuf_init_type_t;
typedef enum tag_comms_init_type
{
COMMS_INIT_TYPE_ALL = 0,
COMMS_INIT_TYPE_BY_RANK = 1,
COMMS_INIT_TYPE_RESERVED ,
} comms_init_type_t;
typedef enum tag_task_run_type
{
TASK_RUN_SERIAL = 0,
TASK_RUN_PARALLEL = 1,
TASK_RUN_RESERVED
} task_run_type_t;
#define PRINT_MASK_SEND 0x1
#define PRINT_MASK_RECV 0x10
#define PRINT_MASK_RSLT 0x100
#define INVALID_RANK -1
#define SEND_RECV_VALID 0xff
#define FLOAT_MAX_DIFF_RANGE 0.01f
typedef struct send_receive_struct /* send receive rank信息结构体 */
{
s32 src_valid;
s32 dest_valid;
s32 src_rank;
s32 dest_rank;
s32 tag;
} send_receive_t;
typedef struct excute_para_struct
{
void* sendbuff;
void* recvbuff;
s32 count;
HcclDataType datatype;
HcclComm comm;
rtStream_t stream;
s32 stream_id;
HcclReduceOp op;
s32 root;
hccl_excute_t op_type;
send_receive_t src_dest_info;
s32 dev_id;
s32 task_num;
} excute_para_t;
typedef struct test_task /* 测试任务结构体,每个对象是一个测试任务 */
{
hccl_excute_t excute_type;
std::vector<void*> dev_sendbuf;
std::vector<void*> dev_recvbuf;
std::vector<void*> host_sendbuf;
std::vector<void*> host_recvbuf;
void* result_buf;
std::vector<sal_thread_t> tids;
HcclDataType data_type;
HcclReduceOp reduce_op;
s32 count;
hccl_sendbuf_init_type_t init_type;
s32 buf_print_enable;
s32 root;
s32 send_rank;
s32 recv_rank;
s32 sendbuf_num;
s32 recvbuf_num;
s32 rsltbuf_num;
} test_task_t;
typedef struct bcast_excute_para
{
s32 root;
} bcast_excute_para_t;
typedef struct reduce_excute_para
{
s32 root;
HcclReduceOp reduce_op;
} reduce_excute_para_t;
typedef struct reduce_scatter_excute_para
{
HcclReduceOp reduce_op;
} reduce_scatter_excute_para_t;
typedef struct allreduce_excute_para
{
HcclReduceOp reduce_op;
} allreduce_excute_para_t;
typedef struct send_recv_excute_para
{
s32 send_rank;
s32 recv_rank;
} send_recv_excute_para_t;
typedef struct test_para /* 测试参数结构体 */
{
HcclDataType data_type;
s32 count;
union
{
bcast_excute_para bcast_para;
reduce_excute_para reduce_para;
reduce_scatter_excute_para rs_para;
allreduce_excute_para allre_para;
send_recv_excute_para p2p_para;
} excute_para;
hccl_sendbuf_init_type_t init_type;
s32 buf_print_enable;
} test_para_t;
typedef struct tester_rank_info /* rank相关信息结构体 */
{
s32 rank;
s32 devid;
HcclComm comm;
s32 nranks;
HcclRootInfo commId;
rtStream_t stream;
sal_thread_t tids;
} rank_info_t;
typedef struct comm_init_para_t
{
comms_init_type_t init_type;
union
{
struct all_rank
{
s32* device_list;
s32 ndev;
} all;
struct unique_rank /* init rank只需要单个rank的信息,对应COMMS_INIT_TYPE_BY_RANK */
{
s32 my_rank;
s32 dev_id;
s32 nranks;
HcclRootInfo* commId;
} unique;
} rank;
} comm_init_para;
typedef struct dev_info
{
s32 rank_id;
s32 dev_id;
} dev_info_t;
class tester
{
private:
std::vector<tester_rank_info> rank_list;
std::vector<test_task> task_vec;
s32 device_count;
comms_init_type_t comm_init_type;
task_run_type_t run_type;
public:
tester();
HcclResult init_comm(comm_init_para_t& init_para);
HcclResult add_test_task(hccl_excute_t excute_type, test_para* para);
HcclResult run(task_run_type_t run_type);
HcclResult check_result();
~tester();
protected:
HcclResult init_comm_all();
HcclResult init_comm_by_rank();
HcclResult excute_malloc_task_mem(test_task_t& task);
HcclResult excute_free_task_mem(test_task_t& task);
HcclResult check_task_para(hccl_excute_t excute_type, test_para* para);
HcclResult get_buff_count(hccl_excute_t type, s32 count,
s32* sendbuf_num, s32* recvbuf_num, s32* rsltbuf_num);
HcclResult get_len_by_datatype(HcclDataType datatype, s32* len);
HcclResult run_by_thread_fix();
HcclResult run_by_thread();
HcclResult run_by_process();
HcclResult wait_all_task_finish();
template <typename T>
HcclResult compute_result(test_task_t* task, T type_para);
template <typename T>
HcclResult print_buf_info(test_task_t* task, T type_para);
template <typename T>
HcclResult init_sendbuf_value(test_task_t* task, T cpu_type);
template <typename T>
HcclResult compare_result(test_task_t* task, T cpu_type);
template <typename T>
HcclResult check_single_task(test_task_t* task, T cpu_type);
template <typename T>
HcclResult malloc_two_dimension_memory(T**& out_mem, s32 first_dimen,
s32 second_dimen, T unit);
template <typename T>
HcclResult free_two_dimension_memory(T** out_mem, s32 first_dimen);
HcclResult dev_to_host_mem_synchronize();
HcclResult destroy_comms();
};
#endif