已合并
【PR】: aclgraph software sq for ub #2494
zhut66创建于 5月29日
【PR】: aclgraph software sq for ub #2494
已合并
共 68 个文件变更+5528-562
| @@ -225,7 +225,7 @@ sequenceDiagram | |||
| 225 | Context-->>App: 返回 CaptureModel | 225 | Context-->>App: 返回 CaptureModel |
| 226 | 226 | ||
| 227 | App->>CaptureModel: rtModelExecute(model, exeStream) | 227 | App->>CaptureModel: rtModelExecute(model, exeStream) |
| 228 | - CaptureModel->>CaptureModel: BuildSqCq(exeStream) | 228 | + CaptureModel->>CaptureModel: BuildResource(exeStream) |
| 229 | CaptureModel->>SqCq: AllocSqCq(streamNum) | 229 | CaptureModel->>SqCq: AllocSqCq(streamNum) |
| 230 | CaptureModel->>CaptureModel: BindSqCqAndSendSqe | 230 | CaptureModel->>CaptureModel: BindSqCqAndSendSqe |
| 231 | CaptureModel->>Notify: SetNotifyBeforeExecute | 231 | CaptureModel->>Notify: SetNotifyBeforeExecute |
| @@ -443,7 +443,7 @@ flowchart TD | |||
| 443 | E --> F{是否 READY} | 443 | E --> F{是否 READY} |
| 444 | F -->|否| G[返回 RT_ERROR_MODEL_EXE_FAILED] | 444 | F -->|否| G[返回 RT_ERROR_MODEL_EXE_FAILED] |
| 445 | F -->|是| H[SetNotifyBeforeExecute] | 445 | F -->|是| H[SetNotifyBeforeExecute] |
| 446 | - H --> I[BuildSqCq] | 446 | + H --> I[BuildResource] |
| 447 | I --> J[AllocSqCqProc] | 447 | I --> J[AllocSqCqProc] |
| 448 | J --> K[AllocSqAddr] | 448 | J --> K[AllocSqAddr] |
| 449 | K --> L[BindSqCqAndSendSqe] | 449 | K --> L[BindSqCqAndSendSqe] |
| @@ -480,7 +480,7 @@ rtError_t CaptureModel::ExecuteCommon(Stream * const stm, int32_t timeout, const | |||
| 480 | // ... | 480 | // ... |
| 481 | 481 | ||
| 482 | // 构建 SQ/CQ | 482 | // 构建 SQ/CQ |
| 483 | - error = BuildSqCq(stm); | 483 | + error = BuildResource(stm); |
| 484 | // ... | 484 | // ... |
| 485 | 485 | ||
| 486 | ReportCacheTrackData(); | 486 | ReportCacheTrackData(); |
| @@ -518,7 +518,7 @@ classDiagram | |||
| 518 | -vector~unique_ptr~TaskGroup~~ taskGroupList_ | 518 | -vector~unique_ptr~TaskGroup~~ taskGroupList_ |
| 519 | +Execute(stm, timeout) rtError_t | 519 | +Execute(stm, timeout) rtError_t |
| 520 | +ExecuteAsync(stm) rtError_t | 520 | +ExecuteAsync(stm) rtError_t |
| 521 | - +BuildSqCq(exeStream) rtError_t | 521 | + +BuildResource(exeStream) rtError_t |
| 522 | +BindSqCq() rtError_t | 522 | +BindSqCq() rtError_t |
| 523 | +UnBindSqCq() rtError_t | 523 | +UnBindSqCq() rtError_t |
| 524 | +AddStreamToCaptureModel(stm) rtError_t | 524 | +AddStreamToCaptureModel(stm) rtError_t |
| @@ -567,7 +567,7 @@ public: | |||
| 567 | // SQ/CQ 管理 | 567 | // SQ/CQ 管理 |
| 568 | bool IsSoftwareSqEnable(void) const; | 568 | bool IsSoftwareSqEnable(void) const; |
| 569 | void SetSoftwareSqEnable(void); | 569 | void SetSoftwareSqEnable(void); |
| 570 | - rtError_t BuildSqCq(Stream * const exeStream); | 570 | + rtError_t BuildResource(Stream * const exeStream); |
| 571 | void DeconstructSqCq(void); | 571 | void DeconstructSqCq(void); |
| 572 | rtError_t ReleaseSqCq(uint32_t &releaseNum); | 572 | rtError_t ReleaseSqCq(uint32_t &releaseNum); |
| 573 | 573 | ||
| @@ -743,7 +743,7 @@ rtError_t Event::CaptureWaitProcess(Stream * const stm) | |||
| 743 | 743 | ||
| 744 | ```cpp | 744 | ```cpp |
| 745 | // 文件位置:src/runtime/feature/aclgraph/capture_model.cc:471-567 | 745 | // 文件位置:src/runtime/feature/aclgraph/capture_model.cc:471-567 |
| 746 | -rtError_t CaptureModel::BuildSqCq(Stream * const exeStream) | 746 | +rtError_t CaptureModel::BuildResource(Stream * const exeStream) |
| 747 | { | 747 | { |
| 748 | // 检查是否启用 Software Sq | 748 | // 检查是否启用 Software Sq |
| 749 | COND_PROC(!IsSoftwareSqEnable(), return RT_ERROR_NONE); | 749 | COND_PROC(!IsSoftwareSqEnable(), return RT_ERROR_NONE); |
| @@ -853,7 +853,7 @@ classDiagram | |||
| 853 | 853 | ||
| 854 | - **捕获阶段**:任务被记录到 CaptureStream,不立即执行 | 854 | - **捕获阶段**:任务被记录到 CaptureStream,不立即执行 |
| 855 | - **构建阶段**:EndCapture 时构建可执行的图结构 | 855 | - **构建阶段**:EndCapture 时构建可执行的图结构 |
| 856 | -- **执行阶段**:BuildSqCq 动态绑定 SQ/CQ,提交优化后的执行任务 | 856 | +- **执行阶段**:BuildResource 动态绑定 SQ/CQ,提交优化后的执行任务 |
| 857 | 857 | ||
| 858 | ### 5.2 级联捕获支持 | 858 | ### 5.2 级联捕获支持 |
| 859 | 859 | ||
| @@ -874,7 +874,7 @@ if ((curCaptureStream->GetCaptureSqeNum() + reserved) >= curCaptureStream->GetSq | |||
| 874 | ### 5.3 Software SQ 动态绑定 | 874 | ### 5.3 Software SQ 动态绑定 |
| 875 | 875 | ||
| 876 | - 支持 SQ/CQ 的动态分配和绑定 | 876 | - 支持 SQ/CQ 的动态分配和绑定 |
| 877 | -- 执行时 BuildSqCq,完成后 ReleaseSqCq | 877 | +- 执行时 BuildResource,完成后 ReleaseSqCq |
| 878 | - 通过 SqSwitchStreamBatch 实现批量流切换 | 878 | - 通过 SqSwitchStreamBatch 实现批量流切换 |
| 879 | 879 | ||
| 880 | ### 5.4 Notify 同步机制 | 880 | ### 5.4 Notify 同步机制 |
| @@ -4620,6 +4620,62 @@ drvError_t halAsyncDmaCreateBatch(uint32_t devId, struct halAsyncDmaInputBatchPa | |||
| 4620 | */ | 4620 | */ |
| 4621 | drvError_t halAsyncDmaDestroyBatch(uint32_t devId, struct halAsyncDmaDestroyBatchPara *para); | 4621 | drvError_t halAsyncDmaDestroyBatch(uint32_t devId, struct halAsyncDmaDestroyBatchPara *para); |
| 4622 | 4622 | ||
| 4623 | +/** | ||
| 4624 | + * @ingroup driver | ||
| 4625 | + * @brief async dma jetty create | ||
| 4626 | + * @attention null | ||
| 4627 | + * @param [in] devId: logic devid | ||
| 4628 | + * @param [in] in: see struct halAsyncDmaJettyCreateIn | ||
| 4629 | + * @param [out] out: see struct halAsyncDmaJettyCreateOut | ||
| 4630 | + * @return 0 for success, others for fail | ||
| 4631 | + */ | ||
| 4632 | +drvError_t halAsyncDmaJettyCreate(uint32_t devId, struct halAsyncDmaJettyCreateIn *in, | ||
| 4633 | + struct halAsyncDmaJettyCreateOut *out); | ||
| 4634 | + | ||
| 4635 | +/** | ||
| 4636 | + * @ingroup driver | ||
| 4637 | + * @brief async dma jetty destroy | ||
| 4638 | + * @attention null | ||
| 4639 | + * @param [in] devId: logic devid | ||
| 4640 | + * @param [in] para: see struct halAsyncJettyDestroyPara | ||
| 4641 | + * @return 0 for success, others for fail | ||
| 4642 | + */ | ||
| 4643 | +drvError_t halAsyncDmaJettyDestroy(uint32_t devId, struct halAsyncJettyDestroyPara *para); | ||
| 4644 | + | ||
| 4645 | +/** | ||
| 4646 | + * @ingroup driver | ||
| 4647 | + * @brief async dma jetty query | ||
| 4648 | + * @attention null | ||
| 4649 | + * @param [in] devId: logic devid | ||
| 4650 | + * @param [in] in: see struct halAsyncDmaJettyQueryIn | ||
| 4651 | + * @param [out] out: see struct halAsyncDmaJettyQueryOut | ||
| 4652 | + * @return 0 for success, others for fail | ||
| 4653 | + */ | ||
| 4654 | +drvError_t halAsyncDmaJettyQuery(uint32_t devId, struct halAsyncDmaJettyQueryIn *in, | ||
| 4655 | + struct halAsyncDmaJettyQueryOut *out); | ||
| 4656 | + | ||
| 4657 | +/** | ||
| 4658 | + * @ingroup driver | ||
| 4659 | + * @brief async dma wqe convert | ||
| 4660 | + * @attention null | ||
| 4661 | + * @param [in] devId: logic devid | ||
| 4662 | + * @param [in] in: see struct halAsyncDmaWqeInputPara | ||
| 4663 | + * @param [out] out: see struct halAsyncDmaWqeOutputPara | ||
| 4664 | + * @return 0 for success, others for fail | ||
| 4665 | + */ | ||
| 4666 | +drvError_t halAsyncDmaWqeConvert(uint32_t devId, struct halAsyncDmaWqeInputPara *in, | ||
| 4667 | + struct halAsyncDmaWqeOutputPara *out); | ||
| 4668 | + | ||
| 4669 | +/** | ||
| 4670 | + * @ingroup driver | ||
| 4671 | + * @brief fill wqe to async dma jetty | ||
| 4672 | + * @attention null | ||
| 4673 | + * @param [in] devId: logic devid | ||
| 4674 | + * @param [in] para: see struct halAsyncDmaJettyFillInfo | ||
| 4675 | + * @return 0 for success, others for fail | ||
| 4676 | + */ | ||
| 4677 | +drvError_t halAsyncDmaJettyWqeFill(uint32_t devId, struct halAsyncDmaJettyFillInfo *para); | ||
| 4678 | + | ||
| 4623 | /** | 4679 | /** |
| 4624 | * @ingroup driver | 4680 | * @ingroup driver |
| 4625 | * @brief ACL IO control interface | 4681 | * @brief ACL IO control interface |
| @@ -1137,6 +1137,7 @@ struct drvMemSharingPara { | |||
| 1137 | 1137 | ||
| 1138 | 1138 | ||
| 1139 | 1139 | ||
| 1140 | + | ||
| 1140 | 1141 | ||
| 1141 | 1142 | ||
| 1142 | 1143 | ||
| @@ -1259,11 +1260,14 @@ struct halSqTaskArgsInfo { | |||
| 1259 | uint32_t rsv[SQCQ_RESV_LENGTH - 4]; | 1260 | uint32_t rsv[SQCQ_RESV_LENGTH - 4]; |
| 1260 | }; | 1261 | }; |
| 1261 | 1262 | ||
| 1262 | -enum drv_async_dma_type { | 1263 | +typedef enum drv_async_dma_type { |
| 1263 | DRV_ASYNC_DMA_TYPE_NORMAL = 0U, | 1264 | DRV_ASYNC_DMA_TYPE_NORMAL = 0U, |
| 1264 | DRV_ASYNC_DMA_TYPE_SQE_UPDATE, | 1265 | DRV_ASYNC_DMA_TYPE_SQE_UPDATE, |
| 1266 | + DRV_ASYNC_DMA_TYPE_2D, | ||
| 1267 | + DRV_ASYNC_DMA_TYPE_BATCH, | ||
| 1268 | + DRV_ASYNC_DMA_TYPE_NOP, | ||
| 1265 | DRV_ASYNC_DMA_TYPE_MAX | 1269 | DRV_ASYNC_DMA_TYPE_MAX |
| 1266 | -}; | 1270 | +} drvAsyncDmaType_t; |
| 1267 | 1271 | ||
| 1268 | struct drv_sqe_update_info { | 1272 | struct drv_sqe_update_info { |
| 1269 | uint32_t sq_id; | 1273 | uint32_t sq_id; |
| @@ -1367,6 +1371,138 @@ struct halAsyncDmaDestroyBatchPara { | |||
| 1367 | unsigned int rsv[TRS_ASYNC_CPY_BATCH_DESTROY_RSV_LEN]; | 1371 | unsigned int rsv[TRS_ASYNC_CPY_BATCH_DESTROY_RSV_LEN]; |
| 1368 | }; | 1372 | }; |
| 1369 | 1373 | ||
| 1374 | +typedef enum tagDrvAsyncDmaJettyType { | ||
| 1375 | + DRV_ASYNC_DMA_JETTY_TYPE_CACHE_LOCK_DWQE = 0x0, | ||
| 1376 | + DRV_ASYNC_DMA_JETTY_TYPE_NORMAL, | ||
| 1377 | + DRV_ASYNC_DMA_JETTY_TYPE_MAX | ||
| 1378 | +} drvAsyncDmaJettyType_t; | ||
| 1379 | + | ||
| 1380 | +typedef enum tagDrvAsyncDmaJettyPiMode { | ||
| 1381 | + DRV_ASYNC_DMA_JETTY_PI_MODE_ABSOLUTE = 0x0, | ||
| 1382 | + DRV_ASYNC_DMA_JETTY_PI_MODE_RELATIVELY, | ||
| 1383 | + DRV_ASYNC_DMA_JETTY_PI_MODE_MAX | ||
| 1384 | +} drvAsyncDmaJettyPiMode_t; | ||
| 1385 | + | ||
| 1386 | +typedef enum tagDrvAsyncJettyDmaDir { | ||
| 1387 | + TRS_ASYNC_JETTY_HOST_DEVICE = 0, | ||
| 1388 | + TRS_ASYNC_JETTY_DEVICE_TO_DEVICE = 1, | ||
| 1389 | + TRS_ASYNC_JETTY_MAX_DIR = 2 | ||
| 1390 | +} drvAsyncDmaJettyDir_t; | ||
| 1391 | + | ||
| 1392 | + | ||
| 1393 | + | ||
| 1394 | +struct halAsyncJettyHandle { | ||
| 1395 | + char handle[TRS_ASYNC_DMA_JETTY_HANDLE_LEN]; | ||
| 1396 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_HANDLE_RSV_LEN]; | ||
| 1397 | +}; | ||
| 1398 | + | ||
| 1399 | + | ||
| 1400 | +struct halAsyncDmaJettyCreateIn { | ||
| 1401 | + drvAsyncDmaJettyType_t jettyType; | ||
| 1402 | + drvAsyncDmaJettyPiMode_t piMode; | ||
| 1403 | + drvAsyncDmaJettyDir_t dir; | ||
| 1404 | + unsigned int depth; /* wqe bb index */ | ||
| 1405 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_INPUT_RSV_LEN]; | ||
| 1406 | +}; | ||
| 1407 | + | ||
| 1408 | + | ||
| 1409 | +struct halAsyncDmaJettyCreateOut { | ||
| 1410 | + struct halAsyncJettyHandle *jettyHandle; | ||
| 1411 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_OUTPUT_RSV_LEN]; | ||
| 1412 | +}; | ||
| 1413 | + | ||
| 1414 | + | ||
| 1415 | +struct halAsyncJettyDestroyPara { | ||
| 1416 | + struct halAsyncJettyHandle *jettyHandle; | ||
| 1417 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_DESTROY_RSV_LEN]; | ||
| 1418 | +}; | ||
| 1419 | + | ||
| 1420 | + | ||
| 1421 | +struct halAsyncDmaJettyQueryIn { | ||
| 1422 | + struct halAsyncJettyHandle *jettyHandle; | ||
| 1423 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_QUERY_IN_RSV_LEN]; | ||
| 1424 | +}; | ||
| 1425 | + | ||
| 1426 | + | ||
| 1427 | +struct halAsyncDmaJettyQueryOut { | ||
| 1428 | + unsigned int dieId; | ||
| 1429 | + unsigned int funcId; | ||
| 1430 | + unsigned int jettyId; | ||
| 1431 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_QUERY_OUT_RSV_LEN]; | ||
| 1432 | +}; | ||
| 1433 | + | ||
| 1434 | +struct drvNormalWqeInputPara { /* normal */ | ||
| 1435 | + drvAsyncDmaType_t asyncDmaType; | ||
| 1436 | + unsigned long long len; | ||
| 1437 | + uint8_t *src; | ||
| 1438 | + union { | ||
| 1439 | + uint8_t *dst; | ||
| 1440 | + struct drv_sqe_update_info info; | ||
| 1441 | + }; | ||
| 1442 | +}; | ||
| 1443 | + | ||
| 1444 | +struct drvBatchWqeInputPara { /* batch */ | ||
| 1445 | + unsigned long long *dst; | ||
| 1446 | + unsigned long long *src; | ||
| 1447 | + unsigned long long *len; | ||
| 1448 | + unsigned long long count; | ||
| 1449 | +}; | ||
| 1450 | + | ||
| 1451 | +struct drv2dWqeInputPara { /* 2d */ | ||
| 1452 | + unsigned long long *dst; /* destination memory address */ | ||
| 1453 | + unsigned long long dpitch; /* pitch of destination memory */ | ||
| 1454 | + unsigned long long *src; /* source memory address */ | ||
| 1455 | + unsigned long long spitch; /* pitch of source memory */ | ||
| 1456 | + unsigned long long width; /* width of matrix transfer */ | ||
| 1457 | + unsigned long long height; /* height of matrix transfer */ | ||
| 1458 | + unsigned long long fixedSize; /* Input: already converted size */ | ||
| 1459 | +}; | ||
| 1460 | + | ||
| 1461 | +struct drvNopWqeInputPara { | ||
| 1462 | + unsigned long long nopCnt; | ||
| 1463 | +}; | ||
| 1464 | + | ||
| 1465 | + | ||
| 1466 | +struct halAsyncDmaWqeInputPara { | ||
| 1467 | + drvAsyncDmaType_t wqeType; | ||
| 1468 | + unsigned char *wqeBuffer; | ||
| 1469 | + unsigned long long wqeBufferLen; | ||
| 1470 | + union { | ||
| 1471 | + struct drvNormalWqeInputPara normal; | ||
| 1472 | + struct drvBatchWqeInputPara batch; | ||
| 1473 | + struct drv2dWqeInputPara matrix2d; | ||
| 1474 | + struct drvNopWqeInputPara nop; | ||
| 1475 | + }; | ||
| 1476 | + | ||
| 1477 | + unsigned int rsv[TRS_ASYNC_DMA_WQE_CONVERT_IN_RSV_LEN]; | ||
| 1478 | +}; | ||
| 1479 | + | ||
| 1480 | + | ||
| 1481 | + | ||
| 1482 | +struct halAsyncDmaWqeOutputPara { | ||
| 1483 | + unsigned int wqeCnt; | ||
| 1484 | + /* | ||
| 1485 | + * batch: already complete-converted array element; | ||
| 1486 | + * others: 0 for partially-converted, 1 for complete-converted | ||
| 1487 | + */ | ||
| 1488 | + unsigned long long fixedCnt; | ||
| 1489 | + /* | ||
| 1490 | + * batch: the actual-converted size for the next partially-converted array element; | ||
| 1491 | + * others: fixedSize return the actual-converted size if fixedCnt is 1, otherwise return 0 | ||
| 1492 | + */ | ||
| 1493 | + unsigned long long fixedSize; | ||
| 1494 | + unsigned int rsv[TRS_ASYNC_DMA_WQE_CONVERT_OUT_RSV_LEN]; | ||
| 1495 | +}; | ||
| 1496 | + | ||
| 1497 | + | ||
| 1498 | +struct halAsyncDmaJettyFillInfo { | ||
| 1499 | + struct halAsyncJettyHandle *jettyHandle; | ||
| 1500 | + unsigned long long offset; | ||
| 1501 | + unsigned char *srcWqe; | ||
| 1502 | + unsigned long long size; | ||
| 1503 | + unsigned int rsv[TRS_ASYNC_DMA_JETTY_WQE_FILL_RSV_LEN]; | ||
| 1504 | +}; | ||
| 1505 | + | ||
| 1370 | struct tsdrv_ctrl_msg { | 1506 | struct tsdrv_ctrl_msg { |
| 1371 | unsigned int tsid; | 1507 | unsigned int tsid; |
| 1372 | unsigned int msg_len; /* TRS_CTRL_MSG_MAX_LEN */ | 1508 | unsigned int msg_len; /* TRS_CTRL_MSG_MAX_LEN */ |
| @@ -302,6 +302,10 @@ set(libruntime_cmodel_src_files_optional | |||
| 302 | ${RUNTIME_CORE_DIR}/src/event/ipc_event.cc | 302 | ${RUNTIME_CORE_DIR}/src/event/ipc_event.cc |
| 303 | ${RUNTIME_CORE_DIR}/src/pool/event_expanding.cc | 303 | ${RUNTIME_CORE_DIR}/src/pool/event_expanding.cc |
| 304 | ${RUNTIME_CORE_DIR}/src/pool/event_pool.cc | 304 | ${RUNTIME_CORE_DIR}/src/pool/event_pool.cc |
| 305 | + ${RUNTIME_FEATURE_DIR}/jetty/jetty_pool.cc | ||
| 306 | + ${RUNTIME_FEATURE_DIR}/jetty/jetty_manager.cc | ||
| 307 | + ${RUNTIME_FEATURE_DIR}/jetty/stream_jetty_context.cc | ||
| 308 | + ${RUNTIME_FEATURE_DIR}/jetty/stream_jetty_handler.cc | ||
| 305 | ) | 309 | ) |
| 306 | 310 | ||
| 307 | set(libruntime_cmodel_api_src_files | 311 | set(libruntime_cmodel_api_src_files |
| @@ -421,6 +425,7 @@ set(libruntime_cmodel_src_files | |||
| 421 | ${RUNTIME_CORE_DIR}/src/task/host_task.cc | 425 | ${RUNTIME_CORE_DIR}/src/task/host_task.cc |
| 422 | ${RUNTIME_CORE_DIR}/src/task/stars_cond_isa_helper.cc | 426 | ${RUNTIME_CORE_DIR}/src/task/stars_cond_isa_helper.cc |
| 423 | ${RUNTIME_CORE_DIR}/src/task/v100/stub_task.cc | 427 | ${RUNTIME_CORE_DIR}/src/task/v100/stub_task.cc |
| 428 | + ${RUNTIME_CORE_DIR}/src/task/v200/task_david_stub.cc | ||
| 424 | ${RUNTIME_CORE_DIR}/src/launch/cond_stars.cc | 429 | ${RUNTIME_CORE_DIR}/src/launch/cond_stars.cc |
| 425 | ${RUNTIME_CORE_DIR}/src/launch/label_stars.cc | 430 | ${RUNTIME_CORE_DIR}/src/launch/label_stars.cc |
| 426 | ${RUNTIME_CORE_DIR}/src/launch/cmo_barrier_stars.cc | 431 | ${RUNTIME_CORE_DIR}/src/launch/cmo_barrier_stars.cc |
| @@ -604,6 +609,7 @@ set(RUNTIME_CMODEL_INC_DIR_COMMON | |||
| 604 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel | 609 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel |
| 605 | ${RUNTIME_DIR}/src/runtime/core/inc/launch | 610 | ${RUNTIME_DIR}/src/runtime/core/inc/launch |
| 606 | ${RUNTIME_DIR}/src/runtime/core/inc/model | 611 | ${RUNTIME_DIR}/src/runtime/core/inc/model |
| 612 | + ${RUNTIME_DIR}/src/runtime/feature/jetty | ||
| 607 | ${RUNTIME_DIR}/src/runtime/core/inc/notify | 613 | ${RUNTIME_DIR}/src/runtime/core/inc/notify |
| 608 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler | 614 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler |
| 609 | ${RUNTIME_DIR}/src/runtime/core/inc/soc | 615 | ${RUNTIME_DIR}/src/runtime/core/inc/soc |
| @@ -355,6 +355,8 @@ set(libruntime_v100_src_files | |||
| 355 | ${RUNTIME_CORE_DIR}/src/stream/stream_state_callback_manager.cc | 355 | ${RUNTIME_CORE_DIR}/src/stream/stream_state_callback_manager.cc |
| 356 | ${RUNTIME_CORE_DIR}/src/event/event_state_callback_manager.cc | 356 | ${RUNTIME_CORE_DIR}/src/event/event_state_callback_manager.cc |
| 357 | ${RUNTIME_CORE_DIR}/src/plugin_manage/v200/plugin_old_arch.cc | 357 | ${RUNTIME_CORE_DIR}/src/plugin_manage/v200/plugin_old_arch.cc |
| 358 | + ${RUNTIME_FEATURE_DIR}/jetty/jetty_stub.cc | ||
| 359 | + ${RUNTIME_CORE_DIR}/src/task/v200/task_david_stub.cc | ||
| 358 | ${libruntime_src_files_optional} | 360 | ${libruntime_src_files_optional} |
| 359 | ${xpu_tprt_api_file} | 361 | ${xpu_tprt_api_file} |
| 360 | ${xpu_tprt_src_file} | 362 | ${xpu_tprt_src_file} |
| @@ -379,6 +381,7 @@ set(RUNTIME_INC_DIR_OPEN | |||
| 379 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel | 381 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel |
| 380 | ${RUNTIME_DIR}/src/runtime/core/inc/launch | 382 | ${RUNTIME_DIR}/src/runtime/core/inc/launch |
| 381 | ${RUNTIME_DIR}/src/runtime/core/inc/model | 383 | ${RUNTIME_DIR}/src/runtime/core/inc/model |
| 384 | + ${RUNTIME_DIR}/src/runtime/feature/jetty | ||
| 382 | ${RUNTIME_DIR}/src/runtime/core/inc/notify | 385 | ${RUNTIME_DIR}/src/runtime/core/inc/notify |
| 383 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler | 386 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler |
| 384 | ${RUNTIME_DIR}/src/runtime/core/inc/soc | 387 | ${RUNTIME_DIR}/src/runtime/core/inc/soc |
| @@ -186,6 +186,7 @@ set(libruntime_src_files_include_for_tiny | |||
| 186 | ${RUNTIME_CORE_DIR}/src/api_impl/api_decorator_tiny_stub.cc | 186 | ${RUNTIME_CORE_DIR}/src/api_impl/api_decorator_tiny_stub.cc |
| 187 | ${RUNTIME_FEATURE_DIR}/model/tiny/model_aclgraph_tiny_stub.cc | 187 | ${RUNTIME_FEATURE_DIR}/model/tiny/model_aclgraph_tiny_stub.cc |
| 188 | ${RUNTIME_FEATURE_DIR}/aclgraph/tiny/stream_capture_tiny_stub.cc | 188 | ${RUNTIME_FEATURE_DIR}/aclgraph/tiny/stream_capture_tiny_stub.cc |
| 189 | + ${RUNTIME_FEATURE_DIR}/jetty/jetty_stub.cc | ||
| 189 | ) | 190 | ) |
| 190 | 191 | ||
| 191 | set(libruntime_api_src_files_exclude_for_tiny | 192 | set(libruntime_api_src_files_exclude_for_tiny |
| @@ -407,6 +408,7 @@ set(libruntime_v100_src_files | |||
| 407 | ${RUNTIME_CORE_DIR}/src/stream/stream_state_callback_manager.cc | 408 | ${RUNTIME_CORE_DIR}/src/stream/stream_state_callback_manager.cc |
| 408 | ${RUNTIME_CORE_DIR}/src/event/event_state_callback_manager.cc | 409 | ${RUNTIME_CORE_DIR}/src/event/event_state_callback_manager.cc |
| 409 | ${RUNTIME_CORE_DIR}/src/plugin_manage/v100/plugin_old_arch.cc | 410 | ${RUNTIME_CORE_DIR}/src/plugin_manage/v100/plugin_old_arch.cc |
| 411 | + ${RUNTIME_CORE_DIR}/src/task/v200/task_david_stub.cc | ||
| 410 | ${libruntime_dev_info_src_files} | 412 | ${libruntime_dev_info_src_files} |
| 411 | ${libruntime_src_files_include_for_tiny} | 413 | ${libruntime_src_files_include_for_tiny} |
| 412 | ) | 414 | ) |
| @@ -427,6 +429,7 @@ set(RUNTIME_INC_DIR_TINY | |||
| 427 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel | 429 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel |
| 428 | ${RUNTIME_DIR}/src/runtime/core/inc/launch | 430 | ${RUNTIME_DIR}/src/runtime/core/inc/launch |
| 429 | ${RUNTIME_DIR}/src/runtime/core/inc/model | 431 | ${RUNTIME_DIR}/src/runtime/core/inc/model |
| 432 | + ${RUNTIME_DIR}/src/runtime/feature/jetty | ||
| 430 | ${RUNTIME_DIR}/src/runtime/core/inc/notify | 433 | ${RUNTIME_DIR}/src/runtime/core/inc/notify |
| 431 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler | 434 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler |
| 432 | ${RUNTIME_DIR}/src/runtime/core/inc/soc | 435 | ${RUNTIME_DIR}/src/runtime/core/inc/soc |
| @@ -161,11 +161,15 @@ set(libruntime_v200_stream_common_src_files | |||
| 161 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc | 161 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc |
| 162 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc | 162 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc |
| 163 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc | 163 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc |
| 164 | - ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc | 164 | + ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc |
| 165 | - ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc | 165 | + ${RUNTIME_FEATURE_DIR}/jetty/jetty_manager.cc |
| 166 | - ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc | 166 | + ${RUNTIME_FEATURE_DIR}/jetty/jetty_pool.cc |
| 167 | - ${RUNTIME_CORE_DIR}/src/stream/stream_factory.cc | 167 | + ${RUNTIME_FEATURE_DIR}/jetty/stream_jetty_context.cc |
| 168 | -) | 168 | + ${RUNTIME_FEATURE_DIR}/jetty/stream_jetty_handler.cc |
| 169 | + ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc | ||
| 170 | + ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc | ||
| 171 | + ${RUNTIME_CORE_DIR}/src/stream/stream_factory.cc | ||
| 172 | +) | ||
| 169 | 173 | ||
| 170 | # david | 174 | # david |
| 171 | set(libruntime_v200_stream_src_files | 175 | set(libruntime_v200_stream_src_files |
| @@ -446,6 +450,7 @@ set(RUNTIME_INC_DIR_COMMON_V200 | |||
| 446 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel | 450 | ${RUNTIME_DIR}/src/runtime/core/inc/kernel |
| 447 | ${RUNTIME_DIR}/src/runtime/core/inc/launch | 451 | ${RUNTIME_DIR}/src/runtime/core/inc/launch |
| 448 | ${RUNTIME_DIR}/src/runtime/core/inc/model | 452 | ${RUNTIME_DIR}/src/runtime/core/inc/model |
| 453 | + ${RUNTIME_DIR}/src/runtime/feature/jetty | ||
| 449 | ${RUNTIME_DIR}/src/runtime/core/inc/notify | 454 | ${RUNTIME_DIR}/src/runtime/core/inc/notify |
| 450 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler | 455 | ${RUNTIME_DIR}/src/runtime/core/inc/profiler |
| 451 | ${RUNTIME_DIR}/src/runtime/core/inc/soc | 456 | ${RUNTIME_DIR}/src/runtime/core/inc/soc |
| @@ -305,6 +305,7 @@ constexpr int32_t RT_ERROR_SEND_MSG = 0x07110013; | |||
| 305 | constexpr int32_t RT_ERROR_NOT_SET_SYSPARAMOPT = 0x07110014; | 305 | constexpr int32_t RT_ERROR_NOT_SET_SYSPARAMOPT = 0x07110014; |
| 306 | constexpr int32_t RT_ERROR_INSUFFICIENT_INPUT_ARRAY = 0x07110015; | 306 | constexpr int32_t RT_ERROR_INSUFFICIENT_INPUT_ARRAY = 0x07110015; |
| 307 | constexpr int32_t RT_ERROR_INVALID_HANDLE = 0x07110016; | 307 | constexpr int32_t RT_ERROR_INVALID_HANDLE = 0x07110016; |
| 308 | +constexpr int32_t RT_ERROR_JETTY_POOL_NO_RESOURCES = 0x07110017; | ||
| 308 | 309 | ||
| 309 | constexpr int32_t RT_ERROR_DEBUG_BASE = 0x07120000; | 310 | constexpr int32_t RT_ERROR_DEBUG_BASE = 0x07120000; |
| 310 | constexpr int32_t RT_ERROR_DEBUG_NULL = 0x07120001; | 311 | constexpr int32_t RT_ERROR_DEBUG_NULL = 0x07120001; |
| @@ -524,6 +524,8 @@ public: | |||
| 524 | void ProcessReportFastRingBuffer() const; | 524 | void ProcessReportFastRingBuffer() const; |
| 525 | rtError_t TryRecycleCaptureModelResource(const uint32_t allocSqNum, const uint32_t ntfCnt, | 525 | rtError_t TryRecycleCaptureModelResource(const uint32_t allocSqNum, const uint32_t ntfCnt, |
| 526 | const CaptureModel * const excludeMdl); | 526 | const CaptureModel * const excludeMdl); |
| 527 | + rtError_t TryRecycleCaptureModelJettyResource(const CaptureModel * const excludeMdl, JettyType type); | ||
| 528 | + | ||
| 527 | void PushContextErrMsg(); | 529 | void PushContextErrMsg(); |
| 528 | void PopContextErrMsg(); | 530 | void PopContextErrMsg(); |
| 529 | virtual rtError_t TearDownStream(Stream *stm, bool flag = true) const; | 531 | virtual rtError_t TearDownStream(Stream *stm, bool flag = true) const; |
| @@ -28,6 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | + | ||
| 31 | 32 | ||
| 32 | namespace cce { | 33 | namespace cce { |
| 33 | namespace runtime { | 34 | namespace runtime { |
| @@ -44,125 +45,6 @@ using rtShmQuery_t = struct tagTsShmTaskMsg; | |||
| 44 | 45 | ||
| 45 | class Cdq; | 46 | class Cdq; |
| 46 | 47 | ||
| 47 | -struct ipcMemInfo_t { | ||
| 48 | - std::string name; | ||
| 49 | - bool locked; | ||
| 50 | - int32_t ref; | ||
| 51 | -}; | ||
| 52 | - | ||
| 53 | -struct LogicCqWaitInfo { | ||
| 54 | - uint32_t devId; | ||
| 55 | - uint32_t tsId; | ||
| 56 | - uint32_t cqId; | ||
| 57 | - bool isFastCq; | ||
| 58 | - int32_t timeout; // ms, -1: wait forever; 0: no wait return | ||
| 59 | - uint32_t streamId; // for v2 | ||
| 60 | - uint32_t taskId; // for v2 | ||
| 61 | -}; | ||
| 62 | - | ||
| 63 | -struct AsyncSqeUpdateInfo { | ||
| 64 | - uint32_t sqId; | ||
| 65 | - uint32_t sqe_pos; | ||
| 66 | -}; | ||
| 67 | - | ||
| 68 | -struct AsyncDmaWqeInputInfo { | ||
| 69 | - void *src; | ||
| 70 | - uint64_t size; | ||
| 71 | - uint32_t sqId; | ||
| 72 | - uint32_t tsId; | ||
| 73 | - uint32_t cpyType; | ||
| 74 | - union { | ||
| 75 | - void *destPtr; | ||
| 76 | - struct AsyncSqeUpdateInfo info; // sqe update场景使用 | ||
| 77 | - }; | ||
| 78 | -}; | ||
| 79 | - | ||
| 80 | -struct AsyncDmaWqeOutputInfo { | ||
| 81 | - union { | ||
| 82 | - struct { | ||
| 83 | - uint16_t dieId; | ||
| 84 | - uint16_t functionId; | ||
| 85 | - uint16_t jettyId; | ||
| 86 | - uint8_t *wqe; | ||
| 87 | - int32_t wqeLen; | ||
| 88 | - uint32_t pi; | ||
| 89 | - union { | ||
| 90 | - unsigned long long fixedSize; // used for 2d async copy in ub doorbell mode | ||
| 91 | - unsigned long long fixedCnt; // used for batch async copy in ub doorbell mode | ||
| 92 | - }; | ||
| 93 | - }; | ||
| 94 | - struct DMA_ADDR dmaAddr; | ||
| 95 | - }; | ||
| 96 | -}; | ||
| 97 | - | ||
| 98 | -struct AsyncDmaWqeDestroyInfo { | ||
| 99 | - uint32_t tsId; | ||
| 100 | - uint32_t sqId; | ||
| 101 | - union { | ||
| 102 | - struct { | ||
| 103 | - uint8_t *wqe; | ||
| 104 | - int32_t size; | ||
| 105 | - }; | ||
| 106 | - struct DMA_ADDR *dmaAddr; | ||
| 107 | - }; | ||
| 108 | -}; | ||
| 109 | - | ||
| 110 | - | ||
| 111 | -struct AsyncDmaWqeInputInfo2D { | ||
| 112 | - drvSqCqType_t type; | ||
| 113 | - uint32_t tsId; /* default is 0 */ | ||
| 114 | - uint32_t sqId; | ||
| 115 | - uint32_t dir; /* reserved copy direction, the real dir is convert by src/dst addr */ | ||
| 116 | - void *dst; /* destination memory address */ | ||
| 117 | - uint64_t dpitch; /* pitch of destination memory */ | ||
| 118 | - void *src; /* source memory address */ | ||
| 119 | - uint64_t destAddr; | ||
| 120 | - uint64_t spitch; /* pitch of source memory */ | ||
| 121 | - uint64_t width; /* width of matrix transfer */ | ||
| 122 | - uint64_t height; /* height of matrix transfer */ | ||
| 123 | - uint64_t fixedSize; /* Input: already converted size, current not support none zero */ | ||
| 124 | - uint32_t rsv[ASYNC_CPY_2D_IN_RSV_LEN]; | ||
| 125 | -}; | ||
| 126 | - | ||
| 127 | - | ||
| 128 | -struct AsyncDmaWqeDestroyInfo2D { | ||
| 129 | - drvSqCqType_t type; | ||
| 130 | - uint32_t tsId; | ||
| 131 | - uint32_t sqId; | ||
| 132 | - uint32_t ci; /* current jetty ci */ | ||
| 133 | - uint32_t rsv[ASYNC_CPY_2D_DESTROY_RSV_LEN]; | ||
| 134 | -}; | ||
| 135 | - | ||
| 136 | - | ||
| 137 | -struct AsyncDmaWqeInputInfoBatch { | ||
| 138 | - drvSqCqType_t type; | ||
| 139 | - uint32_t tsId; /* default is 0 */ | ||
| 140 | - uint32_t sqId; | ||
| 141 | - uint32_t dir; /* reserved copy direction, the real dir is convert by src/dst addr */ | ||
| 142 | - void **dsts; /* destination memory address array */ | ||
| 143 | - void **srcs; /* source memory address array */ | ||
| 144 | - uint64_t *lens; /* cpy size array */ | ||
| 145 | - uint64_t count; /* cpy array elements count */ | ||
| 146 | - uint64_t fixedCnt; /* Input: already converted array cnt */ | ||
| 147 | - uint32_t rsv[ASYNC_CPY_BATCH_IN_RSV_LEN]; | ||
| 148 | -}; | ||
| 149 | - | ||
| 150 | - | ||
| 151 | -struct AsyncDmaWqeDestroyInfoBatch { | ||
| 152 | - drvSqCqType_t type; | ||
| 153 | - uint32_t tsId; | ||
| 154 | - uint32_t sqId; | ||
| 155 | - uint32_t ci; /* current jetty ci */ | ||
| 156 | - uint32_t rsv[ASYNC_CPY_BATCH_DESTROY_RSV_LEN]; | ||
| 157 | -}; | ||
| 158 | - | ||
| 159 | -struct IpcNotifyOpenPara { | ||
| 160 | - const char_t *name; | ||
| 161 | - uint32_t flag; | ||
| 162 | - uint32_t localDevId; | ||
| 163 | - uint32_t localTsId; | ||
| 164 | -}; | ||
| 165 | - | ||
| 166 | constexpr int32_t PRE_ALLOC_SQ_CQ_RETRY_MAX_COUNT = 10; | 48 | constexpr int32_t PRE_ALLOC_SQ_CQ_RETRY_MAX_COUNT = 10; |
| 167 | 49 | ||
| 168 | // facade interface for driver. | 50 | // facade interface for driver. |
| @@ -675,6 +557,13 @@ public: | |||
| 675 | virtual rtError_t StreamMemPoolCreate(const uint32_t deviceId, const uint64_t poolId, const uint64_t va, const uint64_t size, bool isGraphPool) = 0; | 557 | virtual rtError_t StreamMemPoolCreate(const uint32_t deviceId, const uint64_t poolId, const uint64_t va, const uint64_t size, bool isGraphPool) = 0; |
| 676 | virtual rtError_t StreamMemPoolDestroy(const uint32_t deviceId, const uint64_t poolId) = 0; | 558 | virtual rtError_t StreamMemPoolDestroy(const uint32_t deviceId, const uint64_t poolId) = 0; |
| 677 | virtual rtError_t StreamMemPoolTrim(const uint32_t deviceId, const uint64_t poolId, uint64_t *size, uint64_t poolUsedSize, uint64_t poolFreeSize) = 0; | 559 | virtual rtError_t StreamMemPoolTrim(const uint32_t deviceId, const uint64_t poolId, uint64_t *size, uint64_t poolUsedSize, uint64_t poolFreeSize) = 0; |
| 560 | + virtual rtError_t AsyncDmaJettyCreate(const uint32_t devId, const uint32_t piType, | ||
| 561 | + const uint32_t depth, const uint32_t dir, uint64_t *const handle) = 0; | ||
| 562 | + virtual rtError_t AsyncDmaJettyDestroy(const uint32_t devId, const uint64_t handle) = 0; | ||
| 563 | + virtual rtError_t AsyncDmaJettyQuery(const uint32_t devId, const uint64_t handle, | ||
| 564 | + uint32_t &dieId, uint32_t &functionId, uint32_t &jettyId) = 0; | ||
| 565 | + virtual rtError_t AsyncDmaWqeConvert(const uint32_t devId, AsyncWqeInputPara *in, AsyncWqeOutputPara *out) = 0; | ||
| 566 | + virtual rtError_t AsyncDmaWqeFill(const uint32_t devId, AsyncWqeFillInfo *fillInfo) = 0; | ||
| 678 | 567 | ||
| 679 | virtual rtError_t SetStreamPriorityValue(Stream * const stm, const uint32_t streamPriority) = 0; | 568 | virtual rtError_t SetStreamPriorityValue(Stream * const stm, const uint32_t streamPriority) = 0; |
| 680 | virtual rtError_t GetStreamPriorityValue(Stream * const stm, uint32_t * const streamPriority) = 0; | 569 | virtual rtError_t GetStreamPriorityValue(Stream * const stm, uint32_t * const streamPriority) = 0; |
| @@ -0,0 +1,212 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2025 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +namespace cce { | ||
| 18 | +namespace runtime { | ||
| 19 | + | ||
| 20 | +struct ipcMemInfo_t { | ||
| 21 | + std::string name; | ||
| 22 | + bool locked; | ||
| 23 | + int32_t ref; | ||
| 24 | +}; | ||
| 25 | + | ||
| 26 | +struct LogicCqWaitInfo { | ||
| 27 | + uint32_t devId; | ||
| 28 | + uint32_t tsId; | ||
| 29 | + uint32_t cqId; | ||
| 30 | + bool isFastCq; | ||
| 31 | + int32_t timeout; | ||
| 32 | + uint32_t streamId; | ||
| 33 | + uint32_t taskId; | ||
| 34 | +}; | ||
| 35 | + | ||
| 36 | +struct AsyncSqeUpdateInfo { | ||
| 37 | + uint32_t sqId; | ||
| 38 | + uint32_t sqe_pos; | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +struct AsyncDmaWqeInputInfo { | ||
| 42 | + void *src; | ||
| 43 | + uint64_t size; | ||
| 44 | + uint32_t sqId; | ||
| 45 | + uint32_t tsId; | ||
| 46 | + uint32_t cpyType; | ||
| 47 | + union { | ||
| 48 | + void *destPtr; | ||
| 49 | + struct AsyncSqeUpdateInfo info; | ||
| 50 | + }; | ||
| 51 | +}; | ||
| 52 | + | ||
| 53 | +struct AsyncDmaWqeOutputInfo { | ||
| 54 | + union { | ||
| 55 | + struct { | ||
| 56 | + uint16_t dieId; | ||
| 57 | + uint16_t functionId; | ||
| 58 | + uint16_t jettyId; | ||
| 59 | + uint8_t *wqe; | ||
| 60 | + int32_t wqeLen; | ||
| 61 | + uint32_t pi; | ||
| 62 | + union { | ||
| 63 | + unsigned long long fixedSize; | ||
| 64 | + unsigned long long fixedCnt; | ||
| 65 | + }; | ||
| 66 | + }; | ||
| 67 | + struct DMA_ADDR dmaAddr; | ||
| 68 | + }; | ||
| 69 | +}; | ||
| 70 | + | ||
| 71 | +struct AsyncDmaWqeDestroyInfo { | ||
| 72 | + uint32_t tsId; | ||
| 73 | + uint32_t sqId; | ||
| 74 | + union { | ||
| 75 | + struct { | ||
| 76 | + uint8_t *wqe; | ||
| 77 | + int32_t size; | ||
| 78 | + }; | ||
| 79 | + struct DMA_ADDR *dmaAddr; | ||
| 80 | + }; | ||
| 81 | +}; | ||
| 82 | + | ||
| 83 | + | ||
| 84 | +struct AsyncDmaWqeInputInfo2D { | ||
| 85 | + drvSqCqType_t type; | ||
| 86 | + uint32_t tsId; | ||
| 87 | + uint32_t sqId; | ||
| 88 | + uint32_t dir; | ||
| 89 | + void *dst; | ||
| 90 | + uint64_t dpitch; | ||
| 91 | + void *src; | ||
| 92 | + uint64_t destAddr; | ||
| 93 | + uint64_t spitch; | ||
| 94 | + uint64_t width; | ||
| 95 | + uint64_t height; | ||
| 96 | + uint64_t fixedSize; | ||
| 97 | + uint32_t rsv[ASYNC_CPY_2D_IN_RSV_LEN]; | ||
| 98 | +}; | ||
| 99 | + | ||
| 100 | + | ||
| 101 | +struct AsyncDmaWqeDestroyInfo2D { | ||
| 102 | + drvSqCqType_t type; | ||
| 103 | + uint32_t tsId; | ||
| 104 | + uint32_t sqId; | ||
| 105 | + uint32_t ci; | ||
| 106 | + uint32_t rsv[ASYNC_CPY_2D_DESTROY_RSV_LEN]; | ||
| 107 | +}; | ||
| 108 | + | ||
| 109 | +struct AsyncDmaBatchInfo { | ||
| 110 | + void **dsts; | ||
| 111 | + void **srcs; | ||
| 112 | + uint64_t *sizes; | ||
| 113 | + uint64_t count; | ||
| 114 | + uint64_t fixedCnt; | ||
| 115 | + uint64_t fixedSize; | ||
| 116 | +}; | ||
| 117 | + | ||
| 118 | + | ||
| 119 | +struct AsyncDmaWqeInputInfoBatch { | ||
| 120 | + drvSqCqType_t type; | ||
| 121 | + uint32_t tsId; | ||
| 122 | + uint32_t sqId; | ||
| 123 | + uint32_t dir; | ||
| 124 | + void **dsts; | ||
| 125 | + void **srcs; | ||
| 126 | + uint64_t *lens; | ||
| 127 | + uint64_t count; | ||
| 128 | + uint64_t fixedCnt; | ||
| 129 | + uint32_t rsv[ASYNC_CPY_BATCH_IN_RSV_LEN]; | ||
| 130 | +}; | ||
| 131 | + | ||
| 132 | + | ||
| 133 | +struct AsyncDmaWqeDestroyInfoBatch { | ||
| 134 | + drvSqCqType_t type; | ||
| 135 | + uint32_t tsId; | ||
| 136 | + uint32_t sqId; | ||
| 137 | + uint32_t ci; | ||
| 138 | + uint32_t rsv[ASYNC_CPY_BATCH_DESTROY_RSV_LEN]; | ||
| 139 | +}; | ||
| 140 | + | ||
| 141 | +struct IpcNotifyOpenPara { | ||
| 142 | + const char_t *name; | ||
| 143 | + uint32_t flag; | ||
| 144 | + uint32_t localDevId; | ||
| 145 | + uint32_t localTsId; | ||
| 146 | +}; | ||
| 147 | + | ||
| 148 | +struct AsyncDmaJettyHandle { | ||
| 149 | + uint64_t handle; | ||
| 150 | + uint32_t rsv[8]; | ||
| 151 | +}; | ||
| 152 | + | ||
| 153 | +struct AsyncWqeInputPara { | ||
| 154 | + uint32_t wqeType; /* 见drv_async_dma_type */ | ||
| 155 | + uint8_t *wqeBuffer; /* 入参buffer, 直接传入wqe buffer地址,不做二次拷贝 */ | ||
| 156 | + uint32_t size; /* 入参buffer大小 size */ | ||
| 157 | + union { | ||
| 158 | + struct { | ||
| 159 | + uint8_t *src; /* source memory address array */ | ||
| 160 | + uint8_t *dst; /* destination memory address array */ | ||
| 161 | + uint64_t len; /* normal len */ | ||
| 162 | + } normal; | ||
| 163 | + struct { /* h2d/d2h 与 d2d 不混合 */ | ||
| 164 | + uint64_t *src; /* source memory address array */ | ||
| 165 | + uint64_t *dst; /* destination memory address array */ | ||
| 166 | + uint64_t *len; /* cpy size array */ | ||
| 167 | + uint64_t count; /* cpy array elements count */ | ||
| 168 | + } batch; | ||
| 169 | + struct { | ||
| 170 | + uint64_t *src; /* source memory address array */ | ||
| 171 | + uint64_t *dst; /* destination memory address array */ | ||
| 172 | + uint64_t dpitch; /* pitch of destination memory */ | ||
| 173 | + uint64_t spitch; /* pitch of source memory */ | ||
| 174 | + uint64_t width; /* width of matrix transfer */ | ||
| 175 | + uint64_t height; /* height of matrix transfer */ | ||
| 176 | + uint64_t fixedSize; /* Input: already converted size */ | ||
| 177 | + } matrix2d; | ||
| 178 | + struct { /* for nop wqe */ | ||
| 179 | + uint64_t nopCnt; | ||
| 180 | + } nop; | ||
| 181 | + }; | ||
| 182 | + uint32_t rsv[20]; | ||
| 183 | +}; | ||
| 184 | + | ||
| 185 | +struct AsyncWqeOutputPara { | ||
| 186 | + uint32_t wqeCnt; /* 转化出返回多少个wqe */ | ||
| 187 | + /* | ||
| 188 | + * batch: already complete-converted array element; | ||
| 189 | + * others: 0 for partially-converted, 1 for complete-converted | ||
| 190 | + */ | ||
| 191 | + uint64_t fixedCnt; | ||
| 192 | + /* | ||
| 193 | + * batch: the actual-converted size for the next partially-converted array element; | ||
| 194 | + * others: fixedSize return the actual-converted size if fixedCnt is 0, otherwhise return 0 | ||
| 195 | + */ | ||
| 196 | + uint64_t fixedSize; | ||
| 197 | + uint32_t rsv[8]; | ||
| 198 | +}; | ||
| 199 | + | ||
| 200 | +struct AsyncWqeFillInfo { | ||
| 201 | + struct AsyncDmaJettyHandle jettyHandle; | ||
| 202 | + uint32_t offset; | ||
| 203 | + void *srcWqe; | ||
| 204 | + uint64_t size; | ||
| 205 | + uint32_t flag; | ||
| 206 | + uint32_t rsv[16]; | ||
| 207 | +}; | ||
| 208 | + | ||
| 209 | +} // namespace runtime | ||
| 210 | +} // namespace cce | ||
| 211 | + | ||
| 212 | + | ||
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | namespace cce { | 20 | namespace cce { |
| @@ -264,14 +265,17 @@ public: | |||
| 264 | rtError_t ReleaseNotifyId(void); | 265 | rtError_t ReleaseNotifyId(void); |
| 265 | rtError_t UpdateNotifyId(Stream * const exeStream); | 266 | rtError_t UpdateNotifyId(Stream * const exeStream); |
| 266 | // endGraph + alloc sq cq + Send sqe + bind sq cq + load complete + update task | 267 | // endGraph + alloc sq cq + Send sqe + bind sq cq + load complete + update task |
| 267 | - rtError_t BuildSqCq(Stream * const exeStream); | 268 | + rtError_t BuildResource(Stream * const exeStream); |
| 268 | void DeconstructSqCq(void); | 269 | void DeconstructSqCq(void); |
| 269 | rtError_t ReleaseSqCq(uint32_t &releaseNum); | 270 | rtError_t ReleaseSqCq(uint32_t &releaseNum); |
| 270 | - void CaptureModelExecuteFinish(void); | 271 | + void CaptureModelExecuteFinish(const uint32_t errCode); |
| 271 | rtError_t MarkStreamActiveTask(TaskInfo *streamActiveTask); // the task of stream active is need updated | 272 | rtError_t MarkStreamActiveTask(TaskInfo *streamActiveTask); // the task of stream active is need updated |
| 272 | // after sq cq is allocated | 273 | // after sq cq is allocated |
| 273 | rtError_t RestoreForSoftwareSq(Device * const dev); | 274 | rtError_t RestoreForSoftwareSq(Device * const dev); |
| 274 | - | 275 | + |
| 276 | + rtError_t BindJettyForUbdma(); | ||
| 277 | + rtError_t RecycleAllJetty(uint32_t &h2dCount, uint32_t &d2dCount); | ||
| 278 | + rtError_t ReleaseAllJetty(); | ||
| 275 | private: | 279 | private: |
| 276 | rtError_t AllocSqAddr(void) const; // alloc sq addr | 280 | rtError_t AllocSqAddr(void) const; // alloc sq addr |
| 277 | rtError_t AllocSqCqProc(const uint32_t streamNum) const; | 281 | rtError_t AllocSqCqProc(const uint32_t streamNum) const; |
| @@ -284,7 +288,12 @@ private: | |||
| 284 | rtError_t BindSqCqAndSendSqe(void); | 288 | rtError_t BindSqCqAndSendSqe(void); |
| 285 | rtError_t BindStreamToModel(void); | 289 | rtError_t BindStreamToModel(void); |
| 286 | void ReportCacheTrackData(); | 290 | void ReportCacheTrackData(); |
| 287 | - | 291 | + rtError_t BindJetty(Stream * const stm, JettyType type); |
| 292 | + rtError_t RecycleJetty(int32_t streamId, JettyType type, uint32_t &count); | ||
| 293 | + rtError_t ReleaseJetty(int32_t streamId, JettyType type); | ||
| 294 | + rtError_t UnbindLargeJetty(int32_t streamId, JettyType type); | ||
| 295 | + rtError_t ReleaseAllLargeJetty(); | ||
| 296 | + rtError_t RefreshJettyInfoList(); | ||
| 288 | RtCaptureModelStatus captureModelStatus_{RtCaptureModelStatus::NONE}; | 297 | RtCaptureModelStatus captureModelStatus_{RtCaptureModelStatus::NONE}; |
| 289 | mutable uint32_t cacheOpInfoSwitch_{0U}; // aclgraph stream status: 0: false, 1:true | 298 | mutable uint32_t cacheOpInfoSwitch_{0U}; // aclgraph stream status: 0: false, 1:true |
| 290 | std::map<int32_t, std::map<uint32_t, std::unique_ptr<uint8_t []>>> shapeInfos_; | 299 | std::map<int32_t, std::map<uint32_t, std::unique_ptr<uint8_t []>>> shapeInfos_; |
| @@ -313,6 +322,7 @@ private: | |||
| 313 | bool trackDataReportFlag_{false}; | 322 | bool trackDataReportFlag_{false}; |
| 314 | std::atomic<uint32_t> seqId_{0}; | 323 | std::atomic<uint32_t> seqId_{0}; |
| 315 | std::set<void *> argLoaderBackup_; | 324 | std::set<void *> argLoaderBackup_; |
| 325 | + std::mutex jettyMutex_; | ||
| 316 | }; | 326 | }; |
| 317 | } | 327 | } |
| 318 | } | 328 | } |
| @@ -25,7 +25,7 @@ rtError_t GetCaptureStream(Context * const ctx, Stream * const stm, const Event | |||
| 25 | rtError_t CheckCaptureStreamThreadIsMatch(const Stream * const stm); | 25 | rtError_t CheckCaptureStreamThreadIsMatch(const Stream * const stm); |
| 26 | rtError_t CheckCaptureModelSupportSoftwareSq(Device* const dev); | 26 | rtError_t CheckCaptureModelSupportSoftwareSq(Device* const dev); |
| 27 | rtError_t CheckCaptureModelForUpdate(const Stream* stm); | 27 | rtError_t CheckCaptureModelForUpdate(const Stream* stm); |
| 28 | -bool IsSoftwareSqCaptureModel(Model * const mdl); | 28 | +bool IsSoftwareSqCaptureModel(const Model * const mdl); |
| 29 | bool CheckCaptureModeSupport(const Context* ctx, const char* funcName); | 29 | bool CheckCaptureModeSupport(const Context* ctx, const char* funcName); |
| 30 | bool NeedReBuildSqe(const TaskInfo *const task); | 30 | bool NeedReBuildSqe(const TaskInfo *const task); |
| 31 | bool IsUseHardwareEvent(Device * const dev); | 31 | bool IsUseHardwareEvent(Device * const dev); |
| @@ -218,7 +218,7 @@ public: | |||
| 218 | rtError_t ModelGetStreams(Stream **streams, uint32_t *numStreams) const; | 218 | rtError_t ModelGetStreams(Stream **streams, uint32_t *numStreams) const; |
| 219 | rtError_t ModelDestroyRegisterCallback(const rtCallback_t fn, const void *ptr); | 219 | rtError_t ModelDestroyRegisterCallback(const rtCallback_t fn, const void *ptr); |
| 220 | rtError_t ModelDestroyUnregisterCallback(const rtCallback_t fn); | 220 | rtError_t ModelDestroyUnregisterCallback(const rtCallback_t fn); |
| 221 | - rtError_t CacheLastTaskExtendInfo(const Stream* const stm, const char* infoPtr, const size_t infoSize); | 221 | + rtError_t CacheLastTaskExtendInfo(const Stream* const stm, const char* infoPtr, const size_t infoSize); |
| 222 | rtError_t GetTaskExtendInfo(int32_t streamId, uint32_t taskId, std::string& info) const; | 222 | rtError_t GetTaskExtendInfo(int32_t streamId, uint32_t taskId, std::string& info) const; |
| 223 | void ClearTaskExtendInfo(const int32_t streamId, const uint32_t taskId); | 223 | void ClearTaskExtendInfo(const int32_t streamId, const uint32_t taskId); |
| 224 | 224 | ||
| @@ -366,6 +366,16 @@ public: | |||
| 366 | firstExecuteFlag_.store(firstExecuteFlag); | 366 | firstExecuteFlag_.store(firstExecuteFlag); |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | + bool GetNeedUpdateUBPi() const | ||
| 370 | + { | ||
| 371 | + return needUpdateUbPi_.load(); | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + void SetNeedUpdateUBPi(bool needUpdateUbPi) | ||
| 375 | + { | ||
| 376 | + needUpdateUbPi_.store(needUpdateUbPi); | ||
| 377 | + } | ||
| 378 | + | ||
| 369 | void *GetFuncCallHostMem() const | 379 | void *GetFuncCallHostMem() const |
| 370 | { | 380 | { |
| 371 | return funcCallHostMem_; | 381 | return funcCallHostMem_; |
| @@ -462,6 +472,16 @@ public: | |||
| 462 | return d2dJettyInfoList_; | 472 | return d2dJettyInfoList_; |
| 463 | } | 473 | } |
| 464 | 474 | ||
| 475 | + void ClearH2dJettyInfoList() | ||
| 476 | + { | ||
| 477 | + h2dJettyInfoList_.clear(); | ||
| 478 | + } | ||
| 479 | + | ||
| 480 | + void ClearD2dJettyInfoList() | ||
| 481 | + { | ||
| 482 | + d2dJettyInfoList_.clear(); | ||
| 483 | + } | ||
| 484 | + | ||
| 465 | bool GetUbModelD2dFlag() const | 485 | bool GetUbModelD2dFlag() const |
| 466 | { | 486 | { |
| 467 | return isHasD2d_; | 487 | return isHasD2d_; |
| @@ -572,6 +592,7 @@ private: | |||
| 572 | std::list<Stream *> headStreams_; | 592 | std::list<Stream *> headStreams_; |
| 573 | std::mutex firstExecuteMutex_; | 593 | std::mutex firstExecuteMutex_; |
| 574 | std::atomic<bool> firstExecuteFlag_; | 594 | std::atomic<bool> firstExecuteFlag_; |
| 595 | + std::atomic<bool> needUpdateUbPi_; | ||
| 575 | void *funcCallHostMem_; | 596 | void *funcCallHostMem_; |
| 576 | uint64_t funCallMemSize_; | 597 | uint64_t funCallMemSize_; |
| 577 | uint64_t funcCallSvmMem_; // device侧内存 | 598 | uint64_t funcCallSvmMem_; // device侧内存 |
| @@ -550,6 +550,7 @@ void ConstructDavidSqeForProfilingDisableTask(TaskInfo * const taskInfo, rtDavid | |||
| 550 | void ConstructDavidSqeForProfilerTraceExTask(TaskInfo *taskInfo, rtDavidSqe_t *const davidSqe, uint64_t sqBaseAddr); | 550 | void ConstructDavidSqeForProfilerTraceExTask(TaskInfo *taskInfo, rtDavidSqe_t *const davidSqe, uint64_t sqBaseAddr); |
| 551 | void ConstructDavidSqeForMemcpyAsyncTask(TaskInfo * const taskInfo, rtDavidSqe_t *const davidSqe, | 551 | void ConstructDavidSqeForMemcpyAsyncTask(TaskInfo * const taskInfo, rtDavidSqe_t *const davidSqe, |
| 552 | uint64_t sqBaseAddr); | 552 | uint64_t sqBaseAddr); |
| 553 | +void ConstructDavidAsyncUbDbSqe(TaskInfo * const taskInfo, rtDavidSqe_t *const command); | ||
| 553 | void StarsV2MemcpyAsyncTaskUnInit(TaskInfo * const taskInfo); | 554 | void StarsV2MemcpyAsyncTaskUnInit(TaskInfo * const taskInfo); |
| 554 | void StarsV2DoCompleteSuccessForMemcpyAsyncTask(TaskInfo * const taskInfo, const uint32_t devId); | 555 | void StarsV2DoCompleteSuccessForMemcpyAsyncTask(TaskInfo * const taskInfo, const uint32_t devId); |
| 555 | rtError_t UbDbSendTaskInit(TaskInfo *taskInfo, const rtUbDbInfo_t *dbInfo, const uint16_t source); | 556 | rtError_t UbDbSendTaskInit(TaskInfo *taskInfo, const rtUbDbInfo_t *dbInfo, const uint16_t source); |
| @@ -238,10 +238,8 @@ struct UbDma { | |||
| 238 | bool isUbAsyncMode; | 238 | bool isUbAsyncMode; |
| 239 | int32_t wqeLen; | 239 | int32_t wqeLen; |
| 240 | uint32_t pi; | 240 | uint32_t pi; |
| 241 | - union { | 241 | + uint64_t fixedSize; |
| 242 | - uint64_t fixedSize; | 242 | + uint64_t fixedCnt; |
| 243 | - uint64_t fixedCnt; | ||
| 244 | - }; | ||
| 245 | }; | 243 | }; |
| 246 | 244 | ||
| 247 | struct MemcpyAsyncTaskInfo { | 245 | struct MemcpyAsyncTaskInfo { |
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + | ||
| 17 | namespace cce { | 18 | namespace cce { |
| 18 | namespace runtime { | 19 | namespace runtime { |
| 19 | rtError_t MemcopyAsyncPtr(void * const memcpyAddrInfo, const uint64_t destMax, const uint64_t count, | 20 | rtError_t MemcopyAsyncPtr(void * const memcpyAddrInfo, const uint64_t destMax, const uint64_t count, |
| @@ -22,8 +23,7 @@ namespace runtime { | |||
| 22 | rtError_t Memcpy2DAsync(void * const dst, const uint64_t dstPitch, const void * const src, const uint64_t srcPitch, | 23 | rtError_t Memcpy2DAsync(void * const dst, const uint64_t dstPitch, const void * const src, const uint64_t srcPitch, |
| 23 | const uint64_t width, const uint64_t height, const rtMemcpyKind_t kind, uint64_t * const realSize, | 24 | const uint64_t width, const uint64_t height, const rtMemcpyKind_t kind, uint64_t * const realSize, |
| 24 | Stream * const stm, const uint64_t fixedSize); | 25 | Stream * const stm, const uint64_t fixedSize); |
| 25 | - rtError_t MemcopyBatchAsync(void** const dsts, const uint64_t* const destMaxs, void** const srcs, const uint64_t* const sizes, | 26 | + rtError_t MemcopyBatchAsync(AsyncDmaBatchInfo &batchInfo, uint64_t * const realCnt, uint64_t * const realSize, Stream * const stm); |
| 26 | - const uint64_t count, uint64_t * const realSize, Stream * const stm, const uint64_t fixedSize); | ||
| 27 | rtError_t MemcopyAsync(void * const dst, const uint64_t destMax, const void * const src, const uint64_t cpySize, | 27 | rtError_t MemcopyAsync(void * const dst, const uint64_t destMax, const void * const src, const uint64_t cpySize, |
| 28 | const rtMemcpyKind_t kind, Stream * const stm, uint64_t * const realSize, | 28 | const rtMemcpyKind_t kind, Stream * const stm, uint64_t * const realSize, |
| 29 | const std::shared_ptr<void> &guardMem = nullptr, const rtTaskCfgInfo_t * const cfgInfo = nullptr, | 29 | const std::shared_ptr<void> &guardMem = nullptr, const rtTaskCfgInfo_t * const cfgInfo = nullptr, |
| @@ -707,11 +707,10 @@ rtError_t ApiImplDavid::MemCopy2DAsync(void * const dst, const uint64_t dstPitch | |||
| 707 | error = Memcpy2DAsync(dst, dstPitch, src, srcPitch, width, height, kind, &realSize, curStm, fixedSize); | 707 | error = Memcpy2DAsync(dst, dstPitch, src, srcPitch, width, height, kind, &realSize, curStm, fixedSize); |
| 708 | } | 708 | } |
| 709 | COND_RETURN_WITH_NOLOG((error != RT_ERROR_NONE), error); | 709 | COND_RETURN_WITH_NOLOG((error != RT_ERROR_NONE), error); |
| 710 | - if (Runtime::Instance()->GetConnectUbFlag() && !curStm->GetBindFlag() && | 710 | + if (Runtime::Instance()->GetConnectUbFlag() && (kind != RT_MEMCPY_DEVICE_TO_DEVICE)) { |
| 711 | - (kind != RT_MEMCPY_DEVICE_TO_DEVICE)) { | ||
| 712 | fixedSize = realSize; | 711 | fixedSize = realSize; |
| 713 | remainSize = totalSize - fixedSize; | 712 | remainSize = totalSize - fixedSize; |
| 714 | - if (remainSize > 0UL) { | 713 | + if (remainSize > 0UL && !(curStm->GetBindFlag())) { |
| 715 | error = curStm->Synchronize(); | 714 | error = curStm->Synchronize(); |
| 716 | ERROR_RETURN_MSG_INNER(error, "Failed to synchronize stream, retCode=%#x.", | 715 | ERROR_RETURN_MSG_INNER(error, "Failed to synchronize stream, retCode=%#x.", |
| 717 | static_cast<uint32_t>(error)); | 716 | static_cast<uint32_t>(error)); |
| @@ -743,8 +742,10 @@ rtError_t ApiImplDavid::BatchMemcpyAsync(void** const dsts, const size_t* const | |||
| 743 | size_t attrIdx = 0U; | 742 | size_t attrIdx = 0U; |
| 744 | rtPtrAttributes_t dstAttr = {}; | 743 | rtPtrAttributes_t dstAttr = {}; |
| 745 | rtPtrAttributes_t srcAttr = {}; | 744 | rtPtrAttributes_t srcAttr = {}; |
| 745 | + uint64_t realCnt = 0UL; | ||
| 746 | uint64_t realSize = 0UL; | 746 | uint64_t realSize = 0UL; |
| 747 | - uint64_t remainSize = count; | 747 | + uint64_t remainCnt = count; |
| 748 | + uint64_t fixedCnt = 0UL; | ||
| 748 | uint64_t fixedSize = 0UL; | 749 | uint64_t fixedSize = 0UL; |
| 749 | bool isD2HorH2DInvolvePageableMemory = false; | 750 | bool isD2HorH2DInvolvePageableMemory = false; |
| 750 | 751 | ||
| @@ -769,13 +770,15 @@ rtError_t ApiImplDavid::BatchMemcpyAsync(void** const dsts, const size_t* const | |||
| 769 | const_cast<size_t*>(attrsIdxs), numAttrs, failIdx); | 770 | const_cast<size_t*>(attrsIdxs), numAttrs, failIdx); |
| 770 | } | 771 | } |
| 771 | 772 | ||
| 772 | - while (remainSize > 0UL) { | 773 | + while (remainCnt > 0UL) { |
| 773 | - error = MemcopyBatchAsync(dsts, destMaxs, srcs, sizes, count, &realSize, curStm, fixedSize); | 774 | + AsyncDmaBatchInfo batchInfo = {dsts, srcs, const_cast<uint64_t*>(sizes), remainCnt, fixedCnt, fixedSize}; |
| 775 | + error = MemcopyBatchAsync(batchInfo, &realCnt, &realSize, curStm); | ||
| 774 | COND_RETURN_WITH_NOLOG((error != RT_ERROR_NONE), error); | 776 | COND_RETURN_WITH_NOLOG((error != RT_ERROR_NONE), error); |
| 775 | - // 这里的realSize返回的就是累计处理的量 | 777 | + // realCnt 本次处理的 |
| 778 | + fixedCnt = realCnt; | ||
| 776 | fixedSize = realSize; | 779 | fixedSize = realSize; |
| 777 | - remainSize = count - fixedSize; | 780 | + remainCnt -= fixedCnt; |
| 778 | - if (remainSize > 0UL) { | 781 | + if (remainCnt > 0UL && !(curStm->GetBindFlag())) { |
| 779 | error = curStm->Synchronize(); | 782 | error = curStm->Synchronize(); |
| 780 | ERROR_RETURN_MSG_INNER(error, "Failed to synchronize stream, retCode=%#x.", static_cast<uint32_t>(error)); | 783 | ERROR_RETURN_MSG_INNER(error, "Failed to synchronize stream, retCode=%#x.", static_cast<uint32_t>(error)); |
| 781 | } | 784 | } |
| @@ -800,7 +803,7 @@ rtError_t ApiImplDavid::MemcpyBatchAsync(void** const dsts, const size_t* const | |||
| 800 | 803 | ||
| 801 | if (!NpuDriver::CheckIsSupportFeature(curCtx->Device_()->Id_(), FEATURE_MEMCPY_BATCH_ASYNC)) { | 804 | if (!NpuDriver::CheckIsSupportFeature(curCtx->Device_()->Id_(), FEATURE_MEMCPY_BATCH_ASYNC)) { |
| 802 | // ub 单算子 | 805 | // ub 单算子 |
| 803 | - if (Runtime::Instance()->GetConnectUbFlag() && !curStm->GetBindFlag()) { | 806 | + if (Runtime::Instance()->GetConnectUbFlag()) { |
| 804 | return BatchMemcpyAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, curStm); | 807 | return BatchMemcpyAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, curStm); |
| 805 | } else { | 808 | } else { |
| 806 | return LoopMemcpyAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, stm); | 809 | return LoopMemcpyAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, stm); |
| @@ -90,6 +90,7 @@ void ErrorcodeManage::InitRtErrCodeMap() | |||
| 90 | rtErrMap_[RT_ERROR_DRV_OPER_NOT_PERMITTED] = {ACL_ERROR_RT_NO_PERMISSION, "driver error:operation no permitted"}; | 90 | rtErrMap_[RT_ERROR_DRV_OPER_NOT_PERMITTED] = {ACL_ERROR_RT_NO_PERMISSION, "driver error:operation no permitted"}; |
| 91 | rtErrMap_[RT_ERROR_DRV_NO_EVENT_RESOURCES] = {ACL_ERROR_RT_NO_EVENT_RESOURCE, "driver error:no event resource"}; | 91 | rtErrMap_[RT_ERROR_DRV_NO_EVENT_RESOURCES] = {ACL_ERROR_RT_NO_EVENT_RESOURCE, "driver error:no event resource"}; |
| 92 | rtErrMap_[RT_ERROR_DRV_NO_STREAM_RESOURCES] = {ACL_ERROR_RT_NO_STREAM_RESOURCE, "driver error:no stream resource"}; | 92 | rtErrMap_[RT_ERROR_DRV_NO_STREAM_RESOURCES] = {ACL_ERROR_RT_NO_STREAM_RESOURCE, "driver error:no stream resource"}; |
| 93 | + rtErrMap_[RT_ERROR_JETTY_POOL_NO_RESOURCES] = {ACL_ERROR_RT_NO_STREAM_RESOURCE, "driver error:no stream resource"}; | ||
| 93 | rtErrMap_[RT_ERROR_DRV_NO_NOTIFY_RESOURCES] = {ACL_ERROR_RT_NO_NOTIFY_RESOURCE, "driver error:no notify resource"}; | 94 | rtErrMap_[RT_ERROR_DRV_NO_NOTIFY_RESOURCES] = {ACL_ERROR_RT_NO_NOTIFY_RESOURCE, "driver error:no notify resource"}; |
| 94 | rtErrMap_[RT_ERROR_DRV_NO_MODEL_RESOURCES] = {ACL_ERROR_RT_NO_MODEL_RESOURCE, "driver error:no model resource"}; | 95 | rtErrMap_[RT_ERROR_DRV_NO_MODEL_RESOURCES] = {ACL_ERROR_RT_NO_MODEL_RESOURCE, "driver error:no model resource"}; |
| 95 | rtErrMap_[RT_ERROR_DRV_NOT_SUPPORT] = {ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "driver error:feature not support"}; | 96 | rtErrMap_[RT_ERROR_DRV_NOT_SUPPORT] = {ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "driver error:feature not support"}; |
| @@ -33,6 +33,9 @@ | |||
| 33 | 33 | ||
| 34 | namespace cce { | 34 | namespace cce { |
| 35 | namespace runtime { | 35 | namespace runtime { |
| 36 | + | ||
| 37 | +class JettyPool; | ||
| 38 | +class JettyManager; | ||
| 36 | constexpr uint32_t DMA_CPY_NUM_DEVICE_MAX = 5 * 1024U; | 39 | constexpr uint32_t DMA_CPY_NUM_DEVICE_MAX = 5 * 1024U; |
| 37 | 40 | ||
| 38 | constexpr uint32_t RT_DEFAULT_STACK_SIZE_32K = 32U * 1024U; | 41 | constexpr uint32_t RT_DEFAULT_STACK_SIZE_32K = 32U * 1024U; |
| @@ -310,6 +313,7 @@ public: | |||
| 310 | virtual StreamSqCqManage *GetStreamSqCqManage() const = 0; | 313 | virtual StreamSqCqManage *GetStreamSqCqManage() const = 0; |
| 311 | virtual TaskFactory *GetTaskFactory() const = 0; | 314 | virtual TaskFactory *GetTaskFactory() const = 0; |
| 312 | virtual MemoryPoolManager *GetKernelMemoryPool() const = 0; | 315 | virtual MemoryPoolManager *GetKernelMemoryPool() const = 0; |
| 316 | + virtual JettyManager *GetJettyManager() const = 0; | ||
| 313 | virtual uint32_t GetTschVersion() const = 0; | 317 | virtual uint32_t GetTschVersion() const = 0; |
| 314 | virtual uint32_t IsSupportHcomcpu() const = 0; | 318 | virtual uint32_t IsSupportHcomcpu() const = 0; |
| 315 | virtual uint64_t GetStarsRegBaseAddr() const = 0; | 319 | virtual uint64_t GetStarsRegBaseAddr() const = 0; |
| @@ -455,7 +459,8 @@ public: | |||
| 455 | virtual rtError_t GetPrintSimdAddress(uint64_t *const addr) = 0; | 459 | virtual rtError_t GetPrintSimdAddress(uint64_t *const addr) = 0; |
| 456 | virtual rtError_t GetPrintFifoAddrAndCreateThread(uint64_t * const addr, const uint32_t model) = 0; | 460 | virtual rtError_t GetPrintFifoAddrAndCreateThread(uint64_t * const addr, const uint32_t model) = 0; |
| 457 | virtual rtError_t StoreEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) = 0; | 461 | virtual rtError_t StoreEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) = 0; |
| 458 | - virtual rtError_t DeleteEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) = 0; | 462 | + virtual rtError_t DeleteEndGraphNotifyInfo( |
| 463 | + const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos, const uint32_t errCode) = 0; | ||
| 459 | virtual rtError_t ClearEndGraphNotifyInfoByModel(Model* captureModel) = 0; | 464 | virtual rtError_t ClearEndGraphNotifyInfoByModel(Model* captureModel) = 0; |
| 460 | virtual uint64_t AllocSqIdMemAddr() = 0; | 465 | virtual uint64_t AllocSqIdMemAddr() = 0; |
| 461 | virtual void FreeSqIdMemAddr(const uint64_t sqIdAddr) = 0; | 466 | virtual void FreeSqIdMemAddr(const uint64_t sqIdAddr) = 0; |
| @@ -717,6 +717,13 @@ rtError_t RawDevice::Init() | |||
| 717 | CreateMessageQueue(); | 717 | CreateMessageQueue(); |
| 718 | CreateFreeEventQueue(); | 718 | CreateFreeEventQueue(); |
| 719 | isSupportStopOnStreamError_ = IsSupportFeature(RtOptionalFeatureType::RT_FEATURE_DFX_STOP_ON_STREAM_ERROR); | 719 | isSupportStopOnStreamError_ = IsSupportFeature(RtOptionalFeatureType::RT_FEATURE_DFX_STOP_ON_STREAM_ERROR); |
| 720 | + | ||
| 721 | + if (Runtime::Instance()->GetConnectUbFlag()) { | ||
| 722 | + jettyManager_ = std::make_unique<JettyManager>(deviceId_); | ||
| 723 | + NULL_PTR_GOTO_MSG_INNER(jettyManager_, SQ_ADDR_MEMORY_FREE, error, RT_ERROR_MEMORY_ALLOCATION); | ||
| 724 | + RT_LOG(RT_LOG_INFO, "Jetty resources initialized for device_id=%u", deviceId_); | ||
| 725 | + } | ||
| 726 | + | ||
| 720 | return RT_ERROR_NONE; | 727 | return RT_ERROR_NONE; |
| 721 | 728 | ||
| 722 | SQ_ADDR_MEMORY_FREE: | 729 | SQ_ADDR_MEMORY_FREE: |
| @@ -2317,7 +2324,8 @@ rtError_t RawDevice::StoreEndGraphNotifyInfo(const uint32_t streamId, Model* cap | |||
| 2317 | return RT_ERROR_NONE; | 2324 | return RT_ERROR_NONE; |
| 2318 | } | 2325 | } |
| 2319 | 2326 | ||
| 2320 | -rtError_t RawDevice::DeleteEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) | 2327 | +rtError_t RawDevice::DeleteEndGraphNotifyInfo( |
| 2328 | + const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos, const uint32_t errCode) | ||
| 2321 | { | 2329 | { |
| 2322 | auto key = std::make_tuple(streamId, captureModel); | 2330 | auto key = std::make_tuple(streamId, captureModel); |
| 2323 | uint32_t numOfPos = 0; | 2331 | uint32_t numOfPos = 0; |
| @@ -2342,7 +2350,7 @@ rtError_t RawDevice::DeleteEndGraphNotifyInfo(const uint32_t streamId, Model* ca | |||
| 2342 | 2350 | ||
| 2343 | CaptureModel *captureModelTmp = static_cast<CaptureModel*>(captureModel); | 2351 | CaptureModel *captureModelTmp = static_cast<CaptureModel*>(captureModel); |
| 2344 | if (captureModelTmp != nullptr) { | 2352 | if (captureModelTmp != nullptr) { |
| 2345 | - (void)captureModelTmp->CaptureModelExecuteFinish(); | 2353 | + (void)captureModelTmp->CaptureModelExecuteFinish(errCode); |
| 2346 | } | 2354 | } |
| 2347 | } | 2355 | } |
| 2348 | 2356 | ||
| @@ -2419,7 +2427,7 @@ bool RawDevice::JudgeIsEndGraphNotifyWaitExecuted(const Stream* const exeStream, | |||
| 2419 | it = sqePosList.erase(it); | 2427 | it = sqePosList.erase(it); |
| 2420 | CaptureModel *captureModelTmp = static_cast<CaptureModel*>(captureModel); | 2428 | CaptureModel *captureModelTmp = static_cast<CaptureModel*>(captureModel); |
| 2421 | if (captureModelTmp != nullptr) { | 2429 | if (captureModelTmp != nullptr) { |
| 2422 | - (void)captureModelTmp->CaptureModelExecuteFinish(); | 2430 | + (void)captureModelTmp->CaptureModelExecuteFinish(RT_ERROR_NONE); |
| 2423 | } | 2431 | } |
| 2424 | } else { | 2432 | } else { |
| 2425 | break; | 2433 | break; |
| @@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | + | ||
| 24 | namespace cce { | 25 | namespace cce { |
| 25 | namespace runtime { | 26 | namespace runtime { |
| 26 | 27 | ||
| @@ -328,6 +329,11 @@ public: | |||
| 328 | return kernelMemPoolMng_; | 329 | return kernelMemPoolMng_; |
| 329 | } | 330 | } |
| 330 | 331 | ||
| 332 | + JettyManager *GetJettyManager() const override | ||
| 333 | + { | ||
| 334 | + return jettyManager_.get(); | ||
| 335 | + } | ||
| 336 | + | ||
| 331 | uint32_t GetTschVersion() const override | 337 | uint32_t GetTschVersion() const override |
| 332 | { | 338 | { |
| 333 | return tschVersion_; | 339 | return tschVersion_; |
| @@ -790,7 +796,7 @@ public: | |||
| 790 | rtError_t GetPrintFifoAddrAndCreateThread(uint64_t * const addr, const uint32_t model) override; | 796 | rtError_t GetPrintFifoAddrAndCreateThread(uint64_t * const addr, const uint32_t model) override; |
| 791 | 797 | ||
| 792 | rtError_t StoreEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) override; | 798 | rtError_t StoreEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) override; |
| 793 | - rtError_t DeleteEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos) override; | 799 | + rtError_t DeleteEndGraphNotifyInfo(const uint32_t streamId, Model* captureModel, uint32_t endGraphNotifyPos, const uint32_t errCode) override; |
| 794 | rtError_t ClearEndGraphNotifyInfoByModel(Model* captureModel) override; | 800 | rtError_t ClearEndGraphNotifyInfoByModel(Model* captureModel) override; |
| 795 | void PollEndGraphNotifyInfo(); | 801 | void PollEndGraphNotifyInfo(); |
| 796 | void PollEndGraphNotifyInfoByModelId(const uint32_t modelId); | 802 | void PollEndGraphNotifyInfoByModelId(const uint32_t modelId); |
| @@ -950,6 +956,7 @@ private: | |||
| 950 | MemoryPoolManager* kernelMemPoolMng_; | 956 | MemoryPoolManager* kernelMemPoolMng_; |
| 951 | uint64_t devProfStatus_; | 957 | uint64_t devProfStatus_; |
| 952 | StreamSqCqManage *streamSqCqManage_; | 958 | StreamSqCqManage *streamSqCqManage_; |
| 959 | + std::unique_ptr<JettyManager> jettyManager_; | ||
| 953 | uint32_t tschVersion_{static_cast<uint32_t>(TS_VERSION_LATEST)}; | 960 | uint32_t tschVersion_{static_cast<uint32_t>(TS_VERSION_LATEST)}; |
| 954 | uint32_t isSupportHcomcpu_{0U}; | 961 | uint32_t isSupportHcomcpu_{0U}; |
| 955 | DeviceErrorProc *deviceErrorProc_; | 962 | DeviceErrorProc *deviceErrorProc_; |
| @@ -81,6 +81,12 @@ rtError_t UbArgManage::ParseArgsCpyWqe(const StarsArgLoaderResult* const result, | |||
| 81 | { | 81 | { |
| 82 | Device * const dev = stream_->Device_(); | 82 | Device * const dev = stream_->Device_(); |
| 83 | const uint32_t devId = dev->Id_(); | 83 | const uint32_t devId = dev->Id_(); |
| 84 | + // aclgraph走驱动halMemcpy做同步拷贝 | ||
| 85 | + if (stream_->IsSoftwareSqEnable()) { | ||
| 86 | + return dev->Driver_()->MemCopySync( | ||
| 87 | + result->kerArgs, size, result->hostAddr, size, | ||
| 88 | + RT_MEMCPY_HOST_TO_DEVICE); | ||
| 89 | + } | ||
| 84 | struct halSqTaskArgsInfo sqArgsInfo = {}; | 90 | struct halSqTaskArgsInfo sqArgsInfo = {}; |
| 85 | sqArgsInfo.type = DRV_NORMAL_TYPE; | 91 | sqArgsInfo.type = DRV_NORMAL_TYPE; |
| 86 | sqArgsInfo.tsId = dev->DevGetTsId(); | 92 | sqArgsInfo.tsId = dev->DevGetTsId(); |
| @@ -25,16 +25,15 @@ rtError_t MemcpyAsyncTaskInitV2(TaskInfo * const taskInfo, void *const dst, cons | |||
| 25 | const uint64_t height, const uint32_t kind, const uint64_t fixedSize); | 25 | const uint64_t height, const uint32_t kind, const uint64_t fixedSize); |
| 26 | rtError_t MemcpyAsyncTaskInitV3(TaskInfo * const taskInfo, uint32_t cpyType, const void *srcAddr, | 26 | rtError_t MemcpyAsyncTaskInitV3(TaskInfo * const taskInfo, uint32_t cpyType, const void *srcAddr, |
| 27 | void *desAddr, const uint64_t cpySize, const rtTaskCfgInfo_t *cfgInfo, const rtD2DAddrCfgInfo_t * const addrCfg); | 27 | void *desAddr, const uint64_t cpySize, const rtTaskCfgInfo_t *cfgInfo, const rtD2DAddrCfgInfo_t * const addrCfg); |
| 28 | -rtError_t MemcpyAsyncBatchTaskInit(TaskInfo * const taskInfo, void** const dsts, | 28 | +rtError_t MemcpyAsyncBatchTaskInit(TaskInfo * const taskInfo, AsyncDmaBatchInfo &batchInfo); |
| 29 | - void** const srcs, const uint64_t* const sizes, const uint64_t count, const uint64_t fixedSize); | ||
| 30 | rtError_t MemcpyAsyncD2HTaskInit(TaskInfo * const taskInfo, const void *srcAddr, const uint64_t cpySize, | 29 | rtError_t MemcpyAsyncD2HTaskInit(TaskInfo * const taskInfo, const void *srcAddr, const uint64_t cpySize, |
| 31 | uint32_t sqId, uint32_t pos); | 30 | uint32_t sqId, uint32_t pos); |
| 32 | -rtError_t ConvertAsyncDma(TaskInfo * const taskInfo, TaskInfo * const updateTaskInfo, bool isSqeUpdate = false); | 31 | +rtError_t ConvertAsyncDma(TaskInfo * const taskInfo); |
| 32 | +rtError_t ConvertAsyncDmaForTaskUpdate(TaskInfo * const taskInfo, TaskInfo * const updateTaskInfo); | ||
| 33 | rtError_t ConvertAsyncDma2D(TaskInfo * const taskInfo2D, void *const dst, const uint64_t dstPitch, | 33 | rtError_t ConvertAsyncDma2D(TaskInfo * const taskInfo2D, void *const dst, const uint64_t dstPitch, |
| 34 | const void *const src, const uint64_t srcPitch, const uint64_t width, const uint64_t height, | 34 | const void *const src, const uint64_t srcPitch, const uint64_t width, const uint64_t height, |
| 35 | const uint64_t fixedSize); | 35 | const uint64_t fixedSize); |
| 36 | -rtError_t ConvertAsyncDmaBatch(TaskInfo * const taskInfo, void** const dsts, | 36 | +rtError_t ConvertAsyncDmaBatch(TaskInfo * const taskInfo, AsyncDmaBatchInfo &batchInfo); |
| 37 | - void** const srcs, const uint64_t* const sizes, const uint64_t count, const uint64_t fixedSize); | ||
| 38 | void ToCommandBodyForMemcpyAsyncTask(TaskInfo * const taskInfo, rtCommand_t *const command); | 37 | void ToCommandBodyForMemcpyAsyncTask(TaskInfo * const taskInfo, rtCommand_t *const command); |
| 39 | void SetStarsResultForMemcpyAsyncTask(TaskInfo * const taskInfo, const rtLogicCqReport_t &logicCq); | 38 | void SetStarsResultForMemcpyAsyncTask(TaskInfo * const taskInfo, const rtLogicCqReport_t &logicCq); |
| 40 | void PrintErrorInfoForMemcpyAsyncTask(TaskInfo * const taskInfo, const uint32_t devId); | 39 | void PrintErrorInfoForMemcpyAsyncTask(TaskInfo * const taskInfo, const uint32_t devId); |
| @@ -361,7 +361,7 @@ void DoCompleteSuccessForNotifyWaitTask(TaskInfo *taskInfo, const uint32_t devId | |||
| 361 | if ((taskInfo->u.notifywaitTask.isEndGraphNotify) && | 361 | if ((taskInfo->u.notifywaitTask.isEndGraphNotify) && |
| 362 | (taskInfo->u.notifywaitTask.captureModel != nullptr)) { | 362 | (taskInfo->u.notifywaitTask.captureModel != nullptr)) { |
| 363 | taskInfo->stream->Device_()->DeleteEndGraphNotifyInfo(taskInfo->stream->Id_(), | 363 | taskInfo->stream->Device_()->DeleteEndGraphNotifyInfo(taskInfo->stream->Id_(), |
| 364 | - taskInfo->u.notifywaitTask.captureModel, taskInfo->pos); | 364 | + taskInfo->u.notifywaitTask.captureModel, taskInfo->pos, taskInfo->errorCode); |
| 365 | } | 365 | } |
| 366 | } | 366 | } |
| 367 | 367 | ||
| @@ -22,7 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | - | 25 | +#include "stream_jetty_handler.h" |
| 26 | 26 | ||
| 27 | namespace cce { | 27 | namespace cce { |
| 28 | namespace runtime { | 28 | namespace runtime { |
| @@ -439,6 +439,40 @@ rtError_t MemcpyAsyncTaskInitV1(TaskInfo * const taskInfo, void *memcpyAddrInfo, | |||
| 439 | return RT_ERROR_NONE; | 439 | return RT_ERROR_NONE; |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | +static rtError_t ConvertAsyncDma2DForSoftWareSq(TaskInfo * const taskInfo2D, void *const dst, | ||
| 443 | + const void *const src, const uint64_t dstPitch, const uint64_t srcPitch, | ||
| 444 | + const uint64_t width, const uint64_t height, const uint64_t fixedSize) | ||
| 445 | +{ | ||
| 446 | + Stream * const stream = taskInfo2D->stream; | ||
| 447 | + const uint32_t devId = stream->Device_()->Id_(); | ||
| 448 | + MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo2D->u.memcpyAsyncTaskInfo); | ||
| 449 | + | ||
| 450 | + rtError_t error = RT_ERROR_NONE; | ||
| 451 | + JettyType jettyType = StreamJettyHandler::GetJettyTypeFromTask(taskInfo2D); | ||
| 452 | + AsyncWqeInputPara input = {}; | ||
| 453 | + AsyncWqeOutputPara output = {}; | ||
| 454 | + input.wqeType = static_cast<uint32_t>(DRV_ASYNC_DMA_TYPE_2D); | ||
| 455 | + input.matrix2d.src = RtPtrToPtr<uint64_t *>(RtPtrToPtr<uintptr_t>(src)); | ||
| 456 | + input.matrix2d.dst = RtPtrToPtr<uint64_t *>(RtPtrToPtr<uintptr_t>(dst)); | ||
| 457 | + | ||
| 458 | + input.matrix2d.dpitch = dstPitch; | ||
| 459 | + input.matrix2d.spitch = srcPitch; | ||
| 460 | + input.matrix2d.width = width; | ||
| 461 | + input.matrix2d.height = height; | ||
| 462 | + input.matrix2d.fixedSize = fixedSize; | ||
| 463 | + error = StreamJettyHandler::HandleUbDmaTask( | ||
| 464 | + stream, taskInfo2D, jettyType, &input, &output); | ||
| 465 | + if (error != RT_ERROR_NONE) { | ||
| 466 | + RT_LOG(RT_LOG_ERROR, "HandleUbDmaTask failed, device_id=%u, stream_id=%d, ret=%d.", | ||
| 467 | + devId, stream->Id_(), error); | ||
| 468 | + return error; | ||
| 469 | + } | ||
| 470 | + uint64_t size = (output.fixedSize == 0U) ? width * height - fixedSize : output.fixedSize; | ||
| 471 | + memcpyAsyncTaskInfo->ubDma.fixedSize = size; | ||
| 472 | + memcpyAsyncTaskInfo->size = size; | ||
| 473 | + return RT_ERROR_NONE; | ||
| 474 | +} | ||
| 475 | + | ||
| 442 | rtError_t ConvertAsyncDma2D(TaskInfo * const taskInfo2D, void *const dst, const uint64_t dstPitch, | 476 | rtError_t ConvertAsyncDma2D(TaskInfo * const taskInfo2D, void *const dst, const uint64_t dstPitch, |
| 443 | const void *const src, const uint64_t srcPitch, const uint64_t width, | 477 | const void *const src, const uint64_t srcPitch, const uint64_t width, |
| 444 | const uint64_t height, const uint64_t fixedSize) | 478 | const uint64_t height, const uint64_t fixedSize) |
| @@ -447,15 +481,19 @@ rtError_t ConvertAsyncDma2D(TaskInfo * const taskInfo2D, void *const dst, const | |||
| 447 | if (!isUbMode) { | 481 | if (!isUbMode) { |
| 448 | RT_LOG(RT_LOG_ERROR, "pcie does not support"); | 482 | RT_LOG(RT_LOG_ERROR, "pcie does not support"); |
| 449 | return RT_ERROR_INVALID_VALUE; | 483 | return RT_ERROR_INVALID_VALUE; |
| 450 | - } | 484 | + } |
| 451 | - | ||
| 452 | - MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo2D->u.memcpyAsyncTaskInfo); | ||
| 453 | Stream * const stream = taskInfo2D->stream; | 485 | Stream * const stream = taskInfo2D->stream; |
| 454 | - Driver * const driver = taskInfo2D->stream->Device_()->Driver_(); | ||
| 455 | const uint32_t devId = stream->Device_()->Id_(); | 486 | const uint32_t devId = stream->Device_()->Id_(); |
| 487 | + MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo2D->u.memcpyAsyncTaskInfo); | ||
| 488 | + memcpyAsyncTaskInfo->ubDma.isUbAsyncMode = true; | ||
| 489 | + | ||
| 490 | + if (stream->IsSoftwareSqEnable()) { | ||
| 491 | + return ConvertAsyncDma2DForSoftWareSq(taskInfo2D, dst, src, dstPitch, srcPitch, width, height, fixedSize); | ||
| 492 | + } | ||
| 493 | + | ||
| 494 | + Driver * const driver = stream->Device_()->Driver_(); | ||
| 456 | AsyncDmaWqeInputInfo2D input; | 495 | AsyncDmaWqeInputInfo2D input; |
| 457 | (void)memset_s(&input, sizeof(AsyncDmaWqeInputInfo2D), 0, sizeof(AsyncDmaWqeInputInfo2D)); | 496 | (void)memset_s(&input, sizeof(AsyncDmaWqeInputInfo2D), 0, sizeof(AsyncDmaWqeInputInfo2D)); |
| 458 | - memcpyAsyncTaskInfo->ubDma.isUbAsyncMode = true; | ||
| 459 | 497 | ||
| 460 | input.tsId = stream->Device_()->DevGetTsId(); | 498 | input.tsId = stream->Device_()->DevGetTsId(); |
| 461 | input.sqId = stream->GetSqId(); | 499 | input.sqId = stream->GetSqId(); |
| @@ -517,7 +555,7 @@ rtError_t MemcpyAsyncTaskInitV2(TaskInfo * const taskInfo, void *const dst, cons | |||
| 517 | return RT_ERROR_NONE; | 555 | return RT_ERROR_NONE; |
| 518 | } else { | 556 | } else { |
| 519 | // david UB 单算子场景 走 UB Doorbell模式 | 557 | // david UB 单算子场景 走 UB Doorbell模式 |
| 520 | - if (IsDavidUbDma(memcpyAsyncTaskInfo->copyType) && !stream->GetBindFlag()) { | 558 | + if (IsDavidUbDma(memcpyAsyncTaskInfo->copyType)) { |
| 521 | error = ConvertAsyncDma2D(taskInfo, dst, dstPitch, srcAddr, srcPitch, width, height, fixedSize); | 559 | error = ConvertAsyncDma2D(taskInfo, dst, dstPitch, srcAddr, srcPitch, width, height, fixedSize); |
| 522 | ERROR_RETURN_MSG_INNER(error, "ConvertAsyncDma2D failed, retCode=%#x.", error); | 560 | ERROR_RETURN_MSG_INNER(error, "ConvertAsyncDma2D failed, retCode=%#x.", error); |
| 523 | memcpyAsyncTaskInfo->dmaKernelConvertFlag = true; | 561 | memcpyAsyncTaskInfo->dmaKernelConvertFlag = true; |
| @@ -539,56 +577,180 @@ rtError_t MemcpyAsyncTaskInitV2(TaskInfo * const taskInfo, void *const dst, cons | |||
| 539 | } | 577 | } |
| 540 | } | 578 | } |
| 541 | 579 | ||
| 542 | -rtError_t ConvertAsyncDma(TaskInfo * const taskInfo, TaskInfo * const updateTaskInfo, bool isSqeUpdate) | 580 | +static rtError_t HandleUbModeDmaResult(TaskInfo * const taskInfo, const AsyncDmaWqeOutputInfo &output) |
| 543 | { | 581 | { |
| 544 | MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); | 582 | MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); |
| 545 | - Stream * const stream = taskInfo->stream; | 583 | + |
| 546 | - Driver * const driver = taskInfo->stream->Device_()->Driver_(); | 584 | + memcpyAsyncTaskInfo->ubDma.jettyId = output.jettyId; |
| 547 | - const uint32_t devId = stream->Device_()->Id_(); | 585 | + memcpyAsyncTaskInfo->ubDma.functionId = output.functionId; |
| 548 | - AsyncDmaWqeInputInfo input; | 586 | + memcpyAsyncTaskInfo->ubDma.dieId = output.dieId; |
| 549 | - (void)memset_s(&input, sizeof(AsyncDmaWqeInputInfo), 0, sizeof(AsyncDmaWqeInputInfo)); | 587 | + memcpyAsyncTaskInfo->ubDma.wqeLen = output.wqeLen; |
| 550 | - bool isUbMode = Runtime::Instance()->GetConnectUbFlag() ? true : false; | 588 | + memcpyAsyncTaskInfo->ubDma.wqePtr = output.wqe; |
| 551 | - memcpyAsyncTaskInfo->ubDma.isUbAsyncMode = isUbMode ? true : false; | 589 | + memcpyAsyncTaskInfo->ubDma.pi = 1U; |
| 552 | - | 590 | + if (output.wqeLen != 0) { |
| 553 | - if (isSqeUpdate) { | 591 | + const errno_t ret = memcpy_s(memcpyAsyncTaskInfo->ubDma.wqe.data(), sizeof(rtDavidSqe_t), |
| 554 | - input.info.sqe_pos = updateTaskInfo->id; | 592 | + output.wqe, static_cast<size_t>(output.wqeLen)); |
| 555 | - input.info.sqId = updateTaskInfo->stream->GetSqId(); | 593 | + if (ret != EOK) { |
| 556 | - input.tsId = updateTaskInfo->stream->Device_()->DevGetTsId(); | 594 | + RT_LOG(RT_LOG_ERROR, "Failed to call memcpy_s to copy output.wqe, src=%p, dest=%p, dest_max=%zu, count=%zu," |
| 557 | - } else { | 595 | + " retCode=%#x.", output.wqe, memcpyAsyncTaskInfo->ubDma.wqe.data(), sizeof(rtDavidSqe_t), static_cast<size_t>(output.wqeLen), ret); |
| 558 | - if (isUbMode) { | ||
| 559 | - input.destPtr = memcpyAsyncTaskInfo->destPtr; | ||
| 560 | - input.tsId = stream->Device_()->DevGetTsId(); | ||
| 561 | - } else { | ||
| 562 | - RT_LOG_INNER_MSG(RT_LOG_ERROR, "pcie is not supported."); | ||
| 563 | return RT_ERROR_INVALID_VALUE; | 596 | return RT_ERROR_INVALID_VALUE; |
| 564 | } | 597 | } |
| 565 | } | 598 | } |
| 599 | + return RT_ERROR_NONE; | ||
| 600 | +} | ||
| 601 | + | ||
| 602 | +static rtError_t ConvertAsyncDmaForSoftWareSqUb(TaskInfo * const taskInfo, TaskInfo * const updateTask, bool isSqeUpdate) | ||
| 603 | +{ | ||
| 604 | + Stream * const stream = taskInfo->stream; | ||
| 605 | + const uint32_t devId = stream->Device_()->Id_(); | ||
| 606 | + MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); | ||
| 607 | + | ||
| 608 | + // for task update, external event场景, 只会在单算子流上下memcpy | ||
| 609 | + if (isSqeUpdate) { | ||
| 610 | + COND_RETURN_ERROR(updateTask == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 611 | + "updateTask is null when isSqeUpdate is true."); | ||
| 612 | + } | ||
| 613 | + if (isSqeUpdate && ((stream->Flags() & RT_STREAM_PERSISTENT) == 0)) { | ||
| 614 | + AsyncDmaWqeInputInfo input = {}; | ||
| 615 | + memcpyAsyncTaskInfo->ubDma.isUbAsyncMode = true; | ||
| 616 | + input.tsId = stream->Device_()->DevGetTsId(); | ||
| 617 | + input.sqId = stream->GetSqId(); | ||
| 618 | + input.src = memcpyAsyncTaskInfo->src; | ||
| 619 | + input.size = memcpyAsyncTaskInfo->size; | ||
| 620 | + input.cpyType = memcpyAsyncTaskInfo->copyType; | ||
| 621 | + input.destPtr = RtValueToPtr<void *>(updateTask->stream->GetSqBaseAddr() + (updateTask->pos) * sizeof(rtDavidSqe_t)); | ||
| 622 | + AsyncDmaWqeOutputInfo output = {}; | ||
| 623 | + Driver * const driver = stream->Device_()->Driver_(); | ||
| 624 | + const rtError_t error = driver->CreateAsyncDmaWqe(devId, input, &output, true, false); | ||
| 625 | + COND_RETURN_ERROR((error != RT_ERROR_NONE), error, | ||
| 626 | + "Failed to call drv interface to create asyncDmaWqe, retCode=%#x.", static_cast<uint32_t>(error)); | ||
| 627 | + return HandleUbModeDmaResult(taskInfo, output); | ||
| 628 | + } | ||
| 629 | + | ||
| 630 | + JettyType jettyType = StreamJettyHandler::GetJettyTypeFromTask(taskInfo); | ||
| 631 | + AsyncWqeInputPara input = {}; | ||
| 632 | + AsyncWqeOutputPara output = {}; | ||
| 633 | + input.wqeType = static_cast<uint32_t>(DRV_ASYNC_DMA_TYPE_NORMAL); | ||
| 634 | + input.normal.dst = static_cast<uint8_t *>(memcpyAsyncTaskInfo->destPtr); | ||
| 635 | + input.normal.src = static_cast<uint8_t *>(memcpyAsyncTaskInfo->src); | ||
| 636 | + rtError_t error = RT_ERROR_NONE; | ||
| 637 | + if (isSqeUpdate) { | ||
| 638 | + void* sqeDeviceAddr = | ||
| 639 | + RtValueToPtr<void*>(updateTask->stream->GetSqBaseAddr() + (updateTask->pos) * sizeof(rtDavidSqe_t)); | ||
| 640 | + input.normal.dst = static_cast<uint8_t*>(sqeDeviceAddr); | ||
| 641 | + } | ||
| 642 | + input.normal.len = memcpyAsyncTaskInfo->size; | ||
| 643 | + error = StreamJettyHandler::HandleUbDmaTask( | ||
| 644 | + stream, taskInfo, jettyType, &input, &output); | ||
| 645 | + ERROR_RETURN_MSG_INNER(error, "HandleUbDmaTask failed, device_id=%u, stream_id=%d, ret=%d.", | ||
| 646 | + devId, stream->Id_(), error); | ||
| 647 | + return error; | ||
| 648 | +} | ||
| 649 | + | ||
| 650 | +static rtError_t ConvertAsyncDmaForSoftWareSqPcie(MemcpyAsyncTaskInfo * const cpyAsyncTask, TaskInfo * const updateTask) | ||
| 651 | +{ | ||
| 652 | + rtError_t error = RT_ERROR_NONE; | ||
| 653 | + Stream *updateStm = updateTask->stream; | ||
| 654 | + Driver * const curDrv = updateStm->Device_()->Driver_(); | ||
| 655 | + cpyAsyncTask->dmaAddr.offsetAddr.devid = static_cast<uint32_t>(updateStm->Device_()->Id_()); | ||
| 656 | + void *sqeDeviceAddr = RtValueToPtr<void *>(updateStm->GetSqBaseAddr() + (updateTask->pos) * sizeof(rtDavidSqe_t)); | ||
| 657 | + error = curDrv->MemConvertAddr(RtPtrToValue(cpyAsyncTask->src), RtPtrToValue(sqeDeviceAddr), | ||
| 658 | + cpyAsyncTask->size, &(cpyAsyncTask->dmaAddr)); | ||
| 659 | + COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "Failed to convert memory address, device_id=%d, stream_id=%d, retCode=%#x.", | ||
| 660 | + updateStm->Device_()->Id_(), updateStm->Id_(), static_cast<uint32_t>(error)); | ||
| 661 | + cpyAsyncTask->destPtr = sqeDeviceAddr; | ||
| 662 | + cpyAsyncTask->size = cpyAsyncTask->dmaAddr.fixed_size; | ||
| 663 | + return RT_ERROR_NONE; | ||
| 664 | +} | ||
| 665 | + | ||
| 666 | +/* | ||
| 667 | + only for UB | ||
| 668 | + 非扩流场景下, UB通过驱动获取DWQE,扩流场景:走jetty manager | ||
| 669 | + taskInfo: 下ubdma的流 | ||
| 670 | +*/ | ||
| 671 | +rtError_t ConvertAsyncDma(TaskInfo * const taskInfo) | ||
| 672 | +{ | ||
| 673 | + Stream * const stream = taskInfo->stream; | ||
| 674 | + Driver * const driver = stream->Device_()->Driver_(); | ||
| 675 | + const uint32_t devId = stream->Device_()->Id_(); | ||
| 676 | + bool isUbMode = Runtime::Instance()->GetConnectUbFlag() ? true : false; | ||
| 677 | + if (!isUbMode) { | ||
| 678 | + RT_LOG_INNER_MSG(RT_LOG_ERROR, "pcie is not supported."); | ||
| 679 | + return RT_ERROR_INVALID_VALUE; | ||
| 680 | + } | ||
| 681 | + MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); | ||
| 682 | + if (stream->IsSoftwareSqEnable()) { | ||
| 683 | + return ConvertAsyncDmaForSoftWareSqUb(taskInfo, nullptr, false); | ||
| 684 | + } | ||
| 685 | + | ||
| 686 | + AsyncDmaWqeInputInfo input; | ||
| 687 | + (void)memset_s(&input, sizeof(AsyncDmaWqeInputInfo), 0, sizeof(AsyncDmaWqeInputInfo)); | ||
| 688 | + memcpyAsyncTaskInfo->ubDma.isUbAsyncMode = true; | ||
| 689 | + input.destPtr = memcpyAsyncTaskInfo->destPtr; | ||
| 690 | + input.tsId = stream->Device_()->DevGetTsId(); | ||
| 566 | input.sqId = stream->GetSqId(); | 691 | input.sqId = stream->GetSqId(); |
| 567 | input.src = memcpyAsyncTaskInfo->src; | 692 | input.src = memcpyAsyncTaskInfo->src; |
| 568 | input.size = memcpyAsyncTaskInfo->size; | 693 | input.size = memcpyAsyncTaskInfo->size; |
| 569 | input.cpyType = memcpyAsyncTaskInfo->copyType; | 694 | input.cpyType = memcpyAsyncTaskInfo->copyType; |
| 570 | AsyncDmaWqeOutputInfo output; | 695 | AsyncDmaWqeOutputInfo output; |
| 571 | (void)memset_s(&output, sizeof(AsyncDmaWqeOutputInfo), 0, sizeof(AsyncDmaWqeOutputInfo)); | 696 | (void)memset_s(&output, sizeof(AsyncDmaWqeOutputInfo), 0, sizeof(AsyncDmaWqeOutputInfo)); |
| 572 | - const rtError_t error = driver->CreateAsyncDmaWqe(devId, input, &output, isUbMode, isSqeUpdate); | 697 | + const rtError_t error = driver->CreateAsyncDmaWqe(devId, input, &output, true, false); |
| 573 | COND_RETURN_ERROR((error != RT_ERROR_NONE), error, | 698 | COND_RETURN_ERROR((error != RT_ERROR_NONE), error, |
| 574 | "Failed to call drv interface to create asyncDmaWqe, retCode=%#x.", static_cast<uint32_t>(error)); | 699 | "Failed to call drv interface to create asyncDmaWqe, retCode=%#x.", static_cast<uint32_t>(error)); |
| 575 | - if (isUbMode) { | 700 | + |
| 576 | - // 模型场景下驱动接口wqe返回空,wqeLen返回0,不使用这两个参数 | 701 | + return HandleUbModeDmaResult(taskInfo, output); |
| 577 | - memcpyAsyncTaskInfo->ubDma.jettyId = output.jettyId; | 702 | +} |
| 578 | - memcpyAsyncTaskInfo->ubDma.functionId = output.functionId; | 703 | + |
| 579 | - memcpyAsyncTaskInfo->ubDma.dieId = output.dieId; | 704 | +/* |
| 580 | - memcpyAsyncTaskInfo->ubDma.wqeLen = output.wqeLen; | 705 | + for task update |
| 581 | - memcpyAsyncTaskInfo->ubDma.wqePtr = output.wqe; | 706 | + 非扩流场景下, PCIE通过驱动将目标更新的sqe addr转成dmaAddr,UB通过驱动获取DWQE |
| 582 | - memcpyAsyncTaskInfo->ubDma.pi = 1U; | 707 | + 扩流场景:1.pcie通过目的地址转换描述符 2.ub走jetty manager |
| 583 | - if (output.wqeLen != 0) { | 708 | + taskInfo: 下dma任务的stm,可能是模型里的stm,也可能是单算子流 |
| 584 | - const errno_t ret = memcpy_s(memcpyAsyncTaskInfo->ubDma.wqe.data(), sizeof(rtDavidSqe_t), | 709 | + updateTaskInfo: task update目标, 要被更新的task |
| 585 | - output.wqe, static_cast<size_t>(output.wqeLen)); | 710 | +*/ |
| 586 | - COND_AND_MSG_INNER(ret != EOK, "Failed to call memcpy_s to copy output.wqe, src=%p, dest=%p, dest_max=%zu, count=%zu," | 711 | +rtError_t ConvertAsyncDmaForTaskUpdate(TaskInfo * const taskInfo, TaskInfo * const updateTaskInfo) |
| 587 | - " retCode=%#x.", output.wqe, memcpyAsyncTaskInfo->ubDma.wqe.data(), sizeof(rtDavidSqe_t), static_cast<size_t>(output.wqeLen), ret); | 712 | +{ |
| 713 | + Stream * const stream = taskInfo->stream; | ||
| 714 | + bool isUbMode = Runtime::Instance()->GetConnectUbFlag() ? true : false; | ||
| 715 | + MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); | ||
| 716 | + // task update目标流为扩流的流 | ||
| 717 | + if (updateTaskInfo->stream->IsSoftwareSqEnable()) { | ||
| 718 | + Stream *updateStm = updateTaskInfo->stream; | ||
| 719 | + if (updateStm->GetSqBaseAddr() == 0ULL) { | ||
| 720 | + rtError_t err = updateStm->AllocSoftwareSqAddr( | ||
| 721 | + CAPTURE_TASK_RESERVED_NUM + updateStm->Device_()->GetDevProperties().expandStreamRsvTaskNum); | ||
| 722 | + COND_RETURN_ERROR(err != RT_ERROR_NONE, err, "Failed to allocate software SQ address, device_id=%d, stream_id=%d, retCode=%#x.", | ||
| 723 | + updateStm->Device_()->Id_(), updateStm->Id_(), static_cast<uint32_t>(err)); | ||
| 724 | + } | ||
| 725 | + if (isUbMode) { | ||
| 726 | + return ConvertAsyncDmaForSoftWareSqUb(taskInfo, updateTaskInfo, true); | ||
| 727 | + } else { | ||
| 728 | + return ConvertAsyncDmaForSoftWareSqPcie(memcpyAsyncTaskInfo, updateTaskInfo); | ||
| 588 | } | 729 | } |
| 589 | - } else { | ||
| 590 | - memcpyAsyncTaskInfo->dmaAddr = output.dmaAddr; | ||
| 591 | } | 730 | } |
| 731 | + | ||
| 732 | + AsyncDmaWqeInputInfo input; | ||
| 733 | + (void)memset_s(&input, sizeof(AsyncDmaWqeInputInfo), 0, sizeof(AsyncDmaWqeInputInfo)); | ||
| 734 | + memcpyAsyncTaskInfo->ubDma.isUbAsyncMode = isUbMode ? true : false; | ||
| 735 | + input.info.sqe_pos = updateTaskInfo->id; | ||
| 736 | + input.info.sqId = updateTaskInfo->stream->GetSqId(); | ||
| 737 | + input.tsId = updateTaskInfo->stream->Device_()->DevGetTsId(); | ||
| 738 | + input.sqId = stream->GetSqId(); | ||
| 739 | + input.src = memcpyAsyncTaskInfo->src; | ||
| 740 | + input.size = memcpyAsyncTaskInfo->size; | ||
| 741 | + input.cpyType = memcpyAsyncTaskInfo->copyType; | ||
| 742 | + AsyncDmaWqeOutputInfo output; | ||
| 743 | + (void)memset_s(&output, sizeof(AsyncDmaWqeOutputInfo), 0, sizeof(AsyncDmaWqeOutputInfo)); | ||
| 744 | + const uint32_t devId = stream->Device_()->Id_(); | ||
| 745 | + Driver * const driver = stream->Device_()->Driver_(); | ||
| 746 | + const rtError_t error = driver->CreateAsyncDmaWqe(devId, input, &output, isUbMode, true); | ||
| 747 | + COND_RETURN_ERROR((error != RT_ERROR_NONE), error, | ||
| 748 | + "Failed to call drv interface to create asyncDmaWqe, retCode=%#x.", static_cast<uint32_t>(error)); | ||
| 749 | + | ||
| 750 | + if (isUbMode) { | ||
| 751 | + return HandleUbModeDmaResult(taskInfo, output); | ||
| 752 | + } | ||
| 753 | + memcpyAsyncTaskInfo->dmaAddr = output.dmaAddr; | ||
| 592 | return RT_ERROR_NONE; | 754 | return RT_ERROR_NONE; |
| 593 | } | 755 | } |
| 594 | 756 | ||
| @@ -665,7 +827,7 @@ rtError_t MemcpyAsyncTaskInitV3(TaskInfo * const taskInfo, uint32_t cpyType, con | |||
| 665 | return RT_ERROR_NONE; | 827 | return RT_ERROR_NONE; |
| 666 | } | 828 | } |
| 667 | if (IsDavidUbDma(memcpyAsyncTaskInfo->copyType)) { | 829 | if (IsDavidUbDma(memcpyAsyncTaskInfo->copyType)) { |
| 668 | - error = ConvertAsyncDma(taskInfo, nullptr); | 830 | + error = ConvertAsyncDma(taskInfo); |
| 669 | COND_RETURN_ERROR((error != RT_ERROR_NONE), error, "ConvertAsyncDma failed, retCode=%#x.", error); | 831 | COND_RETURN_ERROR((error != RT_ERROR_NONE), error, "ConvertAsyncDma failed, retCode=%#x.", error); |
| 670 | taskInfo->needPostProc = true; | 832 | taskInfo->needPostProc = true; |
| 671 | } else if (IsPcieDma(memcpyAsyncTaskInfo->copyType) && (driver->GetRunMode() == RT_RUN_MODE_ONLINE)) { | 833 | } else if (IsPcieDma(memcpyAsyncTaskInfo->copyType) && (driver->GetRunMode() == RT_RUN_MODE_ONLINE)) { |
| @@ -80,7 +80,7 @@ static void ConstructDavidAsyncDmaSqe(TaskInfo * const taskInfo, rtDavidSqe_t *c | |||
| 80 | return; | 80 | return; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | -static void ConstructDavidAsyncUbDbSqe(TaskInfo * const taskInfo, rtDavidSqe_t *const command) | 83 | +void ConstructDavidAsyncUbDbSqe(TaskInfo * const taskInfo, rtDavidSqe_t *const command) |
| 84 | { | 84 | { |
| 85 | MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); | 85 | MemcpyAsyncTaskInfo *memcpyAsyncTaskInfo = &(taskInfo->u.memcpyAsyncTaskInfo); |
| 86 | Stream * const stream = taskInfo->stream; | 86 | Stream * const stream = taskInfo->stream; |
| @@ -0,0 +1,32 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2025 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +namespace cce { | ||
| 16 | +namespace runtime { | ||
| 17 | + | ||
| 18 | +void ConstructDavidAsyncUbDbSqe(TaskInfo * const taskInfo, rtDavidSqe_t *const command) | ||
| 19 | +{ | ||
| 20 | + UNUSED(taskInfo); | ||
| 21 | + UNUSED(command); | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +void ToConstructDavidSqe(TaskInfo *taskInfo, rtDavidSqe_t * const davidSqe, uint64_t sqBaseAddr) | ||
| 25 | +{ | ||
| 26 | + UNUSED(taskInfo); | ||
| 27 | + UNUSED(davidSqe); | ||
| 28 | + UNUSED(sqBaseAddr); | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +} // namespace runtime | ||
| 32 | +} // namespace cce | ||
| @@ -98,8 +98,10 @@ void ToConstructDavidSqe(TaskInfo *taskInfo, rtDavidSqe_t * const davidSqe, uint | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | if (Runtime::Instance()->GetConnectUbFlag()) { | 100 | if (Runtime::Instance()->GetConnectUbFlag()) { |
| 101 | - uint64_t allocTimes = | 101 | + uint64_t allocTimes = taskInfo->id; |
| 102 | - (RtPtrToPtr<TaskResManageDavid *>(taskInfo->stream->taskResMang_))->GetAllocNum(); | 102 | + if (taskInfo->stream->taskResMang_ != nullptr) { |
| 103 | + allocTimes = (RtPtrToPtr<TaskResManageDavid *>(taskInfo->stream->taskResMang_))->GetAllocNum(); | ||
| 104 | + } | ||
| 103 | davidSqe->phSqe.header.headUpdate = GetHeadUpdateFlag(allocTimes); | 105 | davidSqe->phSqe.header.headUpdate = GetHeadUpdateFlag(allocTimes); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| @@ -699,6 +699,16 @@ public: | |||
| 699 | rtError_t GetChipIdDieId(const uint32_t devId, const uint32_t remoteDevId, const uint32_t remotePhyId, | 699 | rtError_t GetChipIdDieId(const uint32_t devId, const uint32_t remoteDevId, const uint32_t remotePhyId, |
| 700 | int64_t &chipId, int64_t &dieId) override; | 700 | int64_t &chipId, int64_t &dieId) override; |
| 701 | rtError_t GetTopologyType(const uint32_t devId, const uint32_t remoteDevId, const uint32_t remotePhyId, int64_t * const val) override; | 701 | rtError_t GetTopologyType(const uint32_t devId, const uint32_t remoteDevId, const uint32_t remotePhyId, int64_t * const val) override; |
| 702 | + | ||
| 703 | + // jetty | ||
| 704 | + rtError_t AsyncDmaJettyCreate(const uint32_t devId, const uint32_t piType, const uint32_t depth, | ||
| 705 | + const uint32_t dir, uint64_t *const handle) override; | ||
| 706 | + rtError_t AsyncDmaJettyDestroy(const uint32_t devId, const uint64_t handle) override; | ||
| 707 | + rtError_t AsyncDmaJettyQuery(const uint32_t devId, const uint64_t handle, uint32_t &dieId, | ||
| 708 | + uint32_t &functionId, uint32_t &jettyId) override; | ||
| 709 | + rtError_t AsyncDmaWqeConvert(const uint32_t devId, AsyncWqeInputPara *in, AsyncWqeOutputPara *out) override; | ||
| 710 | + rtError_t AsyncDmaWqeFill(const uint32_t devId, AsyncWqeFillInfo *fillInfo) override; | ||
| 711 | + | ||
| 702 | rtError_t SetStreamPriorityValue(Stream * const stm, const uint32_t streamPriority) override; | 712 | rtError_t SetStreamPriorityValue(Stream * const stm, const uint32_t streamPriority) override; |
| 703 | rtError_t GetStreamPriorityValue(Stream * const stm, uint32_t * const streamPriority) override; | 713 | rtError_t GetStreamPriorityValue(Stream * const stm, uint32_t * const streamPriority) override; |
| 704 | 714 | ||
| @@ -134,6 +134,15 @@ drvError_t __attribute__((weak)) halAsyncDmaCreateBatch(uint32_t devId, struct h | |||
| 134 | struct halAsyncDmaOutputPara *out); | 134 | struct halAsyncDmaOutputPara *out); |
| 135 | drvError_t __attribute__((weak)) halAsyncDmaDestroyBatch(uint32_t devId, struct halAsyncDmaDestroyBatchPara *para); | 135 | drvError_t __attribute__((weak)) halAsyncDmaDestroyBatch(uint32_t devId, struct halAsyncDmaDestroyBatchPara *para); |
| 136 | 136 | ||
| 137 | +drvError_t __attribute__((weak)) halAsyncDmaJettyCreate( | ||
| 138 | + uint32_t devId, struct halAsyncDmaJettyCreateIn* in, struct halAsyncDmaJettyCreateOut* out); | ||
| 139 | +drvError_t __attribute__((weak)) halAsyncDmaJettyDestroy(uint32_t devId, struct halAsyncJettyDestroyPara* para); | ||
| 140 | +drvError_t __attribute__((weak)) halAsyncDmaJettyQuery( | ||
| 141 | + uint32_t devId, struct halAsyncDmaJettyQueryIn* in, struct halAsyncDmaJettyQueryOut* out); | ||
| 142 | +drvError_t __attribute__((weak)) halAsyncDmaWqeConvert( | ||
| 143 | + uint32_t devId, struct halAsyncDmaWqeInputPara* in, struct halAsyncDmaWqeOutputPara* out); | ||
| 144 | +drvError_t __attribute__((weak)) halAsyncDmaJettyWqeFill(uint32_t devId, struct halAsyncDmaJettyFillInfo* para); | ||
| 145 | + | ||
| 137 | drvError_t __attribute__((weak)) halSqTaskArgsAsyncCopy(uint32_t devId, struct halSqTaskArgsInfo *info); | 146 | drvError_t __attribute__((weak)) halSqTaskArgsAsyncCopy(uint32_t devId, struct halSqTaskArgsInfo *info); |
| 138 | drvError_t __attribute__((weak)) halResAddrMap(unsigned int devId, struct res_addr_info *res_info, | 147 | drvError_t __attribute__((weak)) halResAddrMap(unsigned int devId, struct res_addr_info *res_info, |
| 139 | unsigned long *va, unsigned int *len); | 148 | unsigned long *va, unsigned int *len); |
| @@ -686,5 +686,149 @@ rtError_t NpuDriver::StreamMemPoolTrim(const uint32_t deviceId, const uint64_t p | |||
| 686 | static_cast<int32_t>(drvRet)); | 686 | static_cast<int32_t>(drvRet)); |
| 687 | return RT_ERROR_NONE; | 687 | return RT_ERROR_NONE; |
| 688 | } | 688 | } |
| 689 | + | ||
| 690 | +rtError_t NpuDriver::AsyncDmaJettyCreate( | ||
| 691 | + const uint32_t devId, const uint32_t piType, const uint32_t depth, const uint32_t dir, uint64_t* const handle) | ||
| 692 | +{ | ||
| 693 | + COND_RETURN_WARN( | ||
| 694 | + &halAsyncDmaJettyCreate == nullptr, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 695 | + "[drv api] halAsyncDmaJettyCreate does not exist"); | ||
| 696 | + struct halAsyncDmaJettyCreateIn input = {}; | ||
| 697 | + input.jettyType = DRV_ASYNC_DMA_JETTY_TYPE_NORMAL; | ||
| 698 | + input.piMode = static_cast<drvAsyncDmaJettyPiMode_t>(piType); | ||
| 699 | + input.dir = static_cast<drvAsyncDmaJettyDir_t>(dir); | ||
| 700 | + input.depth = depth; | ||
| 701 | + struct halAsyncDmaJettyCreateOut output = {}; | ||
| 702 | + const drvError_t drvRet = halAsyncDmaJettyCreate(devId, &input, &output); | ||
| 703 | + if (drvRet != DRV_ERROR_NONE) { | ||
| 704 | + DRV_ERROR_PROCESS( | ||
| 705 | + drvRet, "[drv api] halAsyncDmaJettyCreate failed: devId=%u, drvRetCode=%d", devId, | ||
| 706 | + static_cast<int32_t>(drvRet)); | ||
| 707 | + } | ||
| 708 | + if (drvRet == DRV_ERROR_NONE) { | ||
| 709 | + *handle = RtPtrToValue(output.jettyHandle); | ||
| 710 | + } | ||
| 711 | + return RT_GET_DRV_ERRCODE(drvRet); | ||
| 712 | +} | ||
| 713 | + | ||
| 714 | +rtError_t NpuDriver::AsyncDmaJettyDestroy(const uint32_t devId, const uint64_t handle) | ||
| 715 | +{ | ||
| 716 | + COND_RETURN_WARN( | ||
| 717 | + &halAsyncDmaJettyDestroy == nullptr, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 718 | + "[drv api] halAsyncDmaJettyDestroy does not exist"); | ||
| 719 | + struct halAsyncJettyDestroyPara param = {}; | ||
| 720 | + param.jettyHandle = RtValueToPtr<halAsyncJettyHandle*>(handle); | ||
| 721 | + const drvError_t drvRet = halAsyncDmaJettyDestroy(devId, ¶m); | ||
| 722 | + if (drvRet != DRV_ERROR_NONE) { | ||
| 723 | + DRV_ERROR_PROCESS( | ||
| 724 | + drvRet, "[drv api] halAsyncDmaJettyDestroy failed: handle=%lu, drvRetCode=%d", handle, | ||
| 725 | + static_cast<int32_t>(drvRet)); | ||
| 726 | + } | ||
| 727 | + return RT_GET_DRV_ERRCODE(drvRet); | ||
| 728 | +} | ||
| 729 | + | ||
| 730 | +rtError_t NpuDriver::AsyncDmaJettyQuery( | ||
| 731 | + const uint32_t devId, const uint64_t handle, uint32_t& dieId, uint32_t& functionId, uint32_t& jettyId) | ||
| 732 | +{ | ||
| 733 | + COND_RETURN_WARN( | ||
| 734 | + &halAsyncDmaJettyQuery == nullptr, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 735 | + "[drv api] halAsyncDmaJettyQuery does not exist"); | ||
| 736 | + struct halAsyncDmaJettyQueryIn in = {}; | ||
| 737 | + in.jettyHandle = RtValueToPtr<halAsyncJettyHandle*>(handle); | ||
| 738 | + struct halAsyncDmaJettyQueryOut out = {}; | ||
| 739 | + const drvError_t drvRet = halAsyncDmaJettyQuery(devId, &in, &out); | ||
| 740 | + if (drvRet != DRV_ERROR_NONE) { | ||
| 741 | + DRV_ERROR_PROCESS( | ||
| 742 | + drvRet, "[drv api] halAsyncDmaJettyQuery failed: handle=%lu, drvRetCode=%d", | ||
| 743 | + handle, static_cast<int32_t>(drvRet)); | ||
| 744 | + } | ||
| 745 | + if (drvRet == DRV_ERROR_NONE) { | ||
| 746 | + dieId = out.dieId; | ||
| 747 | + functionId = out.funcId; | ||
| 748 | + jettyId = out.jettyId; | ||
| 749 | + } | ||
| 750 | + return RT_GET_DRV_ERRCODE(drvRet); | ||
| 751 | +} | ||
| 752 | + | ||
| 753 | +// AsyncDmaWqeConvert | ||
| 754 | +rtError_t NpuDriver::AsyncDmaWqeConvert(const uint32_t devId, AsyncWqeInputPara* inParam, AsyncWqeOutputPara* outParam) | ||
| 755 | +{ | ||
| 756 | + COND_RETURN_WARN(&halAsyncDmaWqeConvert == nullptr, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 757 | + "[drv api] halAsyncDmaWqeConvert does not exist"); | ||
| 758 | + COND_RETURN_ERROR(inParam == nullptr || outParam == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 759 | + "AsyncDmaWqeConvert: inParam or outParam is null."); | ||
| 760 | + | ||
| 761 | + struct halAsyncDmaWqeInputPara halIn = {}; | ||
| 762 | + halIn.wqeType = static_cast<drvAsyncDmaType_t>(inParam->wqeType); | ||
| 763 | + halIn.wqeBuffer = inParam->wqeBuffer; | ||
| 764 | + halIn.wqeBufferLen = inParam->size; | ||
| 765 | + | ||
| 766 | + switch (inParam->wqeType) { | ||
| 767 | + case DRV_ASYNC_DMA_TYPE_NORMAL: | ||
| 768 | + halIn.normal.asyncDmaType = DRV_ASYNC_DMA_TYPE_NORMAL; | ||
| 769 | + halIn.normal.src = inParam->normal.src; | ||
| 770 | + halIn.normal.dst = inParam->normal.dst; | ||
| 771 | + halIn.normal.len = inParam->normal.len; | ||
| 772 | + break; | ||
| 773 | + case DRV_ASYNC_DMA_TYPE_BATCH: | ||
| 774 | + halIn.batch.src = RtPtrToPtr<UINT64 *>(inParam->batch.src); | ||
| 775 | + halIn.batch.dst = RtPtrToPtr<UINT64 *>(inParam->batch.dst); | ||
| 776 | + halIn.batch.len = RtPtrToPtr<UINT64 *>(inParam->batch.len); | ||
| 777 | + halIn.batch.count = inParam->batch.count; | ||
| 778 | + break; | ||
| 779 | + case DRV_ASYNC_DMA_TYPE_2D: | ||
| 780 | + halIn.matrix2d.src = RtPtrToPtr<UINT64 *>(inParam->matrix2d.src); | ||
| 781 | + halIn.matrix2d.dst = RtPtrToPtr<UINT64 *>(inParam->matrix2d.dst); | ||
| 782 | + halIn.matrix2d.spitch = inParam->matrix2d.spitch; | ||
| 783 | + halIn.matrix2d.dpitch = inParam->matrix2d.dpitch; | ||
| 784 | + halIn.matrix2d.width = inParam->matrix2d.width; | ||
| 785 | + halIn.matrix2d.height = inParam->matrix2d.height; | ||
| 786 | + halIn.matrix2d.fixedSize = inParam->matrix2d.fixedSize; | ||
| 787 | + break; | ||
| 788 | + case DRV_ASYNC_DMA_TYPE_NOP: | ||
| 789 | + halIn.nop.nopCnt = inParam->nop.nopCnt; | ||
| 790 | + break; | ||
| 791 | + default: | ||
| 792 | + RT_LOG(RT_LOG_ERROR, "Unsupported wqeType=%d, devId=%u.", static_cast<int32_t>(inParam->wqeType), devId); | ||
| 793 | + return RT_ERROR_INVALID_VALUE; | ||
| 794 | + } | ||
| 795 | + | ||
| 796 | + struct halAsyncDmaWqeOutputPara halOut = {}; | ||
| 797 | + const drvError_t drvRet = halAsyncDmaWqeConvert(devId, &halIn, &halOut); | ||
| 798 | + if (drvRet != DRV_ERROR_NONE) { | ||
| 799 | + DRV_ERROR_PROCESS( | ||
| 800 | + drvRet, "[drv api] halAsyncDmaWqeConvert failed, drvRetCode=%d", static_cast<int32_t>(drvRet)); | ||
| 801 | + } | ||
| 802 | + | ||
| 803 | + if (drvRet == DRV_ERROR_NONE) { | ||
| 804 | + RT_LOG(RT_LOG_DEBUG, "halAsyncDmaWqeConvert done, devId=%u, halIn: wqeType=%d, wqeBufferLen=%llu, halOut: wqeCnt=%u, fixedCnt=%llu, fixedSize=%llu.", | ||
| 805 | + devId, static_cast<int32_t>(halIn.wqeType), halIn.wqeBufferLen, halOut.wqeCnt, halOut.fixedCnt, halOut.fixedSize); | ||
| 806 | + outParam->wqeCnt = halOut.wqeCnt; | ||
| 807 | + outParam->fixedSize = halOut.fixedSize; | ||
| 808 | + outParam->fixedCnt = halOut.fixedCnt; | ||
| 809 | + } | ||
| 810 | + return RT_GET_DRV_ERRCODE(drvRet); | ||
| 811 | +} | ||
| 812 | + | ||
| 813 | +rtError_t NpuDriver::AsyncDmaWqeFill(const uint32_t devId, AsyncWqeFillInfo* fillInfo) | ||
| 814 | +{ | ||
| 815 | + COND_RETURN_WARN( | ||
| 816 | + &halAsyncDmaJettyWqeFill == nullptr, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 817 | + "[drv api] halAsyncDmaJettyWqeFill does not exist"); | ||
| 818 | + COND_RETURN_ERROR(fillInfo == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 819 | + "AsyncDmaWqeFill: fillInfo is null."); | ||
| 820 | + struct halAsyncDmaJettyFillInfo info = {}; | ||
| 821 | + | ||
| 822 | + info.jettyHandle = RtValueToPtr<halAsyncJettyHandle*>(fillInfo->jettyHandle.handle); | ||
| 823 | + info.offset = fillInfo->offset; | ||
| 824 | + info.srcWqe = static_cast<unsigned char*>(fillInfo->srcWqe); | ||
| 825 | + info.size = fillInfo->size; | ||
| 826 | + const drvError_t drvRet = halAsyncDmaJettyWqeFill(devId, &info); | ||
| 827 | + if (drvRet != DRV_ERROR_NONE) { | ||
| 828 | + DRV_ERROR_PROCESS( | ||
| 829 | + drvRet, "[drv api] halAsyncDmaJettyWqeFill failed, drvRetCode=%d", static_cast<int32_t>(drvRet)); | ||
| 830 | + } | ||
| 831 | + return RT_GET_DRV_ERRCODE(drvRet); | ||
| 832 | +} | ||
| 689 | } | 833 | } |
| 690 | } | 834 | } |
| @@ -243,5 +243,48 @@ rtError_t NpuDriver::StreamMemPoolTrim(const uint32_t deviceId, const uint64_t p | |||
| 243 | return RT_ERROR_FEATURE_NOT_SUPPORT; | 243 | return RT_ERROR_FEATURE_NOT_SUPPORT; |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | +rtError_t NpuDriver::AsyncDmaJettyCreate( | ||
| 247 | + const uint32_t devId, const uint32_t piType, const uint32_t depth, const uint32_t dir, uint64_t* const handle) | ||
| 248 | +{ | ||
| 249 | + UNUSED(devId); | ||
| 250 | + UNUSED(piType); | ||
| 251 | + UNUSED(depth); | ||
| 252 | + UNUSED(dir); | ||
| 253 | + UNUSED(handle); | ||
| 254 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 255 | +} | ||
| 256 | + | ||
| 257 | +rtError_t NpuDriver::AsyncDmaJettyDestroy(const uint32_t devId, const uint64_t handle) | ||
| 258 | +{ | ||
| 259 | + UNUSED(devId); | ||
| 260 | + UNUSED(handle); | ||
| 261 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 262 | +} | ||
| 263 | + | ||
| 264 | +rtError_t NpuDriver::AsyncDmaJettyQuery( | ||
| 265 | + const uint32_t devId, const uint64_t handle, uint32_t& dieId, uint32_t& functionId, uint32_t& jettyId) | ||
| 266 | +{ | ||
| 267 | + UNUSED(devId); | ||
| 268 | + UNUSED(handle); | ||
| 269 | + UNUSED(dieId); | ||
| 270 | + UNUSED(functionId); | ||
| 271 | + UNUSED(jettyId); | ||
| 272 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 273 | +} | ||
| 274 | + | ||
| 275 | +rtError_t NpuDriver::AsyncDmaWqeConvert(const uint32_t devId, AsyncWqeInputPara* input, AsyncWqeOutputPara* output) | ||
| 276 | +{ | ||
| 277 | + UNUSED(devId); | ||
| 278 | + UNUSED(input); | ||
| 279 | + UNUSED(output); | ||
| 280 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +rtError_t NpuDriver::AsyncDmaWqeFill(const uint32_t devId, AsyncWqeFillInfo* fillInfo) | ||
| 284 | +{ | ||
| 285 | + UNUSED(devId); | ||
| 286 | + UNUSED(fillInfo); | ||
| 287 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 288 | +} | ||
| 246 | } | 289 | } |
| 247 | } | 290 | } |
| @@ -22,6 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | + | ||
| 25 | 26 | ||
| 26 | namespace cce { | 27 | namespace cce { |
| 27 | namespace runtime { | 28 | namespace runtime { |
| @@ -42,8 +43,8 @@ CaptureModel::~CaptureModel() noexcept | |||
| 42 | TryToFreeEventIdAndDestroyEvent(&evt, evt->EventId_(), true, true); | 43 | TryToFreeEventIdAndDestroyEvent(&evt, evt->EventId_(), true, true); |
| 43 | } | 44 | } |
| 44 | captureEvents_.clear(); | 45 | captureEvents_.clear(); |
| 45 | - | ||
| 46 | refCount_ = 0U; | 46 | refCount_ = 0U; |
| 47 | + ReleaseAllJetty(); | ||
| 47 | DeconstructSqCq(); | 48 | DeconstructSqCq(); |
| 48 | ClearStreamActiveTask(); | 49 | ClearStreamActiveTask(); |
| 49 | DELETE_A(switchInfo_); | 50 | DELETE_A(switchInfo_); |
| @@ -191,13 +192,11 @@ rtError_t CaptureModel::ExecuteCommon(Stream * const stm, int32_t timeout, const | |||
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | rtError_t error; | 194 | rtError_t error; |
| 194 | - // begin execute | ||
| 195 | error = SetNotifyBeforeExecute(stm, this); | 195 | error = SetNotifyBeforeExecute(stm, this); |
| 196 | COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, | 196 | COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, |
| 197 | "Set notify before model execute failed, stream_id=%d, model_id=%u, retCode=%#x.", | 197 | "Set notify before model execute failed, stream_id=%d, model_id=%u, retCode=%#x.", |
| 198 | stm->Id_(), Id_(), static_cast<uint32_t>(error)); | 198 | stm->Id_(), Id_(), static_cast<uint32_t>(error)); |
| 199 | - | 199 | + error = BuildResource(stm); |
| 200 | - error = BuildSqCq(stm); | ||
| 201 | COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, | 200 | COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, |
| 202 | "Build SQ/CQ failed, stream_id=%d, model_id=%u, retCode=%#x.", | 201 | "Build SQ/CQ failed, stream_id=%d, model_id=%u, retCode=%#x.", |
| 203 | stm->Id_(), Id_(), static_cast<uint32_t>(error)); | 202 | stm->Id_(), Id_(), static_cast<uint32_t>(error)); |
| @@ -213,7 +212,6 @@ rtError_t CaptureModel::ExecuteCommon(Stream * const stm, int32_t timeout, const | |||
| 213 | "Model execute failed, stream_id=%d, model_id=%u, retCode=%#x.", | 212 | "Model execute failed, stream_id=%d, model_id=%u, retCode=%#x.", |
| 214 | stm->Id_(), Id_(), static_cast<uint32_t>(error)); | 213 | stm->Id_(), Id_(), static_cast<uint32_t>(error)); |
| 215 | 214 | ||
| 216 | - // after execute | ||
| 217 | error = SetNotifyAfterExecute(stm, this); | 215 | error = SetNotifyAfterExecute(stm, this); |
| 218 | COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, | 216 | COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, |
| 219 | "Set notify after model execute failed, stream_id=%d, model_id=%u, retCode=%#x.", | 217 | "Set notify after model execute failed, stream_id=%d, model_id=%u, retCode=%#x.", |
| @@ -473,12 +471,15 @@ rtError_t CaptureModel::UpdateNotifyId(Stream * const exeStream) | |||
| 473 | Context *context = origCaptureStream->Context_(); | 471 | Context *context = origCaptureStream->Context_(); |
| 474 | return context->UpdateEndGraphTask(origCaptureStream, exeStream, ntf); | 472 | return context->UpdateEndGraphTask(origCaptureStream, exeStream, ntf); |
| 475 | } | 473 | } |
| 476 | -rtError_t CaptureModel::BuildSqCq(Stream * const exeStream) | 474 | +rtError_t CaptureModel::BuildResource(Stream * const exeStream) |
| 477 | { | 475 | { |
| 478 | COND_PROC(!IsSoftwareSqEnable(), return RT_ERROR_NONE); | 476 | COND_PROC(!IsSoftwareSqEnable(), return RT_ERROR_NONE); |
| 479 | uint32_t loopCnt = 0U; | 477 | uint32_t loopCnt = 0U; |
| 480 | 478 | ||
| 481 | const std::unique_lock<std::mutex> lk(sqBindMutex_); | 479 | const std::unique_lock<std::mutex> lk(sqBindMutex_); |
| 480 | + rtError_t error = BindJettyForUbdma(); | ||
| 481 | + ERROR_RETURN_MSG_INNER(error, "bind jettys for streams failed, stream_id=%d, model_id=%u", exeStream->Id_(), Id_()); | ||
| 482 | + | ||
| 482 | /* model execute repeat */ | 483 | /* model execute repeat */ |
| 483 | COND_PROC_RETURN_WARN((sqCqArray_ != nullptr) && (sqCqNum_ != 0U), | 484 | COND_PROC_RETURN_WARN((sqCqArray_ != nullptr) && (sqCqNum_ != 0U), |
| 484 | RT_ERROR_NONE, | 485 | RT_ERROR_NONE, |
| @@ -516,7 +517,7 @@ rtError_t CaptureModel::BuildSqCq(Stream * const exeStream) | |||
| 516 | COND_RETURN_AND_MSG_OUTER(sqCqArray_ == nullptr, RT_ERROR_STREAM_NEW, ErrorCode::EE1013, | 517 | COND_RETURN_AND_MSG_OUTER(sqCqArray_ == nullptr, RT_ERROR_STREAM_NEW, ErrorCode::EE1013, |
| 517 | sizeof(rtDeviceSqCqInfo_t) * streamNum); | 518 | sizeof(rtDeviceSqCqInfo_t) * streamNum); |
| 518 | 519 | ||
| 519 | - rtError_t error = AllocSqCqProc(streamNum); | 520 | + error = AllocSqCqProc(streamNum); |
| 520 | ERROR_PROC_RETURN_MSG_INNER(error, DELETE_A(sqCqArray_);, | 521 | ERROR_PROC_RETURN_MSG_INNER(error, DELETE_A(sqCqArray_);, |
| 521 | "alloc sq resource failed, model_id=%u, required number=%u, current available number=%u, " | 522 | "alloc sq resource failed, model_id=%u, required number=%u, current available number=%u, " |
| 522 | "maximum number=%u, retCode=%#x.", | 523 | "maximum number=%u, retCode=%#x.", |
| @@ -541,7 +542,6 @@ rtError_t CaptureModel::BuildSqCq(Stream * const exeStream) | |||
| 541 | 542 | ||
| 542 | /* reconstruct the model execute instr */ | 543 | /* reconstruct the model execute instr */ |
| 543 | SetFirstExecute(true); | 544 | SetFirstExecute(true); |
| 544 | - | ||
| 545 | if (isNeedUpdateEndGraph_) { | 545 | if (isNeedUpdateEndGraph_) { |
| 546 | error = UpdateNotifyId(exeStream); | 546 | error = UpdateNotifyId(exeStream); |
| 547 | ERROR_PROC_RETURN_MSG_INNER(error, | 547 | ERROR_PROC_RETURN_MSG_INNER(error, |
| @@ -748,14 +748,21 @@ void CaptureModel::ClearStreamActiveTask(void) | |||
| 748 | const std::unique_lock<std::mutex> lk(streamActiveTaskListMutex_); | 748 | const std::unique_lock<std::mutex> lk(streamActiveTaskListMutex_); |
| 749 | streamActiveTaskList_.clear(); | 749 | streamActiveTaskList_.clear(); |
| 750 | } | 750 | } |
| 751 | -void CaptureModel::CaptureModelExecuteFinish(void) | 751 | + |
| 752 | +void CaptureModel::CaptureModelExecuteFinish(const uint32_t errCode) | ||
| 752 | { | 753 | { |
| 753 | const std::unique_lock<std::mutex> lk(sqBindMutex_); | 754 | const std::unique_lock<std::mutex> lk(sqBindMutex_); |
| 754 | COND_PROC(refCount_ < 1U, return); | 755 | COND_PROC(refCount_ < 1U, return); |
| 755 | refCount_--; | 756 | refCount_--; |
| 756 | - | 757 | + if (refCount_ == 0) { |
| 758 | + if (errCode != RT_ERROR_NONE) { | ||
| 759 | + ReleaseAllJetty(); | ||
| 760 | + } | ||
| 761 | + ReleaseAllLargeJetty(); | ||
| 762 | + } | ||
| 757 | return; | 763 | return; |
| 758 | } | 764 | } |
| 765 | + | ||
| 759 | rtError_t CaptureModel::AllocSqAddr(void) const | 766 | rtError_t CaptureModel::AllocSqAddr(void) const |
| 760 | { | 767 | { |
| 761 | const uint32_t deviceId = Context_()->Device_()->Id_(); | 768 | const uint32_t deviceId = Context_()->Device_()->Id_(); |
| @@ -173,12 +173,12 @@ bool IsCapturedTask(const Stream * const launchStm, const TaskInfo *submitTask) | |||
| 173 | { | 173 | { |
| 174 | return (launchStm != submitTask->stream); | 174 | return (launchStm != submitTask->stream); |
| 175 | } | 175 | } |
| 176 | -bool IsSoftwareSqCaptureModel(Model * const mdl) | 176 | +bool IsSoftwareSqCaptureModel(const Model * const mdl) |
| 177 | { | 177 | { |
| 178 | if (mdl->GetModelType() != ModelType::RT_MODEL_CAPTURE_MODEL) { | 178 | if (mdl->GetModelType() != ModelType::RT_MODEL_CAPTURE_MODEL) { |
| 179 | return false; | 179 | return false; |
| 180 | } | 180 | } |
| 181 | - CaptureModel *capMdl = dynamic_cast<CaptureModel *>(mdl); | 181 | + const CaptureModel *capMdl = dynamic_cast<const CaptureModel *>(mdl); |
| 182 | return capMdl != nullptr && capMdl->IsSoftwareSqEnable(); | 182 | return capMdl != nullptr && capMdl->IsSoftwareSqEnable(); |
| 183 | } | 183 | } |
| 184 | rtError_t CheckCaptureModelSupportSoftwareSq(Device* const dev) | 184 | rtError_t CheckCaptureModelSupportSoftwareSq(Device* const dev) |
| @@ -56,5 +56,45 @@ rtError_t Context::TryRecycleCaptureModelResource(const uint32_t allocSqNum, con | |||
| 56 | return error; | 56 | return error; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | +rtError_t Context::TryRecycleCaptureModelJettyResource(const CaptureModel * const excludeMdl, JettyType type) | ||
| 60 | +{ | ||
| 61 | + if (!Runtime::Instance()->GetConnectUbFlag()) { | ||
| 62 | + return RT_ERROR_NONE; | ||
| 63 | + } | ||
| 64 | + uint32_t totalRelease = 0U; | ||
| 65 | + uint32_t h2dCount = 0U; | ||
| 66 | + uint32_t d2dCount = 0U; | ||
| 67 | + rtError_t error = RT_ERROR_NONE; | ||
| 68 | + modelLock_.Lock(); | ||
| 69 | + for (Model *model : models_) { | ||
| 70 | + if ((model != nullptr) && (model->GetModelType() == RT_MODEL_CAPTURE_MODEL)) { | ||
| 71 | + CaptureModel *captureMdl = dynamic_cast<CaptureModel *>(model); | ||
| 72 | + if (totalRelease > 0U) { | ||
| 73 | + break; | ||
| 74 | + } | ||
| 75 | + if (!captureMdl->IsSoftwareSqEnable() || (captureMdl == excludeMdl) || | ||
| 76 | + captureMdl->IsCaptureModelRunning()) { | ||
| 77 | + continue; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + h2dCount = 0U; | ||
| 81 | + d2dCount = 0U; | ||
| 82 | + if (captureMdl->ModelSqOperTryLock()) { | ||
| 83 | + error = captureMdl->RecycleAllJetty(h2dCount, d2dCount); | ||
| 84 | + captureMdl->ModelSqOperUnLock(); | ||
| 85 | + COND_PROC(error != RT_ERROR_NONE, break); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + if (type == JettyType::JETTY_TYPE_H2D) { | ||
| 89 | + totalRelease += h2dCount; | ||
| 90 | + } else { | ||
| 91 | + totalRelease += d2dCount; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + modelLock_.Unlock(); | ||
| 96 | + | ||
| 97 | + return (totalRelease > 0U) ? RT_ERROR_NONE : RT_ERROR_JETTY_POOL_NO_RESOURCES; | ||
| 98 | +} | ||
| 59 | } // namespace runtime | 99 | } // namespace runtime |
| 60 | } // namespace cce | 100 | } // namespace cce |
| @@ -64,13 +64,13 @@ rtError_t CaptureModel::ReleaseNotifyId(void) { return RT_ERROR_FEATURE_NOT_SUPP | |||
| 64 | 64 | ||
| 65 | rtError_t CaptureModel::UpdateNotifyId(Stream * const exeStream) { UNUSED(exeStream); return RT_ERROR_FEATURE_NOT_SUPPORT; } | 65 | rtError_t CaptureModel::UpdateNotifyId(Stream * const exeStream) { UNUSED(exeStream); return RT_ERROR_FEATURE_NOT_SUPPORT; } |
| 66 | 66 | ||
| 67 | -rtError_t CaptureModel::BuildSqCq(Stream * const exeStream) { UNUSED(exeStream); return RT_ERROR_FEATURE_NOT_SUPPORT; } | 67 | +rtError_t CaptureModel::BuildResource(Stream * const exeStream) { UNUSED(exeStream); return RT_ERROR_FEATURE_NOT_SUPPORT; } |
| 68 | 68 | ||
| 69 | void CaptureModel::DeconstructSqCq(void) {} | 69 | void CaptureModel::DeconstructSqCq(void) {} |
| 70 | 70 | ||
| 71 | rtError_t CaptureModel::ReleaseSqCq(uint32_t &releaseNum) { UNUSED(releaseNum); return RT_ERROR_FEATURE_NOT_SUPPORT; } | 71 | rtError_t CaptureModel::ReleaseSqCq(uint32_t &releaseNum) { UNUSED(releaseNum); return RT_ERROR_FEATURE_NOT_SUPPORT; } |
| 72 | 72 | ||
| 73 | -void CaptureModel::CaptureModelExecuteFinish(void) {} | 73 | +void CaptureModel::CaptureModelExecuteFinish(const uint32_t errCode) { UNUSED(errCode); } |
| 74 | 74 | ||
| 75 | rtError_t CaptureModel::MarkStreamActiveTask(TaskInfo *streamActiveTask) { UNUSED(streamActiveTask); return RT_ERROR_FEATURE_NOT_SUPPORT; } | 75 | rtError_t CaptureModel::MarkStreamActiveTask(TaskInfo *streamActiveTask) { UNUSED(streamActiveTask); return RT_ERROR_FEATURE_NOT_SUPPORT; } |
| 76 | 76 | ||
| @@ -31,7 +31,7 @@ rtError_t CheckCaptureModelSupportSoftwareSq(Device* const dev) { UNUSED(dev); r | |||
| 31 | 31 | ||
| 32 | rtError_t CheckCaptureModelForUpdate(const Stream* stm) { UNUSED(stm); return RT_ERROR_FEATURE_NOT_SUPPORT; } | 32 | rtError_t CheckCaptureModelForUpdate(const Stream* stm) { UNUSED(stm); return RT_ERROR_FEATURE_NOT_SUPPORT; } |
| 33 | 33 | ||
| 34 | -bool IsSoftwareSqCaptureModel(Model * const mdl) { UNUSED(mdl); return false; } | 34 | +bool IsSoftwareSqCaptureModel(const Model * const mdl) { UNUSED(mdl); return false; } |
| 35 | 35 | ||
| 36 | bool CheckCaptureModeSupport(const Context* ctx, const char* funcName) { UNUSED(ctx); UNUSED(funcName); return true; } | 36 | bool CheckCaptureModeSupport(const Context* ctx, const char* funcName) { UNUSED(ctx); UNUSED(funcName); return true; } |
| 37 | 37 | ||
| @@ -11,8 +11,8 @@ | |||
| 11 | namespace cce { | 11 | namespace cce { |
| 12 | namespace runtime { | 12 | namespace runtime { |
| 13 | 13 | ||
| 14 | -rtError_t Context::TryRecycleCaptureModelResource(const uint32_t allocSqNum, const uint32_t ntfCnt, | 14 | +rtError_t Context::TryRecycleCaptureModelResource( |
| 15 | - const CaptureModel * const excludeMdl) | 15 | + const uint32_t allocSqNum, const uint32_t ntfCnt, const CaptureModel* const excludeMdl) |
| 16 | { | 16 | { |
| 17 | UNUSED(allocSqNum); | 17 | UNUSED(allocSqNum); |
| 18 | UNUSED(ntfCnt); | 18 | UNUSED(ntfCnt); |
| @@ -20,5 +20,12 @@ rtError_t Context::TryRecycleCaptureModelResource(const uint32_t allocSqNum, con | |||
| 20 | return RT_ERROR_FEATURE_NOT_SUPPORT; | 20 | return RT_ERROR_FEATURE_NOT_SUPPORT; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | +rtError_t Context::TryRecycleCaptureModelJettyResource(const CaptureModel * const excludeMdl, JettyType type) | ||
| 24 | +{ | ||
| 25 | + UNUSED(excludeMdl); | ||
| 26 | + UNUSED(type); | ||
| 27 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 28 | +} | ||
| 29 | + | ||
| 23 | } // namespace runtime | 30 | } // namespace runtime |
| 24 | } // namespace cce | 31 | } // namespace cce |
| @@ -29,5 +29,27 @@ rtError_t CaptureModel::BindSqCqAndSendSqe(void) | |||
| 29 | ERROR_RETURN_MSG_INNER(error, "Config sq tail failed, model_id=%u, retCode=%#x.", Id_(), static_cast<uint32_t>(error)); | 29 | ERROR_RETURN_MSG_INNER(error, "Config sq tail failed, model_id=%u, retCode=%#x.", Id_(), static_cast<uint32_t>(error)); |
| 30 | return error; | 30 | return error; |
| 31 | } | 31 | } |
| 32 | + | ||
| 33 | +rtError_t CaptureModel::BindJettyForUbdma() | ||
| 34 | +{ | ||
| 35 | + return RT_ERROR_NONE; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +rtError_t CaptureModel::RecycleAllJetty(uint32_t &h2dCount, uint32_t &d2dCount) | ||
| 39 | +{ | ||
| 40 | + h2dCount = 0; | ||
| 41 | + d2dCount = 0; | ||
| 42 | + return RT_ERROR_NONE; | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +rtError_t CaptureModel::ReleaseAllJetty() | ||
| 46 | +{ | ||
| 47 | + return RT_ERROR_NONE; | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +rtError_t CaptureModel::ReleaseAllLargeJetty() | ||
| 51 | +{ | ||
| 52 | + return RT_ERROR_NONE; | ||
| 53 | +} | ||
| 32 | } // namespace runtime | 54 | } // namespace runtime |
| 33 | } // namespace cce | 55 | } // namespace cce |
| @@ -12,6 +12,11 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 15 | 20 | ||
| 16 | namespace cce { | 21 | namespace cce { |
| 17 | namespace runtime { | 22 | namespace runtime { |
| @@ -32,5 +37,257 @@ rtError_t CaptureModel::BindSqCqAndSendSqe(void) | |||
| 32 | 37 | ||
| 33 | return error; | 38 | return error; |
| 34 | } | 39 | } |
| 40 | + | ||
| 41 | +rtError_t CaptureModel::BindJetty(Stream * const stm, JettyType type) | ||
| 42 | +{ | ||
| 43 | + int32_t streamId = stm->Id_(); | ||
| 44 | + JettyManager *jettyMgr = Context_()->Device_()->GetJettyManager(); | ||
| 45 | + COND_RETURN_ERROR(jettyMgr == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 46 | + "GetJettyManager returned null, stream_id=%d.", streamId); | ||
| 47 | + StreamJettyContext *context = jettyMgr->GetStreamJettyContext(streamId, type); | ||
| 48 | + if (context == nullptr || context->filledWqeCount == 0) { | ||
| 49 | + RT_LOG(RT_LOG_DEBUG, "No ub dma task, stream_id=%d, jetty_type=%d.", | ||
| 50 | + streamId, static_cast<int32_t>(type)); | ||
| 51 | + return RT_ERROR_NONE; | ||
| 52 | + } | ||
| 53 | + // 检查是否已绑定,避免重复执行 WQE 同步和 SQE 刷新, 已绑定场景要刷新pi | ||
| 54 | + if (context->jettyHandle != 0) { | ||
| 55 | + SetNeedUpdateUBPi(true); | ||
| 56 | + RT_LOG(RT_LOG_DEBUG, "Jetty already bound, skip sync, stream_id=%d, jetty_type=%d.", | ||
| 57 | + streamId, static_cast<int32_t>(type)); | ||
| 58 | + return RT_ERROR_NONE; | ||
| 59 | + } | ||
| 60 | + rtError_t error = jettyMgr->BindJettyForStream(streamId, this, type); | ||
| 61 | + ERROR_RETURN_MSG_INNER(error, "BindJettyForStream failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 62 | + | ||
| 63 | + JettyInfo jettyInfo = {}; | ||
| 64 | + error = jettyMgr->GetJettyInfoForStream(streamId, type, jettyInfo); | ||
| 65 | + ERROR_RETURN_MSG_INNER(error, "GetJettyInfoForStream failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 66 | + | ||
| 67 | + error = StreamJettyHandler::SyncWqeBufferToDevice(stm, context, jettyInfo); | ||
| 68 | + ERROR_RETURN_MSG_INNER(error, "SyncWqeBufferToDevice failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 69 | + | ||
| 70 | + error = StreamJettyHandler::UpdateUbdmaSqeWithJettyInfo(stm, context, jettyInfo); | ||
| 71 | + ERROR_RETURN_MSG_INNER(error, "UpdateUbdmaSqeWithJettyInfo failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 72 | + SetNeedUpdateUBPi(false); | ||
| 73 | + return error; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +rtError_t CaptureModel::RefreshJettyInfoList() | ||
| 77 | +{ | ||
| 78 | + JettyManager *jettyMgr = Context_()->Device_()->GetJettyManager(); | ||
| 79 | + NULL_PTR_RETURN(jettyMgr, RT_ERROR_INVALID_VALUE); | ||
| 80 | + ClearH2dJettyInfoList(); | ||
| 81 | + ClearD2dJettyInfoList(); | ||
| 82 | + for (Stream *stm : StreamList_()) { | ||
| 83 | + int32_t streamId = stm->Id_(); | ||
| 84 | + for (JettyType type : {JettyType::JETTY_TYPE_H2D, JettyType::JETTY_TYPE_D2D}) { | ||
| 85 | + StreamJettyContext *ctx = jettyMgr->GetStreamJettyContext(streamId, type); | ||
| 86 | + if (ctx == nullptr || ctx->jettyHandle == 0 || ctx->filledWqeCount == 0) { | ||
| 87 | + continue; | ||
| 88 | + } | ||
| 89 | + JettyInfo jettyInfo = {}; | ||
| 90 | + rtError_t ret = jettyMgr->GetJettyInfoForStream(streamId, type, jettyInfo); | ||
| 91 | + COND_RETURN_ERROR((ret != RT_ERROR_NONE), ret, | ||
| 92 | + "GetJettyInfoForStream failed, stream_id=%d, type=%d, ret=%d.", streamId, static_cast<int32_t>(type), ret); | ||
| 93 | + | ||
| 94 | + UbAsyncJettyInfo info = {}; | ||
| 95 | + info.dieId = static_cast<uint16_t>(jettyInfo.dieId); | ||
| 96 | + info.functionId = static_cast<uint16_t>(jettyInfo.functionId); | ||
| 97 | + info.jettyId = static_cast<uint16_t>(jettyInfo.jettyId); | ||
| 98 | + info.piValue = static_cast<uint16_t>(ctx->capacity - ctx->filledWqeCount); | ||
| 99 | + info.sqId = stm->GetSqId(); | ||
| 100 | + if (type == JettyType::JETTY_TYPE_H2D) { | ||
| 101 | + SetH2dJettyInfo(info); | ||
| 102 | + } else { | ||
| 103 | + SetD2dJettyInfo(info); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + return RT_ERROR_NONE; | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +rtError_t CaptureModel::BindJettyForUbdma() | ||
| 111 | +{ | ||
| 112 | + COND_PROC((!IsSoftwareSqEnable()) || (!Runtime::Instance()->GetConnectUbFlag()), return RT_ERROR_NONE); | ||
| 113 | + RT_LOG(RT_LOG_DEBUG, "BindJettyForUbdma, model_id=%u.", Id_()); | ||
| 114 | + const std::unique_lock<std::mutex> lk(jettyMutex_); | ||
| 115 | + for (Stream *stm : StreamList_()) { | ||
| 116 | + rtError_t error = BindJetty(stm, JettyType::JETTY_TYPE_H2D); | ||
| 117 | + ERROR_RETURN_MSG_INNER(error, "BindJetty H2D failed, stream_id=%d, ret=%d.", stm->Id_(), error); | ||
| 118 | + error = BindJetty(stm, JettyType::JETTY_TYPE_D2D); | ||
| 119 | + ERROR_RETURN_MSG_INNER(error, "BindJetty D2D failed, stream_id=%d, ret=%d.", stm->Id_(), error); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + // jetty 可能因回收而更换,清空旧 info 列表,重新添加 | ||
| 123 | + rtError_t error = RefreshJettyInfoList(); | ||
| 124 | + ERROR_RETURN_MSG_INNER(error, "RefreshJettyInfoList failed, model_id=%u, ret=%d.", Id_(), error); | ||
| 125 | + return RT_ERROR_NONE; | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +rtError_t CaptureModel::RecycleJetty(int32_t streamId, JettyType type, uint32_t &count) | ||
| 129 | +{ | ||
| 130 | + JettyManager *jettyMgr = Context_()->Device_()->GetJettyManager(); | ||
| 131 | + COND_RETURN_ERROR(jettyMgr == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 132 | + "GetJettyManager returned null, stream_id=%d.", streamId); | ||
| 133 | + StreamJettyContext *ctx = jettyMgr->GetStreamJettyContext(streamId, type); | ||
| 134 | + if (ctx == nullptr || ctx->jettyHandle == 0) { | ||
| 135 | + return RT_ERROR_NONE; | ||
| 136 | + } | ||
| 137 | + rtError_t error = RT_ERROR_NONE; | ||
| 138 | + /** | ||
| 139 | + CaptureModel执行成功,这时候要手动下ud db将pi归0,未执行则不需要(未执行时jetty未绑定, ctx->jettyHandle == 0) | ||
| 140 | + 执行失败,则在执行失败时释放所有jetty:ReleaseAllJetty(), 销毁jetty context | ||
| 141 | + */ | ||
| 142 | + if (!ctx->isLargeDepth) { | ||
| 143 | + JettyInfo jettyInfo = {}; | ||
| 144 | + error = jettyMgr->GetJettyInfoForStream(streamId, type, jettyInfo); | ||
| 145 | + COND_RETURN_ERROR((error != RT_ERROR_NONE), error, | ||
| 146 | + "GetJettyInfoForStream failed for recycle, stream_id=%d, error=%d.", streamId, error); | ||
| 147 | + rtUbDbInfo_t dbInfo; | ||
| 148 | + dbInfo.wrCqe = 0U; | ||
| 149 | + dbInfo.dbNum = UB_DOORBELL_NUM_MIN; | ||
| 150 | + dbInfo.info[0].dieId = jettyInfo.dieId; | ||
| 151 | + dbInfo.info[0].jettyId = jettyInfo.jettyId; | ||
| 152 | + dbInfo.info[0].functionId = jettyInfo.functionId; | ||
| 153 | + dbInfo.info[0].piValue = ctx->capacity - ctx->filledWqeCount; | ||
| 154 | + Stream * const stm = Context_()->GetCtrlSQStream(); | ||
| 155 | + error = StreamUbDbSend(&dbInfo, stm, RT_UBDMA_SOURCE_MODEL_EXE); | ||
| 156 | + RT_LOG(RT_LOG_INFO, "sent ub doorbell to reset pi/ci, dieId=%u, functionId=%u, jettyId=%u, piValue=%u.", | ||
| 157 | + jettyInfo.dieId, jettyInfo.functionId, jettyInfo.jettyId, dbInfo.info[0].piValue); | ||
| 158 | + COND_RETURN_ERROR((error != RT_ERROR_NONE), error, | ||
| 159 | + "send h2d ub doorbell failed, stream_id=%d, error=%d.", streamId, error); | ||
| 160 | + error = stm->Synchronize(); | ||
| 161 | + COND_RETURN_ERROR((error != RT_ERROR_NONE), error, | ||
| 162 | + "ub doorbell sync failed, stream_id=%d, error=%d.", streamId, error); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + bool isReleased = false; | ||
| 166 | + error = jettyMgr->UnbindJettyForStream(streamId, type, isReleased); | ||
| 167 | + ERROR_RETURN_MSG_INNER(error, "UnbindJettyForStream failed, stream_id=%d, type=%d, ret=%d.", | ||
| 168 | + streamId, static_cast<int32_t>(type), error); | ||
| 169 | + if (isReleased) { | ||
| 170 | + count++; | ||
| 171 | + } | ||
| 172 | + return RT_ERROR_NONE; | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +rtError_t CaptureModel::RecycleAllJetty(uint32_t &h2dCount, uint32_t &d2dCount) | ||
| 176 | +{ | ||
| 177 | + const std::unique_lock<std::mutex> lk(jettyMutex_); | ||
| 178 | + h2dCount = 0; | ||
| 179 | + d2dCount = 0; | ||
| 180 | + for (Stream *stm : StreamList_()) { | ||
| 181 | + int32_t streamId = stm->Id_(); | ||
| 182 | + rtError_t error = RecycleJetty(streamId, JettyType::JETTY_TYPE_H2D, h2dCount); | ||
| 183 | + ERROR_RETURN_MSG_INNER(error, "RecycleJetty H2D failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 184 | + error = RecycleJetty(streamId, JettyType::JETTY_TYPE_D2D, d2dCount); | ||
| 185 | + ERROR_RETURN_MSG_INNER(error, "RecycleJetty D2D failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 186 | + } | ||
| 187 | + SetNeedUpdateUBPi(false); | ||
| 188 | + ClearH2dJettyInfoList(); | ||
| 189 | + ClearD2dJettyInfoList(); | ||
| 190 | + RT_LOG(RT_LOG_DEBUG, "RecycleAllJetty completed, model_id=%u, h2d_count=%u, d2d_count=%u.", | ||
| 191 | + Id_(), h2dCount, d2dCount); | ||
| 192 | + return RT_ERROR_NONE; | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +rtError_t CaptureModel::ReleaseJetty(int32_t streamId, JettyType type) | ||
| 196 | +{ | ||
| 197 | + JettyManager *jettyMgr = Context_()->Device_()->GetJettyManager(); | ||
| 198 | + COND_RETURN_ERROR(jettyMgr == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 199 | + "GetJettyManager returned null, stream_id=%d.", streamId); | ||
| 200 | + StreamJettyContext* context = jettyMgr->GetStreamJettyContext(streamId, type); | ||
| 201 | + if (context == nullptr) { | ||
| 202 | + return RT_ERROR_NONE; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + const uint64_t savedHandle = context->jettyHandle; | ||
| 206 | + | ||
| 207 | + rtError_t finalError = RT_ERROR_NONE; | ||
| 208 | + bool isReleased = false; | ||
| 209 | + rtError_t error = jettyMgr->UnbindJettyForStream(streamId, type, isReleased); | ||
| 210 | + if (error != RT_ERROR_NONE) { | ||
| 211 | + RT_LOG(RT_LOG_ERROR, "UnbindJettyForStream failed, stream_id=%d, ret=%d.", streamId, error); | ||
| 212 | + finalError = error; | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + if (isReleased && savedHandle != 0) { | ||
| 216 | + error = jettyMgr->ReleaseJettyByHandle(savedHandle, type); | ||
| 217 | + if (error != RT_ERROR_NONE) { | ||
| 218 | + RT_LOG(RT_LOG_ERROR, "ReleaseJettyByHandle failed, stream_id=%d, handle=%lu, ret=%d.", | ||
| 219 | + streamId, savedHandle, error); | ||
| 220 | + finalError = error; | ||
| 221 | + } | ||
| 222 | + } | ||
| 223 | + Driver* driver = context->filledWqeCount > 0 ? Context_()->Device_()->Driver_() : nullptr; | ||
| 224 | + if (driver != nullptr) { | ||
| 225 | + context->ReleaseBuffers(driver); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + jettyMgr->DestroyStreamJettyContext(streamId, type); | ||
| 229 | + return finalError; | ||
| 230 | +} | ||
| 231 | + | ||
| 232 | +rtError_t CaptureModel::ReleaseAllJetty() | ||
| 233 | +{ | ||
| 234 | + COND_PROC((!IsSoftwareSqEnable()) || (!Runtime::Instance()->GetConnectUbFlag()), return RT_ERROR_NONE); | ||
| 235 | + RT_LOG(RT_LOG_DEBUG, "ReleaseAllJetty, model_id=%u.", Id_()); | ||
| 236 | + const std::unique_lock<std::mutex> lk(jettyMutex_); | ||
| 237 | + rtError_t finalError = RT_ERROR_NONE; | ||
| 238 | + for (Stream *stm : StreamList_()) { | ||
| 239 | + int32_t streamId = stm->Id_(); | ||
| 240 | + rtError_t ret = ReleaseJetty(streamId, JettyType::JETTY_TYPE_H2D); | ||
| 241 | + if (ret != RT_ERROR_NONE) { | ||
| 242 | + RT_LOG(RT_LOG_ERROR, "ReleaseJetty H2D failed, stream_id=%d, ret=%d.", streamId, static_cast<int32_t>(ret)); | ||
| 243 | + finalError = ret; | ||
| 244 | + } | ||
| 245 | + ret = ReleaseJetty(streamId, JettyType::JETTY_TYPE_D2D); | ||
| 246 | + if (ret != RT_ERROR_NONE) { | ||
| 247 | + RT_LOG(RT_LOG_ERROR, "ReleaseJetty D2D failed, stream_id=%d, ret=%d.", streamId, static_cast<int32_t>(ret)); | ||
| 248 | + finalError = ret; | ||
| 249 | + } | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + RT_LOG(RT_LOG_DEBUG, "ReleaseAllJetty completed, model_id=%u.", Id_()); | ||
| 253 | + return finalError; | ||
| 254 | +} | ||
| 255 | + | ||
| 256 | +rtError_t CaptureModel::UnbindLargeJetty(int32_t streamId, JettyType type) | ||
| 257 | +{ | ||
| 258 | + JettyManager *jettyMgr = Context_()->Device_()->GetJettyManager(); | ||
| 259 | + COND_RETURN_ERROR(jettyMgr == nullptr, RT_ERROR_INVALID_VALUE, | ||
| 260 | + "GetJettyManager returned null, stream_id=%d.", streamId); | ||
| 261 | + StreamJettyContext* context = jettyMgr->GetStreamJettyContext(streamId, type); | ||
| 262 | + if (context == nullptr) { | ||
| 263 | + return RT_ERROR_NONE; | ||
| 264 | + } | ||
| 265 | + bool isReleased = false; | ||
| 266 | + if (context->isLargeDepth && context->jettyHandle != 0) { | ||
| 267 | + rtError_t ret = jettyMgr->UnbindJettyForStream(streamId, type, isReleased); | ||
| 268 | + if (ret != RT_ERROR_NONE) { | ||
| 269 | + RT_LOG(RT_LOG_ERROR, "UnbindJettyForStream(large) failed, stream_id=%d, ret=%d.", | ||
| 270 | + streamId, static_cast<int32_t>(ret)); | ||
| 271 | + return ret; | ||
| 272 | + } | ||
| 273 | + } | ||
| 274 | + return RT_ERROR_NONE; | ||
| 275 | +} | ||
| 276 | + | ||
| 277 | +rtError_t CaptureModel::ReleaseAllLargeJetty() | ||
| 278 | +{ | ||
| 279 | + COND_PROC((!IsSoftwareSqEnable()) || (!Runtime::Instance()->GetConnectUbFlag()), return RT_ERROR_NONE); | ||
| 280 | + const std::unique_lock<std::mutex> lk(jettyMutex_); | ||
| 281 | + RT_LOG(RT_LOG_DEBUG, "release all large jetty, model_id=%u.", Id_()); | ||
| 282 | + | ||
| 283 | + for (Stream *stm : StreamList_()) { | ||
| 284 | + int32_t streamId = stm->Id_(); | ||
| 285 | + (void)UnbindLargeJetty(streamId, JettyType::JETTY_TYPE_H2D); | ||
| 286 | + (void)UnbindLargeJetty(streamId, JettyType::JETTY_TYPE_D2D); | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + RT_LOG(RT_LOG_DEBUG, "release all large jetty completed, model_id=%u.", Id_()); | ||
| 290 | + return RT_ERROR_NONE; | ||
| 291 | +} | ||
| 35 | } // namespace runtime | 292 | } // namespace runtime |
| 36 | } // namespace cce | 293 | } // namespace cce |
| @@ -0,0 +1,216 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2025 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +namespace cce { | ||
| 17 | +namespace runtime { | ||
| 18 | + | ||
| 19 | +JettyManager::JettyManager(uint32_t deviceId) : jettyPool_(std::make_unique<JettyPool>(deviceId)) | ||
| 20 | +{ | ||
| 21 | + RT_LOG(RT_LOG_INFO, "JettyManager created for device_id=%u.", deviceId); | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +rtError_t JettyManager::ReserveJetty(JettyType type) | ||
| 25 | +{ | ||
| 26 | + rtError_t error = jettyPool_->ReserveJetty(type); | ||
| 27 | + ERROR_RETURN_MSG_INNER(error, | ||
| 28 | + "Reserve jetty for stream failed, type=%d, ret=%d.", static_cast<int32_t>(type), error); | ||
| 29 | + return RT_ERROR_NONE; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +rtError_t JettyManager::AcquireJettyWithRetry(JettyType type, int32_t streamId, | ||
| 33 | + const CaptureModel * const excludeMdl, JettyInfo& jettyInfo) | ||
| 34 | +{ | ||
| 35 | + rtError_t error = jettyPool_->AcquireJetty(type, jettyInfo); | ||
| 36 | + if (error != RT_ERROR_JETTY_POOL_NO_RESOURCES) { | ||
| 37 | + return error; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + Runtime* rt = Runtime::Instance(); | ||
| 41 | + COND_RETURN_ERROR(rt == nullptr, RT_ERROR_INVALID_VALUE, "Runtime instance is null."); | ||
| 42 | + Context* curCtx = rt->CurrentContext(); | ||
| 43 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 44 | + | ||
| 45 | + for (uint32_t retry = 0U; retry < JETTY_POOL_ACQUIRE_RETRY_MAX_COUNT; ++retry) { | ||
| 46 | + RT_LOG(RT_LOG_DEBUG, "Jetty pool exhausted, try recycle (retry=%u/%u), stream_id=%d, type=%d.", | ||
| 47 | + retry + 1U, JETTY_POOL_ACQUIRE_RETRY_MAX_COUNT, streamId, static_cast<int32_t>(type)); | ||
| 48 | + (void)ReserveJetty(type); | ||
| 49 | + error = jettyPool_->AcquireJetty(type, jettyInfo); | ||
| 50 | + if (error == RT_ERROR_NONE) { | ||
| 51 | + RT_LOG(RT_LOG_DEBUG, "Acquire jetty success after recycle (retry=%u), stream_id=%d, type=%d.", | ||
| 52 | + retry + 1U, streamId, static_cast<int32_t>(type)); | ||
| 53 | + return RT_ERROR_NONE; | ||
| 54 | + } | ||
| 55 | + error = curCtx->TryRecycleCaptureModelJettyResource(excludeMdl, type); | ||
| 56 | + if (error != RT_ERROR_NONE) { | ||
| 57 | + RT_LOG(RT_LOG_INFO, "Recycle jetty failed (retry=%u), stream_id=%d, type=%d, ret=%d.", | ||
| 58 | + retry + 1U, streamId, static_cast<int32_t>(type), error); | ||
| 59 | + continue; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + RT_LOG(RT_LOG_ERROR, "Acquire jetty failed after %u retries, stream_id=%d, type=%d.", | ||
| 64 | + JETTY_POOL_ACQUIRE_RETRY_MAX_COUNT, streamId, static_cast<int32_t>(type)); | ||
| 65 | + return RT_ERROR_JETTY_POOL_NO_RESOURCES; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +rtError_t JettyManager::BindJettyForStream(int32_t streamId, const CaptureModel * const excludeMdl, JettyType type) | ||
| 69 | +{ | ||
| 70 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 71 | + StreamJettyContext* ctx = GetStreamJettyContext(streamId, type); | ||
| 72 | + if (ctx == nullptr) { | ||
| 73 | + RT_LOG(RT_LOG_ERROR, "GetStreamJettyContext failed, stream_id=%d, type=%d.", | ||
| 74 | + streamId, static_cast<int32_t>(type)); | ||
| 75 | + return RT_ERROR_INVALID_VALUE; | ||
| 76 | + } | ||
| 77 | + if (ctx->jettyHandle != 0) { | ||
| 78 | + return RT_ERROR_NONE; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + JettyInfo jettyInfo = {}; | ||
| 82 | + rtError_t error = RT_ERROR_NONE; | ||
| 83 | + | ||
| 84 | + if (ctx->isLargeDepth) { | ||
| 85 | + error = jettyPool_->CreateLargeDepthJetty(type, ctx->capacity, jettyInfo); | ||
| 86 | + ERROR_RETURN_MSG_INNER(error, "Create large depth jetty failed, stream_id=%d, type=%d, ret=%d.", | ||
| 87 | + streamId, static_cast<int32_t>(type), error); | ||
| 88 | + } else { | ||
| 89 | + error = AcquireJettyWithRetry(type, streamId, excludeMdl, jettyInfo); | ||
| 90 | + ERROR_RETURN_MSG_INNER(error, "Acquire jetty failed, stream_id=%d, type=%d, ret=%d.", | ||
| 91 | + streamId, static_cast<int32_t>(type), error); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + ctx->jettyHandle = jettyInfo.handle; | ||
| 95 | + RT_LOG(RT_LOG_INFO, "Bind jetty for stream success, stream_id=%d, type=%d, jetty_id=%u.", | ||
| 96 | + streamId, static_cast<int32_t>(type), jettyInfo.jettyId); | ||
| 97 | + return RT_ERROR_NONE; | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +rtError_t JettyManager::UnbindJettyForStream(int32_t streamId, JettyType type, bool& isReleased) | ||
| 101 | +{ | ||
| 102 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 103 | + StreamJettyContext* ctx = GetStreamJettyContext(streamId, type); | ||
| 104 | + if (ctx == nullptr || ctx->jettyHandle == 0) { | ||
| 105 | + return RT_ERROR_NONE; | ||
| 106 | + } | ||
| 107 | + isReleased = false; | ||
| 108 | + rtError_t error = RT_ERROR_NONE; | ||
| 109 | + if (ctx->isLargeDepth) { | ||
| 110 | + error = jettyPool_->DestroyLargeDepthJetty(ctx->jettyHandle); | ||
| 111 | + } else { | ||
| 112 | + error = jettyPool_->MarkFree(ctx->jettyHandle); | ||
| 113 | + } | ||
| 114 | + ERROR_RETURN_MSG_INNER( | ||
| 115 | + error, "Unbind jetty for stream failed, stream_id=%d, type=%d, ret=%d.", streamId, static_cast<int32_t>(type), | ||
| 116 | + error); | ||
| 117 | + | ||
| 118 | + isReleased = true; | ||
| 119 | + ctx->jettyHandle = 0; | ||
| 120 | + | ||
| 121 | + RT_LOG( | ||
| 122 | + RT_LOG_INFO, "Unbind jetty for stream success, stream_id=%d, type=%d.", streamId, static_cast<int32_t>(type)); | ||
| 123 | + return RT_ERROR_NONE; | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +rtError_t JettyManager::ReleaseJettyByHandle(uint64_t handle, JettyType type) | ||
| 127 | +{ | ||
| 128 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 129 | + if (handle == 0) { | ||
| 130 | + return RT_ERROR_NONE; | ||
| 131 | + } | ||
| 132 | + rtError_t error = jettyPool_->ReleaseJetty(handle, type); | ||
| 133 | + ERROR_RETURN_MSG_INNER(error, "Release jetty by handle failed, handle=%lu, type=%d, ret=%d.", | ||
| 134 | + handle, static_cast<int32_t>(type), error); | ||
| 135 | + RT_LOG(RT_LOG_INFO, "Release jetty by handle success, handle=%lu, type=%d.", | ||
| 136 | + handle, static_cast<int32_t>(type)); | ||
| 137 | + return RT_ERROR_NONE; | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +rtError_t JettyManager::GetJettyInfoForStream(int32_t streamId, JettyType type, JettyInfo& jettyInfo) | ||
| 141 | +{ | ||
| 142 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 143 | + | ||
| 144 | + auto key = std::make_pair(static_cast<uint32_t>(streamId), type); | ||
| 145 | + auto it = streamCaptureContexts_.find(key); | ||
| 146 | + if (it == streamCaptureContexts_.end() || it->second->jettyHandle == 0) { | ||
| 147 | + RT_LOG(RT_LOG_WARNING, "Jetty not found, stream_id=%d, type=%d.", streamId, static_cast<int32_t>(type)); | ||
| 148 | + return RT_ERROR_INVALID_VALUE; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + // Query full jetty info from JettyPool (single source of truth, thread-safe) | ||
| 152 | + rtError_t error = jettyPool_->GetJettyInfoByHandle(it->second->jettyHandle, jettyInfo); | ||
| 153 | + if (error != RT_ERROR_NONE) { | ||
| 154 | + RT_LOG( | ||
| 155 | + RT_LOG_WARNING, "Jetty info not found in pool, stream_id=%d, type=%d.", streamId, | ||
| 156 | + static_cast<int32_t>(type)); | ||
| 157 | + return RT_ERROR_INVALID_VALUE; | ||
| 158 | + } | ||
| 159 | + return RT_ERROR_NONE; | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +StreamJettyContext* JettyManager::GetOrCreateStreamJettyContext(Stream *stream, JettyType type) | ||
| 163 | +{ | ||
| 164 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 165 | + int32_t streamId = static_cast<int32_t>(stream->Id_()); | ||
| 166 | + auto key = std::make_pair(static_cast<uint32_t>(streamId), type); | ||
| 167 | + auto it = streamCaptureContexts_.find(key); | ||
| 168 | + if (it != streamCaptureContexts_.end()) { | ||
| 169 | + return it->second.get(); | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + auto context = std::make_unique<StreamJettyContext>(); | ||
| 173 | + context->jettyType = type; | ||
| 174 | + StreamJettyContext* ctxPtr = context.get(); | ||
| 175 | + streamCaptureContexts_[key] = std::move(context); | ||
| 176 | + | ||
| 177 | + rtError_t error = ReserveJetty(type); | ||
| 178 | + if (error != RT_ERROR_NONE) { | ||
| 179 | + RT_LOG(RT_LOG_ERROR, "ReserveJetty failed, stream_id=%d, type=%d, ret=%d.", | ||
| 180 | + streamId, static_cast<int32_t>(type), error); | ||
| 181 | + streamCaptureContexts_.erase(key); | ||
| 182 | + return nullptr; | ||
| 183 | + } | ||
| 184 | + RT_LOG(RT_LOG_INFO, "Create context with reserved jetty (FREE), stream_id=%d.", streamId); | ||
| 185 | + return ctxPtr; | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +StreamJettyContext* JettyManager::GetStreamJettyContext(int32_t streamId, JettyType type) const | ||
| 189 | +{ | ||
| 190 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 191 | + auto key = std::make_pair(static_cast<uint32_t>(streamId), type); | ||
| 192 | + auto it = streamCaptureContexts_.find(key); | ||
| 193 | + if (it != streamCaptureContexts_.end()) { | ||
| 194 | + return it->second.get(); | ||
| 195 | + } | ||
| 196 | + return nullptr; | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +void JettyManager::DestroyStreamJettyContext(int32_t streamId, JettyType type) | ||
| 200 | +{ | ||
| 201 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 202 | + auto key = std::make_pair(static_cast<uint32_t>(streamId), type); | ||
| 203 | + auto it = streamCaptureContexts_.find(key); | ||
| 204 | + if (it != streamCaptureContexts_.end()) { | ||
| 205 | + streamCaptureContexts_.erase(it); | ||
| 206 | + } | ||
| 207 | +} | ||
| 208 | + | ||
| 209 | +void JettyManager::Clear() | ||
| 210 | +{ | ||
| 211 | + std::lock_guard<std::recursive_mutex> lock(managerLock_); | ||
| 212 | + streamCaptureContexts_.clear(); | ||
| 213 | +} | ||
| 214 | + | ||
| 215 | +} // namespace runtime | ||
| 216 | +} // namespace cce | ||
| @@ -0,0 +1,115 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2025 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace cce { | ||
| 22 | +namespace runtime { | ||
| 23 | + | ||
| 24 | +constexpr uint32_t JETTY_POOL_ACQUIRE_RETRY_MAX_COUNT = 10U; | ||
| 25 | + | ||
| 26 | +class JettyManager { | ||
| 27 | +public: | ||
| 28 | + explicit JettyManager(uint32_t deviceId); | ||
| 29 | + ~JettyManager() | ||
| 30 | + { | ||
| 31 | + Clear(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * @brief 为流预留 Jetty(Capture 阶段使用) | ||
| 36 | + * @param type Jetty 类型 | ||
| 37 | + * @return rtError_t 错误码 | ||
| 38 | + */ | ||
| 39 | + rtError_t ReserveJetty(JettyType type); | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * @brief 绑定 Jetty 到流(Graph Reply 阶段使用) | ||
| 43 | + * @param streamId 流 ID | ||
| 44 | + * @param excludeMdl model | ||
| 45 | + * @param type Jetty 类型 | ||
| 46 | + * @return rtError_t 错误码 | ||
| 47 | + */ | ||
| 48 | + rtError_t BindJettyForStream(int32_t streamId, const CaptureModel * const excludeMdl, JettyType type); | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * @brief 解绑 Jetty 从流 | ||
| 52 | + * @param streamId 流 ID | ||
| 53 | + * @param type Jetty 类型 | ||
| 54 | + * @return rtError_t 错误码 | ||
| 55 | + */ | ||
| 56 | + rtError_t UnbindJettyForStream(int32_t streamId, JettyType type, bool& isReleased); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * @brief 根据 handle 直接释放 Jetty(不依赖 context) | ||
| 60 | + * @param handle Jetty 句柄 | ||
| 61 | + * @param type Jetty 类型 | ||
| 62 | + * @return rtError_t 错误码 | ||
| 63 | + */ | ||
| 64 | + rtError_t ReleaseJettyByHandle(uint64_t handle, JettyType type); | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * @brief 获取流的 Jetty 信息 | ||
| 68 | + * @param streamId 流 ID | ||
| 69 | + * @param type Jetty 类型 | ||
| 70 | + * @param jettyInfo 输出参数,返回 Jetty 信息 | ||
| 71 | + * @return rtError_t 错误码 | ||
| 72 | + */ | ||
| 73 | + rtError_t GetJettyInfoForStream(int32_t streamId, JettyType type, JettyInfo& jettyInfo); | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * @brief 获取或创建流的 Capture Jetty 上下文 | ||
| 77 | + * @param stream 流 | ||
| 78 | + * @param type Jetty 类型 | ||
| 79 | + * @return StreamJettyContext* 上下文指针 | ||
| 80 | + */ | ||
| 81 | + StreamJettyContext* GetOrCreateStreamJettyContext(Stream *stream, JettyType type); | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * @brief 获取流的 Capture Jetty 上下文(只读,不创建) | ||
| 85 | + * @param streamId 流 ID | ||
| 86 | + * @param type Jetty 类型 | ||
| 87 | + * @return StreamJettyContext* 上下文指针,不存在返回 nullptr | ||
| 88 | + */ | ||
| 89 | + StreamJettyContext* GetStreamJettyContext(int32_t streamId, JettyType type) const; | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * @brief 销毁流的 Capture Jetty 上下文 | ||
| 93 | + * @param streamId 流 ID | ||
| 94 | + * @param type Jetty 类型 | ||
| 95 | + */ | ||
| 96 | + void DestroyStreamJettyContext(int32_t streamId, JettyType type); | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * @brief 清空所有 Jetty | ||
| 100 | + */ | ||
| 101 | + void Clear(); | ||
| 102 | + | ||
| 103 | +private: | ||
| 104 | + std::unique_ptr<JettyPool> jettyPool_; | ||
| 105 | + std::map<std::pair<uint32_t, JettyType>, std::unique_ptr<StreamJettyContext>> streamCaptureContexts_; | ||
| 106 | + mutable std::recursive_mutex managerLock_; | ||
| 107 | + | ||
| 108 | + rtError_t AcquireJettyWithRetry(JettyType type, int32_t streamId, | ||
| 109 | + const CaptureModel * const excludeMdl, JettyInfo& jettyInfo); | ||
| 110 | +}; | ||
| 111 | + | ||
| 112 | +} // namespace runtime | ||
| 113 | +} // namespace cce | ||
| 114 | + | ||
| 115 | + | ||
| @@ -0,0 +1,270 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2025 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +namespace cce { | ||
| 17 | +namespace runtime { | ||
| 18 | + | ||
| 19 | +JettyPool::JettyPool(uint32_t deviceId) : deviceId_(deviceId) | ||
| 20 | +{ | ||
| 21 | + h2dJettyPool_.reserve(JETTY_POOL_H2D_MAX_SIZE); | ||
| 22 | + d2dJettyPool_.reserve(JETTY_POOL_D2D_MAX_SIZE); | ||
| 23 | + RT_LOG(RT_LOG_INFO, "Jetty pool created, device_id=%u.", deviceId_); | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +JettyPool::~JettyPool() | ||
| 27 | +{ | ||
| 28 | + Clear(); | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +rtError_t JettyPool::CreateJetty(JettyType type, uint32_t depth, JettyInfo &jettyInfo) | ||
| 32 | +{ | ||
| 33 | + Driver* const driver = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER); | ||
| 34 | + if (driver == nullptr) { | ||
| 35 | + return RT_ERROR_INVALID_VALUE; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + uint32_t dir = (type == JettyType::JETTY_TYPE_H2D) ? TRS_ASYNC_JETTY_HOST_DEVICE : TRS_ASYNC_JETTY_DEVICE_TO_DEVICE; | ||
| 39 | + uint64_t handle = 0U; | ||
| 40 | + | ||
| 41 | + rtError_t error = driver->AsyncDmaJettyCreate(deviceId_, 1U, depth, dir, &handle); | ||
| 42 | + ERROR_RETURN_MSG_INNER(error, "Create jetty failed, device_id=%u, type=%d, depth=%u, ret=%d.", | ||
| 43 | + deviceId_, static_cast<int32_t>(type), depth, error); | ||
| 44 | + | ||
| 45 | + uint32_t dieId = 0U; | ||
| 46 | + uint32_t functionId = 0U; | ||
| 47 | + uint32_t jettyId = 0U; | ||
| 48 | + error = driver->AsyncDmaJettyQuery(deviceId_, handle, dieId, functionId, jettyId); | ||
| 49 | + if (error != RT_ERROR_NONE) { | ||
| 50 | + RT_LOG(RT_LOG_ERROR, "Query jetty failed, device_id=%u, handle=%llu, ret=%d.", | ||
| 51 | + deviceId_, handle, error); | ||
| 52 | + (void)driver->AsyncDmaJettyDestroy(deviceId_, handle); | ||
| 53 | + return error; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + jettyInfo.handle = handle; | ||
| 57 | + jettyInfo.dieId = dieId; | ||
| 58 | + jettyInfo.functionId = functionId; | ||
| 59 | + jettyInfo.jettyId = jettyId; | ||
| 60 | + jettyInfo.depth = depth; | ||
| 61 | + jettyInfo.type = type; | ||
| 62 | + jettyInfo.state = JettyState::FREE; | ||
| 63 | + | ||
| 64 | + RT_LOG(RT_LOG_INFO, "Create jetty success, device_id=%u, type=%d, depth=%u, jetty_id=%u, die_id=%u, func_id=%u.", | ||
| 65 | + deviceId_, static_cast<int32_t>(type), depth, jettyId, dieId, functionId); | ||
| 66 | + return RT_ERROR_NONE; | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +rtError_t JettyPool::ReserveJetty(JettyType type) | ||
| 70 | +{ | ||
| 71 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 72 | + std::vector<JettyInfo> &pool = (type == JettyType::JETTY_TYPE_H2D) ? h2dJettyPool_ : d2dJettyPool_; | ||
| 73 | + uint32_t maxSize = (type == JettyType::JETTY_TYPE_H2D) ? JETTY_POOL_H2D_MAX_SIZE : JETTY_POOL_D2D_MAX_SIZE; | ||
| 74 | + if (pool.size() < maxSize) { | ||
| 75 | + JettyInfo newJetty; | ||
| 76 | + rtError_t error = CreateJetty(type, JETTY_DEPTH_STANDARD, newJetty); | ||
| 77 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); | ||
| 78 | + newJetty.state = JettyState::FREE; | ||
| 79 | + pool.push_back(newJetty); | ||
| 80 | + RT_LOG(RT_LOG_INFO, "Create jetty (FREE), device_id=%u, type=%d, jetty_id=%u.", | ||
| 81 | + deviceId_, static_cast<int32_t>(type), newJetty.jettyId); | ||
| 82 | + return RT_ERROR_NONE; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + RT_LOG(RT_LOG_DEBUG, "Jetty pool exhausted, device_id=%u, type=%d.", | ||
| 86 | + deviceId_, static_cast<int32_t>(type)); | ||
| 87 | + return RT_ERROR_NONE; | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +rtError_t JettyPool::ReleaseJetty(uint64_t handle, JettyType type) | ||
| 91 | +{ | ||
| 92 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 93 | + | ||
| 94 | + Driver* const driver = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER); | ||
| 95 | + if (driver == nullptr) { | ||
| 96 | + return RT_ERROR_INVALID_VALUE; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + std::vector<JettyInfo> &pool = (type == JettyType::JETTY_TYPE_H2D) ? h2dJettyPool_ : d2dJettyPool_; | ||
| 100 | + for (auto it = pool.begin(); it != pool.end(); ++it) { | ||
| 101 | + if (it->handle == handle) { | ||
| 102 | + rtError_t ret = driver->AsyncDmaJettyDestroy(deviceId_, it->handle); | ||
| 103 | + if (ret != RT_ERROR_NONE) { | ||
| 104 | + RT_LOG(RT_LOG_ERROR, "Destroy jetty failed, device_id=%u, type=%d, jetty_id=%u, ret=%d.", | ||
| 105 | + deviceId_, static_cast<int32_t>(type), it->jettyId, static_cast<int32_t>(ret)); | ||
| 106 | + return ret; | ||
| 107 | + } | ||
| 108 | + RT_LOG(RT_LOG_INFO, "Release jetty success, device_id=%u, type=%d, jetty_id=%u.", | ||
| 109 | + deviceId_, static_cast<int32_t>(type), it->jettyId); | ||
| 110 | + pool.erase(it); | ||
| 111 | + return RT_ERROR_NONE; | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + return RT_ERROR_INVALID_VALUE; | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +rtError_t JettyPool::AcquireJetty(JettyType type, JettyInfo &jettyInfo) | ||
| 119 | +{ | ||
| 120 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 121 | + JettyInfo *freeJetty = nullptr; | ||
| 122 | + if (FindJettyByState(type, JettyState::FREE, freeJetty)) { | ||
| 123 | + freeJetty->state = JettyState::BOUND; | ||
| 124 | + jettyInfo = *freeJetty; | ||
| 125 | + RT_LOG(RT_LOG_INFO, "Acquire jetty (FREE->BOUND), device_id=%u, type=%d, jetty_id=%u.", | ||
| 126 | + deviceId_, static_cast<int32_t>(type), freeJetty->jettyId); | ||
| 127 | + return RT_ERROR_NONE; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + RT_LOG(RT_LOG_WARNING, "No FREE jetty to acquire, device_id=%u, type=%d.", deviceId_, static_cast<int32_t>(type)); | ||
| 131 | + return RT_ERROR_JETTY_POOL_NO_RESOURCES; | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +rtError_t JettyPool::MarkFree(uint64_t handle) | ||
| 135 | +{ | ||
| 136 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 137 | + | ||
| 138 | + JettyInfo *jetty = nullptr; | ||
| 139 | + if (!FindJettyByHandle(handle, jetty)) { | ||
| 140 | + RT_LOG(RT_LOG_ERROR, "Jetty not found for MarkFree, device_id=%u, handle=%llu.", | ||
| 141 | + deviceId_, handle); | ||
| 142 | + return RT_ERROR_INVALID_VALUE; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + jetty->state = JettyState::FREE; | ||
| 146 | + RT_LOG(RT_LOG_INFO, "MarkFree jetty success, device_id=%u, jetty_id=%u.", | ||
| 147 | + deviceId_, jetty->jettyId); | ||
| 148 | + return RT_ERROR_NONE; | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +rtError_t JettyPool::CreateLargeDepthJetty(JettyType type, uint32_t depth, JettyInfo &jettyInfo) | ||
| 152 | +{ | ||
| 153 | + if (depth < JETTY_DEPTH_STANDARD) { | ||
| 154 | + RT_LOG(RT_LOG_ERROR, "Invalid large depth jetty depth=%u.", depth); | ||
| 155 | + return RT_ERROR_INVALID_VALUE; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 159 | + | ||
| 160 | + JettyInfo newJetty; | ||
| 161 | + rtError_t error = CreateJetty(type, depth, newJetty); | ||
| 162 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); | ||
| 163 | + newJetty.state = JettyState::BOUND; | ||
| 164 | + largeJettyPool_.push_back(newJetty); | ||
| 165 | + jettyInfo = newJetty; | ||
| 166 | + | ||
| 167 | + RT_LOG(RT_LOG_INFO, "Create large depth jetty success, device_id=%u, type=%d, depth=%u, jetty_id=%u.", | ||
| 168 | + deviceId_, static_cast<int32_t>(type), depth, newJetty.jettyId); | ||
| 169 | + return RT_ERROR_NONE; | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +rtError_t JettyPool::DestroyLargeDepthJetty(uint64_t handle) | ||
| 173 | +{ | ||
| 174 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 175 | + | ||
| 176 | + Driver* const driver = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER); | ||
| 177 | + if (driver == nullptr) { | ||
| 178 | + return RT_ERROR_INVALID_VALUE; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + for (auto it = largeJettyPool_.begin(); it != largeJettyPool_.end(); ++it) { | ||
| 182 | + if (it->handle == handle) { | ||
| 183 | + rtError_t ret = driver->AsyncDmaJettyDestroy(deviceId_, it->handle); | ||
| 184 | + if (ret != RT_ERROR_NONE) { | ||
| 185 | + RT_LOG(RT_LOG_ERROR, "Destroy large depth jetty failed, device_id=%u, handle=%llu, ret=%d.", | ||
| 186 | + deviceId_, handle, static_cast<int32_t>(ret)); | ||
| 187 | + return ret; | ||
| 188 | + } | ||
| 189 | + RT_LOG(RT_LOG_INFO, "Destroy large depth jetty success, device_id=%u, handle=%llu, jetty_id=%u.", | ||
| 190 | + deviceId_, handle, it->jettyId); | ||
| 191 | + largeJettyPool_.erase(it); | ||
| 192 | + return RT_ERROR_NONE; | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + return RT_ERROR_INVALID_VALUE; | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +rtError_t JettyPool::GetJettyInfoByHandle(uint64_t handle, JettyInfo &jettyInfo) | ||
| 200 | +{ | ||
| 201 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 202 | + | ||
| 203 | + JettyInfo *jetty = nullptr; | ||
| 204 | + if (!FindJettyByHandle(handle, jetty) || jetty == nullptr) { | ||
| 205 | + RT_LOG(RT_LOG_ERROR, "Jetty not found for GetJettyInfoByHandle, device_id=%u, handle=%llu.", | ||
| 206 | + deviceId_, handle); | ||
| 207 | + return RT_ERROR_INVALID_VALUE; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + jettyInfo = *jetty; | ||
| 211 | + return RT_ERROR_NONE; | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | +rtError_t JettyPool::QueryJettyInfo(uint64_t handle, uint32_t &dieId, uint32_t &functionId, uint32_t &jettyId) | ||
| 215 | +{ | ||
| 216 | + Driver* const driver = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER); | ||
| 217 | + if (driver == nullptr) { | ||
| 218 | + return RT_ERROR_INVALID_VALUE; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + return driver->AsyncDmaJettyQuery(deviceId_, handle, dieId, functionId, jettyId); | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | +void JettyPool::Clear() | ||
| 225 | +{ | ||
| 226 | + // jetty handle destroy by tsdrv | ||
| 227 | + std::lock_guard<std::mutex> lock(poolLock_); | ||
| 228 | + h2dJettyPool_.clear(); | ||
| 229 | + d2dJettyPool_.clear(); | ||
| 230 | + largeJettyPool_.clear(); | ||
| 231 | + RT_LOG(RT_LOG_INFO, "Jetty pool cleared, device_id=%u.", deviceId_); | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +bool JettyPool::FindJettyByState(JettyType type, JettyState state, JettyInfo *&jettyInfo) | ||
| 235 | +{ | ||
| 236 | + std::vector<JettyInfo> &pool = (type == JettyType::JETTY_TYPE_H2D) ? h2dJettyPool_ : d2dJettyPool_; | ||
| 237 | + for (auto &jetty : pool) { | ||
| 238 | + if (jetty.state == state) { | ||
| 239 | + jettyInfo = &jetty; | ||
| 240 | + return true; | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | + return false; | ||
| 244 | +} | ||
| 245 | + | ||
| 246 | +bool JettyPool::FindJettyByHandle(uint64_t handle, JettyInfo *&jettyInfo) | ||
| 247 | +{ | ||
| 248 | + for (auto &jetty : h2dJettyPool_) { | ||
| 249 | + if (jetty.handle == handle) { | ||
| 250 | + jettyInfo = &jetty; | ||
| 251 | + return true; | ||
| 252 | + } | ||
| 253 | + } | ||
| 254 | + for (auto &jetty : d2dJettyPool_) { | ||
| 255 | + if (jetty.handle == handle) { | ||
| 256 | + jettyInfo = &jetty; | ||
| 257 | + return true; | ||
| 258 | + } | ||
| 259 | + } | ||
| 260 | + for (auto &jetty : largeJettyPool_) { | ||
| 261 | + if (jetty.handle == handle) { | ||
| 262 | + jettyInfo = &jetty; | ||
| 263 | + return true; | ||
| 264 | + } | ||
| 265 | + } | ||
| 266 | + return false; | ||
| 267 | +} | ||
| 268 | + | ||
| 269 | +} // namespace runtime | ||
| 270 | +} // namespace cce | ||
| @@ -0,0 +1,136 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2025 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +namespace cce { | ||
| 21 | +namespace runtime { | ||
| 22 | + | ||
| 23 | +constexpr uint32_t JETTY_POOL_H2D_MAX_SIZE = 1792U; | ||
| 24 | +constexpr uint32_t JETTY_POOL_D2D_MAX_SIZE = 256U; | ||
| 25 | +constexpr uint32_t JETTY_DEPTH_STANDARD = 2048U; | ||
| 26 | + | ||
| 27 | +enum class JettyType : uint8_t { JETTY_TYPE_H2D = 0, JETTY_TYPE_D2D = 1, JETTY_TYPE_MAX }; | ||
| 28 | + | ||
| 29 | +enum class JettyState : uint8_t { FREE = 0, BOUND }; | ||
| 30 | + | ||
| 31 | +struct JettyInfo { | ||
| 32 | + uint64_t handle = 0; | ||
| 33 | + uint32_t dieId = 0; | ||
| 34 | + uint32_t functionId = 0; | ||
| 35 | + uint32_t jettyId = 0; | ||
| 36 | + uint32_t depth = JETTY_DEPTH_STANDARD; | ||
| 37 | + JettyType type = JettyType::JETTY_TYPE_MAX; | ||
| 38 | + JettyState state = JettyState::FREE; | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +class JettyPool { | ||
| 42 | +public: | ||
| 43 | + explicit JettyPool(uint32_t deviceId); | ||
| 44 | + ~JettyPool(); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * @brief 创建 jetty 并放入 pool(状态为 FREE) | ||
| 48 | + * @param type Jetty 类型 | ||
| 49 | + * @return rtError_t 错误码 | ||
| 50 | + */ | ||
| 51 | + rtError_t ReserveJetty(JettyType type); | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * @brief 释放 Jetty, 适用于非large jetty | ||
| 55 | + * @param handle Jetty 句柄 | ||
| 56 | + * @param type Jetty 类型 | ||
| 57 | + * @return rtError_t 错误码 | ||
| 58 | + */ | ||
| 59 | + rtError_t ReleaseJetty(uint64_t handle, JettyType type); | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * @brief 获取 FREE jetty 并标记为 BOUND(用于 Graph Reply 阶段绑定) | ||
| 63 | + * @param type Jetty 类型 | ||
| 64 | + * @param jettyInfo 输出参数,返回 Jetty 信息 | ||
| 65 | + * @return rtError_t 错误码 | ||
| 66 | + */ | ||
| 67 | + rtError_t AcquireJetty(JettyType type, JettyInfo& jettyInfo); | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * @brief 标记 Jetty 为空闲 | ||
| 71 | + * @param handle Jetty 句柄 | ||
| 72 | + * @return rtError_t 错误码 | ||
| 73 | + */ | ||
| 74 | + rtError_t MarkFree(uint64_t handle); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * @brief 创建大深度 Jetty(深度 > 2k,不走标准池) | ||
| 78 | + * @param type Jetty 类型 | ||
| 79 | + * @param depth Jetty 深度(必须是 2^n) | ||
| 80 | + * @param jettyInfo 输出参数,返回创建的 Jetty 信息 | ||
| 81 | + * @return rtError_t 错误码 | ||
| 82 | + */ | ||
| 83 | + rtError_t CreateLargeDepthJetty(JettyType type, uint32_t depth, JettyInfo& jettyInfo); | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * @brief 销毁大深度 Jetty | ||
| 87 | + * @param handle Jetty 句柄 | ||
| 88 | + * @return rtError_t 错误码 | ||
| 89 | + */ | ||
| 90 | + rtError_t DestroyLargeDepthJetty(uint64_t handle); | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * @brief 查询 Jetty 信息 | ||
| 94 | + * @param handle Jetty 句柄 | ||
| 95 | + * @param dieId 输出参数,返回 DIE ID | ||
| 96 | + * @param functionId 输出参数,返回函数 ID | ||
| 97 | + * @param jettyId 输出参数,返回 Jetty ID | ||
| 98 | + * @return rtError_t 错误码 | ||
| 99 | + */ | ||
| 100 | + rtError_t QueryJettyInfo(uint64_t handle, uint32_t& dieId, uint32_t& functionId, uint32_t& jettyId); | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * @brief 根据句柄查找 Jetty 信息(适用于全部类型) | ||
| 104 | + * @param handle Jetty 句柄 | ||
| 105 | + * @param jettyInfo 输出参数,返回 Jetty 信息指针 | ||
| 106 | + * @return bool 是否找到 | ||
| 107 | + */ | ||
| 108 | + bool FindJettyByHandle(uint64_t handle, JettyInfo*& jettyInfo); | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * @brief 根据句柄查找 Jetty 信息并拷贝(线程安全,内部持有 poolLock_) | ||
| 112 | + * @param handle Jetty 句柄 | ||
| 113 | + * @param jettyInfo 输出参数,返回 Jetty 信息副本 | ||
| 114 | + * @return rtError_t 错误码 | ||
| 115 | + */ | ||
| 116 | + rtError_t GetJettyInfoByHandle(uint64_t handle, JettyInfo& jettyInfo); | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * @brief 清空 JettyPool | ||
| 120 | + */ | ||
| 121 | + void Clear(); | ||
| 122 | + | ||
| 123 | +private: | ||
| 124 | + rtError_t CreateJetty(JettyType type, uint32_t depth, JettyInfo& jettyInfo); | ||
| 125 | + bool FindJettyByState(JettyType type, JettyState state, JettyInfo *&jettyInfo); | ||
| 126 | + | ||
| 127 | + uint32_t deviceId_; | ||
| 128 | + std::vector<JettyInfo> h2dJettyPool_; | ||
| 129 | + std::vector<JettyInfo> d2dJettyPool_; | ||
| 130 | + std::vector<JettyInfo> largeJettyPool_; | ||
| 131 | + std::mutex poolLock_; | ||
| 132 | +}; | ||
| 133 | +} // namespace runtime | ||
| 134 | +} // namespace cce | ||
| 135 | + | ||
| 136 | + | ||