已合并
refactor: 数据面适配POD契约v2 #152
pandeng创建于 9月4日
refactor: 数据面适配POD契约v2 #152
已合并
共 43 个文件变更+6119-2
| @@ -19,6 +19,7 @@ set(CMAKE_CXX_STANDARD 17) | |||
| 19 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | 19 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 20 | 20 | ||
| 21 | option(ASCCOMM_BUILD_CCU "Build asc-comm CCU launch wrapper library" ON) | 21 | option(ASCCOMM_BUILD_CCU "Build asc-comm CCU launch wrapper library" ON) |
| 22 | +option(ASCCOMM_BUILD_AICPU "Build asc-comm AICPU data plane library" ON) | ||
| 22 | 23 | ||
| 23 | if(CUSTOM_ASCEND_CANN_PACKAGE_PATH) | 24 | if(CUSTOM_ASCEND_CANN_PACKAGE_PATH) |
| 24 | set(_ASCCOMM_CANN_PACKAGE_PATH "${CUSTOM_ASCEND_CANN_PACKAGE_PATH}") | 25 | set(_ASCCOMM_CANN_PACKAGE_PATH "${CUSTOM_ASCEND_CANN_PACKAGE_PATH}") |
| @@ -50,3 +51,6 @@ endif() | |||
| 50 | if(ASCCOMM_BUILD_CCU) | 51 | if(ASCCOMM_BUILD_CCU) |
| 51 | add_subdirectory(src/ccu) | 52 | add_subdirectory(src/ccu) |
| 52 | endif() | 53 | endif() |
| 54 | +if(ASCCOMM_BUILD_AICPU) | ||
| 55 | + add_subdirectory(src/aicpu) | ||
| 56 | +endif() | ||
| @@ -180,6 +180,19 @@ function run_ccu_ut() { | |||
| 180 | (cd "${ccu_ctest_dir}" && ctest --output-on-failure) | 180 | (cd "${ccu_ctest_dir}" && ctest --output-on-failure) |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | +function run_aicpu_ut() { | ||
| 184 | + local ut_build_dir="$1" | ||
| 185 | + local aicpu_ctest_dir="${ut_build_dir}/aicpu_asccomm" | ||
| 186 | + | ||
| 187 | + if [[ ! -f "${aicpu_ctest_dir}/CTestTestfile.cmake" ]]; then | ||
| 188 | + log "ERROR" "AICPU CTest registration not found: ${aicpu_ctest_dir}" | ||
| 189 | + return 1 | ||
| 190 | + fi | ||
| 191 | + | ||
| 192 | + log "INFO" "run AICPU UT through CTest" | ||
| 193 | + (cd "${aicpu_ctest_dir}" && ctest --output-on-failure) | ||
| 194 | +} | ||
| 195 | + | ||
| 183 | function collect_coverage() { | 196 | function collect_coverage() { |
| 184 | local ut_build_dir="$1" | 197 | local ut_build_dir="$1" |
| 185 | 198 | ||
| @@ -200,7 +213,7 @@ main(){ | |||
| 200 | 213 | ||
| 201 | if [[ "${TEST}" != true ]]; then | 214 | if [[ "${TEST}" != true ]]; then |
| 202 | if [[ "${PACKAGE}" != true ]]; then | 215 | if [[ "${PACKAGE}" != true ]]; then |
| 203 | - log "INFO" "use -t/--test to build hcomm UT" | 216 | + log "INFO" "use -t/--test to build UT" |
| 204 | fi | 217 | fi |
| 205 | exit 0 | 218 | exit 0 |
| 206 | fi | 219 | fi |
| @@ -218,6 +231,7 @@ main(){ | |||
| 218 | cmake_config "${UT_DIR}" "${ut_build_dir}" "${CUSTOM_OPTION[@]}" | 231 | cmake_config "${UT_DIR}" "${ut_build_dir}" "${CUSTOM_OPTION[@]}" |
| 219 | build "${ut_build_dir}" | 232 | build "${ut_build_dir}" |
| 220 | run_ccu_ut "${ut_build_dir}" | 233 | run_ccu_ut "${ut_build_dir}" |
| 234 | + run_aicpu_ut "${ut_build_dir}" | ||
| 221 | if [[ "${COV}" == true ]]; then | 235 | if [[ "${COV}" == true ]]; then |
| 222 | collect_coverage "${ut_build_dir}" | 236 | collect_coverage "${ut_build_dir}" |
| 223 | log "INFO" "coverage report generated at ${ut_build_dir}/cov_report/index.html" | 237 | log "INFO" "coverage report generated at ${ut_build_dir}/cov_report/index.html" |
| @@ -0,0 +1,72 @@ | |||
| 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 ASCCOMM_PRIMITIVES_H | ||
| 12 | +#define ASCCOMM_PRIMITIVES_H | ||
| 13 | + | ||
| 14 | +#include "asccomm_res_defs.h" | ||
| 15 | + | ||
| 16 | +#if defined(__GNUC__) | ||
| 17 | +#define ASCCOMM_API __attribute__((visibility("default"))) | ||
| 18 | +#else | ||
| 19 | +#define ASCCOMM_API | ||
| 20 | +#endif | ||
| 21 | + | ||
| 22 | +#ifdef __cplusplus | ||
| 23 | +extern "C" { | ||
| 24 | +#endif | ||
| 25 | + | ||
| 26 | +ASCCOMM_API int32_t asccomm_batch_mode_start(const char* batchTag); | ||
| 27 | +ASCCOMM_API int32_t asccomm_batch_mode_end(const char* batchTag); | ||
| 28 | + | ||
| 29 | +ASCCOMM_API int32_t asccomm_local_copy_on_thread(ThreadHandle thread, void* dst, const void* src, uint64_t len); | ||
| 30 | +ASCCOMM_API int32_t asccomm_local_reduce_on_thread( | ||
| 31 | + ThreadHandle thread, void* dst, const void* src, uint64_t count, AsccommDataType dataType, | ||
| 32 | + AsccommReduceOp reduceOp); | ||
| 33 | +ASCCOMM_API int32_t | ||
| 34 | +asccomm_thread_notify_record_on_thread(ThreadHandle thread, ThreadHandle dstThread, uint32_t dstNotifyIdx); | ||
| 35 | +ASCCOMM_API int32_t asccomm_thread_notify_wait_on_thread(ThreadHandle thread, uint32_t notifyIdx, uint32_t timeOut); | ||
| 36 | +ASCCOMM_API int32_t asccomm_aclrt_notify_record_on_thread(ThreadHandle thread, uint64_t dstNotifyId); | ||
| 37 | +ASCCOMM_API int32_t asccomm_aclrt_notify_wait_on_thread(ThreadHandle thread, uint64_t notifyId, uint32_t timeOut); | ||
| 38 | +ASCCOMM_API int32_t | ||
| 39 | +asccomm_write_on_thread(ThreadHandle thread, ChannelHandle channel, void* dst, const void* src, uint64_t len); | ||
| 40 | +ASCCOMM_API int32_t asccomm_write_reduce_on_thread( | ||
| 41 | + ThreadHandle thread, ChannelHandle channel, void* dst, const void* src, uint64_t count, AsccommDataType dataType, | ||
| 42 | + AsccommReduceOp reduceOp); | ||
| 43 | +ASCCOMM_API int32_t asccomm_write_with_notify_on_thread( | ||
| 44 | + ThreadHandle thread, ChannelHandle channel, void* dst, const void* src, uint64_t len, uint32_t remoteNotifyIdx); | ||
| 45 | +ASCCOMM_API int32_t asccomm_write_reduce_with_notify_on_thread( | ||
| 46 | + ThreadHandle thread, ChannelHandle channel, void* dst, const void* src, uint64_t count, AsccommDataType dataType, | ||
| 47 | + AsccommReduceOp reduceOp, uint32_t remoteNotifyIdx); | ||
| 48 | +ASCCOMM_API int32_t | ||
| 49 | +asccomm_read_on_thread(ThreadHandle thread, ChannelHandle channel, void* dst, const void* src, uint64_t len); | ||
| 50 | +ASCCOMM_API int32_t asccomm_read_reduce_on_thread( | ||
| 51 | + ThreadHandle thread, ChannelHandle channel, void* dst, const void* src, uint64_t count, AsccommDataType dataType, | ||
| 52 | + AsccommReduceOp reduceOp); | ||
| 53 | +ASCCOMM_API int32_t asccomm_batch_transfer_on_thread( | ||
| 54 | + ThreadHandle thread, ChannelHandle channel, const AsccommBatchTransferDesc* transferDescs, | ||
| 55 | + uint32_t transferDescNum); | ||
| 56 | +ASCCOMM_API int32_t | ||
| 57 | +asccomm_channel_notify_record_on_thread(ThreadHandle thread, ChannelHandle channel, uint32_t remoteNotifyIdx); | ||
| 58 | +ASCCOMM_API int32_t asccomm_channel_notify_wait_on_thread( | ||
| 59 | + ThreadHandle thread, ChannelHandle channel, uint32_t localNotifyIdx, uint32_t timeOut); | ||
| 60 | +ASCCOMM_API int32_t asccomm_channel_fence_on_thread(ThreadHandle thread, ChannelHandle channel); | ||
| 61 | +ASCCOMM_API int32_t asccomm_channel_notify_wait_on_thread_with_default_timeout( | ||
| 62 | + ThreadHandle thread, ChannelHandle channel, uint32_t localNotifyIdx); | ||
| 63 | +ASCCOMM_API int32_t asccomm_thread_notify_wait_on_thread_with_default_timeout(ThreadHandle thread, uint32_t notifyIdx); | ||
| 64 | +ASCCOMM_API int32_t asccomm_set_notify_wait_timeout(float timeOut); | ||
| 65 | +ASCCOMM_API int32_t asccomm_thread_res_acquire_timeout(float timeOut); | ||
| 66 | +ASCCOMM_API int32_t asccomm_channel_drain_on_thread(ThreadHandle thread, ChannelHandle channel); | ||
| 67 | + | ||
| 68 | +#ifdef __cplusplus | ||
| 69 | +} | ||
| 70 | +#endif | ||
| 71 | + | ||
| 72 | +#endif // ASCCOMM_PRIMITIVES_H | ||
| @@ -0,0 +1,122 @@ | |||
| 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 ASCCOMM_RES_DEFS_H | ||
| 12 | +#define ASCCOMM_RES_DEFS_H | ||
| 13 | + | ||
| 14 | +#include <stdint.h> | ||
| 15 | + | ||
| 16 | +#include "hcomm_res_defs.h" | ||
| 17 | +#include "hcomm_res_entity_defs.h" | ||
| 18 | + | ||
| 19 | +// ASCCOMM AICPU公共类型定义;基础ABI类型由CANN包pkg_inc/hcomm/hcomm_res_defs.h提供。 | ||
| 20 | +#ifdef __cplusplus | ||
| 21 | +extern "C" { | ||
| 22 | +#endif | ||
| 23 | + | ||
| 24 | +#ifndef ASCCOMM_REDUCE_OP_DEFINED | ||
| 25 | +#define ASCCOMM_REDUCE_OP_DEFINED | ||
| 26 | +typedef enum { | ||
| 27 | + ASCCOMM_REDUCE_SUM = 0, | ||
| 28 | + ASCCOMM_REDUCE_PROD = 1, | ||
| 29 | + ASCCOMM_REDUCE_MAX = 2, | ||
| 30 | + ASCCOMM_REDUCE_MIN = 3, | ||
| 31 | + ASCCOMM_REDUCE_RESERVED = 255 | ||
| 32 | +} AsccommReduceOp; | ||
| 33 | +#endif | ||
| 34 | + | ||
| 35 | +#ifndef ASCCOMM_DATA_TYPE_DEFINED | ||
| 36 | +#define ASCCOMM_DATA_TYPE_DEFINED | ||
| 37 | +typedef enum { | ||
| 38 | + ASCCOMM_DATA_TYPE_INT8 = 0, | ||
| 39 | + ASCCOMM_DATA_TYPE_INT16 = 1, | ||
| 40 | + ASCCOMM_DATA_TYPE_INT32 = 2, | ||
| 41 | + ASCCOMM_DATA_TYPE_FP16 = 3, | ||
| 42 | + ASCCOMM_DATA_TYPE_FP32 = 4, | ||
| 43 | + ASCCOMM_DATA_TYPE_INT64 = 5, | ||
| 44 | + ASCCOMM_DATA_TYPE_UINT64 = 6, | ||
| 45 | + ASCCOMM_DATA_TYPE_UINT8 = 7, | ||
| 46 | + ASCCOMM_DATA_TYPE_UINT16 = 8, | ||
| 47 | + ASCCOMM_DATA_TYPE_UINT32 = 9, | ||
| 48 | + ASCCOMM_DATA_TYPE_FP64 = 10, | ||
| 49 | + ASCCOMM_DATA_TYPE_BFP16 = 11, | ||
| 50 | + ASCCOMM_DATA_TYPE_INT128 = 12, | ||
| 51 | + ASCCOMM_DATA_TYPE_HIF8 = 14, | ||
| 52 | + ASCCOMM_DATA_TYPE_FP8E4M3 = 15, | ||
| 53 | + ASCCOMM_DATA_TYPE_FP8E5M2 = 16, | ||
| 54 | + ASCCOMM_DATA_TYPE_FP8E8M0 = 17, | ||
| 55 | + ASCCOMM_DATA_TYPE_RESERVED = 255 | ||
| 56 | +} AsccommDataType; | ||
| 57 | +#endif | ||
| 58 | + | ||
| 59 | +#ifndef ASCCOMM_TRANSFER_TYPE_DEFINED | ||
| 60 | +#define ASCCOMM_TRANSFER_TYPE_DEFINED | ||
| 61 | +typedef enum { | ||
| 62 | + ASCCOMM_TRANSFER_TYPE_INVALID = -1, | ||
| 63 | + ASCCOMM_TRANSFER_TYPE_WRITE = 0, | ||
| 64 | + ASCCOMM_TRANSFER_TYPE_WRITE_REDUCE = 1, | ||
| 65 | + ASCCOMM_TRANSFER_TYPE_WRITE_WITH_NOTIFY = 2, | ||
| 66 | + ASCCOMM_TRANSFER_TYPE_WRITE_REDUCE_WITH_NOTIFY = 3, | ||
| 67 | + ASCCOMM_TRANSFER_TYPE_READ = 4, | ||
| 68 | + ASCCOMM_TRANSFER_TYPE_READ_REDUCE = 5, | ||
| 69 | + ASCCOMM_TRANSFER_TYPE_NOTIFY_RECORD = 6, | ||
| 70 | +} AsccommTransferType; | ||
| 71 | +#endif | ||
| 72 | + | ||
| 73 | +#ifndef ASCCOMM_BATCH_TRANSFER_DESC_DEFINED | ||
| 74 | +#define ASCCOMM_BATCH_TRANSFER_DESC_DEFINED | ||
| 75 | +typedef struct { | ||
| 76 | + AsccommTransferType transType; | ||
| 77 | + uint8_t reserved[4]; | ||
| 78 | + union { | ||
| 79 | + uint8_t raws[56]; | ||
| 80 | + struct { | ||
| 81 | + uint64_t len; | ||
| 82 | + void* dst; | ||
| 83 | + void* src; | ||
| 84 | + } write; | ||
| 85 | + struct { | ||
| 86 | + uint64_t len; | ||
| 87 | + void* dst; | ||
| 88 | + void* src; | ||
| 89 | + } read; | ||
| 90 | + struct { | ||
| 91 | + uint64_t count; | ||
| 92 | + void* dst; | ||
| 93 | + void* src; | ||
| 94 | + AsccommReduceOp reduceOp; | ||
| 95 | + AsccommDataType dataType; | ||
| 96 | + } reduce; | ||
| 97 | + struct { | ||
| 98 | + uint32_t notifyIdx; | ||
| 99 | + } notifyRecord; | ||
| 100 | + struct { | ||
| 101 | + uint64_t len; | ||
| 102 | + void* dst; | ||
| 103 | + void* src; | ||
| 104 | + uint32_t notifyIdx; | ||
| 105 | + } writeWithNotify; | ||
| 106 | + struct { | ||
| 107 | + uint64_t count; | ||
| 108 | + void* dst; | ||
| 109 | + void* src; | ||
| 110 | + AsccommReduceOp reduceOp; | ||
| 111 | + AsccommDataType dataType; | ||
| 112 | + uint32_t notifyIdx; | ||
| 113 | + } writeReduceWithNotify; | ||
| 114 | + } transferInfo; | ||
| 115 | +} AsccommBatchTransferDesc; | ||
| 116 | +#endif | ||
| 117 | + | ||
| 118 | +#ifdef __cplusplus | ||
| 119 | +} | ||
| 120 | +#endif | ||
| 121 | + | ||
| 122 | +#endif // ASCCOMM_RES_DEFS_H | ||
| @@ -0,0 +1,436 @@ | |||
| 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_RES_ENTITY_DEFS_H | ||
| 12 | +#define HCOMM_RES_ENTITY_DEFS_H | ||
| 13 | + | ||
| 14 | +#include <stdint.h> | ||
| 15 | +#include <stddef.h> | ||
| 16 | +#include "hcomm_res_defs.h" | ||
| 17 | + | ||
| 18 | +#ifdef __cplusplus | ||
| 19 | +extern "C" { | ||
| 20 | +#endif | ||
| 21 | + | ||
| 22 | +typedef uint64_t ChannelPtr; | ||
| 23 | + | ||
| 24 | +typedef enum { | ||
| 25 | + PROTECTION_TYPE_INVALID = -1, | ||
| 26 | + PROTECTION_TYPE_ROCE = 0, | ||
| 27 | + PROTECTION_TYPE_UB = 1, | ||
| 28 | +} ProtectionType; | ||
| 29 | + | ||
| 30 | +typedef enum { | ||
| 31 | + SQ_CONTEXT_TYPE_INVALID = -1, | ||
| 32 | + SQ_CONTEXT_TYPE_UB_JFS = 0, | ||
| 33 | + SQ_CONTEXT_TYPE_ROCE = 1, | ||
| 34 | +} SqContextType; | ||
| 35 | + | ||
| 36 | +typedef enum { | ||
| 37 | + CQ_CONTEXT_TYPE_INVALID = -1, | ||
| 38 | + CQ_CONTEXT_TYPE_UB_JFC = 0, | ||
| 39 | + CQ_CONTEXT_TYPE_ROCE = 1, | ||
| 40 | +} CqContextType; | ||
| 41 | + | ||
| 42 | +typedef enum { | ||
| 43 | + REGED_NOTIFY_INVALID = -1, | ||
| 44 | + REGED_NOTIFY_IPC_RT = 0, | ||
| 45 | + REGED_NOTIFY_IPC_MEM = 1, | ||
| 46 | + REGED_NOTIFY_RMA_RT = 2, | ||
| 47 | + REGED_NOTIFY_RMA_MEM = 3, | ||
| 48 | +} RegedNotifyType; | ||
| 49 | + | ||
| 50 | +typedef enum { | ||
| 51 | + REGED_BUFFER_INVALID = -1, | ||
| 52 | + REGED_BUFFER_IPC = 0, | ||
| 53 | + REGED_BUFFER_RMA = 1, | ||
| 54 | +} RegedBufferType; | ||
| 55 | + | ||
| 56 | +typedef struct { | ||
| 57 | + ProtectionType type; | ||
| 58 | + union { | ||
| 59 | + struct { | ||
| 60 | + uint32_t lkey; | ||
| 61 | + uint32_t rkey; | ||
| 62 | + } roce; | ||
| 63 | + struct { | ||
| 64 | + uint32_t tokenId; | ||
| 65 | + uint32_t tokenValue; | ||
| 66 | + } ub; | ||
| 67 | + uint8_t raws[24]; | ||
| 68 | + } memInfo; | ||
| 69 | +} ProtectionInfo; // 32B | ||
| 70 | + | ||
| 71 | +typedef struct { | ||
| 72 | + RegedBufferType type; | ||
| 73 | + union { | ||
| 74 | + struct { | ||
| 75 | + uint64_t addr; | ||
| 76 | + uint64_t size; | ||
| 77 | + } ipc; | ||
| 78 | + struct { | ||
| 79 | + uint64_t addr; | ||
| 80 | + uint64_t size; | ||
| 81 | + ProtectionInfo protectionInfo; | ||
| 82 | + } rma; | ||
| 83 | + uint8_t raws[56]; | ||
| 84 | + } bufferInfo; | ||
| 85 | +} RegedBufferEntity; // 64B | ||
| 86 | + | ||
| 87 | +typedef struct { | ||
| 88 | + RegedNotifyType type; | ||
| 89 | + union { | ||
| 90 | + struct { | ||
| 91 | + uint64_t addr; | ||
| 92 | + uint32_t size; | ||
| 93 | + int32_t notifyId; | ||
| 94 | + } ipcRt; | ||
| 95 | + struct { | ||
| 96 | + uint64_t addr; | ||
| 97 | + uint32_t size; | ||
| 98 | + } ipcMem; | ||
| 99 | + struct { | ||
| 100 | + uint64_t addr; | ||
| 101 | + uint32_t size; | ||
| 102 | + int32_t notifyId; | ||
| 103 | + ProtectionInfo protectionInfo; | ||
| 104 | + } rmaRt; | ||
| 105 | + struct { | ||
| 106 | + uint64_t addr; | ||
| 107 | + uint32_t size; | ||
| 108 | + ProtectionInfo protectionInfo; | ||
| 109 | + } rmaMem; | ||
| 110 | + uint8_t raws[56]; | ||
| 111 | + } notifyInfo; | ||
| 112 | +} RegedNotifyEntity; // 64B | ||
| 113 | + | ||
| 114 | +typedef struct { | ||
| 115 | + SqContextType type; | ||
| 116 | + union { | ||
| 117 | + struct { | ||
| 118 | + uint64_t sqVa; | ||
| 119 | + uint64_t headAddr; | ||
| 120 | + uint64_t tailAddr; | ||
| 121 | + uint64_t dbVa; | ||
| 122 | + uint32_t jfsID; | ||
| 123 | + uint32_t wqeSize; | ||
| 124 | + uint32_t sqDepth; | ||
| 125 | + uint32_t tpID; | ||
| 126 | + uint8_t remoteEID[16]; | ||
| 127 | + } ubJfs; | ||
| 128 | + struct { | ||
| 129 | + uint64_t sqVa; | ||
| 130 | + uint64_t headAddr; | ||
| 131 | + uint64_t tailAddr; | ||
| 132 | + uint64_t dbHwVa; | ||
| 133 | + uint64_t dbSwVa; | ||
| 134 | + uint32_t qpn; | ||
| 135 | + uint32_t wqeSize; | ||
| 136 | + uint32_t depth; | ||
| 137 | + uint8_t sl; | ||
| 138 | + uint64_t dbVendorSpecified; | ||
| 139 | + } roceSq; | ||
| 140 | + uint8_t raws[120]; | ||
| 141 | + } contextInfo; | ||
| 142 | +} SqContext; | ||
| 143 | + | ||
| 144 | +typedef struct { | ||
| 145 | + CqContextType type; | ||
| 146 | + union { | ||
| 147 | + struct { | ||
| 148 | + uint64_t scqVa; | ||
| 149 | + uint64_t headAddr; | ||
| 150 | + uint64_t tailAddr; | ||
| 151 | + uint64_t dbVa; | ||
| 152 | + uint32_t jfcID; | ||
| 153 | + uint32_t cqeSize; | ||
| 154 | + uint32_t cqDepth; | ||
| 155 | + } ubJfc; | ||
| 156 | + struct { | ||
| 157 | + uint64_t cqVa; | ||
| 158 | + uint64_t headAddr; | ||
| 159 | + uint64_t tailAddr; | ||
| 160 | + uint64_t dbHwVa; | ||
| 161 | + uint64_t dbSwVa; | ||
| 162 | + uint32_t cqn; | ||
| 163 | + uint32_t cqeSize; | ||
| 164 | + uint32_t cqDepth; | ||
| 165 | + uint64_t dbVendorSpecified; | ||
| 166 | + } roceCq; | ||
| 167 | + uint8_t raws[120]; | ||
| 168 | + } contextInfo; | ||
| 169 | +} CqContext; | ||
| 170 | + | ||
| 171 | +#define HCOMM_RESOURCE_CHANNEL_VERSION 0U ///< Channel resource ABI版本号 | ||
| 172 | +#define HCOMM_RESOURCE_CHANNEL_MAGIC_WORD 0x0fcf0f5fU ///< Channel 资源合法性校验魔术字 | ||
| 173 | +#define HCOMM_RESOURCE_THREAD_VERSION 0U ///< Thread resource ABI版本号 | ||
| 174 | +#define HCOMM_RESOURCE_THREAD_MAGIC_WORD 0x0fcf0f6fU ///< Thread 资源合法性校验魔术字 | ||
| 175 | +#define HCOMM_RESOURCE_RTSQ_SQE_SIZE 64U ///< 单个RTSQ SQE占用字节数 | ||
| 176 | +#define HCOMM_RESOURCE_RTSQ_BATCH_SIZE 128U ///< 本地最多缓存的RTSQ SQE数量 | ||
| 177 | +#define HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE 1024U ///< 单次申请的RTSQ Task ID数量 | ||
| 178 | +#define HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE 256U ///< Channel resource ABI固定大小 | ||
| 179 | +#define HCOMM_RESOURCE_THREAD_ENTITY_SIZE 256U ///< Thread resource ABI固定大小 | ||
| 180 | + | ||
| 181 | +#pragma pack(push, 4) | ||
| 182 | + | ||
| 183 | +typedef enum { | ||
| 184 | + HCOMM_PROTECTION_TYPE_INVALID = -1, | ||
| 185 | + HCOMM_PROTECTION_TYPE_ROCE = 0, | ||
| 186 | + HCOMM_PROTECTION_TYPE_RDMA = HCOMM_PROTECTION_TYPE_ROCE, | ||
| 187 | + HCOMM_PROTECTION_TYPE_UB = 1, | ||
| 188 | + HCOMM_PROTECTION_TYPE_URMA = HCOMM_PROTECTION_TYPE_UB, | ||
| 189 | +} HcommProtectionType; | ||
| 190 | + | ||
| 191 | +typedef enum { | ||
| 192 | + HCOMM_SQ_CONTEXT_TYPE_INVALID = -1, | ||
| 193 | + HCOMM_SQ_CONTEXT_TYPE_UB_JFS = 0, | ||
| 194 | + HCOMM_SQ_CONTEXT_TYPE_ROCE = 1, | ||
| 195 | +} HcommSqContextType; | ||
| 196 | + | ||
| 197 | +typedef enum { | ||
| 198 | + HCOMM_CQ_CONTEXT_TYPE_INVALID = -1, | ||
| 199 | + HCOMM_CQ_CONTEXT_TYPE_UB_JFC = 0, | ||
| 200 | + HCOMM_CQ_CONTEXT_TYPE_ROCE = 1, | ||
| 201 | +} HcommCqContextType; | ||
| 202 | + | ||
| 203 | +typedef enum { | ||
| 204 | + HCOMM_REGED_NOTIFY_INVALID = -1, | ||
| 205 | + HCOMM_REGED_NOTIFY_IPC_RT = 0, | ||
| 206 | + HCOMM_REGED_NOTIFY_IPC_MEM = 1, | ||
| 207 | + HCOMM_REGED_NOTIFY_RMA_RT = 2, | ||
| 208 | + HCOMM_REGED_NOTIFY_RMA_MEM = 3, | ||
| 209 | +} HcommRegedNotifyType; | ||
| 210 | + | ||
| 211 | +typedef enum { | ||
| 212 | + HCOMM_REGED_BUFFER_INVALID = -1, | ||
| 213 | + HCOMM_REGED_BUFFER_IPC = 0, | ||
| 214 | + HCOMM_REGED_BUFFER_RMA = 1, | ||
| 215 | +} HcommRegedBufferType; | ||
| 216 | + | ||
| 217 | +typedef enum { | ||
| 218 | + HCOMM_NOTIFY_TYPE_HCCS = 0, | ||
| 219 | + HCOMM_NOTIFY_TYPE_RMA = 1, | ||
| 220 | + HCOMM_NOTIFY_TYPE_LOCAL = 2, | ||
| 221 | +} HcommNotifyType; | ||
| 222 | + | ||
| 223 | +typedef struct { | ||
| 224 | + HcommProtectionType type; | ||
| 225 | + union { | ||
| 226 | + struct { | ||
| 227 | + uint32_t lkey; | ||
| 228 | + uint32_t rkey; | ||
| 229 | + } roce; | ||
| 230 | + struct { | ||
| 231 | + uint32_t tokenId; | ||
| 232 | + uint32_t tokenValue; | ||
| 233 | + } ub; | ||
| 234 | + uint8_t raws[24]; | ||
| 235 | + } memInfo; | ||
| 236 | +} HcommProtectionInfo; | ||
| 237 | + | ||
| 238 | +typedef struct { | ||
| 239 | + HcommRegedBufferType type; | ||
| 240 | + union { | ||
| 241 | + struct { | ||
| 242 | + uint64_t addr; | ||
| 243 | + uint64_t size; | ||
| 244 | + } ipc; | ||
| 245 | + struct { | ||
| 246 | + uint64_t addr; | ||
| 247 | + uint64_t size; | ||
| 248 | + HcommProtectionInfo protectionInfo; | ||
| 249 | + } rma; | ||
| 250 | + uint8_t raws[56]; | ||
| 251 | + } bufferInfo; | ||
| 252 | +} HcommRegedBufferEntity; | ||
| 253 | + | ||
| 254 | +typedef struct { | ||
| 255 | + HcommRegedNotifyType type; | ||
| 256 | + union { | ||
| 257 | + struct { | ||
| 258 | + uint64_t addr; | ||
| 259 | + uint32_t size; | ||
| 260 | + int32_t notifyId; | ||
| 261 | + } ipcRt; | ||
| 262 | + struct { | ||
| 263 | + uint64_t addr; | ||
| 264 | + uint32_t size; | ||
| 265 | + } ipcMem; | ||
| 266 | + struct { | ||
| 267 | + uint64_t addr; | ||
| 268 | + uint32_t size; | ||
| 269 | + int32_t notifyId; | ||
| 270 | + HcommProtectionInfo protectionInfo; | ||
| 271 | + } rmaRt; | ||
| 272 | + struct { | ||
| 273 | + uint64_t addr; | ||
| 274 | + uint32_t size; | ||
| 275 | + HcommProtectionInfo protectionInfo; | ||
| 276 | + } rmaMem; | ||
| 277 | + uint8_t raws[56]; | ||
| 278 | + } notifyInfo; | ||
| 279 | +} HcommRegedNotifyEntity; | ||
| 280 | + | ||
| 281 | +typedef struct { | ||
| 282 | + HcommSqContextType type; ///< SQ上下文类型 | ||
| 283 | + uint8_t fence; ///< 一次性Fence标志,由下一次相关传输消费并清零(独立字段,不与union重叠) | ||
| 284 | + uint8_t reserved[3]; ///< 对齐保留 | ||
| 285 | + union { | ||
| 286 | + struct { | ||
| 287 | + uint64_t sqVa; ///< UB SQ的CPU虚拟地址(WQE写入位置) | ||
| 288 | + uint64_t headAddr; ///< SQ硬件Head地址(预留) | ||
| 289 | + uint64_t tailAddr; ///< SQ CI地址(软件轮询预留,当前恒0) | ||
| 290 | + uint64_t dbVa; ///< Doorbell寄存器地址(预留,doorbell走RTSQ UBDMA SQE) | ||
| 291 | + uint32_t jfsID; ///< Jetty ID | ||
| 292 | + uint32_t wqeSize; ///< 单个WQE字节数(64) | ||
| 293 | + uint32_t sqDepth; ///< WQEBB深度(控制面已乘4,数据面直用) | ||
| 294 | + uint32_t tpID; ///< TP号 | ||
| 295 | + uint8_t remoteEID[16]; ///< 远端EID【硬件逆序形态】;控制面已Reversed(),数据面直取填入WQE.rmtEid | ||
| 296 | + uint32_t sqHead; ///< 软件维护的SQ生产者索引(pi,数据面持续自增) | ||
| 297 | + uint32_t sqTail; ///< 已完成WQE计数(ci,数据面维护;当前无消费方可恒0) | ||
| 298 | + uint32_t maxReadSize; ///< 单个UB Read WQE允许的最大传输字节数 | ||
| 299 | + uint32_t maxWriteSize; ///< 单个UB Write WQE允许的最大传输字节数 | ||
| 300 | + } ubJfs; | ||
| 301 | + struct { | ||
| 302 | + uint64_t sqVa; | ||
| 303 | + uint64_t headAddr; | ||
| 304 | + uint64_t tailAddr; | ||
| 305 | + uint64_t dbHwVa; | ||
| 306 | + uint64_t dbSwVa; | ||
| 307 | + uint32_t qpn; | ||
| 308 | + uint32_t wqeSize; | ||
| 309 | + uint32_t depth; | ||
| 310 | + uint8_t sl; | ||
| 311 | + uint64_t dbVendorSpecified; ///< RoCE厂商Doorbell字段,包含mtuShift和dbCos | ||
| 312 | + uint32_t sqHead; ///< 软件维护的SQ生产者索引 | ||
| 313 | + uint32_t sqTail; ///< 已完成WQE计数 | ||
| 314 | + } roceSq; | ||
| 315 | + uint8_t raws[120]; | ||
| 316 | + } contextInfo; | ||
| 317 | +} HcommSqContext; | ||
| 318 | + | ||
| 319 | +typedef struct { | ||
| 320 | + HcommCqContextType type; ///< CQ上下文类型 | ||
| 321 | + union { | ||
| 322 | + struct { | ||
| 323 | + uint64_t scqVa; | ||
| 324 | + uint64_t headAddr; | ||
| 325 | + uint64_t tailAddr; | ||
| 326 | + uint64_t dbVa; | ||
| 327 | + uint32_t jfcID; | ||
| 328 | + uint32_t cqeSize; | ||
| 329 | + uint32_t cqDepth; | ||
| 330 | + } ubJfc; | ||
| 331 | + struct { | ||
| 332 | + uint64_t cqVa; | ||
| 333 | + uint64_t headAddr; | ||
| 334 | + uint64_t tailAddr; | ||
| 335 | + uint64_t dbHwVa; | ||
| 336 | + uint64_t dbSwVa; | ||
| 337 | + uint32_t cqn; | ||
| 338 | + uint32_t cqeSize; | ||
| 339 | + uint32_t cqDepth; | ||
| 340 | + uint32_t cqHead; ///< 软件轮询的下一个CQE索引 | ||
| 341 | + uint32_t cqTail; ///< 已消费CQE计数 | ||
| 342 | + uint8_t cqDbFlush; ///< 是否需要刷新CQ软件Doorbell | ||
| 343 | + } roceCq; | ||
| 344 | + uint8_t raws[124]; | ||
| 345 | + } contextInfo; | ||
| 346 | +} HcommCqContext; | ||
| 347 | + | ||
| 348 | +typedef struct { | ||
| 349 | + uint32_t version; ///< 设备信息结构版本号 | ||
| 350 | + uint32_t devId; ///< 设备物理或逻辑ID,由资源创建端约定 | ||
| 351 | + uint8_t dieId; ///< 设备Die编号(UB doorbell jetty三元素之一) | ||
| 352 | + uint8_t funcId; ///< 设备Function编号(UB doorbell jetty三元素之一) | ||
| 353 | + uint8_t reserve[30]; ///< 设备信息扩展空间,创建资源时置0 | ||
| 354 | +} HcommDevInfo; | ||
| 355 | + | ||
| 356 | +typedef struct { | ||
| 357 | + CommAbiHeader abiHeader; | ||
| 358 | + CommEngine engine; | ||
| 359 | + CommProtocol protocol; | ||
| 360 | + HcommDevInfo devInfo; ///< Channel本地通信资源所属设备信息(dieId/funcId为doorbell唯一来源) | ||
| 361 | + uint32_t localNotifyNum; | ||
| 362 | + uint32_t remoteNotifyNum; | ||
| 363 | + uint32_t localBufferNum; | ||
| 364 | + uint32_t remoteBufferNum; | ||
| 365 | + uint32_t sqNum; | ||
| 366 | + uint32_t cqNum; | ||
| 367 | + HcommRegedNotifyEntity* localNotifyAddr; | ||
| 368 | + HcommRegedNotifyEntity* remoteNotifyAddr; | ||
| 369 | + HcommRegedBufferEntity* localBufferAddr; | ||
| 370 | + HcommRegedBufferEntity* remoteBufferAddr; | ||
| 371 | + HcommSqContext* sqContextAddr; | ||
| 372 | + HcommCqContext* cqContextAddr; | ||
| 373 | + ChannelHandle originChannelHandle; ///< 控制面原始Channel句柄值;数据面只作关联信息,不解引用 | ||
| 374 | +} ChannelEntity; | ||
| 375 | + | ||
| 376 | +// RTSQ硬件字段由HCOMM控制面在资源构造阶段查询并填充;数据面只消费初始快照, | ||
| 377 | +// 并在提交过程中维护运行态head/tail。 | ||
| 378 | +typedef struct { | ||
| 379 | + uint32_t localDevId; ///< 调用halSqCqQuery/halSqCqConfig使用的本地设备ID(控制面填充) | ||
| 380 | + uint32_t streamId; ///< RTSQ关联的Stream ID,写入部分SQE或用于诊断 | ||
| 381 | + uint32_t sqId; ///< 硬件RTSQ编号 | ||
| 382 | + uint32_t sqDepth; ///< 硬件RTSQ可容纳的SQE数量 | ||
| 383 | + uint32_t sqHead; ///< 最近一次查询到的硬件RTSQ Head | ||
| 384 | + uint32_t sqTail; ///< 资源运行时维护的硬件RTSQ Tail | ||
| 385 | + uint64_t sqBaseAddr; ///< 硬件RTSQ SQE环形缓冲区的CPU虚拟地址 | ||
| 386 | + uint64_t localSqeAddr; ///< 控制面申请、数据面维护的本地SQE缓存地址 | ||
| 387 | + uint32_t taskId; ///< 数据面下一次使用的Task ID,控制面创建资源时置0 | ||
| 388 | + uint32_t taskIdEnd; ///< 当前已申请Task ID区间的开区间上界,控制面创建资源时置0 | ||
| 389 | + uint32_t pendingSqeCnt; ///< 本地缓存中尚未提交的SQE数量 | ||
| 390 | + uint8_t launchFlag; ///< 非0时在非Batch模式下每生成一个SQE立即提交 | ||
| 391 | + uint8_t reserved[3]; ///< RTSQ状态扩展及对齐空间,创建资源时置0 | ||
| 392 | +} HcommRtsqContext; | ||
| 393 | + | ||
| 394 | +typedef struct { | ||
| 395 | + CommAbiHeader abiHeader; ///< ABI版本、魔术字和结构大小,用于句柄合法性校验 | ||
| 396 | + HcommDevInfo devInfo; ///< Thread所属设备信息 | ||
| 397 | + uint32_t localNotifyNum; ///< localNotifyAddr数组元素个数 | ||
| 398 | + HcommRegedNotifyEntity* localNotifyAddr; ///< Thread本地Notify数组,用于线程间Record/Wait(type=IPC_RT) | ||
| 399 | + HcommRtsqContext* sqContextAddr; ///< Thread直接持有的resource RTSQ运行上下文 | ||
| 400 | + ThreadHandle originThreadHandle; ///< 控制面原始Thread句柄值;数据面只作关联信息,不解引用 | ||
| 401 | + uint8_t raw[172]; ///< Thread固定256字节中的ABI预留扩展空间 | ||
| 402 | + | ||
| 403 | +} ThreadEntity; | ||
| 404 | + | ||
| 405 | +#pragma pack(pop) | ||
| 406 | + | ||
| 407 | +#ifdef __cplusplus | ||
| 408 | +} | ||
| 409 | +#endif | ||
| 410 | + | ||
| 411 | +#ifdef __cplusplus | ||
| 412 | +#include <type_traits> | ||
| 413 | +using HcommRdmaMemProtectionInfo = decltype(((HcommProtectionInfo*)nullptr)->memInfo.roce); | ||
| 414 | +using HcommUrmaMemProtectionInfo = decltype(((HcommProtectionInfo*)nullptr)->memInfo.ub); | ||
| 415 | +using HcommJfsContext = decltype(((HcommSqContext*)nullptr)->contextInfo.ubJfs); | ||
| 416 | +using HcommRdmaSqContext = decltype(((HcommSqContext*)nullptr)->contextInfo.roceSq); | ||
| 417 | +using HcommRdmaCqContext = decltype(((HcommCqContext*)nullptr)->contextInfo.roceCq); | ||
| 418 | +static_assert(std::is_pod<HcommProtectionInfo>::value, "HcommProtectionInfo must be POD"); | ||
| 419 | +static_assert(std::is_pod<HcommRegedBufferEntity>::value, "HcommRegedBufferEntity must be POD"); | ||
| 420 | +static_assert(std::is_pod<HcommRegedNotifyEntity>::value, "HcommRegedNotifyEntity must be POD"); | ||
| 421 | +static_assert(std::is_pod<HcommSqContext>::value, "HcommSqContext must be POD"); | ||
| 422 | +static_assert(std::is_pod<HcommCqContext>::value, "HcommCqContext must be POD"); | ||
| 423 | +static_assert( | ||
| 424 | + sizeof(ChannelEntity) <= HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE, "ChannelEntity ABI size must not exceed 256 bytes"); | ||
| 425 | +static_assert(sizeof(ThreadEntity) == HCOMM_RESOURCE_THREAD_ENTITY_SIZE, "ThreadEntity ABI size must be 256 bytes"); | ||
| 426 | +static_assert(alignof(ChannelEntity) == 4, "ChannelEntity ABI alignment must be 4 bytes"); | ||
| 427 | +static_assert(alignof(ThreadEntity) == 4, "ThreadEntity ABI alignment must be 4 bytes"); | ||
| 428 | +static_assert( | ||
| 429 | + offsetof(ThreadEntity, originThreadHandle) + sizeof(ThreadHandle) <= HCOMM_RESOURCE_THREAD_ENTITY_SIZE, | ||
| 430 | + "ThreadEntity origin handle must fit in the fixed ABI storage"); | ||
| 431 | +static_assert( | ||
| 432 | + offsetof(ChannelEntity, originChannelHandle) + sizeof(ChannelHandle) <= HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE, | ||
| 433 | + "ChannelEntity origin handle must fit in the fixed ABI storage"); | ||
| 434 | +#endif | ||
| 435 | + | ||
| 436 | +#endif // HCOMM_RES_ENTITY_DEFS_H | ||
| @@ -0,0 +1,157 @@ | |||
| 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 | +set(ASCCOMM_AICPU_ROOT ${CMAKE_CURRENT_LIST_DIR}) | ||
| 12 | +get_filename_component(ASCCOMM_ROOT ${ASCCOMM_AICPU_ROOT}/../.. ABSOLUTE) | ||
| 13 | +set(ASCCOMM_DFX_SRC_DIR "${ASCCOMM_ROOT}/src/common/dfx/logging") | ||
| 14 | + | ||
| 15 | +if(NOT ASCEND_CANN_PACKAGE_PATH) | ||
| 16 | + if(DEFINED ENV{ASCEND_HOME_PATH}) | ||
| 17 | + set(ASCEND_CANN_PACKAGE_PATH "$ENV{ASCEND_HOME_PATH}") | ||
| 18 | + elseif(DEFINED ENV{ASCEND_CANN_PACKAGE_PATH}) | ||
| 19 | + set(ASCEND_CANN_PACKAGE_PATH "$ENV{ASCEND_CANN_PACKAGE_PATH}") | ||
| 20 | + else() | ||
| 21 | + set(ASCEND_CANN_PACKAGE_PATH "/usr/local/Ascend/ascend-toolkit/latest") | ||
| 22 | + endif() | ||
| 23 | +endif() | ||
| 24 | +message(STATUS "ASCEND_CANN_PACKAGE_PATH = ${ASCEND_CANN_PACKAGE_PATH}") | ||
| 25 | + | ||
| 26 | +if(NOT ASCCOMM_CANN_ARCH_DIR) | ||
| 27 | + if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm") | ||
| 28 | + set(_ASCCOMM_CANN_ARCH "aarch64-linux") | ||
| 29 | + else() | ||
| 30 | + set(_ASCCOMM_CANN_ARCH "x86_64-linux") | ||
| 31 | + endif() | ||
| 32 | + set(ASCCOMM_CANN_ARCH_DIR "${ASCEND_CANN_PACKAGE_PATH}/${_ASCCOMM_CANN_ARCH}") | ||
| 33 | +endif() | ||
| 34 | +message(STATUS "ASCCOMM_CANN_ARCH_DIR = ${ASCCOMM_CANN_ARCH_DIR}") | ||
| 35 | + | ||
| 36 | +# 查找控制面源码:优先使用显式路径, | ||
| 37 | +# 最后探测相邻源码仓;没有契约头时回退到随仓自包含头文件。 | ||
| 38 | +if(NOT ASCCOMM_CONTROL_PLANE_SOURCE_DIR) | ||
| 39 | + foreach(_candidate | ||
| 40 | + "${ASCCOMM_ROOT}/../hcomm_pkg_inc" | ||
| 41 | + "${ASCCOMM_ROOT}/../hcomm") | ||
| 42 | + if(EXISTS "${_candidate}/pkg_inc/hcomm/hcomm_res_entity_defs.h") | ||
| 43 | + get_filename_component(ASCCOMM_CONTROL_PLANE_SOURCE_DIR "${_candidate}" ABSOLUTE) | ||
| 44 | + break() | ||
| 45 | + endif() | ||
| 46 | + endforeach() | ||
| 47 | +endif() | ||
| 48 | +if(ASCCOMM_CONTROL_PLANE_SOURCE_DIR AND NOT EXISTS "${ASCCOMM_CONTROL_PLANE_SOURCE_DIR}/pkg_inc/hcomm/hcomm_res_entity_defs.h") | ||
| 49 | + # 指定路径无AICPU契约头(如devkit的cc包):退回自包含。 | ||
| 50 | + set(ASCCOMM_CONTROL_PLANE_SOURCE_DIR "") | ||
| 51 | +endif() | ||
| 52 | +set(ASCCOMM_CONTROL_PLANE_SOURCE_DIR "${ASCCOMM_CONTROL_PLANE_SOURCE_DIR}" CACHE PATH "Original control-plane source tree") | ||
| 53 | +message(STATUS "ASCCOMM_CONTROL_PLANE_SOURCE_DIR = ${ASCCOMM_CONTROL_PLANE_SOURCE_DIR}") | ||
| 54 | + | ||
| 55 | +add_library(asc_comm_dfx INTERFACE) | ||
| 56 | +target_include_directories(asc_comm_dfx INTERFACE ${ASCCOMM_DFX_SRC_DIR}) | ||
| 57 | + | ||
| 58 | +add_library(asccomm_aicpu SHARED) | ||
| 59 | +add_subdirectory(asccomm) | ||
| 60 | + | ||
| 61 | +target_compile_definitions(asccomm_aicpu PRIVATE | ||
| 62 | + HCCD | ||
| 63 | + CCL_KERNEL_AICPU | ||
| 64 | + OPEN_BUILD_PROJECT | ||
| 65 | + _GLIBCXX_USE_CXX11_ABI=1 | ||
| 66 | +) | ||
| 67 | + | ||
| 68 | +target_compile_options(asccomm_aicpu PRIVATE | ||
| 69 | + -Wfloat-equal | ||
| 70 | + -Wall | ||
| 71 | + -fno-common | ||
| 72 | + -fstack-protector-strong | ||
| 73 | + -fno-strict-aliasing | ||
| 74 | + -ffunction-sections | ||
| 75 | + -fdata-sections | ||
| 76 | + -fvisibility=hidden | ||
| 77 | + -fvisibility-inlines-hidden | ||
| 78 | + -pipe | ||
| 79 | + -O3 | ||
| 80 | +) | ||
| 81 | + | ||
| 82 | +target_include_directories(asccomm_aicpu PRIVATE | ||
| 83 | + ${ASCCOMM_ROOT}/include/aicpu | ||
| 84 | + ${ASCCOMM_ROOT}/include/aicpu/hcomm | ||
| 85 | + # CANN包公共依赖头(securec.h/dlog_pub.h/ascend_hal.h/acl头), | ||
| 86 | + # 独立构建不依赖cann-cmake导入目标,直接取CANN包目录 | ||
| 87 | + ${ASCEND_CANN_PACKAGE_PATH}/pkg_inc/hcomm | ||
| 88 | + ${ASCCOMM_CANN_ARCH_DIR}/pkg_inc/hcomm | ||
| 89 | + ${ASCCOMM_CANN_ARCH_DIR}/include | ||
| 90 | + ${ASCCOMM_CANN_ARCH_DIR}/include/hcomm | ||
| 91 | + ${ASCCOMM_CANN_ARCH_DIR}/pkg_inc/base | ||
| 92 | + ${ASCCOMM_CANN_ARCH_DIR}/pkg_inc/driver | ||
| 93 | + ${ASCCOMM_AICPU_ROOT}/asccomm/primitives/api_c_adpt | ||
| 94 | + ${ASCCOMM_AICPU_ROOT}/asccomm/primitives/launch | ||
| 95 | + ${ASCCOMM_AICPU_ROOT}/asccomm/common/exception | ||
| 96 | + ${ASCCOMM_AICPU_ROOT}/asccomm/common/utils | ||
| 97 | + ${ASCCOMM_AICPU_ROOT}/asccomm/resource/buffer | ||
| 98 | + ${ASCCOMM_AICPU_ROOT}/asccomm/resource/common | ||
| 99 | + ${ASCCOMM_AICPU_ROOT}/asccomm/resource/connection | ||
| 100 | + ${ASCCOMM_AICPU_ROOT}/asccomm/resource/stream | ||
| 101 | +) | ||
| 102 | +# 控制面源码可用时附加其pkg_inc包含路径(可选依赖,自包含构建时跳过) | ||
| 103 | +if(ASCCOMM_CONTROL_PLANE_SOURCE_DIR) | ||
| 104 | + target_include_directories(asccomm_aicpu PRIVATE | ||
| 105 | + ${ASCCOMM_CONTROL_PLANE_SOURCE_DIR}/include | ||
| 106 | + ${ASCCOMM_CONTROL_PLANE_SOURCE_DIR}/pkg_inc | ||
| 107 | + ${ASCCOMM_CONTROL_PLANE_SOURCE_DIR}/pkg_inc/hcomm) | ||
| 108 | +endif() | ||
| 109 | + | ||
| 110 | +# 设备侧库:securec/dlog/驱动符号由设备运行环境(ccl_kernel/内核驱动)在加载期解析, | ||
| 111 | +# 链接期不强制落地;cann-cmake导入目标存在时按需附加,避免独立构建缺目标报错 | ||
| 112 | +set(_asccomm_aicpu_link_targets asc_comm_dfx) | ||
| 113 | +foreach(_target acl_rt_headers slog_headers ascend_hal c_sec) | ||
| 114 | + if(TARGET ${_target}) | ||
| 115 | + list(APPEND _asccomm_aicpu_link_targets ${_target}) | ||
| 116 | + endif() | ||
| 117 | +endforeach() | ||
| 118 | +target_link_libraries(asccomm_aicpu PRIVATE | ||
| 119 | + ${_asccomm_aicpu_link_targets} | ||
| 120 | + dl | ||
| 121 | + pthread | ||
| 122 | +) | ||
| 123 | + | ||
| 124 | +target_link_options(asccomm_aicpu PRIVATE | ||
| 125 | + -Wl,-z,relro | ||
| 126 | + -Wl,-z,now | ||
| 127 | + -Wl,-z,noexecstack | ||
| 128 | + -Wl,--gc-sections | ||
| 129 | +) | ||
| 130 | + | ||
| 131 | +set_target_properties(asccomm_aicpu PROPERTIES SKIP_BUILD_RPATH TRUE) | ||
| 132 | + | ||
| 133 | +# install规则仅在asc-comm根工程(独立/自包含构建)下注册; | ||
| 134 | +# 第三方超构建(runtime cann_device等)直接add_subdirectory(src/aicpu)时, | ||
| 135 | +# 设备超构建的默认目标集可能不包含本目标(EXCLUDE_FROM_ALL或不被默认依赖拉入), | ||
| 136 | +# 但install规则会残留到宿主CPack,导致"file INSTALL cannot find"硬失败。 | ||
| 137 | +# 超构建场景由宿主自行install/打包(如runtime的DEVICE_LIBRARY_PATH)。 | ||
| 138 | +if("${PROJECT_SOURCE_DIR}" STREQUAL "${ASCCOMM_ROOT}") | ||
| 139 | + if(NOT INSTALL_LIBRARY_DIR) | ||
| 140 | + set(INSTALL_LIBRARY_DIR lib64) | ||
| 141 | + endif() | ||
| 142 | + if(NOT INSTALL_PKG_INCLUDE_DIR) | ||
| 143 | + set(INSTALL_PKG_INCLUDE_DIR pkg_inc) | ||
| 144 | + endif() | ||
| 145 | + install(TARGETS asccomm_aicpu | ||
| 146 | + LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR} | ||
| 147 | + COMPONENT asccomm) | ||
| 148 | + install(DIRECTORY ${ASCCOMM_ROOT}/include/aicpu/hcomm/ | ||
| 149 | + DESTINATION ${INSTALL_PKG_INCLUDE_DIR}/asccomm | ||
| 150 | + COMPONENT asccomm | ||
| 151 | + FILES_MATCHING PATTERN "*.h") | ||
| 152 | +endif() | ||
| 153 | + | ||
| 154 | +# Keep an explicit aggregate target, matching the CCU CMake integration, so | ||
| 155 | +# superbuilds can depend on the AICPU data-plane project without knowing its | ||
| 156 | +# internal source layout. | ||
| 157 | +add_custom_target(asccomm_aicpu_compile_check DEPENDS asccomm_aicpu) | ||
| @@ -0,0 +1,28 @@ | |||
| 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 | +target_sources(asccomm_aicpu PRIVATE | ||
| 12 | + primitives/api_c_adpt/aicpu_ts_asccomm_primitives_c_adpt.cc | ||
| 13 | + primitives/launch/asccomm_launch.cc | ||
| 14 | + resource/common/asccomm_runtime.cc | ||
| 15 | + resource/common/asccomm_transport.cc | ||
| 16 | + resource/connection/ub_conn_lite.cc | ||
| 17 | + resource/stream/sqe_build_a5.cc | ||
| 18 | +) | ||
| 19 | + | ||
| 20 | +set_source_files_properties( | ||
| 21 | + primitives/api_c_adpt/aicpu_ts_asccomm_primitives_c_adpt.cc | ||
| 22 | + primitives/launch/asccomm_launch.cc | ||
| 23 | + resource/common/asccomm_runtime.cc | ||
| 24 | + resource/common/asccomm_transport.cc | ||
| 25 | + resource/connection/ub_conn_lite.cc | ||
| 26 | + resource/stream/sqe_build_a5.cc | ||
| 27 | + PROPERTIES COMPILE_OPTIONS "-ffunction-sections;-fdata-sections;-fvisibility=hidden;-fvisibility-inlines-hidden" | ||
| 28 | +) | ||
| @@ -0,0 +1,36 @@ | |||
| 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 ASCCOMM_EXCEPTION_H | ||
| 12 | +#define ASCCOMM_EXCEPTION_H | ||
| 13 | + | ||
| 14 | +#include <exception> | ||
| 15 | +#include <string> | ||
| 16 | +#include "../utils/asccomm_result.h" | ||
| 17 | + | ||
| 18 | +namespace Asc { | ||
| 19 | + | ||
| 20 | +class AsccommException : public std::exception { | ||
| 21 | +public: | ||
| 22 | + AsccommException(AsccommResult errorCode, const char* prefix, const std::string& message) | ||
| 23 | + : errorCode_(errorCode), errorMessage_(std::string(prefix) + message) | ||
| 24 | + {} | ||
| 25 | + | ||
| 26 | + const char* what() const noexcept override { return errorMessage_.c_str(); } | ||
| 27 | + AsccommResult get_error_code() const { return errorCode_; } | ||
| 28 | + | ||
| 29 | +private: | ||
| 30 | + AsccommResult errorCode_; | ||
| 31 | + std::string errorMessage_; | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +} // namespace Asc | ||
| 35 | + | ||
| 36 | +#endif // ASCCOMM_EXCEPTION_H | ||
| @@ -0,0 +1,25 @@ | |||
| 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 ASCCOMM_INTERNAL_EXCEPTION_H | ||
| 12 | +#define ASCCOMM_INTERNAL_EXCEPTION_H | ||
| 13 | + | ||
| 14 | +#include "asccomm_exception.h" | ||
| 15 | + | ||
| 16 | +namespace Asc { | ||
| 17 | +class InternalException : public AsccommException { | ||
| 18 | +public: | ||
| 19 | + explicit InternalException(const std::string& userDefinedMsg) | ||
| 20 | + : AsccommException(ASCCOMM_E_INTERNAL, "Internal exception: ", userDefinedMsg) | ||
| 21 | + {} | ||
| 22 | +}; | ||
| 23 | +} // namespace Asc | ||
| 24 | + | ||
| 25 | +#endif // ASCCOMM_INTERNAL_EXCEPTION_H | ||
| @@ -0,0 +1,25 @@ | |||
| 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 ASCCOMM_INVALID_PARAMS_EXCEPTION_H | ||
| 12 | +#define ASCCOMM_INVALID_PARAMS_EXCEPTION_H | ||
| 13 | + | ||
| 14 | +#include "asccomm_exception.h" | ||
| 15 | + | ||
| 16 | +namespace Asc { | ||
| 17 | +class InvalidParamsException : public AsccommException { | ||
| 18 | +public: | ||
| 19 | + explicit InvalidParamsException(const std::string& userDefinedMsg) | ||
| 20 | + : AsccommException(ASCCOMM_E_PARA, "Invalid params exception: ", userDefinedMsg) | ||
| 21 | + {} | ||
| 22 | +}; | ||
| 23 | +} // namespace Asc | ||
| 24 | + | ||
| 25 | +#endif // ASCCOMM_INVALID_PARAMS_EXCEPTION_H | ||
| @@ -0,0 +1,52 @@ | |||
| 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 ASCCOMM_RESULT_H | ||
| 12 | +#define ASCCOMM_RESULT_H | ||
| 13 | + | ||
| 14 | +#ifdef __cplusplus | ||
| 15 | +extern "C" { | ||
| 16 | +#endif | ||
| 17 | + | ||
| 18 | +typedef enum { | ||
| 19 | + ASCCOMM_SUCCESS = 0, | ||
| 20 | + ASCCOMM_E_PARA = 1, | ||
| 21 | + ASCCOMM_E_PTR = 2, | ||
| 22 | + ASCCOMM_E_MEMORY = 3, | ||
| 23 | + ASCCOMM_E_INTERNAL = 4, | ||
| 24 | + ASCCOMM_E_NOT_SUPPORT = 5, | ||
| 25 | + ASCCOMM_E_NOT_FOUND = 6, | ||
| 26 | + ASCCOMM_E_UNAVAIL = 7, | ||
| 27 | + ASCCOMM_E_SYSCALL = 8, | ||
| 28 | + ASCCOMM_E_TIMEOUT = 9, | ||
| 29 | + ASCCOMM_E_OPEN_FILE_FAILURE = 10, | ||
| 30 | + ASCCOMM_E_TCP_CONNECT = 11, | ||
| 31 | + ASCCOMM_E_ROCE_CONNECT = 12, | ||
| 32 | + ASCCOMM_E_TCP_TRANSFER = 13, | ||
| 33 | + ASCCOMM_E_ROCE_TRANSFER = 14, | ||
| 34 | + ASCCOMM_E_RUNTIME = 15, | ||
| 35 | + ASCCOMM_E_DRV = 16, | ||
| 36 | + ASCCOMM_E_PROFILING = 17, | ||
| 37 | + ASCCOMM_E_CCE = 18, | ||
| 38 | + ASCCOMM_E_NETWORK = 19, | ||
| 39 | + ASCCOMM_E_AGAIN = 20, | ||
| 40 | + ASCCOMM_E_REMOTE = 21, | ||
| 41 | + ASCCOMM_E_SUSPENDING = 22, | ||
| 42 | + ASCCOMM_E_OPRETRY_FAIL = 23, | ||
| 43 | + ASCCOMM_E_OOM = 24, | ||
| 44 | + ASCCOMM_E_IN_STATUS = 1041, | ||
| 45 | + ASCCOMM_E_RESERVED | ||
| 46 | +} AsccommResult; | ||
| 47 | + | ||
| 48 | +#ifdef __cplusplus | ||
| 49 | +} | ||
| 50 | +#endif | ||
| 51 | + | ||
| 52 | +#endif // ASCCOMM_RESULT_H | ||
| @@ -0,0 +1,35 @@ | |||
| 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 ASCCOMM_EXCEPTION_UTIL_H | ||
| 12 | +#define ASCCOMM_EXCEPTION_UTIL_H | ||
| 13 | + | ||
| 14 | +#include <string> | ||
| 15 | +#include "asccomm_log.h" | ||
| 16 | +#include "string_util.h" | ||
| 17 | + | ||
| 18 | +namespace Asc { | ||
| 19 | + | ||
| 20 | +template <typename Exception> | ||
| 21 | +[[noreturn]] inline void throw_exception(const std::string& message) | ||
| 22 | +{ | ||
| 23 | + ASCCOMM_ERROR("%s", message.c_str()); | ||
| 24 | + throw Exception(message); | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +template <typename Exception, typename... Args> | ||
| 28 | +[[noreturn]] inline void throw_exception(const char* format, Args... args) | ||
| 29 | +{ | ||
| 30 | + throw_exception<Exception>(string_format(format, args...)); | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +} // namespace Asc | ||
| 34 | + | ||
| 35 | +#endif // ASCCOMM_EXCEPTION_UTIL_H | ||
| @@ -0,0 +1,48 @@ | |||
| 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 ASCCOMM_STRING_UTIL_H | ||
| 12 | +#define ASCCOMM_STRING_UTIL_H | ||
| 13 | + | ||
| 14 | +#include <string> | ||
| 15 | +#include <vector> | ||
| 16 | +#include "securec.h" | ||
| 17 | +#include "asccomm_log.h" | ||
| 18 | + | ||
| 19 | +namespace Asc { | ||
| 20 | + | ||
| 21 | +template <typename... Args> | ||
| 22 | +inline std::string string_format(const char* format, Args... args) | ||
| 23 | +{ | ||
| 24 | + using namespace std; | ||
| 25 | + constexpr size_t bufSize = BUFSIZ; | ||
| 26 | + char buffer[bufSize]; | ||
| 27 | + int result = snprintf_s(&buffer[0], bufSize, bufSize, format, args...); | ||
| 28 | + if (result < 0) { | ||
| 29 | + ASCCOMM_ERROR("[string_format] data snprintf_s failed."); | ||
| 30 | + return ""; | ||
| 31 | + } | ||
| 32 | + size_t actualSize = static_cast<size_t>(result); | ||
| 33 | + if (actualSize + 1 > bufSize) { | ||
| 34 | + actualSize++; | ||
| 35 | + std::vector<char> newbuffer(actualSize); | ||
| 36 | + auto ret = snprintf_s(newbuffer.data(), actualSize, actualSize, format, args...); | ||
| 37 | + if (ret != EOK) { | ||
| 38 | + ASCCOMM_ERROR("[string_format] data snprintf_s failed."); | ||
| 39 | + return ""; | ||
| 40 | + } | ||
| 41 | + return newbuffer.data(); | ||
| 42 | + } | ||
| 43 | + return buffer; | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +} // namespace Asc | ||
| 47 | + | ||
| 48 | +#endif // ASCCOMM_STRING_UTIL_H | ||
| @@ -0,0 +1,511 @@ | |||
| 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 | +#include <cmath> | ||
| 12 | +#include <limits> | ||
| 13 | +#include "asccomm_primitives.h" | ||
| 14 | +#include "asccomm_res_defs.h" | ||
| 15 | +#include "asccomm_launch.h" | ||
| 16 | +#include "asccomm_runtime.h" | ||
| 17 | +#include "asccomm_transport.h" | ||
| 18 | +#include "../../common/utils/exception_util.h" | ||
| 19 | +#include "asccomm_log.h" | ||
| 20 | + | ||
| 21 | +namespace { | ||
| 22 | + | ||
| 23 | +struct CommContext { | ||
| 24 | + ThreadEntity* thread; | ||
| 25 | + ChannelEntity* channel; | ||
| 26 | +}; | ||
| 27 | + | ||
| 28 | +template <typename Entity> | ||
| 29 | +AsccommResult validate_entity(const Entity* entity, uint32_t version, uint32_t magicWord) | ||
| 30 | +{ | ||
| 31 | + CHK_PTR_NULL(entity); | ||
| 32 | + CHK_PRT_RET( | ||
| 33 | + entity->abiHeader.version != version || entity->abiHeader.magicWord != magicWord, | ||
| 34 | + ASCCOMM_ERROR( | ||
| 35 | + "[%s] invalid resource ABI header, version[%u], magicWord[0x%x].", __func__, entity->abiHeader.version, | ||
| 36 | + entity->abiHeader.magicWord), | ||
| 37 | + ASCCOMM_E_PARA); | ||
| 38 | + CHK_PRT_RET( | ||
| 39 | + entity->abiHeader.size < sizeof(Entity), | ||
| 40 | + ASCCOMM_ERROR( | ||
| 41 | + "[%s] resource entity size[%u] is less than expected size[%zu].", __func__, entity->abiHeader.size, | ||
| 42 | + sizeof(Entity)), | ||
| 43 | + ASCCOMM_E_PARA); | ||
| 44 | + return ASCCOMM_SUCCESS; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +AsccommResult get_thread_entity(ThreadHandle thread, bool registerThread, bool resolveRtsq, ThreadEntity*& threadEntity) | ||
| 48 | +{ | ||
| 49 | + CHK_PRT_RET(thread == 0, ASCCOMM_ERROR("[%s] thread handle is 0.", __func__), ASCCOMM_E_PTR); | ||
| 50 | + // The public ThreadHandle is the device resource entity address. The control | ||
| 51 | + // plane performs the original-handle -> POD conversion before launch. | ||
| 52 | + threadEntity = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(thread)); | ||
| 53 | + CHK_RET(validate_entity(threadEntity, HCOMM_RESOURCE_THREAD_VERSION, HCOMM_RESOURCE_THREAD_MAGIC_WORD)); | ||
| 54 | + CHK_PTR_NULL(threadEntity->sqContextAddr); | ||
| 55 | + if (resolveRtsq) { | ||
| 56 | + CHK_RET(asccomm_resolve_thread_rtsq(threadEntity)); | ||
| 57 | + } | ||
| 58 | + if (registerThread) { | ||
| 59 | + asccomm_register_thread(thread); | ||
| 60 | + } | ||
| 61 | + return ASCCOMM_SUCCESS; | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +AsccommResult get_context(ThreadHandle thread, ChannelHandle channel, bool registerThread, CommContext& context) | ||
| 65 | +{ | ||
| 66 | + CHK_PRT_RET(channel == 0, ASCCOMM_ERROR("[%s] channel handle is 0.", __func__), ASCCOMM_E_PTR); | ||
| 67 | + CHK_RET(get_thread_entity(thread, registerThread, true, context.thread)); | ||
| 68 | + // ChannelHandle follows the same resource-address ABI as ThreadHandle. | ||
| 69 | + context.channel = reinterpret_cast<ChannelEntity*>(static_cast<uintptr_t>(channel)); | ||
| 70 | + CHK_RET(validate_entity(context.channel, HCOMM_RESOURCE_CHANNEL_VERSION, HCOMM_RESOURCE_CHANNEL_MAGIC_WORD)); | ||
| 71 | + return ASCCOMM_SUCCESS; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +AsccommResult get_thread_notify_id(const ThreadEntity& thread, uint32_t notifyIdx, uint32_t& notifyId) | ||
| 75 | +{ | ||
| 76 | + CHK_PRT_RET( | ||
| 77 | + notifyIdx >= thread.localNotifyNum || thread.localNotifyAddr == nullptr, | ||
| 78 | + ASCCOMM_ERROR("[%s] local notify index[%u] out of range[%u].", __func__, notifyIdx, thread.localNotifyNum), | ||
| 79 | + ASCCOMM_E_PARA); | ||
| 80 | + CHK_PRT_RET( | ||
| 81 | + thread.localNotifyAddr[notifyIdx].type != HCOMM_REGED_NOTIFY_IPC_RT, | ||
| 82 | + ASCCOMM_ERROR("[%s] local notify type[%u] is not IPC_RT.", __func__, thread.localNotifyAddr[notifyIdx].type), | ||
| 83 | + ASCCOMM_E_PARA); | ||
| 84 | + const int32_t resourceId = thread.localNotifyAddr[notifyIdx].notifyInfo.ipcRt.notifyId; | ||
| 85 | + CHK_PRT_RET(resourceId < 0, ASCCOMM_ERROR("[%s] invalid notify id[%d].", __func__, resourceId), ASCCOMM_E_PARA); | ||
| 86 | + notifyId = static_cast<uint32_t>(resourceId); | ||
| 87 | + return ASCCOMM_SUCCESS; | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +AsccommResult convert_reduce_in( | ||
| 91 | + AsccommDataType dataType, AsccommReduceOp reduceOp, Asc::DataType& innerDataType, Asc::ReduceOp& innerReduceOp, | ||
| 92 | + uint32_t& typeSize) | ||
| 93 | +{ | ||
| 94 | + switch (dataType) { | ||
| 95 | + case ASCCOMM_DATA_TYPE_INT8: | ||
| 96 | + innerDataType = Asc::DataType::INT8; | ||
| 97 | + typeSize = 1; | ||
| 98 | + break; | ||
| 99 | + case ASCCOMM_DATA_TYPE_INT16: | ||
| 100 | + innerDataType = Asc::DataType::INT16; | ||
| @@ -0,0 +1,76 @@ | |||
| 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 | +#include <algorithm> | ||
| 12 | +#include <vector> | ||
| 13 | +#include "asccomm_launch.h" | ||
| 14 | +#include "asccomm_runtime.h" | ||
| 15 | + | ||
| 16 | +namespace { | ||
| 17 | +constexpr uint32_t DEFAULT_NOTIFY_WAIT_TIMEOUT = 1836U; | ||
| 18 | +constexpr uint32_t DEFAULT_SQ_FULL_TIMEOUT = 1856U; | ||
| 19 | + | ||
| 20 | +struct LaunchState { | ||
| 21 | + std::vector<ThreadHandle> threads; | ||
| 22 | + uint32_t notifyWaitTimeout{DEFAULT_NOTIFY_WAIT_TIMEOUT}; | ||
| 23 | + uint32_t sqFullTimeout{0}; | ||
| 24 | + bool sqFullTimeoutSet{false}; | ||
| 25 | + bool batchMode{false}; | ||
| 26 | +}; | ||
| 27 | + | ||
| 28 | +thread_local LaunchState g_launchState; | ||
| 29 | +} // namespace | ||
| 30 | + | ||
| 31 | +void asccomm_register_thread(ThreadHandle thread) | ||
| 32 | +{ | ||
| 33 | + if (!g_launchState.batchMode) { | ||
| 34 | + return; | ||
| 35 | + } | ||
| 36 | + if (std::find(g_launchState.threads.begin(), g_launchState.threads.end(), thread) == g_launchState.threads.end()) { | ||
| 37 | + g_launchState.threads.push_back(thread); | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +bool asccomm_is_batch_launch_mode() { return g_launchState.batchMode; } | ||
| 42 | + | ||
| 43 | +uint32_t asccomm_get_notify_wait_timeout() { return g_launchState.notifyWaitTimeout; } | ||
| 44 | + | ||
| 45 | +void asccomm_set_notify_wait_timeout(uint32_t timeout) { g_launchState.notifyWaitTimeout = timeout; } | ||
| 46 | + | ||
| 47 | +uint32_t asccomm_get_sq_full_timeout() | ||
| 48 | +{ | ||
| 49 | + return g_launchState.sqFullTimeoutSet ? g_launchState.sqFullTimeout : DEFAULT_SQ_FULL_TIMEOUT; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +void asccomm_set_sq_full_timeout(uint32_t timeout) | ||
| 53 | +{ | ||
| 54 | + g_launchState.sqFullTimeout = timeout; | ||
| 55 | + g_launchState.sqFullTimeoutSet = true; | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +void asccomm_set_batch_launch_mode(bool batchMode) { g_launchState.batchMode = batchMode; } | ||
| 59 | + | ||
| 60 | +AsccommResult asccomm_launch_registered_threads() | ||
| 61 | +{ | ||
| 62 | + if (g_launchState.threads.empty()) { | ||
| 63 | + return ASCCOMM_SUCCESS; | ||
| 64 | + } | ||
| 65 | + return asccomm_task_launch(g_launchState.threads.data(), g_launchState.threads.size()); | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +AsccommResult asccomm_try_launch_registered_threads() | ||
| 69 | +{ | ||
| 70 | + if (g_launchState.threads.empty()) { | ||
| 71 | + return ASCCOMM_SUCCESS; | ||
| 72 | + } | ||
| 73 | + return asccomm_try_launch(g_launchState.threads.data(), g_launchState.threads.size()); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +void asccomm_clear_registered_threads() { g_launchState.threads.clear(); } | ||
| @@ -0,0 +1,29 @@ | |||
| 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 ASCCOMM_LAUNCH_H | ||
| 12 | +#define ASCCOMM_LAUNCH_H | ||
| 13 | + | ||
| 14 | +#include "asccomm_primitives.h" | ||
| 15 | +#include "../../common/utils/asccomm_result.h" | ||
| 16 | + | ||
| 17 | +// 登记batch模式批量launch的ThreadHandle;句柄值为控制面提供的资源实体地址。 | ||
| 18 | +void asccomm_register_thread(ThreadHandle thread); | ||
| 19 | +bool asccomm_is_batch_launch_mode(); | ||
| 20 | +uint32_t asccomm_get_notify_wait_timeout(); | ||
| 21 | +void asccomm_set_notify_wait_timeout(uint32_t timeout); | ||
| 22 | +uint32_t asccomm_get_sq_full_timeout(); | ||
| 23 | +void asccomm_set_sq_full_timeout(uint32_t timeout); | ||
| 24 | +void asccomm_set_batch_launch_mode(bool batchMode); | ||
| 25 | +AsccommResult asccomm_launch_registered_threads(); | ||
| 26 | +AsccommResult asccomm_try_launch_registered_threads(); | ||
| 27 | +void asccomm_clear_registered_threads(); | ||
| 28 | + | ||
| 29 | +#endif // ASCCOMM_LAUNCH_H | ||
| @@ -0,0 +1,37 @@ | |||
| 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 | +#ifndef ASCCOMM_RMA_BUFFER_SLICE_LITE_H | ||
| 11 | +#define ASCCOMM_RMA_BUFFER_SLICE_LITE_H | ||
| 12 | + | ||
| 13 | +#include <stdint.h> | ||
| 14 | + | ||
| 15 | +namespace Asc { | ||
| 16 | +class RmaBufSliceLite { | ||
| 17 | +public: | ||
| 18 | + constexpr RmaBufSliceLite(uint64_t addr, uint64_t size, uint32_t lkey, uint32_t tokenId) | ||
| 19 | + : addr_(addr), size_(size), lkey_(lkey), tokenId_(tokenId) | ||
| 20 | + {} | ||
| 21 | + | ||
| 22 | + inline uint64_t get_addr() const { return addr_; } | ||
| 23 | + | ||
| 24 | + inline uint64_t get_size() const { return size_; } | ||
| 25 | + | ||
| 26 | + inline uint32_t get_lkey() const { return lkey_; } | ||
| 27 | + | ||
| 28 | + inline uint32_t get_token_id() const { return tokenId_; } | ||
| 29 | + | ||
| 30 | +private: | ||
| 31 | + uint64_t addr_; | ||
| 32 | + uint64_t size_; | ||
| 33 | + uint32_t lkey_; | ||
| 34 | + uint32_t tokenId_; | ||
| 35 | +}; | ||
| 36 | +} // namespace Asc | ||
| 37 | +#endif | ||
| @@ -0,0 +1,44 @@ | |||
| 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 | +#ifndef ASCCOMM_RMT_RMA_BUF_SLICE_LITE_H | ||
| 11 | +#define ASCCOMM_RMT_RMA_BUF_SLICE_LITE_H | ||
| 12 | + | ||
| 13 | +#include <stdint.h> | ||
| 14 | + | ||
| 15 | +namespace Asc { | ||
| 16 | +class RmtRmaBufSliceLite { | ||
| 17 | +public: | ||
| 18 | + constexpr RmtRmaBufSliceLite( | ||
| 19 | + uint64_t addr, uint64_t size, uint32_t rkey, uint32_t tokenId, uint32_t tokenValue, uint32_t notifyId) | ||
| 20 | + : addr_(addr), size_(size), rkey_(rkey), tokenId_(tokenId), tokenValue_(tokenValue), notifyId_(notifyId) | ||
| 21 | + {} | ||
| 22 | + | ||
| 23 | + inline uint64_t get_addr() const { return addr_; } | ||
| 24 | + | ||
| 25 | + inline uint64_t get_size() const { return size_; } | ||
| 26 | + | ||
| 27 | + inline uint32_t get_rkey() const { return rkey_; } | ||
| 28 | + | ||
| 29 | + inline uint32_t get_token_id() const { return tokenId_; } | ||
| 30 | + | ||
| 31 | + inline uint32_t get_token_value() const { return tokenValue_; } | ||
| 32 | + | ||
| 33 | + inline uint32_t get_notify_id() const { return notifyId_; } | ||
| 34 | + | ||
| 35 | +private: | ||
| 36 | + uint64_t addr_; | ||
| 37 | + uint64_t size_; | ||
| 38 | + uint32_t rkey_; | ||
| 39 | + uint32_t tokenId_; | ||
| 40 | + uint32_t tokenValue_; | ||
| 41 | + uint32_t notifyId_{UINT32_MAX}; | ||
| 42 | +}; | ||
| 43 | +} // namespace Asc | ||
| 44 | +#endif | ||
| @@ -0,0 +1,389 @@ | |||
| 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 | +#include <chrono> | ||
| 12 | +#include "asccomm_runtime.h" | ||
| 13 | +#include "asccomm_launch.h" | ||
| 14 | +#include "../stream/sqe_build_a5.h" | ||
| 15 | +#include "../stream/sqe.h" | ||
| 16 | +#include "securec.h" | ||
| 17 | +#include "ascend_hal.h" | ||
| 18 | +#include "asccomm_log.h" | ||
| 19 | + | ||
| 20 | +namespace aicpu { | ||
| 21 | +void __attribute__((weak)) __attribute__((visibility("default"))) GetSqeId( | ||
| 22 | + uint32_t batchNum, uint32_t& taskId, uint32_t& taskIdEnd); | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +namespace { | ||
| 26 | + | ||
| 27 | +AsccommResult acquire_task_id(HcommRtsqContext& context, uint32_t& taskId) | ||
| 28 | +{ | ||
| 29 | + CHK_PRT_RET( | ||
| 30 | + context.localSqeAddr == 0, ASCCOMM_ERROR("[%s] local SQE buffer address is 0.", __func__), ASCCOMM_E_PTR); | ||
| 31 | + CHK_PRT_RET( | ||
| 32 | + context.pendingSqeCnt >= HCOMM_RESOURCE_RTSQ_BATCH_SIZE, | ||
| 33 | + ASCCOMM_ERROR("[%s] pending SQE count[%u] exceeds buffer capacity.", __func__, context.pendingSqeCnt), | ||
| 34 | + ASCCOMM_E_INTERNAL); | ||
| 35 | + if (context.taskId >= context.taskIdEnd) { | ||
| 36 | + CHK_PRT_RET( | ||
| 37 | + aicpu::GetSqeId == nullptr, ASCCOMM_ERROR("[%s] GetSqeId is unavailable.", __func__), ASCCOMM_E_INTERNAL); | ||
| 38 | + aicpu::GetSqeId(HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE, context.taskId, context.taskIdEnd); | ||
| 39 | + CHK_PRT_RET( | ||
| 40 | + context.taskId >= context.taskIdEnd || | ||
| 41 | + context.taskIdEnd - context.taskId > HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE, | ||
| 42 | + ASCCOMM_ERROR("[%s] invalid Task ID range[%u, %u).", __func__, context.taskId, context.taskIdEnd), | ||
| 43 | + ASCCOMM_E_INTERNAL); | ||
| 44 | + } | ||
| 45 | + taskId = context.taskId; | ||
| 46 | + ++context.taskId; | ||
| 47 | + return ASCCOMM_SUCCESS; | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +AsccommResult query_sq_value(const HcommRtsqContext& context, drvSqCqPropType_t property, uint32_t& value) | ||
| 51 | +{ | ||
| 52 | + halSqCqQueryInfo queryInfo{}; | ||
| 53 | + queryInfo.tsId = 0; | ||
| 54 | + queryInfo.sqId = context.sqId; | ||
| 55 | + queryInfo.cqId = 0; | ||
| 56 | + queryInfo.type = DRV_NORMAL_TYPE; | ||
| 57 | + queryInfo.prop = property; | ||
| 58 | + drvError_t ret = halSqCqQuery(context.localDevId, &queryInfo); | ||
| 59 | + CHK_PRT_RET( | ||
| 60 | + ret != 0, | ||
| 61 | + ASCCOMM_ERROR( | ||
| 62 | + "[%s] halSqCqQuery failed, localDevId[%u], sqId[%u], property[%u], ret[%d].", __func__, context.localDevId, | ||
| 63 | + context.sqId, property, ret), | ||
| 64 | + ASCCOMM_E_INTERNAL); | ||
| 65 | + value = queryInfo.value[0]; | ||
| 66 | + return ASCCOMM_SUCCESS; | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +AsccommResult query_sq_base(const HcommRtsqContext& context, uint64_t& value) | ||
| 70 | +{ | ||
| 71 | + halSqCqQueryInfo queryInfo{}; | ||
| 72 | + queryInfo.tsId = 0; | ||
| 73 | + queryInfo.sqId = context.sqId; | ||
| 74 | + queryInfo.cqId = 0; | ||
| 75 | + queryInfo.type = DRV_NORMAL_TYPE; | ||
| 76 | + queryInfo.prop = DRV_SQCQ_PROP_SQ_BASE; | ||
| 77 | + drvError_t ret = halSqCqQuery(context.localDevId, &queryInfo); | ||
| 78 | + CHK_PRT_RET( | ||
| 79 | + ret != 0, | ||
| 80 | + ASCCOMM_ERROR( | ||
| 81 | + "[%s] halSqCqQuery failed, localDevId[%u], sqId[%u], ret[%d].", __func__, context.localDevId, context.sqId, | ||
| 82 | + ret), | ||
| 83 | + ASCCOMM_E_INTERNAL); | ||
| 84 | + value = (static_cast<uint64_t>(queryInfo.value[1]) << 32U) | queryInfo.value[0]; | ||
| 85 | + return ASCCOMM_SUCCESS; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +AsccommResult config_sq_tail(const HcommRtsqContext& context, uint32_t value) | ||
| 89 | +{ | ||
| 90 | + halSqCqConfigInfo configInfo{}; | ||
| 91 | + configInfo.tsId = 0; | ||
| 92 | + configInfo.sqId = context.sqId; | ||
| 93 | + configInfo.cqId = 0; | ||
| 94 | + configInfo.type = DRV_NORMAL_TYPE; | ||
| 95 | + configInfo.prop = DRV_SQCQ_PROP_SQ_TAIL; | ||
| 96 | + configInfo.value[0] = value; | ||
| 97 | + drvError_t ret = halSqCqConfig(context.localDevId, &configInfo); | ||
| 98 | + CHK_PRT_RET( | ||
| 99 | + ret != 0, | ||
| 100 | + ASCCOMM_ERROR( | ||
| 101 | + "[%s] halSqCqConfig failed, localDevId[%u], sqId[%u], tail[%u], ret[%d].", __func__, context.localDevId, | ||
| 102 | + context.sqId, value, ret), | ||
| 103 | + ASCCOMM_E_INTERNAL); | ||
| 104 | + return ASCCOMM_SUCCESS; | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +uint32_t get_tail_to_head_distance(const HcommRtsqContext& context) | ||
| 108 | +{ | ||
| 109 | + if (context.sqHead == context.sqTail) { | ||
| 110 | + return context.sqDepth; | ||
| 111 | + } | ||
| 112 | + return context.sqTail < context.sqHead ? context.sqHead - context.sqTail : | ||
| 113 | + context.sqDepth - (context.sqTail - context.sqHead); | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +AsccommResult ensure_queue_space(HcommRtsqContext& context) | ||
| 117 | +{ | ||
| 118 | + auto startTime = std::chrono::steady_clock::now(); | ||
| 119 | + const uint32_t sqFullTimeout = asccomm_get_sq_full_timeout(); | ||
| 120 | + uint32_t availableSpace = get_tail_to_head_distance(context); | ||
| 121 | + while (availableSpace <= context.pendingSqeCnt) { | ||
| 122 | + CHK_RET(query_sq_value(context, DRV_SQCQ_PROP_SQ_HEAD, context.sqHead)); | ||
| 123 | + availableSpace = get_tail_to_head_distance(context); | ||
| 124 | + if (availableSpace > context.pendingSqeCnt) { | ||
| 125 | + break; | ||
| 126 | + } | ||
| 127 | + const bool timeout = | ||
| 128 | + sqFullTimeout != 0 && std::chrono::steady_clock::now() - startTime >= std::chrono::seconds(sqFullTimeout); | ||
| 129 | + CHK_PRT_RET( | ||
| 130 | + timeout, | ||
| 131 | + ASCCOMM_ERROR( | ||
| 132 | + "[%s] RTSQ full timeout, sqId[%u], head[%u], tail[%u], pending[%u].", __func__, context.sqId, | ||
| 133 | + context.sqHead, context.sqTail, context.pendingSqeCnt), | ||
| 134 | + ASCCOMM_E_TIMEOUT); | ||
| 135 | + CHK_RET(asccomm_try_launch_registered_threads()); | ||
| 136 | + } | ||
| 137 | + return ASCCOMM_SUCCESS; | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +AsccommResult copy_pending_sqes(HcommRtsqContext& context) | ||
| 141 | +{ | ||
| 142 | + CHK_PRT_RET( | ||
| 143 | + context.localSqeAddr == 0, ASCCOMM_ERROR("[%s] local SQE buffer address is 0.", __func__), ASCCOMM_E_PTR); | ||
| 144 | + auto* localSqeBuffer = reinterpret_cast<uint8_t*>(context.localSqeAddr); | ||
| 145 | + const uint32_t byteCount = context.pendingSqeCnt * HCOMM_RESOURCE_RTSQ_SQE_SIZE; | ||
| 146 | + uint8_t* sqCurrent = reinterpret_cast<uint8_t*>(context.sqBaseAddr) + context.sqTail * HCOMM_RESOURCE_RTSQ_SQE_SIZE; | ||
| 147 | + if (context.sqTail >= context.sqHead) { | ||
| 148 | + const uint32_t depthLeft = context.sqDepth - context.sqTail; | ||
| 149 | + const uint32_t firstCount = context.pendingSqeCnt < depthLeft ? context.pendingSqeCnt : depthLeft; | ||
| 150 | + const uint32_t firstBytes = firstCount * HCOMM_RESOURCE_RTSQ_SQE_SIZE; | ||
| 151 | + CHK_PRT_RET( | ||
| 152 | + memcpy_sp(sqCurrent, firstBytes, localSqeBuffer, firstBytes) != EOK, | ||
| 153 | + ASCCOMM_ERROR("[%s] first RTSQ memcpy failed.", __func__), ASCCOMM_E_INTERNAL); | ||
| 154 | + if (firstCount != context.pendingSqeCnt) { | ||
| 155 | + const uint32_t remainingBytes = byteCount - firstBytes; | ||
| 156 | + CHK_PRT_RET( | ||
| 157 | + memcpy_sp( | ||
| 158 | + reinterpret_cast<void*>(context.sqBaseAddr), remainingBytes, localSqeBuffer + firstBytes, | ||
| 159 | + remainingBytes) != EOK, | ||
| 160 | + ASCCOMM_ERROR("[%s] wrapped RTSQ memcpy failed.", __func__), ASCCOMM_E_INTERNAL); | ||
| 161 | + } | ||
| 162 | + return ASCCOMM_SUCCESS; | ||
| 163 | + } | ||
| 164 | + CHK_PRT_RET( | ||
| 165 | + memcpy_sp(sqCurrent, byteCount, localSqeBuffer, byteCount) != EOK, | ||
| 166 | + ASCCOMM_ERROR("[%s] RTSQ memcpy failed.", __func__), ASCCOMM_E_INTERNAL); | ||
| 167 | + return ASCCOMM_SUCCESS; | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +AsccommResult refresh_rtsq(HcommRtsqContext& context) | ||
| 171 | +{ | ||
| 172 | + ++context.pendingSqeCnt; | ||
| 173 | + if ((context.launchFlag != 0 && !asccomm_is_batch_launch_mode()) || | ||
| 174 | + context.pendingSqeCnt == HCOMM_RESOURCE_RTSQ_BATCH_SIZE) { | ||
| 175 | + return asccomm_rtsq_launch(context); | ||
| 176 | + } | ||
| 177 | + return ASCCOMM_SUCCESS; | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +uint8_t* get_current_sqe(HcommRtsqContext& context) | ||
| 181 | +{ | ||
| 182 | + return reinterpret_cast<uint8_t*>(context.localSqeAddr) + context.pendingSqeCnt * HCOMM_RESOURCE_RTSQ_SQE_SIZE; | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +AsccommResult validate_thread_entity(ThreadEntity* thread) | ||
| 186 | +{ | ||
| 187 | + CHK_PTR_NULL(thread); | ||
| 188 | + CHK_PRT_RET( | ||
| 189 | + thread->abiHeader.version != HCOMM_RESOURCE_THREAD_VERSION || | ||
| 190 | + thread->abiHeader.magicWord != HCOMM_RESOURCE_THREAD_MAGIC_WORD || | ||
| 191 | + thread->abiHeader.size < sizeof(ThreadEntity), | ||
| 192 | + ASCCOMM_ERROR("[%s] invalid resource thread entity.", __func__), ASCCOMM_E_PARA); | ||
| 193 | + CHK_PTR_NULL(thread->sqContextAddr); | ||
| 194 | + const HcommRtsqContext& rtsq = *thread->sqContextAddr; | ||
| 195 | + CHK_PRT_RET( | ||
| 196 | + rtsq.sqBaseAddr == 0 || rtsq.sqDepth == 0 || rtsq.sqHead >= rtsq.sqDepth || rtsq.sqTail >= rtsq.sqDepth, | ||
| 197 | + ASCCOMM_ERROR( | ||
| 198 | + "[%s] invalid RTSQ parameters, base[0x%llx], depth[%u], head[%u], tail[%u].", __func__, | ||
| 199 | + static_cast<unsigned long long>(rtsq.sqBaseAddr), rtsq.sqDepth, rtsq.sqHead, rtsq.sqTail), | ||
| 200 | + ASCCOMM_E_PARA); | ||
| 201 | + return ASCCOMM_SUCCESS; | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +} // namespace | ||
| 205 | + | ||
| 206 | +AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread) | ||
| 207 | +{ | ||
| 208 | + CHK_PTR_NULL(thread); | ||
| 209 | + CHK_PTR_NULL(thread->sqContextAddr); | ||
| 210 | + HcommRtsqContext& rtsq = *thread->sqContextAddr; | ||
| 211 | + if (rtsq.sqBaseAddr != 0) { | ||
| 212 | + return ASCCOMM_SUCCESS; | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + drvError_t ret = drvGetLocalDevIDByHostDevID(thread->devInfo.devId, &rtsq.localDevId); | ||
| 216 | + CHK_PRT_RET( | ||
| 217 | + ret != 0, | ||
| 218 | + ASCCOMM_ERROR( | ||
| 219 | + "[%s] drvGetLocalDevIDByHostDevID failed, devicePhyId[%u], ret[%d].", __func__, thread->devInfo.devId, ret), | ||
| 220 | + ASCCOMM_E_INTERNAL); | ||
| 221 | + CHK_RET(query_sq_base(rtsq, rtsq.sqBaseAddr)); | ||
| 222 | + CHK_RET(query_sq_value(rtsq, DRV_SQCQ_PROP_SQ_DEPTH, rtsq.sqDepth)); | ||
| 223 | + CHK_RET(query_sq_value(rtsq, DRV_SQCQ_PROP_SQ_HEAD, rtsq.sqHead)); | ||
| 224 | + CHK_RET(query_sq_value(rtsq, DRV_SQCQ_PROP_SQ_TAIL, rtsq.sqTail)); | ||
| 225 | + CHK_PRT_RET( | ||
| 226 | + rtsq.sqBaseAddr == 0 || rtsq.sqDepth == 0, | ||
| 227 | + ASCCOMM_ERROR( | ||
| 228 | + "[%s] invalid RTSQ resource, base[0x%llx], depth[%u].", __func__, | ||
| 229 | + static_cast<unsigned long long>(rtsq.sqBaseAddr), rtsq.sqDepth), | ||
| 230 | + ASCCOMM_E_INTERNAL); | ||
| 231 | + return ASCCOMM_SUCCESS; | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +AsccommResult asccomm_rtsq_launch(HcommRtsqContext& context) | ||
| 235 | +{ | ||
| 236 | + if (context.pendingSqeCnt == 0) { | ||
| 237 | + return ASCCOMM_SUCCESS; | ||
| 238 | + } | ||
| 239 | + CHK_PRT_RET( | ||
| 240 | + context.sqDepth == 0 || context.sqBaseAddr == 0, | ||
| 241 | + ASCCOMM_ERROR( | ||
| 242 | + "[%s] invalid RTSQ context, depth[%u], base[0x%llx].", __func__, context.sqDepth, context.sqBaseAddr), | ||
| 243 | + ASCCOMM_E_PARA); | ||
| 244 | + CHK_RET(ensure_queue_space(context)); | ||
| 245 | + CHK_RET(copy_pending_sqes(context)); | ||
| 246 | + const uint32_t newTail = (context.sqTail + context.pendingSqeCnt) % context.sqDepth; | ||
| 247 | + CHK_RET(config_sq_tail(context, newTail)); | ||
| 248 | + context.sqTail = newTail; | ||
| 249 | + context.pendingSqeCnt = 0; | ||
| 250 | + auto* localSqeBuffer = reinterpret_cast<uint8_t*>(context.localSqeAddr); | ||
| 251 | + constexpr size_t LOCAL_SQE_BUFFER_SIZE = HCOMM_RESOURCE_RTSQ_SQE_SIZE * HCOMM_RESOURCE_RTSQ_BATCH_SIZE; | ||
| 252 | + CHK_PRT_RET( | ||
| 253 | + memset_s(localSqeBuffer, LOCAL_SQE_BUFFER_SIZE, 0, LOCAL_SQE_BUFFER_SIZE) != EOK, | ||
| 254 | + ASCCOMM_ERROR("[%s] clear SQE buffer failed.", __func__), ASCCOMM_E_INTERNAL); | ||
| 255 | + return ASCCOMM_SUCCESS; | ||
| 256 | +} | ||
| 257 | + | ||
| 258 | +AsccommResult asccomm_rtsq_try_launch(HcommRtsqContext& context) | ||
| 259 | +{ | ||
| 260 | + if (context.pendingSqeCnt == 0) { | ||
| 261 | + return ASCCOMM_SUCCESS; | ||
| 262 | + } | ||
| 263 | + CHK_RET(query_sq_value(context, DRV_SQCQ_PROP_SQ_HEAD, context.sqHead)); | ||
| 264 | + if (get_tail_to_head_distance(context) <= context.pendingSqeCnt) { | ||
| 265 | + return ASCCOMM_SUCCESS; | ||
| 266 | + } | ||
| 267 | + return asccomm_rtsq_launch(context); | ||
| 268 | +} | ||
| 269 | + | ||
| 270 | +AsccommResult asccomm_rtsq_notify_wait(HcommRtsqContext& context, uint32_t notifyId, uint32_t timeout) | ||
| 271 | +{ | ||
| 272 | + uint32_t taskId = 0; | ||
| 273 | + CHK_RET(acquire_task_id(context, taskId)); | ||
| 274 | + Asc::build_a5_sqe_notify_wait(context.streamId, taskId, notifyId, timeout, get_current_sqe(context)); | ||
| 275 | + return refresh_rtsq(context); | ||
| 276 | +} | ||
| 277 | + | ||
| 278 | +AsccommResult asccomm_rtsq_notify_record(HcommRtsqContext& context, uint32_t notifyId) | ||
| 279 | +{ | ||
| 280 | + uint32_t taskId = 0; | ||
| 281 | + CHK_RET(acquire_task_id(context, taskId)); | ||
| 282 | + Asc::build_a5_sqe_notify_record(context.streamId, taskId, notifyId, get_current_sqe(context)); | ||
| 283 | + return refresh_rtsq(context); | ||
| 284 | +} | ||
| 285 | + | ||
| 286 | +AsccommResult asccomm_rtsq_sdma_copy(HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size) | ||
| 287 | +{ | ||
| 288 | + constexpr uint32_t RTSQ_PART_ID = 0; | ||
| 289 | + constexpr uint32_t COPY_OPCODE = 0; | ||
| 290 | + uint32_t taskId = 0; | ||
| 291 | + CHK_RET(acquire_task_id(context, taskId)); | ||
| 292 | + Asc::build_a5_sqe_sdma_copy( | ||
| 293 | + context.streamId, taskId, dstAddr, srcAddr, size, RTSQ_PART_ID, COPY_OPCODE, get_current_sqe(context)); | ||
| 294 | + return refresh_rtsq(context); | ||
| 295 | +} | ||
| 296 | + | ||
| 297 | +AsccommResult asccomm_rtsq_sdma_reduce( | ||
| 298 | + HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn) | ||
| 299 | +{ | ||
| 300 | + uint32_t operation = 0; | ||
| 301 | + switch (reduceIn.reduceOp) { | ||
| 302 | + case Asc::ReduceOp::SUM: | ||
| 303 | + operation = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncOperationKind::RT_STARS_MEMCPY_ASYNC_OP_KIND_ADD); | ||
| 304 | + break; | ||
| 305 | + case Asc::ReduceOp::MAX: | ||
| 306 | + operation = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncOperationKind::RT_STARS_MEMCPY_ASYNC_OP_KIND_MAX); | ||
| 307 | + break; | ||
| 308 | + case Asc::ReduceOp::MIN: | ||
| 309 | + operation = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncOperationKind::RT_STARS_MEMCPY_ASYNC_OP_KIND_MIN); | ||
| 310 | + break; | ||
| 311 | + default: | ||
| 312 | + ASCCOMM_ERROR("[%s] unsupported SDMA reduce operation[%u].", __func__, reduceIn.reduceOp); | ||
| 313 | + return ASCCOMM_E_NOT_SUPPORT; | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + uint32_t dataType = 0; | ||
| 317 | + switch (reduceIn.dataType) { | ||
| 318 | + case Asc::DataType::INT8: | ||
| 319 | + dataType = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncDataType::RT_STARS_MEMCPY_ASYNC_DATA_TYPE_INT8); | ||
| 320 | + break; | ||
| 321 | + case Asc::DataType::INT16: | ||
| 322 | + dataType = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncDataType::RT_STARS_MEMCPY_ASYNC_DATA_TYPE_INT16); | ||
| 323 | + break; | ||
| 324 | + case Asc::DataType::INT32: | ||
| 325 | + dataType = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncDataType::RT_STARS_MEMCPY_ASYNC_DATA_TYPE_INT32); | ||
| 326 | + break; | ||
| 327 | + case Asc::DataType::FP16: | ||
| 328 | + dataType = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncDataType::RT_STARS_MEMCPY_ASYNC_DATA_TYPE_FP16); | ||
| 329 | + break; | ||
| 330 | + case Asc::DataType::FP32: | ||
| 331 | + dataType = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncDataType::RT_STARS_MEMCPY_ASYNC_DATA_TYPE_FP32); | ||
| 332 | + break; | ||
| 333 | + case Asc::DataType::BFP16: | ||
| 334 | + dataType = static_cast<uint32_t>(Asc::RtStarsMemcpyAsyncDataType::RT_STARS_MEMCPY_ASYNC_DATA_TYPE_BFP16); | ||
| 335 | + break; | ||
| 336 | + default: | ||
| 337 | + ASCCOMM_ERROR("[%s] unsupported SDMA data type[%u].", __func__, reduceIn.dataType); | ||
| 338 | + return ASCCOMM_E_NOT_SUPPORT; | ||
| 339 | + } | ||
| 340 | + | ||
| 341 | + constexpr uint32_t RTSQ_PART_ID = 0; | ||
| 342 | + uint32_t taskId = 0; | ||
| 343 | + CHK_RET(acquire_task_id(context, taskId)); | ||
| 344 | + Asc::build_a5_sqe_sdma_copy( | ||
| 345 | + context.streamId, taskId, dstAddr, srcAddr, size, RTSQ_PART_ID, operation | dataType, get_current_sqe(context)); | ||
| 346 | + return refresh_rtsq(context); | ||
| 347 | +} | ||
| 348 | + | ||
| 349 | +AsccommResult asccomm_rtsq_ub_db_send(HcommRtsqContext& context, const Asc::UbJettyLiteId& jettyId, uint16_t piValue) | ||
| 350 | +{ | ||
| 351 | + uint32_t taskId = 0; | ||
| 352 | + CHK_RET(acquire_task_id(context, taskId)); | ||
| 353 | + Asc::build_a5_sqe_ub_db_send(context.streamId, taskId, jettyId, piValue, get_current_sqe(context)); | ||
| 354 | + return refresh_rtsq(context); | ||
| 355 | +} | ||
| 356 | + | ||
| 357 | +AsccommResult asccomm_rtsq_rdma_db_send(HcommRtsqContext& context, uint64_t dbAddr, uint64_t dbValue) | ||
| 358 | +{ | ||
| 359 | + uint32_t taskId = 0; | ||
| 360 | + CHK_RET(acquire_task_id(context, taskId)); | ||
| 361 | + Asc::build_a5_sqe_rdma_db_send(context.streamId, taskId, dbAddr, dbValue, get_current_sqe(context)); | ||
| 362 | + return refresh_rtsq(context); | ||
| 363 | +} | ||
| 364 | + | ||
| 365 | +AsccommResult asccomm_task_launch(ThreadHandle* threads, uint32_t threadNum) | ||
| 366 | +{ | ||
| 367 | + CHK_PTR_NULL(threads); | ||
| 368 | + for (uint32_t index = 0; index < threadNum; ++index) { | ||
| 369 | + CHK_PRT_RET(threads[index] == 0, ASCCOMM_ERROR("[%s] thread handle is 0.", __func__), ASCCOMM_E_PTR); | ||
| 370 | + ThreadEntity* thread = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(threads[index])); | ||
| 371 | + CHK_RET(asccomm_resolve_thread_rtsq(thread)); | ||
| 372 | + CHK_RET(validate_thread_entity(thread)); | ||
| 373 | + CHK_RET(asccomm_rtsq_launch(*thread->sqContextAddr)); | ||
| 374 | + } | ||
| 375 | + return ASCCOMM_SUCCESS; | ||
| 376 | +} | ||
| 377 | + | ||
| 378 | +AsccommResult asccomm_try_launch(ThreadHandle* threads, uint32_t threadNum) | ||
| 379 | +{ | ||
| 380 | + CHK_PTR_NULL(threads); | ||
| 381 | + for (uint32_t index = 0; index < threadNum; ++index) { | ||
| 382 | + CHK_PRT_RET(threads[index] == 0, ASCCOMM_ERROR("[%s] thread handle is 0.", __func__), ASCCOMM_E_PTR); | ||
| 383 | + ThreadEntity* thread = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(threads[index])); | ||
| 384 | + CHK_RET(asccomm_resolve_thread_rtsq(thread)); | ||
| 385 | + CHK_RET(validate_thread_entity(thread)); | ||
| 386 | + CHK_RET(asccomm_rtsq_try_launch(*thread->sqContextAddr)); | ||
| 387 | + } | ||
| 388 | + return ASCCOMM_SUCCESS; | ||
| 389 | +} | ||
| @@ -0,0 +1,39 @@ | |||
| 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 ASCCOMM_RUNTIME_H | ||
| 12 | +#define ASCCOMM_RUNTIME_H | ||
| 13 | + | ||
| 14 | +// Internal resource RTSQ runtime. This header is not part of the public API. | ||
| 15 | + | ||
| 16 | +#include "asccomm_res_defs.h" | ||
| 17 | +#include "../../common/utils/asccomm_result.h" | ||
| 18 | +#include "../connection/asccomm_backend_types.h" | ||
| 19 | + | ||
| 20 | +namespace Asc { | ||
| 21 | +struct UbJettyLiteId; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +AsccommResult asccomm_rtsq_launch(HcommRtsqContext& context); | ||
| 25 | +AsccommResult asccomm_rtsq_try_launch(HcommRtsqContext& context); | ||
| 26 | +AsccommResult asccomm_rtsq_notify_wait(HcommRtsqContext& context, uint32_t notifyId, uint32_t timeout); | ||
| 27 | +AsccommResult asccomm_rtsq_notify_record(HcommRtsqContext& context, uint32_t notifyId); | ||
| 28 | +AsccommResult asccomm_rtsq_sdma_copy(HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size); | ||
| 29 | +AsccommResult asccomm_rtsq_sdma_reduce( | ||
| 30 | + HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn); | ||
| 31 | +AsccommResult asccomm_rtsq_ub_db_send(HcommRtsqContext& context, const Asc::UbJettyLiteId& jettyId, uint16_t piValue); | ||
| 32 | +AsccommResult asccomm_rtsq_rdma_db_send(HcommRtsqContext& context, uint64_t dbAddr, uint64_t dbValue); | ||
| 33 | +AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread); | ||
| 34 | + | ||
| 35 | +// RTSQ硬件属性由数据面在首次使用Thread resource时懒解析。 | ||
| 36 | +AsccommResult asccomm_task_launch(ThreadHandle* threads, uint32_t threadNum); | ||
| 37 | +AsccommResult asccomm_try_launch(ThreadHandle* threads, uint32_t threadNum); | ||
| 38 | + | ||
| 39 | +#endif // ASCCOMM_RUNTIME_H | ||
| @@ -0,0 +1,44 @@ | |||
| 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 ASCCOMM_TRANSPORT_H | ||
| 12 | +#define ASCCOMM_TRANSPORT_H | ||
| 13 | + | ||
| 14 | +#include "asccomm_res_defs.h" | ||
| 15 | +#include "asccomm_primitives.h" | ||
| 16 | +#include "../../common/utils/asccomm_result.h" | ||
| 17 | +#include "../connection/asccomm_backend_types.h" | ||
| 18 | + | ||
| 19 | +AsccommResult asccomm_write( | ||
| 20 | + ThreadEntity& thread, ChannelEntity& channel, uintptr_t localAddr, uintptr_t remoteAddr, uint64_t len); | ||
| 21 | +AsccommResult asccomm_write_reduce( | ||
| 22 | + ThreadEntity& thread, ChannelEntity& channel, uintptr_t localAddr, uintptr_t remoteAddr, uint64_t len, | ||
| 23 | + const Asc::ReduceIn& reduceIn); | ||
| 24 | +AsccommResult asccomm_write_with_notify( | ||
| 25 | + ThreadEntity& thread, ChannelEntity& channel, uintptr_t localAddr, uintptr_t remoteAddr, uint64_t len, | ||
| 26 | + uint32_t remoteNotifyIdx); | ||
| 27 | +AsccommResult asccomm_write_reduce_with_notify( | ||
| 28 | + ThreadEntity& thread, ChannelEntity& channel, uintptr_t localAddr, uintptr_t remoteAddr, uint64_t len, | ||
| 29 | + const Asc::ReduceIn& reduceIn, uint32_t remoteNotifyIdx); | ||
| 30 | +AsccommResult asccomm_read( | ||
| 31 | + ThreadEntity& thread, ChannelEntity& channel, uintptr_t localAddr, uintptr_t remoteAddr, uint64_t len); | ||
| 32 | +AsccommResult asccomm_read_reduce( | ||
| 33 | + ThreadEntity& thread, ChannelEntity& channel, uintptr_t localAddr, uintptr_t remoteAddr, uint64_t len, | ||
| 34 | + const Asc::ReduceIn& reduceIn); | ||
| 35 | +AsccommResult asccomm_batch_transfer( | ||
| 36 | + ThreadEntity& thread, ChannelEntity& channel, const AsccommBatchTransferDesc* transferDescs, | ||
| 37 | + uint32_t transferDescNum); | ||
| 38 | +AsccommResult asccomm_notify_record(ThreadEntity& thread, ChannelEntity& channel, uint32_t remoteNotifyIdx); | ||
| 39 | +AsccommResult asccomm_notify_wait( | ||
| 40 | + ThreadEntity& thread, const ChannelEntity& channel, uint32_t localNotifyIdx, uint32_t timeout); | ||
| 41 | +AsccommResult asccomm_fence(ChannelEntity& channel); | ||
| 42 | +AsccommResult asccomm_drain(ThreadEntity& thread, ChannelEntity& channel); | ||
| 43 | + | ||
| 44 | +#endif // ASCCOMM_TRANSPORT_H | ||
| @@ -0,0 +1,86 @@ | |||
| 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 ASCCOMM_BACKEND_TYPES_H | ||
| 12 | +#define ASCCOMM_BACKEND_TYPES_H | ||
| 13 | + | ||
| 14 | +#include <stdint.h> | ||
| 15 | + | ||
| 16 | +namespace Asc { | ||
| 17 | + | ||
| 18 | +class DataType { | ||
| 19 | +public: | ||
| 20 | + enum Value : uint8_t { | ||
| 21 | + INT8, | ||
| 22 | + INT16, | ||
| 23 | + INT32, | ||
| 24 | + FP16, | ||
| 25 | + FP32, | ||
| 26 | + INT64, | ||
| 27 | + UINT64, | ||
| 28 | + UINT8, | ||
| 29 | + UINT16, | ||
| 30 | + UINT32, | ||
| 31 | + FP64, | ||
| 32 | + BFP16, | ||
| 33 | + INT128, | ||
| 34 | + BF16_SAT, | ||
| 35 | + HIF8, | ||
| 36 | + FP8E4M3, | ||
| 37 | + FP8E5M2, | ||
| 38 | + FP8E8M0, | ||
| 39 | + COUNT, | ||
| 40 | + INVALID | ||
| 41 | + }; | ||
| 42 | + | ||
| 43 | + constexpr DataType() = default; | ||
| 44 | + constexpr DataType(Value value) : value_(value) {} | ||
| 45 | + constexpr operator Value() const { return value_; } | ||
| 46 | + | ||
| 47 | +private: | ||
| 48 | + Value value_{INVALID}; | ||
| 49 | +}; | ||
| 50 | + | ||
| 51 | +class ReduceOp { | ||
| 52 | +public: | ||
| 53 | + enum Value : uint8_t { SUM, PROD, MAX, MIN, EQUAL, COUNT, INVALID }; | ||
| 54 | + | ||
| 55 | + constexpr ReduceOp() = default; | ||
| 56 | + constexpr ReduceOp(Value value) : value_(value) {} | ||
| 57 | + constexpr operator Value() const { return value_; } | ||
| 58 | + | ||
| 59 | +private: | ||
| 60 | + Value value_{INVALID}; | ||
| 61 | +}; | ||
| 62 | + | ||
| 63 | +struct ReduceIn { | ||
| 64 | + DataType dataType; | ||
| 65 | + ReduceOp reduceOp; | ||
| 66 | + | ||
| 67 | + constexpr ReduceIn(DataType dataTypeValue, ReduceOp reduceOpValue) | ||
| 68 | + : dataType(dataTypeValue), reduceOp(reduceOpValue) | ||
| 69 | + {} | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +struct SqeConfigLite { | ||
| 73 | + SqeConfigLite() : placeOdr(1), compOrder(1), fence(1) {} | ||
| 74 | + bool cqeEn{true}; | ||
| 75 | + uint8_t placeOdr : 2; | ||
| 76 | + uint8_t compOrder : 1; | ||
| 77 | + uint8_t fence : 1; | ||
| 78 | +}; | ||
| 79 | + | ||
| 80 | +struct ConnLiteOperationOut { | ||
| 81 | + uint16_t pi{0}; | ||
| 82 | +}; | ||
| 83 | + | ||
| 84 | +} // namespace Asc | ||
| 85 | + | ||
| 86 | +#endif // ASCCOMM_BACKEND_TYPES_H | ||
| @@ -0,0 +1,536 @@ | |||
| 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 RDMA_VENDOR_1825_OPS_H | ||
| 12 | +#define RDMA_VENDOR_1825_OPS_H | ||
| 13 | + | ||
| 14 | +#include "rdma_vendor_base_ops.h" | ||
| 15 | + | ||
| 16 | +namespace Asc { | ||
| 17 | + | ||
| 18 | +// 先默认所有WQE都只占一个WQEBB | ||
| 19 | +#define WQEBB_SHIFT 6 | ||
| 20 | + | ||
| 21 | +#define ROCE_WQE_OWNERBIT_SHIFT 7 | ||
| 22 | +#define ROCE_WQE_CTRL_VALUE 0x40 | ||
| 23 | +#define ROCE_SQ_VA_VALUE 0x20 | ||
| 24 | +#define ROCE_SQ_SIGNAL_SHIFT 7 | ||
| 25 | +#define ROCE_WQE_CQE_SIGNAL_SHIFT 7 | ||
| 26 | +#define ROCE_WQE_CMP_TASK_LEN1 1u /* wqe cl is set to 1 */ | ||
| 27 | +#define ROCE_WQE_CMP_TASK_LEN_SHIFT 28 | ||
| 28 | +#define ROCE_TASK_SEG_ALIGN 8 | ||
| 29 | +#define ROCE_WQE_FAST_DMA_SHIFT 10 | ||
| 30 | +#define ROCE_WQE_SSN_MASK 0x3 | ||
| 31 | +#define ROCE_WQE_SSN_SHIFT 12 | ||
| 32 | +#define ROCE_WQE_DATA_SEG_SHIFT 4 | ||
| 33 | +#define ROCE_WQE_TASK_SEG_LAST_EXT_LEN 4 | ||
| 34 | +#define ROCE_WQE_TASK_REDUCE_OP_OFFSET 4 | ||
| 35 | +#define WQE_SECTION_ALIGN_SHIFT 3 | ||
| 36 | + | ||
| 37 | +#define ROCE_WQE_NEXT_SGE_INVALID (1u << 31) | ||
| 38 | + | ||
| 39 | +using Roce3CtrlSeg = struct { | ||
| 40 | + // Control Segment | ||
| 41 | + uint8_t owner_sl; /* ownerbit:ctrl_section_length:csl:dif_sl = 1:2:2:3; */ | ||
| 42 | + uint8_t df_tsl; /* cr:df:va:tal = 1:1:1:5; */ | ||
| 43 | + uint16_t wf_bdsl; /* cf:wf:wqe_msn:fde:fast:drvsl:bdsl = 1:1:2:1:1:2:8; */ | ||
| 44 | + uint32_t cl_pi; /* cl:signature:mask_pi = 4:8:20; */ | ||
| 45 | + uint64_t db; /* used by direct wqe*/ | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +union Roce3TaskSeg { | ||
| 49 | + struct { | ||
| 50 | + uint32_t xrcSrqn : 18; | ||
| 51 | + uint32_t ext : 1; | ||
| 52 | + uint32_t dif : 1; | ||
| 53 | + uint32_t rsvd0 : 3; | ||
| 54 | + uint32_t so : 1; | ||
| 55 | + uint32_t opType : 5; | ||
| 56 | + uint32_t signal : 1; | ||
| 57 | + uint32_t fence : 1; | ||
| 58 | + uint32_t se : 1; /* solited event flag; */ | ||
| 59 | + } dw0; | ||
| 60 | + uint32_t value; | ||
| 61 | +}; | ||
| 62 | + | ||
| 63 | +using Roce3TaskWqeSeg = struct { | ||
| 64 | + // Task Wqe Segment | ||
| 65 | + union Roce3TaskSeg tskSeg; | ||
| 66 | + uint32_t dataLen; | ||
| 67 | + uint32_t immData; | ||
| 68 | + union { | ||
| 69 | + struct { | ||
| 70 | + uint32_t lastExtLen : 8; | ||
| 71 | + uint32_t cmdLen : 8; | ||
| 72 | + uint32_t pi : 16; | ||
| 73 | + } bs; | ||
| 74 | + | ||
| 75 | + uint32_t feth; /* cflush feth header */ | ||
| 76 | + uint32_t value; | ||
| 77 | + } dw3; | ||
| 78 | + uint64_t va; /* to indicate remote buf address; */ | ||
| 79 | + uint32_t rkey; /* to indicate remote mr buf; */ | ||
| 80 | + uint32_t ulp; /* ulp预留字段 */ | ||
| 81 | +}; | ||
| 82 | + | ||
| 83 | +static constexpr uint32_t DTYPE_INVALID = 0xFFu; | ||
| 84 | + | ||
| 85 | +static const uint32_t Roce3ReduceDataTypeMap[] = { | ||
| 86 | + /* [DINT8] = */ 0x0, // INT8 | ||
| 87 | + /* [DINT16] = */ 0x1, // INT16 | ||
| 88 | + /* [DINT32] = */ 0x2, // INT32 | ||
| 89 | + /* [DFP16] = */ 0x6, // FP16_NORMAL | ||
| 90 | + /* [DFP32] = */ 0x7, // FP32 | ||
| 91 | + /* [DINT64] = */ DTYPE_INVALID, // 硬件不支持 | ||
| 92 | + /* [DUINT32] = */ DTYPE_INVALID, // 硬件不支持 | ||
| 93 | +}; | ||
| 94 | + | ||
| 95 | +static const uint32_t Roce3ReduceOpTypeMap[] = { | ||
| 96 | + /* [SUM] = */ 0xA, // ADD | ||
| 97 | + /* [PROD] = */ DTYPE_INVALID, // 求积, 硬件不支持 | ||
| 98 | + /* [MAX] = */ 0x8, // MAX | ||
| 99 | + /* [MIN] = */ 0x9, // MIN | ||
| 100 | + /* [EQUAL] = */ 0xB, // EQUAL | ||
HcommDataType 这些可以换成AsccommDataType