Merged
fix: align AICPU entity ABI with hcomm #268
ca1kwAdd on 26 days ago
fix: align AICPU entity ABI with hcomm #268
Merged
ca1kwAdd on 26 days ago
Total: 8 files changed+193-164
@@ -168,17 +168,15 @@ typedef struct {
168 } contextInfo;168 } contextInfo;
169} CqContext;169} CqContext;
170 170 
171-#define HCOMM_RESOURCE_CHANNEL_VERSION 0U ///< Channel resource ABI版本号171+#define HCOMM_CHANNEL_ENTITY_VERSION 0U //< Channel resource ABI版本号
172-#define HCOMM_RESOURCE_CHANNEL_MAGIC_WORD 0x0fcf0f5fU ///< Channel 资源合法性校验魔术字172+#define HCOMM_CHANNEL_ENTITY_MAGIC_WORD 0x0fcf0f5fU //< Channel 资源合法性校验魔术字
173-#define HCOMM_RESOURCE_THREAD_VERSION 0U ///< Thread resource ABI版本号173+#define HCOMM_THREAD_ENTITY_VERSION 0U //< Thread resource ABI版本号
174-#define HCOMM_RESOURCE_THREAD_MAGIC_WORD 0x0fcf0f6fU ///< Thread 资源合法性校验魔术字174+#define HCOMM_THREAD_ENTITY_MAGIC_WORD 0x0fcf0f6fU //< Thread 资源合法性校验魔术字
175-#define HCOMM_RESOURCE_RTSQ_SQE_SIZE 64U ///< 单个RTSQ SQE占用字节数175+#define HCOMM_RESOURCE_RTSQ_SQE_SIZE 64U //< 单个RTSQ SQE占用字节数
176-#define HCOMM_RESOURCE_RTSQ_BATCH_SIZE 128U ///< 本地最多缓存的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数量177+#define HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE 1024U //< 单次申请的RTSQ Task ID数量
178-#define HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE 256U ///< Channel resource ABI固定大小178+#define HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE 256U //< Channel resource ABI固定大小
179-#define HCOMM_RESOURCE_THREAD_ENTITY_SIZE 256U ///< Thread resource ABI固定大小179+#define HCOMM_RESOURCE_THREAD_ENTITY_SIZE 256U //< Thread resource ABI固定大小
180- 
181-#pragma pack(push, 4)
182 180 
183typedef enum {181typedef enum {
184 HCOMM_PROTECTION_TYPE_INVALID = -1,182 HCOMM_PROTECTION_TYPE_INVALID = -1,
@@ -280,8 +278,6 @@ typedef struct {
280 278 
281typedef struct {279typedef struct {
282 HcommSqContextType type; ///< SQ上下文类型280 HcommSqContextType type; ///< SQ上下文类型
283- uint8_t fence; ///< 一次性Fence标志,由下一次相关传输消费并清零(独立字段,不与union重叠)
284- uint8_t reserved[3]; ///< 对齐保留
285 union {281 union {
286 struct {282 struct {
287 uint64_t sqVa; ///< UB SQ的CPU虚拟地址(WQE写入位置)283 uint64_t sqVa; ///< UB SQ的CPU虚拟地址(WQE写入位置)
@@ -312,8 +308,10 @@ typedef struct {
312 uint32_t sqHead; ///< 软件维护的SQ生产者索引308 uint32_t sqHead; ///< 软件维护的SQ生产者索引
313 uint32_t sqTail; ///< 已完成WQE计数309 uint32_t sqTail; ///< 已完成WQE计数
314 } roceSq;310 } roceSq;
315- uint8_t raws[120];311+ uint8_t raws[112];
316 } contextInfo;312 } contextInfo;
313+ uint8_t fence; ///< 一次性Fence标志,由下一次相关传输消费并清零(独立字段,不与union重叠)
314+ uint8_t reserved[3]; ///< 对齐保留
317} HcommSqContext;315} HcommSqContext;
318 316 
319typedef struct {317typedef struct {
@@ -341,23 +339,22 @@ typedef struct {
341 uint32_t cqTail; ///< 已消费CQE计数339 uint32_t cqTail; ///< 已消费CQE计数
342 uint8_t cqDbFlush; ///< 是否需要刷新CQ软件Doorbell340 uint8_t cqDbFlush; ///< 是否需要刷新CQ软件Doorbell
343 } roceCq;341 } roceCq;
344- uint8_t raws[124];342+ uint8_t raws[120];
345 } contextInfo;343 } contextInfo;
346} HcommCqContext;344} HcommCqContext;
347 345 
348typedef struct {346typedef struct {
349- uint32_t version; ///< 设备信息结构版本号347+ uint32_t chipVersion; ///< 预留芯片版本字段,当前默认0
350- uint32_t devId; ///< 设备物理或逻辑ID,由资源创建端约定348+ uint32_t devPhyId; ///< Host 侧 NPU 物理设备 ID;Device 侧可转换为本地设备 ID
351- uint8_t dieId; ///< 设备Die编号(UB doorbell jetty三元素之一)349+ uint8_t dieId; ///< 设备Die编号(UB doorbell jetty三元素之一)
352- uint8_t funcId; ///< 设备Function编号(UB doorbell jetty三元素之一)350+ uint8_t funcId; ///< 设备Function编号(UB doorbell jetty三元素之一)
353- uint8_t reserve[30]; ///< 设备信息扩展空间,创建资源时置0351+ uint8_t reserve[30]; ///< 设备信息扩展空间,创建资源时置0
354} HcommDevInfo;352} HcommDevInfo;
355 353 
356typedef struct {354typedef struct {
357 CommAbiHeader abiHeader;355 CommAbiHeader abiHeader;
358 CommEngine engine;356 CommEngine engine;
359 CommProtocol protocol;357 CommProtocol protocol;
360- HcommDevInfo devInfo; ///< Channel本地通信资源所属设备信息(dieId/funcId为doorbell唯一来源)
361 uint32_t localNotifyNum;358 uint32_t localNotifyNum;
362 uint32_t remoteNotifyNum;359 uint32_t remoteNotifyNum;
363 uint32_t localBufferNum;360 uint32_t localBufferNum;
@@ -370,40 +367,43 @@ typedef struct {
370 HcommRegedBufferEntity* remoteBufferAddr;367 HcommRegedBufferEntity* remoteBufferAddr;
371 HcommSqContext* sqContextAddr;368 HcommSqContext* sqContextAddr;
372 HcommCqContext* cqContextAddr;369 HcommCqContext* cqContextAddr;
370+ HcommDevInfo devInfo; ///< Channel本地通信资源所属设备信息(dieId/funcId为doorbell唯一来源)
373 ChannelHandle originChannelHandle; ///< 控制面原始Channel句柄值;数据面只作关联信息,不解引用371 ChannelHandle originChannelHandle; ///< 控制面原始Channel句柄值;数据面只作关联信息,不解引用
372+ uint8_t reserve[112]; ///< 固定256字节ABI的预留扩展空间
374} ChannelEntity;373} ChannelEntity;
375 374 
376// RTSQ硬件字段由HCOMM控制面在资源构造阶段查询并填充;数据面只消费初始快照,375// RTSQ硬件字段由HCOMM控制面在资源构造阶段查询并填充;数据面只消费初始快照,
377// 并在提交过程中维护运行态head/tail。376// 并在提交过程中维护运行态head/tail。
378typedef struct {377typedef struct {
379- uint32_t localDevId; ///< 调用halSqCqQuery/halSqCqConfig使用的本地设备ID(控制面填充)378+ uint32_t type;
380- uint32_t streamId; ///< RTSQ关联的Stream ID,写入部分SQE或用于诊断379+ union {
381- uint32_t sqId; ///< 硬件RTSQ编号380+ struct {
382- uint32_t sqDepth; ///< 硬件RTSQ可容纳的SQE数量381+ uint32_t streamId;
383- uint32_t sqHead; ///< 最近一次查询到的硬件RTSQ Head382+ uint32_t sqId;
384- uint32_t sqTail; ///< 资源运行时维护的硬件RTSQ Tail383+ uint64_t sqBaseAddr;
385- uint64_t sqBaseAddr; ///< 硬件RTSQ SQE环形缓冲区的CPU虚拟地址384+ uint32_t sqDepth;
386- uint64_t localSqeAddr; ///< 控制面申请、数据面维护的本地SQE缓存地址385+ uint32_t sqHead;
387- uint32_t taskId; ///< 数据面下一次使用的Task ID,控制面创建资源时置0386+ uint32_t sqTail;
388- uint32_t taskIdEnd; ///< 当前已申请Task ID区间的开区间上界,控制面创建资源时置0387+ uint32_t taskId;
389- uint32_t pendingSqeCnt; ///< 本地缓存中尚未提交的SQE数量388+ uint32_t taskIdEnd;
390- uint8_t launchFlag; ///< 非0时在非Batch模式下每生成一个SQE立即提交389+ uint64_t localSqAddr; ///< 本地SQE暂存缓冲区起始地址,控制面创建Entity时填充
391- uint8_t reserved[3]; ///< RTSQ状态扩展及对齐空间,创建资源时置0390+ uint32_t localSqDepth; ///< 本地SQE暂存缓冲区可容纳的SQE数量
392-} HcommRtsqContext;391+ uint32_t pendingSqeCnt; ///< 已写入本地SQE暂存缓冲区、尚未提交到硬件RTSQ的SQE数量
392+ } RtsqContext;
393+ uint8_t raw[120];
394+ } contextInfo;
395+} HcommThreadSqContext; // 128B
393 396 
394typedef struct {397typedef struct {
395 CommAbiHeader abiHeader; ///< ABI版本、魔术字和结构大小,用于句柄合法性校验398 CommAbiHeader abiHeader; ///< ABI版本、魔术字和结构大小,用于句柄合法性校验
396 HcommDevInfo devInfo; ///< Thread所属设备信息399 HcommDevInfo devInfo; ///< Thread所属设备信息
397 uint32_t localNotifyNum; ///< localNotifyAddr数组元素个数400 uint32_t localNotifyNum; ///< localNotifyAddr数组元素个数
398 HcommRegedNotifyEntity* localNotifyAddr; ///< Thread本地Notify数组,用于线程间Record/Wait(type=IPC_RT)401 HcommRegedNotifyEntity* localNotifyAddr; ///< Thread本地Notify数组,用于线程间Record/Wait(type=IPC_RT)
399- HcommRtsqContext* sqContextAddr; ///< Thread直接持有的resource RTSQ运行上下文402+ HcommThreadSqContext* sqContextAddr; ///< Thread直接持有的resource RTSQ运行上下文
400 ThreadHandle originThreadHandle; ///< 控制面原始Thread句柄值;数据面只作关联信息,不解引用403 ThreadHandle originThreadHandle; ///< 控制面原始Thread句柄值;数据面只作关联信息,不解引用
401- uint8_t raw[172]; ///< Thread固定256字节中的ABI预留扩展空间404+ uint8_t raw[168]; ///< Thread固定256字节中的ABI预留扩展空间
402- 
403} ThreadEntity;405} ThreadEntity;
404 406 
405-#pragma pack(pop)
406- 
407#ifdef __cplusplus407#ifdef __cplusplus
408}408}
409#endif409#endif
@@ -423,11 +423,7 @@ static_assert(std::is_pod<HcommCqContext>::value, "HcommCqContext must be POD");
423static_assert(423static_assert(
424 sizeof(ChannelEntity) <= HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE, "ChannelEntity ABI size must not exceed 256 bytes");424 sizeof(ChannelEntity) <= HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE, "ChannelEntity ABI size must not exceed 256 bytes");
425static_assert(sizeof(ThreadEntity) == HCOMM_RESOURCE_THREAD_ENTITY_SIZE, "ThreadEntity ABI size must be 256 bytes");425static_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");426+static_assert(sizeof(ChannelEntity) == HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE, "ChannelEntity ABI size must be 256 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");
431static_assert(427static_assert(
432 offsetof(ChannelEntity, originChannelHandle) + sizeof(ChannelHandle) <= HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE,428 offsetof(ChannelEntity, originChannelHandle) + sizeof(ChannelHandle) <= HCOMM_RESOURCE_CHANNEL_ENTITY_SIZE,
433 "ChannelEntity origin handle must fit in the fixed ABI storage");429 "ChannelEntity origin handle must fit in the fixed ABI storage");
@@ -50,9 +50,11 @@ AsccommResult get_thread_entity(ThreadHandle thread, bool registerThread, bool r
50 // The public ThreadHandle is the device resource entity address. The control50 // The public ThreadHandle is the device resource entity address. The control
51 // plane performs the original-handle -> POD conversion before launch.51 // plane performs the original-handle -> POD conversion before launch.
52 threadEntity = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(thread));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));53+ CHK_RET(validate_entity(threadEntity, HCOMM_THREAD_ENTITY_VERSION, HCOMM_THREAD_ENTITY_MAGIC_WORD));
54- CHK_PTR_NULL(threadEntity->sqContextAddr);54+ // A host stream can be exported as a notify-only thread entity. Such an entity
55+ // has no RTSQ, so only callers that submit work through the thread require it.
55 if (resolveRtsq) {56 if (resolveRtsq) {
57+ CHK_PTR_NULL(threadEntity->sqContextAddr);
56 CHK_RET(asccomm_resolve_thread_rtsq(threadEntity));58 CHK_RET(asccomm_resolve_thread_rtsq(threadEntity));
57 }59 }
58 if (registerThread) {60 if (registerThread) {
@@ -67,7 +69,7 @@ AsccommResult get_context(ThreadHandle thread, ChannelHandle channel, bool regis
67 CHK_RET(get_thread_entity(thread, registerThread, true, context.thread));69 CHK_RET(get_thread_entity(thread, registerThread, true, context.thread));
68 // ChannelHandle follows the same resource-address ABI as ThreadHandle.70 // ChannelHandle follows the same resource-address ABI as ThreadHandle.
69 context.channel = reinterpret_cast<ChannelEntity*>(static_cast<uintptr_t>(channel));71 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));72+ CHK_RET(validate_entity(context.channel, HCOMM_CHANNEL_ENTITY_VERSION, HCOMM_CHANNEL_ENTITY_MAGIC_WORD));
71 return ASCCOMM_SUCCESS;73 return ASCCOMM_SUCCESS;
72}74}
73 75 
@@ -252,8 +254,8 @@ int32_t asccomm_local_copy_on_thread(ThreadHandle thread, void* dst, const void*
252 const uint64_t remaining = len - offset;254 const uint64_t remaining = len - offset;
253 const uint64_t realSize = remaining > SDMA_SEND_MAX_SIZE ? SDMA_SEND_MAX_SIZE : remaining;255 const uint64_t realSize = remaining > SDMA_SEND_MAX_SIZE ? SDMA_SEND_MAX_SIZE : remaining;
254 CHK_RET(asccomm_rtsq_sdma_copy(256 CHK_RET(asccomm_rtsq_sdma_copy(
255- *threadEntity->sqContextAddr, reinterpret_cast<uintptr_t>(dst) + offset,257+ *threadEntity, reinterpret_cast<uintptr_t>(dst) + offset, reinterpret_cast<uintptr_t>(src) + offset,
256- reinterpret_cast<uintptr_t>(src) + offset, static_cast<uint32_t>(realSize)));258+ static_cast<uint32_t>(realSize)));
257 offset += realSize;259 offset += realSize;
258 }260 }
259 return ASCCOMM_SUCCESS;261 return ASCCOMM_SUCCESS;
@@ -277,8 +279,8 @@ int32_t asccomm_local_reduce_on_thread(
277 const uint64_t remaining = len - offset;279 const uint64_t remaining = len - offset;
278 const uint64_t realSize = remaining > SDMA_SEND_MAX_SIZE ? SDMA_SEND_MAX_SIZE : remaining;280 const uint64_t realSize = remaining > SDMA_SEND_MAX_SIZE ? SDMA_SEND_MAX_SIZE : remaining;
279 CHK_RET(asccomm_rtsq_sdma_reduce(281 CHK_RET(asccomm_rtsq_sdma_reduce(
280- *threadEntity->sqContextAddr, reinterpret_cast<uintptr_t>(dst) + offset,282+ *threadEntity, reinterpret_cast<uintptr_t>(dst) + offset, reinterpret_cast<uintptr_t>(src) + offset,
281- reinterpret_cast<uintptr_t>(src) + offset, static_cast<uint32_t>(realSize), reduceIn));283+ static_cast<uint32_t>(realSize), reduceIn));
282 offset += realSize;284 offset += realSize;
283 }285 }
284 return ASCCOMM_SUCCESS;286 return ASCCOMM_SUCCESS;
@@ -294,7 +296,7 @@ int32_t asccomm_thread_notify_record_on_thread(ThreadHandle thread, ThreadHandle
294 CHK_RET(get_thread_entity(dstThread, false, false, dstThreadEntity));296 CHK_RET(get_thread_entity(dstThread, false, false, dstThreadEntity));
295 uint32_t notifyId = 0;297 uint32_t notifyId = 0;
296 CHK_RET(get_thread_notify_id(*dstThreadEntity, dstNotifyIdx, notifyId));298 CHK_RET(get_thread_notify_id(*dstThreadEntity, dstNotifyIdx, notifyId));
297- return asccomm_rtsq_notify_record(*threadEntity->sqContextAddr, notifyId);299+ return asccomm_rtsq_notify_record(*threadEntity, notifyId);
298 });300 });
299}301}
300 302 
@@ -305,7 +307,7 @@ int32_t asccomm_thread_notify_wait_on_thread(ThreadHandle thread, uint32_t notif
305 CHK_RET(get_thread_entity(thread, true, true, threadEntity));307 CHK_RET(get_thread_entity(thread, true, true, threadEntity));
306 uint32_t notifyId = 0;308 uint32_t notifyId = 0;
307 CHK_RET(get_thread_notify_id(*threadEntity, notifyIdx, notifyId));309 CHK_RET(get_thread_notify_id(*threadEntity, notifyIdx, notifyId));
308- return asccomm_rtsq_notify_wait(*threadEntity->sqContextAddr, notifyId, timeOut);310+ return asccomm_rtsq_notify_wait(*threadEntity, notifyId, timeOut);
309 });311 });
310}312}
311 313 
@@ -314,7 +316,7 @@ int32_t asccomm_aclrt_notify_record_on_thread(ThreadHandle thread, uint64_t dstN
314 return execute_api([&]() {316 return execute_api([&]() {
315 ThreadEntity* threadEntity = nullptr;317 ThreadEntity* threadEntity = nullptr;
316 CHK_RET(get_thread_entity(thread, true, true, threadEntity));318 CHK_RET(get_thread_entity(thread, true, true, threadEntity));
317- return asccomm_rtsq_notify_record(*threadEntity->sqContextAddr, static_cast<uint32_t>(dstNotifyId));319+ return asccomm_rtsq_notify_record(*threadEntity, static_cast<uint32_t>(dstNotifyId));
318 });320 });
319}321}
320 322 
@@ -323,7 +325,7 @@ int32_t asccomm_aclrt_notify_wait_on_thread(ThreadHandle thread, uint64_t notify
323 return execute_api([&]() {325 return execute_api([&]() {
324 ThreadEntity* threadEntity = nullptr;326 ThreadEntity* threadEntity = nullptr;
325 CHK_RET(get_thread_entity(thread, true, true, threadEntity));327 CHK_RET(get_thread_entity(thread, true, true, threadEntity));
326- return asccomm_rtsq_notify_wait(*threadEntity->sqContextAddr, static_cast<uint32_t>(notifyId), timeOut);328+ return asccomm_rtsq_notify_wait(*threadEntity, static_cast<uint32_t>(notifyId), timeOut);
327 });329 });
328}330}
329 331 
@@ -477,7 +479,7 @@ int32_t asccomm_thread_notify_wait_on_thread_with_default_timeout(ThreadHandle t
477 CHK_RET(get_thread_entity(thread, true, true, threadEntity));479 CHK_RET(get_thread_entity(thread, true, true, threadEntity));
478 uint32_t notifyId = 0;480 uint32_t notifyId = 0;
479 CHK_RET(get_thread_notify_id(*threadEntity, notifyIdx, notifyId));481 CHK_RET(get_thread_notify_id(*threadEntity, notifyIdx, notifyId));
480- return asccomm_rtsq_notify_wait(*threadEntity->sqContextAddr, notifyId, timeout);482+ return asccomm_rtsq_notify_wait(*threadEntity, notifyId, timeout);
481 });483 });
482}484}
483 485 
@@ -23,31 +23,34 @@ void __attribute__((weak)) __attribute__((visibility("default"))) GetSqeId(
23}23}
24 24 
25namespace {25namespace {
26+using HcommRtsqContext = decltype(((HcommThreadSqContext*)nullptr)->contextInfo.RtsqContext);
26 27 
27-AsccommResult acquire_task_id(HcommRtsqContext& context, uint32_t& taskId)28+AsccommResult acquire_task_id(HcommThreadSqContext& contextOuter, uint32_t& taskId)
28{29{
30+ HcommRtsqContext& rtsq = contextOuter.contextInfo.RtsqContext;
29 CHK_PRT_RET(31 CHK_PRT_RET(
30- context.localSqeAddr == 0, ASCCOMM_ERROR("[%s] local SQE buffer address is 0.", __func__), ASCCOMM_E_PTR);32+ contextOuter.type != HCOMM_SQ_CONTEXT_TYPE_UB_JFS || rtsq.localSqAddr == 0,
33+ ASCCOMM_ERROR("[%s] invalid local SQE buffer.", __func__), ASCCOMM_E_PTR);
31 CHK_PRT_RET(34 CHK_PRT_RET(
32- context.pendingSqeCnt >= HCOMM_RESOURCE_RTSQ_BATCH_SIZE,35+ rtsq.pendingSqeCnt >= HCOMM_RESOURCE_RTSQ_BATCH_SIZE,
33- ASCCOMM_ERROR("[%s] pending SQE count[%u] exceeds buffer capacity.", __func__, context.pendingSqeCnt),36+ ASCCOMM_ERROR("[%s] pending SQE count[%u] exceeds buffer capacity.", __func__, rtsq.pendingSqeCnt),
34 ASCCOMM_E_INTERNAL);37 ASCCOMM_E_INTERNAL);
35- if (context.taskId >= context.taskIdEnd) {38+ if (rtsq.taskId >= rtsq.taskIdEnd) {
36 CHK_PRT_RET(39 CHK_PRT_RET(
37 aicpu::GetSqeId == nullptr, ASCCOMM_ERROR("[%s] GetSqeId is unavailable.", __func__), ASCCOMM_E_INTERNAL);40 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);41+ aicpu::GetSqeId(HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE, rtsq.taskId, rtsq.taskIdEnd);
39 CHK_PRT_RET(42 CHK_PRT_RET(
40- context.taskId >= context.taskIdEnd ||43+ rtsq.taskId >= rtsq.taskIdEnd || rtsq.taskIdEnd - rtsq.taskId > HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE,
41- context.taskIdEnd - context.taskId > HCOMM_RESOURCE_RTSQ_TASK_ID_BATCH_SIZE,44+ ASCCOMM_ERROR("[%s] invalid Task ID range[%u, %u).", __func__, rtsq.taskId, rtsq.taskIdEnd),
42- ASCCOMM_ERROR("[%s] invalid Task ID range[%u, %u).", __func__, context.taskId, context.taskIdEnd),
43 ASCCOMM_E_INTERNAL);45 ASCCOMM_E_INTERNAL);
44 }46 }
45- taskId = context.taskId;47+ taskId = rtsq.taskId;
46- ++context.taskId;48+ ++rtsq.taskId;
47 return ASCCOMM_SUCCESS;49 return ASCCOMM_SUCCESS;
48}50}
49 51 
50-AsccommResult query_sq_value(const HcommRtsqContext& context, drvSqCqPropType_t property, uint32_t& value)52+AsccommResult query_sq_value(
53+ uint32_t localDevId, const HcommRtsqContext& context, drvSqCqPropType_t property, uint32_t& value)
51{54{
52 halSqCqQueryInfo queryInfo{};55 halSqCqQueryInfo queryInfo{};
53 queryInfo.tsId = 0;56 queryInfo.tsId = 0;
@@ -55,18 +58,18 @@ AsccommResult query_sq_value(const HcommRtsqContext& context, drvSqCqPropType_t
55 queryInfo.cqId = 0;58 queryInfo.cqId = 0;
56 queryInfo.type = DRV_NORMAL_TYPE;59 queryInfo.type = DRV_NORMAL_TYPE;
57 queryInfo.prop = property;60 queryInfo.prop = property;
58- drvError_t ret = halSqCqQuery(context.localDevId, &queryInfo);61+ drvError_t ret = halSqCqQuery(localDevId, &queryInfo);
59 CHK_PRT_RET(62 CHK_PRT_RET(
60 ret != 0,63 ret != 0,
61 ASCCOMM_ERROR(64 ASCCOMM_ERROR(
62- "[%s] halSqCqQuery failed, localDevId[%u], sqId[%u], property[%u], ret[%d].", __func__, context.localDevId,65+ "[%s] halSqCqQuery failed, localDevId[%u], sqId[%u], property[%u], ret[%d].", __func__, localDevId,
63 context.sqId, property, ret),66 context.sqId, property, ret),
64 ASCCOMM_E_INTERNAL);67 ASCCOMM_E_INTERNAL);
65 value = queryInfo.value[0];68 value = queryInfo.value[0];
66 return ASCCOMM_SUCCESS;69 return ASCCOMM_SUCCESS;
67}70}
68 71 
69-AsccommResult query_sq_base(const HcommRtsqContext& context, uint64_t& value)72+AsccommResult query_sq_base(uint32_t localDevId, const HcommRtsqContext& context, uint64_t& value)
70{73{
71 halSqCqQueryInfo queryInfo{};74 halSqCqQueryInfo queryInfo{};
72 queryInfo.tsId = 0;75 queryInfo.tsId = 0;
@@ -74,18 +77,17 @@ AsccommResult query_sq_base(const HcommRtsqContext& context, uint64_t& value)
74 queryInfo.cqId = 0;77 queryInfo.cqId = 0;
75 queryInfo.type = DRV_NORMAL_TYPE;78 queryInfo.type = DRV_NORMAL_TYPE;
76 queryInfo.prop = DRV_SQCQ_PROP_SQ_BASE;79 queryInfo.prop = DRV_SQCQ_PROP_SQ_BASE;
77- drvError_t ret = halSqCqQuery(context.localDevId, &queryInfo);80+ drvError_t ret = halSqCqQuery(localDevId, &queryInfo);
78 CHK_PRT_RET(81 CHK_PRT_RET(
79 ret != 0,82 ret != 0,
80 ASCCOMM_ERROR(83 ASCCOMM_ERROR(
81- "[%s] halSqCqQuery failed, localDevId[%u], sqId[%u], ret[%d].", __func__, context.localDevId, context.sqId,84+ "[%s] halSqCqQuery failed, localDevId[%u], sqId[%u], ret[%d].", __func__, localDevId, context.sqId, ret),
82- ret),
83 ASCCOMM_E_INTERNAL);85 ASCCOMM_E_INTERNAL);
84 value = (static_cast<uint64_t>(queryInfo.value[1]) << 32U) | queryInfo.value[0];86 value = (static_cast<uint64_t>(queryInfo.value[1]) << 32U) | queryInfo.value[0];
85 return ASCCOMM_SUCCESS;87 return ASCCOMM_SUCCESS;
86}88}
87 89 
88-AsccommResult config_sq_tail(const HcommRtsqContext& context, uint32_t value)90+AsccommResult config_sq_tail(uint32_t localDevId, const HcommRtsqContext& context, uint32_t value)
89{91{
90 halSqCqConfigInfo configInfo{};92 halSqCqConfigInfo configInfo{};
91 configInfo.tsId = 0;93 configInfo.tsId = 0;
@@ -94,11 +96,11 @@ AsccommResult config_sq_tail(const HcommRtsqContext& context, uint32_t value)
94 configInfo.type = DRV_NORMAL_TYPE;96 configInfo.type = DRV_NORMAL_TYPE;
95 configInfo.prop = DRV_SQCQ_PROP_SQ_TAIL;97 configInfo.prop = DRV_SQCQ_PROP_SQ_TAIL;
96 configInfo.value[0] = value;98 configInfo.value[0] = value;
97- drvError_t ret = halSqCqConfig(context.localDevId, &configInfo);99+ drvError_t ret = halSqCqConfig(localDevId, &configInfo);
98 CHK_PRT_RET(100 CHK_PRT_RET(
99 ret != 0,101 ret != 0,
100 ASCCOMM_ERROR(102 ASCCOMM_ERROR(
101- "[%s] halSqCqConfig failed, localDevId[%u], sqId[%u], tail[%u], ret[%d].", __func__, context.localDevId,103+ "[%s] halSqCqConfig failed, localDevId[%u], sqId[%u], tail[%u], ret[%d].", __func__, localDevId,
102 context.sqId, value, ret),104 context.sqId, value, ret),
103 ASCCOMM_E_INTERNAL);105 ASCCOMM_E_INTERNAL);
104 return ASCCOMM_SUCCESS;106 return ASCCOMM_SUCCESS;
@@ -113,13 +115,13 @@ uint32_t get_tail_to_head_distance(const HcommRtsqContext& context)
113 context.sqDepth - (context.sqTail - context.sqHead);115 context.sqDepth - (context.sqTail - context.sqHead);
114}116}
115 117 
116-AsccommResult ensure_queue_space(HcommRtsqContext& context)118+AsccommResult ensure_queue_space(uint32_t localDevId, HcommRtsqContext& context)
117{119{
118 auto startTime = std::chrono::steady_clock::now();120 auto startTime = std::chrono::steady_clock::now();
119 const uint32_t sqFullTimeout = asccomm_get_sq_full_timeout();121 const uint32_t sqFullTimeout = asccomm_get_sq_full_timeout();
120 uint32_t availableSpace = get_tail_to_head_distance(context);122 uint32_t availableSpace = get_tail_to_head_distance(context);
121 while (availableSpace <= context.pendingSqeCnt) {123 while (availableSpace <= context.pendingSqeCnt) {
122- CHK_RET(query_sq_value(context, DRV_SQCQ_PROP_SQ_HEAD, context.sqHead));124+ CHK_RET(query_sq_value(localDevId, context, DRV_SQCQ_PROP_SQ_HEAD, context.sqHead));
123 availableSpace = get_tail_to_head_distance(context);125 availableSpace = get_tail_to_head_distance(context);
124 if (availableSpace > context.pendingSqeCnt) {126 if (availableSpace > context.pendingSqeCnt) {
125 break;127 break;
@@ -140,8 +142,8 @@ AsccommResult ensure_queue_space(HcommRtsqContext& context)
140AsccommResult copy_pending_sqes(HcommRtsqContext& context)142AsccommResult copy_pending_sqes(HcommRtsqContext& context)
141{143{
142 CHK_PRT_RET(144 CHK_PRT_RET(
143- context.localSqeAddr == 0, ASCCOMM_ERROR("[%s] local SQE buffer address is 0.", __func__), ASCCOMM_E_PTR);145+ context.localSqAddr == 0, ASCCOMM_ERROR("[%s] local SQE buffer address is 0.", __func__), ASCCOMM_E_PTR);
144- auto* localSqeBuffer = reinterpret_cast<uint8_t*>(context.localSqeAddr);146+ auto* localSqeBuffer = reinterpret_cast<uint8_t*>(static_cast<uintptr_t>(context.localSqAddr));
145 const uint32_t byteCount = context.pendingSqeCnt * HCOMM_RESOURCE_RTSQ_SQE_SIZE;147 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;148 uint8_t* sqCurrent = reinterpret_cast<uint8_t*>(context.sqBaseAddr) + context.sqTail * HCOMM_RESOURCE_RTSQ_SQE_SIZE;
147 if (context.sqTail >= context.sqHead) {149 if (context.sqTail >= context.sqHead) {
@@ -167,31 +169,33 @@ AsccommResult copy_pending_sqes(HcommRtsqContext& context)
167 return ASCCOMM_SUCCESS;169 return ASCCOMM_SUCCESS;
168}170}
169 171 
170-AsccommResult refresh_rtsq(HcommRtsqContext& context)172+AsccommResult refresh_rtsq(ThreadEntity& thread)
171{173{
172- ++context.pendingSqeCnt;174+ HcommThreadSqContext& contextOuter = *thread.sqContextAddr;
173- if ((context.launchFlag != 0 && !asccomm_is_batch_launch_mode()) ||175+ HcommRtsqContext& rtsq = contextOuter.contextInfo.RtsqContext;
174- context.pendingSqeCnt == HCOMM_RESOURCE_RTSQ_BATCH_SIZE) {176+ ++rtsq.pendingSqeCnt;
175- return asccomm_rtsq_launch(context);177+ if (rtsq.pendingSqeCnt == HCOMM_RESOURCE_RTSQ_BATCH_SIZE) {
178+ return asccomm_rtsq_launch(thread);
176 }179 }
177 return ASCCOMM_SUCCESS;180 return ASCCOMM_SUCCESS;
178}181}
179 182 
180-uint8_t* get_current_sqe(HcommRtsqContext& context)183+uint8_t* get_current_sqe(HcommThreadSqContext& contextOuter)
181{184{
182- return reinterpret_cast<uint8_t*>(context.localSqeAddr) + context.pendingSqeCnt * HCOMM_RESOURCE_RTSQ_SQE_SIZE;185+ return reinterpret_cast<uint8_t*>(static_cast<uintptr_t>(contextOuter.contextInfo.RtsqContext.localSqAddr)) +
186+ contextOuter.contextInfo.RtsqContext.pendingSqeCnt * HCOMM_RESOURCE_RTSQ_SQE_SIZE;
183}187}
184 188 
185AsccommResult validate_thread_entity(ThreadEntity* thread)189AsccommResult validate_thread_entity(ThreadEntity* thread)
186{190{
187 CHK_PTR_NULL(thread);191 CHK_PTR_NULL(thread);
188 CHK_PRT_RET(192 CHK_PRT_RET(
189- thread->abiHeader.version != HCOMM_RESOURCE_THREAD_VERSION ||193+ thread->abiHeader.version != HCOMM_THREAD_ENTITY_VERSION ||
190- thread->abiHeader.magicWord != HCOMM_RESOURCE_THREAD_MAGIC_WORD ||194+ thread->abiHeader.magicWord != HCOMM_THREAD_ENTITY_MAGIC_WORD ||
191 thread->abiHeader.size < sizeof(ThreadEntity),195 thread->abiHeader.size < sizeof(ThreadEntity),
192 ASCCOMM_ERROR("[%s] invalid resource thread entity.", __func__), ASCCOMM_E_PARA);196 ASCCOMM_ERROR("[%s] invalid resource thread entity.", __func__), ASCCOMM_E_PARA);
193 CHK_PTR_NULL(thread->sqContextAddr);197 CHK_PTR_NULL(thread->sqContextAddr);
194- const HcommRtsqContext& rtsq = *thread->sqContextAddr;198+ const HcommRtsqContext& rtsq = thread->sqContextAddr->contextInfo.RtsqContext;
195 CHK_PRT_RET(199 CHK_PRT_RET(
196 rtsq.sqBaseAddr == 0 || rtsq.sqDepth == 0 || rtsq.sqHead >= rtsq.sqDepth || rtsq.sqTail >= rtsq.sqDepth,200 rtsq.sqBaseAddr == 0 || rtsq.sqDepth == 0 || rtsq.sqHead >= rtsq.sqDepth || rtsq.sqTail >= rtsq.sqDepth,
197 ASCCOMM_ERROR(201 ASCCOMM_ERROR(
@@ -207,21 +211,23 @@ AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread)
207{211{
208 CHK_PTR_NULL(thread);212 CHK_PTR_NULL(thread);
209 CHK_PTR_NULL(thread->sqContextAddr);213 CHK_PTR_NULL(thread->sqContextAddr);
210- HcommRtsqContext& rtsq = *thread->sqContextAddr;214+ HcommRtsqContext& rtsq = thread->sqContextAddr->contextInfo.RtsqContext;
211 if (rtsq.sqBaseAddr != 0) {215 if (rtsq.sqBaseAddr != 0) {
212 return ASCCOMM_SUCCESS;216 return ASCCOMM_SUCCESS;
213 }217 }
214 218 
215- drvError_t ret = drvGetLocalDevIDByHostDevID(thread->devInfo.devId, &rtsq.localDevId);219+ uint32_t localDevId = 0;
220+ drvError_t ret = drvGetLocalDevIDByHostDevID(thread->devInfo.devPhyId, &localDevId);
216 CHK_PRT_RET(221 CHK_PRT_RET(
217 ret != 0,222 ret != 0,
218 ASCCOMM_ERROR(223 ASCCOMM_ERROR(
219- "[%s] drvGetLocalDevIDByHostDevID failed, devicePhyId[%u], ret[%d].", __func__, thread->devInfo.devId, ret),224+ "[%s] drvGetLocalDevIDByHostDevID failed, devicePhyId[%u], ret[%d].", __func__, thread->devInfo.devPhyId,
225+ ret),
220 ASCCOMM_E_INTERNAL);226 ASCCOMM_E_INTERNAL);
221- CHK_RET(query_sq_base(rtsq, rtsq.sqBaseAddr));227+ CHK_RET(query_sq_base(localDevId, rtsq, rtsq.sqBaseAddr));
222- CHK_RET(query_sq_value(rtsq, DRV_SQCQ_PROP_SQ_DEPTH, rtsq.sqDepth));228+ CHK_RET(query_sq_value(localDevId, rtsq, DRV_SQCQ_PROP_SQ_DEPTH, rtsq.sqDepth));
223- CHK_RET(query_sq_value(rtsq, DRV_SQCQ_PROP_SQ_HEAD, rtsq.sqHead));229+ CHK_RET(query_sq_value(localDevId, rtsq, DRV_SQCQ_PROP_SQ_HEAD, rtsq.sqHead));
224- CHK_RET(query_sq_value(rtsq, DRV_SQCQ_PROP_SQ_TAIL, rtsq.sqTail));230+ CHK_RET(query_sq_value(localDevId, rtsq, DRV_SQCQ_PROP_SQ_TAIL, rtsq.sqTail));
225 CHK_PRT_RET(231 CHK_PRT_RET(
226 rtsq.sqBaseAddr == 0 || rtsq.sqDepth == 0,232 rtsq.sqBaseAddr == 0 || rtsq.sqDepth == 0,
227 ASCCOMM_ERROR(233 ASCCOMM_ERROR(
@@ -231,23 +237,29 @@ AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread)
231 return ASCCOMM_SUCCESS;237 return ASCCOMM_SUCCESS;
232}238}
233 239 
234-AsccommResult asccomm_rtsq_launch(HcommRtsqContext& context)240+AsccommResult asccomm_rtsq_launch(ThreadEntity& thread)
235{241{
236- if (context.pendingSqeCnt == 0) {242+ CHK_PTR_NULL(thread.sqContextAddr);
243+ HcommThreadSqContext& contextOuter = *thread.sqContextAddr;
244+ HcommRtsqContext& rtsq = contextOuter.contextInfo.RtsqContext;
245+ if (rtsq.pendingSqeCnt == 0) {
237 return ASCCOMM_SUCCESS;246 return ASCCOMM_SUCCESS;
238 }247 }
239 CHK_PRT_RET(248 CHK_PRT_RET(
240- context.sqDepth == 0 || context.sqBaseAddr == 0,249+ rtsq.sqDepth == 0 || rtsq.sqBaseAddr == 0,
241- ASCCOMM_ERROR(250+ ASCCOMM_ERROR("[%s] invalid RTSQ context, depth[%u], base[0x%llx].", __func__, rtsq.sqDepth, rtsq.sqBaseAddr),
242- "[%s] invalid RTSQ context, depth[%u], base[0x%llx].", __func__, context.sqDepth, context.sqBaseAddr),
243 ASCCOMM_E_PARA);251 ASCCOMM_E_PARA);
244- CHK_RET(ensure_queue_space(context));252+ uint32_t localDevId = 0;
245- CHK_RET(copy_pending_sqes(context));253+ CHK_PRT_RET(
246- const uint32_t newTail = (context.sqTail + context.pendingSqeCnt) % context.sqDepth;254+ drvGetLocalDevIDByHostDevID(thread.devInfo.devPhyId, &localDevId) != 0,
247- CHK_RET(config_sq_tail(context, newTail));255+ ASCCOMM_ERROR("[%s] resolve local device failed.", __func__), ASCCOMM_E_INTERNAL);
248- context.sqTail = newTail;256+ CHK_RET(ensure_queue_space(localDevId, rtsq));
249- context.pendingSqeCnt = 0;257+ CHK_RET(copy_pending_sqes(rtsq));
250- auto* localSqeBuffer = reinterpret_cast<uint8_t*>(context.localSqeAddr);258+ const uint32_t newTail = (rtsq.sqTail + rtsq.pendingSqeCnt) % rtsq.sqDepth;
259+ CHK_RET(config_sq_tail(localDevId, rtsq, newTail));
260+ rtsq.sqTail = newTail;
261+ rtsq.pendingSqeCnt = 0;
262+ auto* localSqeBuffer = reinterpret_cast<uint8_t*>(static_cast<uintptr_t>(rtsq.localSqAddr));
251 constexpr size_t LOCAL_SQE_BUFFER_SIZE = HCOMM_RESOURCE_RTSQ_SQE_SIZE * HCOMM_RESOURCE_RTSQ_BATCH_SIZE;263 constexpr size_t LOCAL_SQE_BUFFER_SIZE = HCOMM_RESOURCE_RTSQ_SQE_SIZE * HCOMM_RESOURCE_RTSQ_BATCH_SIZE;
252 CHK_PRT_RET(264 CHK_PRT_RET(
253 memset_s(localSqeBuffer, LOCAL_SQE_BUFFER_SIZE, 0, LOCAL_SQE_BUFFER_SIZE) != EOK,265 memset_s(localSqeBuffer, LOCAL_SQE_BUFFER_SIZE, 0, LOCAL_SQE_BUFFER_SIZE) != EOK,
@@ -255,48 +267,62 @@ AsccommResult asccomm_rtsq_launch(HcommRtsqContext& context)
255 return ASCCOMM_SUCCESS;267 return ASCCOMM_SUCCESS;
256}268}
257 269 
258-AsccommResult asccomm_rtsq_try_launch(HcommRtsqContext& context)270+AsccommResult asccomm_rtsq_try_launch(ThreadEntity& thread)
259{271{
260- if (context.pendingSqeCnt == 0) {272+ CHK_PTR_NULL(thread.sqContextAddr);
273+ HcommThreadSqContext& contextOuter = *thread.sqContextAddr;
274+ HcommRtsqContext& rtsq = contextOuter.contextInfo.RtsqContext;
275+ if (rtsq.pendingSqeCnt == 0) {
261 return ASCCOMM_SUCCESS;276 return ASCCOMM_SUCCESS;
262 }277 }
263- CHK_RET(query_sq_value(context, DRV_SQCQ_PROP_SQ_HEAD, context.sqHead));278+ uint32_t localDevId = 0;
264- if (get_tail_to_head_distance(context) <= context.pendingSqeCnt) {279+ CHK_PRT_RET(
280+ drvGetLocalDevIDByHostDevID(thread.devInfo.devPhyId, &localDevId) != 0,
281+ ASCCOMM_ERROR("[%s] resolve local device failed.", __func__), ASCCOMM_E_INTERNAL);
282+ CHK_RET(query_sq_value(localDevId, rtsq, DRV_SQCQ_PROP_SQ_HEAD, rtsq.sqHead));
283+ if (get_tail_to_head_distance(rtsq) <= rtsq.pendingSqeCnt) {
265 return ASCCOMM_SUCCESS;284 return ASCCOMM_SUCCESS;
266 }285 }
267- return asccomm_rtsq_launch(context);286+ return asccomm_rtsq_launch(thread);
268}287}
269 288 
270-AsccommResult asccomm_rtsq_notify_wait(HcommRtsqContext& context, uint32_t notifyId, uint32_t timeout)289+AsccommResult asccomm_rtsq_notify_wait(ThreadEntity& thread, uint32_t notifyId, uint32_t timeout)
271{290{
291+ HcommThreadSqContext& context = *thread.sqContextAddr;
272 uint32_t taskId = 0;292 uint32_t taskId = 0;
273 CHK_RET(acquire_task_id(context, taskId));293 CHK_RET(acquire_task_id(context, taskId));
274- Asc::build_a5_sqe_notify_wait(context.streamId, taskId, notifyId, timeout, get_current_sqe(context));294+ Asc::build_a5_sqe_notify_wait(
275- return refresh_rtsq(context);295+ context.contextInfo.RtsqContext.streamId, taskId, notifyId, timeout, get_current_sqe(context));
296+ return refresh_rtsq(thread);
276}297}
277 298 
278-AsccommResult asccomm_rtsq_notify_record(HcommRtsqContext& context, uint32_t notifyId)299+AsccommResult asccomm_rtsq_notify_record(ThreadEntity& thread, uint32_t notifyId)
279{300{
301+ HcommThreadSqContext& context = *thread.sqContextAddr;
280 uint32_t taskId = 0;302 uint32_t taskId = 0;
281 CHK_RET(acquire_task_id(context, taskId));303 CHK_RET(acquire_task_id(context, taskId));
282- Asc::build_a5_sqe_notify_record(context.streamId, taskId, notifyId, get_current_sqe(context));304+ Asc::build_a5_sqe_notify_record(
283- return refresh_rtsq(context);305+ context.contextInfo.RtsqContext.streamId, taskId, notifyId, get_current_sqe(context));
306+ return refresh_rtsq(thread);
284}307}
285 308 
286-AsccommResult asccomm_rtsq_sdma_copy(HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size)309+AsccommResult asccomm_rtsq_sdma_copy(ThreadEntity& thread, uint64_t dstAddr, uint64_t srcAddr, uint32_t size)
287{310{
311+ HcommThreadSqContext& context = *thread.sqContextAddr;
288 constexpr uint32_t RTSQ_PART_ID = 0;312 constexpr uint32_t RTSQ_PART_ID = 0;
289 constexpr uint32_t COPY_OPCODE = 0;313 constexpr uint32_t COPY_OPCODE = 0;
290 uint32_t taskId = 0;314 uint32_t taskId = 0;
291 CHK_RET(acquire_task_id(context, taskId));315 CHK_RET(acquire_task_id(context, taskId));
292 Asc::build_a5_sqe_sdma_copy(316 Asc::build_a5_sqe_sdma_copy(
293- context.streamId, taskId, dstAddr, srcAddr, size, RTSQ_PART_ID, COPY_OPCODE, get_current_sqe(context));317+ context.contextInfo.RtsqContext.streamId, taskId, dstAddr, srcAddr, size, RTSQ_PART_ID, COPY_OPCODE,
294- return refresh_rtsq(context);318+ get_current_sqe(context));
319+ return refresh_rtsq(thread);
295}320}
296 321 
297AsccommResult asccomm_rtsq_sdma_reduce(322AsccommResult asccomm_rtsq_sdma_reduce(
298- HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn)323+ ThreadEntity& thread, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn)
299{324{
325+ HcommThreadSqContext& context = *thread.sqContextAddr;
300 uint32_t operation = 0;326 uint32_t operation = 0;
301 switch (reduceIn.reduceOp) {327 switch (reduceIn.reduceOp) {
302 case Asc::ReduceOp::SUM:328 case Asc::ReduceOp::SUM:
@@ -342,24 +368,29 @@ AsccommResult asccomm_rtsq_sdma_reduce(
342 uint32_t taskId = 0;368 uint32_t taskId = 0;
343 CHK_RET(acquire_task_id(context, taskId));369 CHK_RET(acquire_task_id(context, taskId));
344 Asc::build_a5_sqe_sdma_copy(370 Asc::build_a5_sqe_sdma_copy(
345- context.streamId, taskId, dstAddr, srcAddr, size, RTSQ_PART_ID, operation | dataType, get_current_sqe(context));371+ context.contextInfo.RtsqContext.streamId, taskId, dstAddr, srcAddr, size, RTSQ_PART_ID, operation | dataType,
346- return refresh_rtsq(context);372+ get_current_sqe(context));
373+ return refresh_rtsq(thread);
347}374}
348 375 
349-AsccommResult asccomm_rtsq_ub_db_send(HcommRtsqContext& context, const Asc::UbJettyLiteId& jettyId, uint16_t piValue)376+AsccommResult asccomm_rtsq_ub_db_send(ThreadEntity& thread, const Asc::UbJettyLiteId& jettyId, uint16_t piValue)
350{377{
378+ HcommThreadSqContext& context = *thread.sqContextAddr;
351 uint32_t taskId = 0;379 uint32_t taskId = 0;
352 CHK_RET(acquire_task_id(context, taskId));380 CHK_RET(acquire_task_id(context, taskId));
353- Asc::build_a5_sqe_ub_db_send(context.streamId, taskId, jettyId, piValue, get_current_sqe(context));381+ Asc::build_a5_sqe_ub_db_send(
354- return refresh_rtsq(context);382+ context.contextInfo.RtsqContext.streamId, taskId, jettyId, piValue, get_current_sqe(context));
383+ return refresh_rtsq(thread);
355}384}
356 385 
357-AsccommResult asccomm_rtsq_rdma_db_send(HcommRtsqContext& context, uint64_t dbAddr, uint64_t dbValue)386+AsccommResult asccomm_rtsq_rdma_db_send(ThreadEntity& thread, uint64_t dbAddr, uint64_t dbValue)
358{387{
388+ HcommThreadSqContext& context = *thread.sqContextAddr;
359 uint32_t taskId = 0;389 uint32_t taskId = 0;
360 CHK_RET(acquire_task_id(context, taskId));390 CHK_RET(acquire_task_id(context, taskId));
361- Asc::build_a5_sqe_rdma_db_send(context.streamId, taskId, dbAddr, dbValue, get_current_sqe(context));391+ Asc::build_a5_sqe_rdma_db_send(
362- return refresh_rtsq(context);392+ context.contextInfo.RtsqContext.streamId, taskId, dbAddr, dbValue, get_current_sqe(context));
393+ return refresh_rtsq(thread);
363}394}
364 395 
365AsccommResult asccomm_task_launch(ThreadHandle* threads, uint32_t threadNum)396AsccommResult asccomm_task_launch(ThreadHandle* threads, uint32_t threadNum)
@@ -370,7 +401,7 @@ AsccommResult asccomm_task_launch(ThreadHandle* threads, uint32_t threadNum)
370 ThreadEntity* thread = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(threads[index]));401 ThreadEntity* thread = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(threads[index]));
371 CHK_RET(asccomm_resolve_thread_rtsq(thread));402 CHK_RET(asccomm_resolve_thread_rtsq(thread));
372 CHK_RET(validate_thread_entity(thread));403 CHK_RET(validate_thread_entity(thread));
373- CHK_RET(asccomm_rtsq_launch(*thread->sqContextAddr));404+ CHK_RET(asccomm_rtsq_launch(*thread));
374 }405 }
375 return ASCCOMM_SUCCESS;406 return ASCCOMM_SUCCESS;
376}407}
@@ -383,7 +414,7 @@ AsccommResult asccomm_try_launch(ThreadHandle* threads, uint32_t threadNum)
383 ThreadEntity* thread = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(threads[index]));414 ThreadEntity* thread = reinterpret_cast<ThreadEntity*>(static_cast<uintptr_t>(threads[index]));
384 CHK_RET(asccomm_resolve_thread_rtsq(thread));415 CHK_RET(asccomm_resolve_thread_rtsq(thread));
385 CHK_RET(validate_thread_entity(thread));416 CHK_RET(validate_thread_entity(thread));
386- CHK_RET(asccomm_rtsq_try_launch(*thread->sqContextAddr));417+ CHK_RET(asccomm_rtsq_try_launch(*thread));
387 }418 }
388 return ASCCOMM_SUCCESS;419 return ASCCOMM_SUCCESS;
389}420}
@@ -21,15 +21,15 @@ namespace Asc {
21struct UbJettyLiteId;21struct UbJettyLiteId;
22}22}
23 23 
24-AsccommResult asccomm_rtsq_launch(HcommRtsqContext& context);24+AsccommResult asccomm_rtsq_launch(ThreadEntity& thread);
25-AsccommResult asccomm_rtsq_try_launch(HcommRtsqContext& context);25+AsccommResult asccomm_rtsq_try_launch(ThreadEntity& thread);
26-AsccommResult asccomm_rtsq_notify_wait(HcommRtsqContext& context, uint32_t notifyId, uint32_t timeout);26+AsccommResult asccomm_rtsq_notify_wait(ThreadEntity& thread, uint32_t notifyId, uint32_t timeout);
27-AsccommResult asccomm_rtsq_notify_record(HcommRtsqContext& context, uint32_t notifyId);27+AsccommResult asccomm_rtsq_notify_record(ThreadEntity& thread, uint32_t notifyId);
28-AsccommResult asccomm_rtsq_sdma_copy(HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size);28+AsccommResult asccomm_rtsq_sdma_copy(ThreadEntity& thread, uint64_t dstAddr, uint64_t srcAddr, uint32_t size);
29AsccommResult asccomm_rtsq_sdma_reduce(29AsccommResult asccomm_rtsq_sdma_reduce(
30- HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn);30+ ThreadEntity& thread, 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);31+AsccommResult asccomm_rtsq_ub_db_send(ThreadEntity& thread, const Asc::UbJettyLiteId& jettyId, uint16_t piValue);
32-AsccommResult asccomm_rtsq_rdma_db_send(HcommRtsqContext& context, uint64_t dbAddr, uint64_t dbValue);32+AsccommResult asccomm_rtsq_rdma_db_send(ThreadEntity& thread, uint64_t dbAddr, uint64_t dbValue);
33AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread);33AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread);
34 34 
35// RTSQ硬件属性由数据面在首次使用Thread resource时懒解析。35// RTSQ硬件属性由数据面在首次使用Thread resource时懒解析。
@@ -61,7 +61,7 @@ const HcommRegedBufferEntity* find_buffer(
61 return nullptr;61 return nullptr;
62}62}
63 63 
64-AsccommResult get_rtsq(ThreadEntity& thread, HcommRtsqContext*& rtsq)64+AsccommResult get_rtsq(ThreadEntity& thread, HcommThreadSqContext*& rtsq)
65{65{
66 CHK_PTR_NULL(thread.sqContextAddr);66 CHK_PTR_NULL(thread.sqContextAddr);
67 rtsq = thread.sqContextAddr;67 rtsq = thread.sqContextAddr;
@@ -159,10 +159,10 @@ void export_ub_state(Asc::UbConnLite& connection, HcommJfsContext& jfs)
159AsccommResult ring_ub_doorbell(159AsccommResult ring_ub_doorbell(
160 ThreadEntity& thread, const ChannelEntity& channel, const HcommJfsContext& jfs, uint16_t pi)160 ThreadEntity& thread, const ChannelEntity& channel, const HcommJfsContext& jfs, uint16_t pi)
161{161{
162- HcommRtsqContext* rtsq = nullptr;162+ HcommThreadSqContext* rtsq = nullptr;
163 CHK_RET(get_rtsq(thread, rtsq));163 CHK_RET(get_rtsq(thread, rtsq));
164 const Asc::UbJettyLiteId jettyId(channel.devInfo.dieId, channel.devInfo.funcId, jfs.jfsID);164 const Asc::UbJettyLiteId jettyId(channel.devInfo.dieId, channel.devInfo.funcId, jfs.jfsID);
165- return asccomm_rtsq_ub_db_send(*rtsq, jettyId, pi);165+ return asccomm_rtsq_ub_db_send(thread, jettyId, pi);
166}166}
167 167 
168Asc::SqeConfigLite get_ub_config(ChannelEntity& channel)168Asc::SqeConfigLite get_ub_config(ChannelEntity& channel)
@@ -388,9 +388,9 @@ AsccommResult execute_rdma(
388 bool cqDbFlush = false;388 bool cqDbFlush = false;
389 ops.export_queue_state(resourceSq->sqHead, resourceSq->sqTail, resourceCq->cqHead, resourceCq->cqTail, cqDbFlush);389 ops.export_queue_state(resourceSq->sqHead, resourceSq->sqTail, resourceCq->cqHead, resourceCq->cqTail, cqDbFlush);
390 resourceCq->cqDbFlush = cqDbFlush ? 1 : 0;390 resourceCq->cqDbFlush = cqDbFlush ? 1 : 0;
391- HcommRtsqContext* rtsq = nullptr;391+ HcommThreadSqContext* rtsq = nullptr;
392 CHK_RET(get_rtsq(thread, rtsq));392 CHK_RET(get_rtsq(thread, rtsq));
393- CHK_RET(asccomm_rtsq_rdma_db_send(*rtsq, dbAddr, dbValue));393+ CHK_RET(asccomm_rtsq_rdma_db_send(thread, dbAddr, dbValue));
394 394 
395 const int32_t pollNum =395 const int32_t pollNum =
396 (operation == RdmaOperation::WRITE_WITH_NOTIFY || operation == RdmaOperation::WRITE_REDUCE_WITH_NOTIFY) ? 2 : 1;396 (operation == RdmaOperation::WRITE_WITH_NOTIFY || operation == RdmaOperation::WRITE_REDUCE_WITH_NOTIFY) ? 2 : 1;
@@ -625,7 +625,7 @@ AsccommResult asccomm_notify_wait(
625 "[%s] local notify index[%u] out of range[%u].", __func__, localNotifyIdx,625 "[%s] local notify index[%u] out of range[%u].", __func__, localNotifyIdx,
626 channel.localNotifyNum > 0 ? channel.localNotifyNum - 1U : 0U),626 channel.localNotifyNum > 0 ? channel.localNotifyNum - 1U : 0U),
627 ASCCOMM_E_PARA);627 ASCCOMM_E_PARA);
628- HcommRtsqContext* rtsq = nullptr;628+ HcommThreadSqContext* rtsq = nullptr;
629 CHK_RET(get_rtsq(thread, rtsq));629 CHK_RET(get_rtsq(thread, rtsq));
630 const HcommRegedNotifyEntity& notify = channel.localNotifyAddr[localNotifyIdx + 1U];630 const HcommRegedNotifyEntity& notify = channel.localNotifyAddr[localNotifyIdx + 1U];
631 CHK_PRT_RET(631 CHK_PRT_RET(
@@ -633,7 +633,7 @@ AsccommResult asccomm_notify_wait(
633 ASCCOMM_E_PARA);633 ASCCOMM_E_PARA);
634 const int32_t notifyId = notify.notifyInfo.rmaRt.notifyId;634 const int32_t notifyId = notify.notifyInfo.rmaRt.notifyId;
635 CHK_PRT_RET(notifyId < 0, ASCCOMM_ERROR("[%s] invalid notify id[%d].", __func__, notifyId), ASCCOMM_E_PARA);635 CHK_PRT_RET(notifyId < 0, ASCCOMM_ERROR("[%s] invalid notify id[%d].", __func__, notifyId), ASCCOMM_E_PARA);
636- return asccomm_rtsq_notify_wait(*rtsq, static_cast<uint32_t>(notifyId), timeout);636+ return asccomm_rtsq_notify_wait(thread, static_cast<uint32_t>(notifyId), timeout);
637}637}
638 638 
639AsccommResult asccomm_fence(ChannelEntity& channel)639AsccommResult asccomm_fence(ChannelEntity& channel)
@@ -697,12 +697,12 @@ AsccommResult asccomm_drain(ThreadEntity& thread, ChannelEntity& channel)
697 connection.read(local, remote, cfg, out);697 connection.read(local, remote, cfg, out);
698 export_ub_state(connection, *jfs);698 export_ub_state(connection, *jfs);
699 CHK_RET(ring_ub_doorbell(thread, channel, *jfs, out.pi));699 CHK_RET(ring_ub_doorbell(thread, channel, *jfs, out.pi));
700- HcommRtsqContext* rtsq = nullptr;700+ HcommThreadSqContext* rtsq = nullptr;
701 CHK_RET(get_rtsq(thread, rtsq));701 CHK_RET(get_rtsq(thread, rtsq));
702 CHK_PRT_RET(702 CHK_PRT_RET(
703 localResource.notifyId < 0,703 localResource.notifyId < 0,
704 ASCCOMM_ERROR("[%s] invalid drain notify id[%d].", __func__, localResource.notifyId), ASCCOMM_E_PARA);704 ASCCOMM_ERROR("[%s] invalid drain notify id[%d].", __func__, localResource.notifyId), ASCCOMM_E_PARA);
705- return asccomm_rtsq_notify_wait(*rtsq, static_cast<uint32_t>(localResource.notifyId), DEFAULT_TIMEOUT);705+ return asccomm_rtsq_notify_wait(thread, static_cast<uint32_t>(localResource.notifyId), DEFAULT_TIMEOUT);
706}706}
707 707 
708AsccommResult asccomm_batch_transfer(708AsccommResult asccomm_batch_transfer(
@@ -22,26 +22,26 @@ AsccommResult asccomm_resolve_thread_rtsq(ThreadEntity* thread)
22 return g_runtimeStubState.resolveResult;22 return g_runtimeStubState.resolveResult;
23}23}
24 24 
25-AsccommResult asccomm_rtsq_sdma_copy(HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size)25+AsccommResult asccomm_rtsq_sdma_copy(ThreadEntity& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size)
26{26{
27 g_runtimeStubState.copyCalls.push_back({&context, dstAddr, srcAddr, size});27 g_runtimeStubState.copyCalls.push_back({&context, dstAddr, srcAddr, size});
28 return g_runtimeStubState.copyResult;28 return g_runtimeStubState.copyResult;
29}29}
30 30 
31AsccommResult asccomm_rtsq_sdma_reduce(31AsccommResult asccomm_rtsq_sdma_reduce(
32- HcommRtsqContext& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn)32+ ThreadEntity& context, uint64_t dstAddr, uint64_t srcAddr, uint32_t size, const Asc::ReduceIn& reduceIn)
33{33{
34 g_runtimeStubState.reduceCalls.push_back({&context, dstAddr, srcAddr, size, reduceIn.dataType, reduceIn.reduceOp});34 g_runtimeStubState.reduceCalls.push_back({&context, dstAddr, srcAddr, size, reduceIn.dataType, reduceIn.reduceOp});
35 return g_runtimeStubState.reduceResult;35 return g_runtimeStubState.reduceResult;
36}36}
37 37 
38-AsccommResult asccomm_rtsq_notify_record(HcommRtsqContext& context, uint32_t notifyId)38+AsccommResult asccomm_rtsq_notify_record(ThreadEntity& context, uint32_t notifyId)
39{39{
40 g_runtimeStubState.notifyRecordCalls.push_back({&context, notifyId});40 g_runtimeStubState.notifyRecordCalls.push_back({&context, notifyId});
41 return g_runtimeStubState.notifyRecordResult;41 return g_runtimeStubState.notifyRecordResult;
42}42}
43 43 
44-AsccommResult asccomm_rtsq_notify_wait(HcommRtsqContext& context, uint32_t notifyId, uint32_t timeout)44+AsccommResult asccomm_rtsq_notify_wait(ThreadEntity& context, uint32_t notifyId, uint32_t timeout)
45{45{
46 g_runtimeStubState.notifyWaitCalls.push_back({&context, notifyId, timeout});46 g_runtimeStubState.notifyWaitCalls.push_back({&context, notifyId, timeout});
47 return g_runtimeStubState.notifyWaitResult;47 return g_runtimeStubState.notifyWaitResult;
@@ -20,14 +20,14 @@
20struct AicpuRuntimeStubState {20struct AicpuRuntimeStubState {
21 std::vector<ThreadEntity*> resolveCalls;21 std::vector<ThreadEntity*> resolveCalls;
22 struct CopyCall {22 struct CopyCall {
23- HcommRtsqContext* context;23+ ThreadEntity* context;
24 uint64_t dst;24 uint64_t dst;
25 uint64_t src;25 uint64_t src;
26 uint32_t size;26 uint32_t size;
27 };27 };
28 std::vector<CopyCall> copyCalls;28 std::vector<CopyCall> copyCalls;
29 struct ReduceCall {29 struct ReduceCall {
30- HcommRtsqContext* context;30+ ThreadEntity* context;
31 uint64_t dst;31 uint64_t dst;
32 uint64_t src;32 uint64_t src;
33 uint32_t size;33 uint32_t size;
@@ -36,12 +36,12 @@ struct AicpuRuntimeStubState {
36 };36 };
37 std::vector<ReduceCall> reduceCalls;37 std::vector<ReduceCall> reduceCalls;
38 struct NotifyRecordCall {38 struct NotifyRecordCall {
39- HcommRtsqContext* context;39+ ThreadEntity* context;
40 uint32_t notifyId;40 uint32_t notifyId;
41 };41 };
42 std::vector<NotifyRecordCall> notifyRecordCalls;42 std::vector<NotifyRecordCall> notifyRecordCalls;
43 struct NotifyWaitCall {43 struct NotifyWaitCall {
44- HcommRtsqContext* context;44+ ThreadEntity* context;
45 uint32_t notifyId;45 uint32_t notifyId;
46 uint32_t timeout;46 uint32_t timeout;
47 };47 };
@@ -21,8 +21,8 @@ namespace {
21ThreadEntity MakeThread()21ThreadEntity MakeThread()
22{22{
23 ThreadEntity thread{};23 ThreadEntity thread{};
24- thread.abiHeader = {HCOMM_RESOURCE_THREAD_VERSION, HCOMM_RESOURCE_THREAD_MAGIC_WORD, sizeof(ThreadEntity), 0};24+ thread.abiHeader = {HCOMM_THREAD_ENTITY_VERSION, HCOMM_THREAD_ENTITY_MAGIC_WORD, sizeof(ThreadEntity), 0};
25- static HcommRtsqContext rtsq{};25+ static HcommThreadSqContext rtsq{};
26 thread.sqContextAddr = &rtsq;26 thread.sqContextAddr = &rtsq;
27 return thread;27 return thread;
28}28}
@@ -30,7 +30,7 @@ ThreadEntity MakeThread()
30ChannelEntity MakeChannel()30ChannelEntity MakeChannel()
31{31{
32 ChannelEntity channel{};32 ChannelEntity channel{};
33- channel.abiHeader = {HCOMM_RESOURCE_CHANNEL_VERSION, HCOMM_RESOURCE_CHANNEL_MAGIC_WORD, sizeof(ChannelEntity), 0};33+ channel.abiHeader = {HCOMM_CHANNEL_ENTITY_VERSION, HCOMM_CHANNEL_ENTITY_MAGIC_WORD, sizeof(ChannelEntity), 0};
34 return channel;34 return channel;
35}35}
36 36