Merged
【PR】: runtime support launch blocking #4247
xiachanglinAdd on Aug 14
【PR】: runtime support launch blocking #4247
Merged
Total: 82 files changed+3768-314
| @@ -12,6 +12,8 @@ | |||
| 12 | - [`aclError aclrtStreamQuery(aclrtStream stream, aclrtStreamStatus *status)`](#aclrtStreamQuery):查询指定Stream上的所有任务的执行状态。 | 12 | - [`aclError aclrtStreamQuery(aclrtStream stream, aclrtStreamStatus *status)`](#aclrtStreamQuery):查询指定Stream上的所有任务的执行状态。 |
| 13 | - [`aclError aclrtSynchronizeStream(aclrtStream stream)`](#aclrtSynchronizeStream):阻塞Host侧当前线程直到指定Stream中的所有任务都完成。 | 13 | - [`aclError aclrtSynchronizeStream(aclrtStream stream)`](#aclrtSynchronizeStream):阻塞Host侧当前线程直到指定Stream中的所有任务都完成。 |
| 14 | - [`aclError aclrtSynchronizeStreamWithTimeout(aclrtStream stream, int32_t timeout)`](#aclrtSynchronizeStreamWithTimeout):阻塞Host侧当前线程直到指定Stream中的所有任务都完成,该接口是在[aclrtSynchronizeStream](#aclrtSynchronizeStream)接口基础上进行了增强,支持用户设置超时时间,当应用程序异常时可根据所设置的超时时间自行退出。 | 14 | - [`aclError aclrtSynchronizeStreamWithTimeout(aclrtStream stream, int32_t timeout)`](#aclrtSynchronizeStreamWithTimeout):阻塞Host侧当前线程直到指定Stream中的所有任务都完成,该接口是在[aclrtSynchronizeStream](#aclrtSynchronizeStream)接口基础上进行了增强,支持用户设置超时时间,当应用程序异常时可根据所设置的超时时间自行退出。 |
| 15 | +- [`aclError aclrtNonBlockingLaunchBegin(aclrtStream stream, uint64_t flag)`](#aclrtNonBlockingLaunchBegin):与[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口配合使用,用于标记指定Stream上任务异步执行的起始点。 | ||
| 16 | +- [`aclError aclrtNonBlockingLaunchEnd(aclrtStream stream, uint64_t flag)`](#aclrtNonBlockingLaunchEnd):与[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口配合使用,用于标记指定Stream上任务异步执行的结束点。 | ||
| 15 | - [`aclError aclrtStreamAbort(aclrtStream stream)`](#aclrtStreamAbort):停止指定Stream上正在执行的任务、丢弃指定Stream上已下发但未执行的任务。本接口执行期间,指定Stream上新下发的任务不再生效。 | 17 | - [`aclError aclrtStreamAbort(aclrtStream stream)`](#aclrtStreamAbort):停止指定Stream上正在执行的任务、丢弃指定Stream上已下发但未执行的任务。本接口执行期间,指定Stream上新下发的任务不再生效。 |
| 16 | - [`aclError aclrtStreamGetId(aclrtStream stream, int32_t *streamId)`](#aclrtStreamGetId):获取指定Stream的ID。 | 18 | - [`aclError aclrtStreamGetId(aclrtStream stream, int32_t *streamId)`](#aclrtStreamGetId):获取指定Stream的ID。 |
| 17 | - [`aclError aclrtGetStreamAvailableNum(uint32_t *streamCount)`](#aclrtGetStreamAvailableNum):获取当前Device上剩余可用的Stream数量。 | 19 | - [`aclError aclrtGetStreamAvailableNum(uint32_t *streamCount)`](#aclrtGetStreamAvailableNum):获取当前Device上剩余可用的Stream数量。 |
| @@ -663,6 +665,156 @@ aclError aclrtSynchronizeStreamWithTimeout(aclrtStream stream, int32_t timeout) | |||
| 663 | <br> | 665 | <br> |
| 664 | <br> | 666 | <br> |
| 665 | 667 | ||
| 668 | +<a id="aclrtNonBlockingLaunchBegin"></a> | ||
| 669 | + | ||
| 670 | +## aclrtNonBlockingLaunchBegin | ||
| 671 | + | ||
| 672 | +```c | ||
| 673 | +aclError aclrtNonBlockingLaunchBegin(aclrtStream stream, uint64_t flag) | ||
| 674 | +``` | ||
| 675 | + | ||
| 676 | +### 产品支持情况 | ||
| 677 | + | ||
| 678 | +<!-- npu="950" id3600 --> | ||
| 679 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 680 | +<!-- end id3600 --> | ||
| 681 | +<!-- npu="A3" id3601 --> | ||
| 682 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持 | ||
| 683 | +<!-- end id3601 --> | ||
| 684 | +<!-- npu="910b" id3602 --> | ||
| 685 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持 | ||
| 686 | +<!-- end id3602 --> | ||
| 687 | +<!-- npu="310b" id3603 --> | ||
| 688 | +- Atlas 200I/500 A2 推理产品:不支持 | ||
| 689 | +<!-- end id3603 --> | ||
| 690 | +<!-- npu="310p" id3604 --> | ||
| 691 | +- Atlas 推理系列产品:不支持 | ||
| 692 | +<!-- end id3604 --> | ||
| 693 | +<!-- npu="910" id3605 --> | ||
| 694 | +- Atlas 训练系列产品:不支持 | ||
| 695 | +<!-- end id3605 --> | ||
| 696 | +<!-- npu="IPV350" id3606 --> | ||
| 697 | +- IPV350:不支持 | ||
| 698 | +<!-- end id3606 --> | ||
| 699 | +<!-- @ref: runtime/res/docs/zh/api_ref/06_stream_management_res.md#id29 --> | ||
| 700 | + | ||
| 701 | +### 功能说明 | ||
| 702 | + | ||
| 703 | +本接口需与[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口配合使用。当`ASCEND_RT_LAUNCH_BLOCKING`环境变量配置为1,或通过[aclrtSetStreamAttribute](#aclrtSetStreamAttribute)接口将指定Stream设置为同步模式时,调用本接口和[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口分别标记指定Stream上任务异步执行的起始点和结束点。在[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口和[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口之间,以下接口下发的任务将保持异步模式: | ||
| 704 | + | ||
| 705 | +- aclrtLaunchKernel | ||
| 706 | +- aclrtLaunchKernelV2 | ||
| 707 | +- aclrtLaunchKernelWithConfig | ||
| 708 | +- aclrtLaunchKernelWithHostArgs | ||
| 709 | +- aclrtLaunchKernelWithArgsArray | ||
| 710 | +- aclrtLaunchSIMTKernelWithArgsArray | ||
| 711 | +- aclrtLaunchSIMTKernelWithHostArgs | ||
| 712 | +- aclmdlRIExecuteAsync | ||
| 713 | + | ||
| 714 | +### 参数说明 | ||
| 715 | + | ||
| 716 | +| 参数名 | 输入/输出 | 说明 | | ||
| 717 | +| --- | :---: | --- | | ||
| 718 | +| stream | 输入 | 指定Stream。传入NULL时,表示当前Context的默认Stream。类型定义请参见[aclrtStream](25-05_Typedefs.md#aclrtStream)。 | | ||
| 719 | +| flag | 输入 | 预留参数。当前固定配置为0。 | | ||
| 720 | + | ||
| 721 | +### 返回值说明 | ||
| 722 | + | ||
| 723 | +返回0表示成功,返回其他值表示失败,请参见[aclError](25-01_aclError.md#aclError)。 | ||
| 724 | + | ||
| 725 | +### 约束说明 | ||
| 726 | + | ||
| 727 | +- 不支持使用[aclmdlRIBindStream](15_model_running_instance_management.md#aclmdlRIBindStream)接口来绑定模型运行实例的Stream。 | ||
| 728 | +- stream参数指定的Stream必须是不在捕获状态的Stream。 | ||
| 729 | +- 不支持调用[aclrtCreateStreamWithConfig](#aclrtCreateStreamWithConfig)接口,将flag设置为ACL_STREAM_PERSISTENT、ACL_STREAM_CPU_SCHEDULE或ACL_STREAM_DEVICE_USE_ONLY创建的Stream。 | ||
| 730 | +- 本接口仅对上述接口生效。 | ||
| 731 | +- 本接口设置的异步模式优先级高于`ASCEND_RT_LAUNCH_BLOCKING`环境变量和通过[aclrtSetStreamAttribute](#aclrtSetStreamAttribute)接口设置的`ACL_STREAM_LAUNCH_BLOCKING_MODE`属性。 | ||
| 732 | +- 本接口和[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口要成对使用,且两个接口中的Stream应相同。 | ||
| 733 | +- 支持嵌套调用。每调用一次本接口,需对应调用一次[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口。两层嵌套调用示例如下: | ||
| 734 | + | ||
| 735 | + ```c | ||
| 736 | + aclrtNonBlockingLaunchBegin(stream, 0); // 外层开始 | ||
| 737 | + aclrtNonBlockingLaunchBegin(stream, 0); // 内层开始 | ||
| 738 | + aclrtNonBlockingLaunchEnd(stream, 0); // 内层结束 | ||
| 739 | + aclrtNonBlockingLaunchEnd(stream, 0); // 外层结束 | ||
| 740 | + ``` | ||
| 741 | + | ||
| 742 | +<br> | ||
| 743 | +<br> | ||
| 744 | +<br> | ||
| 745 | + | ||
| 746 | +<a id="aclrtNonBlockingLaunchEnd"></a> | ||
| 747 | + | ||
| 748 | +## aclrtNonBlockingLaunchEnd | ||
| 749 | + | ||
| 750 | +```c | ||
| 751 | +aclError aclrtNonBlockingLaunchEnd(aclrtStream stream, uint64_t flag) | ||
| 752 | +``` | ||
| 753 | + | ||
| 754 | +### 产品支持情况 | ||
| 755 | + | ||
| 756 | +<!-- npu="950" id3607 --> | ||
| 757 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 758 | +<!-- end id3607 --> | ||
| 759 | +<!-- npu="A3" id3608 --> | ||
| 760 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持 | ||
| 761 | +<!-- end id3608 --> | ||
| 762 | +<!-- npu="910b" id3609 --> | ||
| 763 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持 | ||
| 764 | +<!-- end id3609 --> | ||
| 765 | +<!-- npu="310b" id3610 --> | ||
| 766 | +- Atlas 200I/500 A2 推理产品:不支持 | ||
| 767 | +<!-- end id3610 --> | ||
| 768 | +<!-- npu="310p" id3611 --> | ||
| 769 | +- Atlas 推理系列产品:不支持 | ||
| 770 | +<!-- end id3611 --> | ||
| 771 | +<!-- npu="910" id3612 --> | ||
| 772 | +- Atlas 训练系列产品:不支持 | ||
| 773 | +<!-- end id3612 --> | ||
| 774 | +<!-- npu="IPV350" id3613 --> | ||
| 775 | +- IPV350:不支持 | ||
| 776 | +<!-- end id3613 --> | ||
| 777 | +<!-- @ref: runtime/res/docs/zh/api_ref/06_stream_management_res.md#id30 --> | ||
| 778 | + | ||
缺其他产品型号 ![]() ![]() | |||
| 779 | +### 功能说明 | ||
| 780 | + | ||
| 781 | +本接口需与[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口配合使用。当`ASCEND_RT_LAUNCH_BLOCKING`环境变量配置为1,或通过[aclrtSetStreamAttribute](#aclrtSetStreamAttribute)接口将指定Stream设置为同步模式时,调用[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口和本接口分别标记指定Stream上任务异步执行的起始点和结束点。在[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口和[aclrtNonBlockingLaunchEnd](#aclrtNonBlockingLaunchEnd)接口之间,以下接口下发的任务将保持异步模式: | ||
| 782 | + | ||
| 783 | +- aclrtLaunchKernel | ||
| 784 | +- aclrtLaunchKernelV2 | ||
| 785 | +- aclrtLaunchKernelWithConfig | ||
| 786 | +- aclrtLaunchKernelWithHostArgs | ||
| 787 | +- aclrtLaunchKernelWithArgsArray | ||
| 788 | +- aclrtLaunchSIMTKernelWithArgsArray | ||
| 789 | +- aclrtLaunchSIMTKernelWithHostArgs | ||
| 790 | +- aclmdlRIExecuteAsync | ||
| 791 | + | ||
| 792 | +调用本接口后,若已不存在尚未结束的[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口调用,且当前Stream需要同步,本接口会等待调用前指定Stream上已下发的任务执行完成后返回。若仍有尚未结束的[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口调用,则指定Stream上的相关接口继续采用异步模式,不执行同步等待。 | ||
| 793 | + | ||
| 794 | +### 参数说明 | ||
| 795 | + | ||
| 796 | +| 参数名 | 输入/输出 | 说明 | | ||
| 797 | +| --- | :---: | --- | | ||
| 798 | +| stream | 输入 | 指定Stream。传入NULL时,表示当前Context的默认Stream。类型定义请参见[aclrtStream](25-05_Typedefs.md#aclrtStream)。 | | ||
| 799 | +| flag | 输入 | 预留参数。当前固定配置为0。 | | ||
| 800 | + | ||
| 801 | +### 返回值说明 | ||
| 802 | + | ||
| 803 | +返回0表示成功,返回其他值表示失败,请参见[aclError](25-01_aclError.md#aclError)。 | ||
| 804 | + | ||
| 805 | +### 约束说明 | ||
| 806 | + | ||
| 807 | +- 不支持使用[aclmdlRIBindStream](15_model_running_instance_management.md#aclmdlRIBindStream)接口来绑定模型运行实例的Stream。 | ||
| 808 | +- stream参数指定的Stream必须是不在捕获状态的Stream。 | ||
| 809 | +- 不支持调用[aclrtCreateStreamWithConfig](#aclrtCreateStreamWithConfig)接口,将flag设置为ACL_STREAM_PERSISTENT、ACL_STREAM_CPU_SCHEDULE或ACL_STREAM_DEVICE_USE_ONLY创建的Stream。 | ||
| 810 | +- 本接口仅对上述接口生效。 | ||
| 811 | +- [aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口和本接口要成对使用,且两个接口中的Stream应相同。若未先调用[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口,本接口返回失败。 | ||
| 812 | +- 支持嵌套调用,只有所有[aclrtNonBlockingLaunchBegin](#aclrtNonBlockingLaunchBegin)接口调用均已结束时才可能执行同步等待。 | ||
| 813 | + | ||
| 814 | +<br> | ||
| 815 | +<br> | ||
| 816 | +<br> | ||
| 817 | + | ||
| 666 | <a id="aclrtStreamAbort"></a> | 818 | <a id="aclrtStreamAbort"></a> |
| 667 | 819 | ||
| 668 | ## aclrtStreamAbort | 820 | ## aclrtStreamAbort |
| @@ -879,6 +1031,9 @@ aclError aclrtSetStreamAttribute(aclrtStream stream, aclrtStreamAttr stmAttrType | |||
| 879 | ### 约束说明 | 1031 | ### 约束说明 |
| 880 | 1032 | ||
| 881 | - 溢出检测属性:调用该接口打开或关闭溢出检测开关后,仅对后续新下发的任务生效,已下发的任务仍维持原样。 | 1033 | - 溢出检测属性:调用该接口打开或关闭溢出检测开关后,仅对后续新下发的任务生效,已下发的任务仍维持原样。 |
| 1034 | +<!-- npu="950,A3,910b" id3618 --> | ||
| 1035 | +- `ACL_STREAM_LAUNCH_BLOCKING_MODE`属性:仅Ascend 950PR/Ascend 950DT、Atlas A3 训练系列产品/Atlas A3 推理系列产品、Atlas A2 训练系列产品/Atlas A2 推理系列产品支持设置该属性。不支持对使用[aclmdlRIBindStream](15_model_running_instance_management.md#aclmdlRIBindStream)接口绑定模型运行实例的Stream设置该属性。不支持对调用[aclrtCreateStreamWithConfig](#aclrtCreateStreamWithConfig)接口,将flag设置为ACL_STREAM_PERSISTENT、ACL_STREAM_CPU_SCHEDULE或ACL_STREAM_DEVICE_USE_ONLY创建的Stream设置该属性。设置该属性时,stream参数指定的Stream必须是不在捕获状态的Stream。 | ||
| 1036 | +<!-- end id3618 --> | ||
| 882 | <!-- npu="950,A3,910b,910,310p,310b" id15 --> | 1037 | <!-- npu="950,A3,910b,910,310p,310b" id15 --> |
| 883 | - 当Stream上设置了遇错即停模式,该Stream所在的Context下的其它Stream也是遇错即停。 | 1038 | - 当Stream上设置了遇错即停模式,该Stream所在的Context下的其它Stream也是遇错即停。 |
| 884 | <!-- end id15 --> | 1039 | <!-- end id15 --> |
| @@ -953,6 +1108,9 @@ aclError aclrtGetStreamAttribute(aclrtStream stream, aclrtStreamAttr stmAttrType | |||
| 953 | <!-- npu="910,310p,310b" id20 --> | 1108 | <!-- npu="910,310p,310b" id20 --> |
| 954 | 对于Atlas 200I/500 A2 推理产品、Atlas 推理系列产品、Atlas 训练系列产品,不支持指定默认Stream(即stream参数传入NULL)。 | 1109 | 对于Atlas 200I/500 A2 推理产品、Atlas 推理系列产品、Atlas 训练系列产品,不支持指定默认Stream(即stream参数传入NULL)。 |
| 955 | <!-- end id20 --> | 1110 | <!-- end id20 --> |
| 1111 | +<!-- npu="950,A3,910b" id3619 --> | ||
| 1112 | +- `ACL_STREAM_LAUNCH_BLOCKING_MODE`属性:仅Ascend 950PR/Ascend 950DT、Atlas A3 训练系列产品/Atlas A3 推理系列产品、Atlas A2 训练系列产品/Atlas A2 推理系列产品支持获取该属性。不支持对使用[aclmdlRIBindStream](15_model_running_instance_management.md#aclmdlRIBindStream)接口绑定模型运行实例的Stream获取该属性。不支持对调用[aclrtCreateStreamWithConfig](#aclrtCreateStreamWithConfig)接口,将flag设置为ACL_STREAM_PERSISTENT、ACL_STREAM_CPU_SCHEDULE或ACL_STREAM_DEVICE_USE_ONLY创建的Stream获取该属性。获取该属性时,stream参数指定的Stream必须是不在捕获状态的Stream。 | ||
| 1113 | +<!-- end id3619 --> | ||
| 956 | <!-- end id18 --> | 1114 | <!-- end id18 --> |
| 957 | <!-- @ref: runtime/res/docs/zh/api_ref/06_stream_management_res.md#id28 --> | 1115 | <!-- @ref: runtime/res/docs/zh/api_ref/06_stream_management_res.md#id28 --> |
| 958 | 1116 | ||
| @@ -2272,6 +2272,7 @@ typedef enum { | |||
| 2272 | ACL_STREAM_ATTR_USER_CUSTOM_TAG = 3, | 2272 | ACL_STREAM_ATTR_USER_CUSTOM_TAG = 3, |
| 2273 | ACL_STREAM_ATTR_CACHE_OP_INFO = 4, | 2273 | ACL_STREAM_ATTR_CACHE_OP_INFO = 4, |
| 2274 | ACL_STREAM_ATTR_PRIORITY = 5, | 2274 | ACL_STREAM_ATTR_PRIORITY = 5, |
| 2275 | + ACL_STREAM_LAUNCH_BLOCKING_MODE = 6, | ||
| 2275 | } aclrtStreamAttr; | 2276 | } aclrtStreamAttr; |
| 2276 | ``` | 2277 | ``` |
| 2277 | 2278 | ||
| @@ -2282,17 +2283,21 @@ typedef enum { | |||
| 2282 | | ACL_STREAM_ATTR_USER_CUSTOM_TAG | 设置Stream上的溢出检测分组标签,以确定溢出发生时检测的粒度。如果不设置分组标签,默认为进程粒度。如果设置了分组标签,则仅检测与发生溢出的Stream具有相同分组标签的Stream。 | | 2283 | | ACL_STREAM_ATTR_USER_CUSTOM_TAG | 设置Stream上的溢出检测分组标签,以确定溢出发生时检测的粒度。如果不设置分组标签,默认为进程粒度。如果设置了分组标签,则仅检测与发生溢出的Stream具有相同分组标签的Stream。 | |
| 2283 | | ACL_STREAM_ATTR_CACHE_OP_INFO | 基于捕获方式构建模型运行实例场景下,通过该属性设置Stream的算子信息缓存开关,以便于控制后续采集性能数据时是否附带算子信息。<br>该属性需与其它接口配合使用,请参见[aclrtCacheLastTaskOpInfo](24_other_APIs.md#aclrtCacheLastTaskOpInfo)中的接口调用流程。<br>跨Stream的任务捕获时,与主流关联的其他Stream,其算子信息缓存开关状态与主流一致。 | | 2284 | | ACL_STREAM_ATTR_CACHE_OP_INFO | 基于捕获方式构建模型运行实例场景下,通过该属性设置Stream的算子信息缓存开关,以便于控制后续采集性能数据时是否附带算子信息。<br>该属性需与其它接口配合使用,请参见[aclrtCacheLastTaskOpInfo](24_other_APIs.md#aclrtCacheLastTaskOpInfo)中的接口调用流程。<br>跨Stream的任务捕获时,与主流关联的其他Stream,其算子信息缓存开关状态与主流一致。 | |
| 2284 | | ACL_STREAM_ATTR_PRIORITY | 基于该属性值动态设置/查询stream优先级。 | | 2285 | | ACL_STREAM_ATTR_PRIORITY | 基于该属性值动态设置/查询stream优先级。 | |
| 2286 | +| ACL_STREAM_LAUNCH_BLOCKING_MODE | 用于控制以下接口在指定Stream上的执行模式为同步模式或异步模式:<br><br> - aclrtLaunchKernel<br> - aclrtLaunchKernelV2<br> - aclrtLaunchKernelWithConfig<br> - aclrtLaunchKernelWithHostArgs<br> - aclrtLaunchKernelWithArgsArray<br> - aclrtLaunchSIMTKernelWithArgsArray<br> - aclrtLaunchSIMTKernelWithHostArgs<br> - aclmdlRIExecuteAsync<br><br>通过[aclrtSetStreamAttribute](06_stream_management.md#aclrtSetStreamAttribute)接口设置,通过[aclrtGetStreamAttribute](06_stream_management.md#aclrtGetStreamAttribute)接口获取。属性值说明请参见[aclrtStreamAttrValue](25-04_Structs.md#aclrtStreamAttrValue)中的launchBlockingMode。 | | ||
| 2285 | 2287 | ||
| 2286 | <!-- npu="950,A3,910b" id84 --> | 2288 | <!-- npu="950,A3,910b" id84 --> |
| 2287 | 对于Ascend 950PR/Ascend 950DT、Atlas A3 训练系列产品/Atlas A3 推理系列产品、Atlas A2 训练系列产品/Atlas A2 推理系列产品,支持设置Stream优先级。 | 2289 | 对于Ascend 950PR/Ascend 950DT、Atlas A3 训练系列产品/Atlas A3 推理系列产品、Atlas A2 训练系列产品/Atlas A2 推理系列产品,支持设置Stream优先级。 |
| 2290 | +对于Ascend 950PR/Ascend 950DT、Atlas A3 训练系列产品/Atlas A3 推理系列产品、Atlas A2 训练系列产品/Atlas A2 推理系列产品,支持设置或获取`ACL_STREAM_LAUNCH_BLOCKING_MODE`属性。 | ||
| 2288 | <!-- end id84 --> | 2291 | <!-- end id84 --> |
| 2289 | 2292 | ||
| 2290 | <!-- npu="910,310p,310b" id82 --> | 2293 | <!-- npu="910,310p,310b" id82 --> |
| 2291 | 对于Atlas 200I/500 A2 推理产品、Atlas 推理系列产品、Atlas 训练系列产品,不支持设置Stream优先级。 | 2294 | 对于Atlas 200I/500 A2 推理产品、Atlas 推理系列产品、Atlas 训练系列产品,不支持设置Stream优先级。 |
| 2295 | +对于Atlas 200I/500 A2 推理产品、Atlas 推理系列产品、Atlas 训练系列产品,不支持设置或获取`ACL_STREAM_LAUNCH_BLOCKING_MODE`属性。 | ||
| 2292 | <!-- end id82 --> | 2296 | <!-- end id82 --> |
| 2293 | 2297 | ||
| 2294 | <!-- npu="IPV350" id83 --> | 2298 | <!-- npu="IPV350" id83 --> |
| 2295 | 当前不支持设置Stream优先级。 | 2299 | 当前不支持设置Stream优先级。 |
| 2300 | +当前不支持设置或获取`ACL_STREAM_LAUNCH_BLOCKING_MODE`属性。 | ||
| 2296 | <!-- end id83 --> | 2301 | <!-- end id83 --> |
| 2297 | <!-- @ref: runtime/res/docs/zh/api_ref/25-02_Enumerations_res.md#id15 --> | 2302 | <!-- @ref: runtime/res/docs/zh/api_ref/25-02_Enumerations_res.md#id15 --> |
| 2298 | 2303 | ||
| @@ -2502,4 +2507,3 @@ typedef enum aclrtDeviceLimit { | |||
| 2502 | - `ACL_RT_DEV_LIMIT_SIMD_PRINTF_FIFO_SIZE_PER_CORE`:用于控制每个Core上SIMD算子可以Printf打印的空间大小,单位Byte。默认值为32768Byte(即32KB)。设置为`ACL_RT_DEV_LIMIT_SIMD_PRINTF_FIFO_SIZE_PER_CORE`类型时,value取值必须是8Byte的整数倍,如果传入的不是8Byte的整数倍,则接口内部会自动向上取整,确保其为8Byte的整数倍。value的取值范围为[1024, 67108864]Byte,即[1KB, 64MB]。 | 2507 | - `ACL_RT_DEV_LIMIT_SIMD_PRINTF_FIFO_SIZE_PER_CORE`:用于控制每个Core上SIMD算子可以Printf打印的空间大小,单位Byte。默认值为32768Byte(即32KB)。设置为`ACL_RT_DEV_LIMIT_SIMD_PRINTF_FIFO_SIZE_PER_CORE`类型时,value取值必须是8Byte的整数倍,如果传入的不是8Byte的整数倍,则接口内部会自动向上取整,确保其为8Byte的整数倍。value的取值范围为[1024, 67108864]Byte,即[1KB, 64MB]。 |
| 2503 | 2508 | ||
| 2504 | - `ACL_RT_DEV_LIMIT_SIMT_PRINTF_FIFO_SIZE`:用于控制SIMT算子可以Printf打印的空间大小,单位Byte。默认值为2097152Byte(即2MB)。设置为`ACL_RT_DEV_LIMIT_SIMT_PRINTF_FIFO_SIZE`类型时,value取值必须是8Byte的整数倍,如果传入的不是8Byte的整数倍,则接口内部会自动向上取整,确保其为8Byte的整数倍。value的取值范围为[1048576, 67108864]Byte,即[1, 64]MB。 | 2509 | - `ACL_RT_DEV_LIMIT_SIMT_PRINTF_FIFO_SIZE`:用于控制SIMT算子可以Printf打印的空间大小,单位Byte。默认值为2097152Byte(即2MB)。设置为`ACL_RT_DEV_LIMIT_SIMT_PRINTF_FIFO_SIZE`类型时,value取值必须是8Byte的整数倍,如果传入的不是8Byte的整数倍,则接口内部会自动向上取整,确保其为8Byte的整数倍。value的取值范围为[1048576, 67108864]Byte,即[1, 64]MB。 |
| 2505 | - | ||
| @@ -1083,6 +1083,7 @@ typedef union { | |||
| 1083 | uint32_t userCustomTag; | 1083 | uint32_t userCustomTag; |
| 1084 | uint32_t cacheOpInfoSwitch; | 1084 | uint32_t cacheOpInfoSwitch; |
| 1085 | uint32_t streamPriority; | 1085 | uint32_t streamPriority; |
| 1086 | + uint32_t launchBlockingMode; | ||
| 1086 | uint32_t reserve[4]; | 1087 | uint32_t reserve[4]; |
| 1087 | } aclrtStreamAttrValue; | 1088 | } aclrtStreamAttrValue; |
| 1088 | ``` | 1089 | ``` |
| @@ -1094,6 +1095,7 @@ typedef union { | |||
| 1094 | | userCustomTag | 设置aclrtStreamAttr中的ACL_STREAM_ATTR_USER_CUSTOM_TAG(表示溢出检测分组标签)属性时,属性值的取值范围:0~uint32_t类型的最大值。 | | 1095 | | userCustomTag | 设置aclrtStreamAttr中的ACL_STREAM_ATTR_USER_CUSTOM_TAG(表示溢出检测分组标签)属性时,属性值的取值范围:0~uint32_t类型的最大值。 | |
| 1095 | | cacheOpInfoSwitch | 设置aclrtStreamAttr中的ACL_STREAM_ATTR_CACHE_OP_INFO (表示算子信息缓存开关)属性时,属性值的取值如下:<br><br> - 0:关闭算子信息缓存开关。默认值为0。<br> - 1:开启算子信息缓存开关。 | | 1096 | | cacheOpInfoSwitch | 设置aclrtStreamAttr中的ACL_STREAM_ATTR_CACHE_OP_INFO (表示算子信息缓存开关)属性时,属性值的取值如下:<br><br> - 0:关闭算子信息缓存开关。默认值为0。<br> - 1:开启算子信息缓存开关。 | |
| 1096 | | streamPriority | 设置aclrtStreamAttr中的ACL_STREAM_ATTR_PRIORITY (表示stream优先级)属性时,属性值的取值范围:0~7 值越小优先级级别越高,默认值为0。| | 1097 | | streamPriority | 设置aclrtStreamAttr中的ACL_STREAM_ATTR_PRIORITY (表示stream优先级)属性时,属性值的取值范围:0~7 值越小优先级级别越高,默认值为0。| |
| 1098 | +| launchBlockingMode | 设置aclrtStreamAttr中的ACL_STREAM_LAUNCH_BLOCKING_MODE属性时,用于控制以下接口在指定Stream上的执行模式为同步模式或异步模式:<br><br> - aclrtLaunchKernel<br> - aclrtLaunchKernelV2<br> - aclrtLaunchKernelWithConfig<br> - aclrtLaunchKernelWithHostArgs<br> - aclrtLaunchKernelWithArgsArray<br> - aclrtLaunchSIMTKernelWithArgsArray<br> - aclrtLaunchSIMTKernelWithHostArgs<br> - aclmdlRIExecuteAsync<br><br>属性值为如下宏:<br><br> - ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV:默认值。上述接口的执行模式由ASCEND_RT_LAUNCH_BLOCKING环境变量控制。环境变量配置为1时采用同步模式,其他情况采用异步模式。<br> - ACL_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING:上述接口采用异步模式。<br> - ACL_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING:上述接口采用同步模式。<br><br>宏的定义如下:<br>#define ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV 0x00000000U<br>#define ACL_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING 0x00000001U<br>#define ACL_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING 0x00000002U<br><br>在[aclrtNonBlockingLaunchBegin](06_stream_management.md#aclrtNonBlockingLaunchBegin)和[aclrtNonBlockingLaunchEnd](06_stream_management.md#aclrtNonBlockingLaunchEnd)接口之间,指定Stream保持异步模式,不执行同步等待。 | | ||
| 1097 | | reserve | 预留值。 | | 1099 | | reserve | 预留值。 | |
| 1098 | 1100 | ||
| 1099 | <br> | 1101 | <br> |
| @@ -0,0 +1,53 @@ | |||
| 1 | +# ASCEND\_RT\_LAUNCH\_BLOCKING | ||
| 2 | + | ||
| 3 | +## 功能描述 | ||
| 4 | + | ||
| 5 | +控制Kernel Launch和模型执行任务采用同步模式或异步模式,可用于算子调试场景。 | ||
| 6 | + | ||
| 7 | +取值为: | ||
| 8 | + | ||
| 9 | +- 0:关闭。接口采用异步模式,完成任务下发后返回,不等待任务执行完成。 | ||
| 10 | +- 1:开启。以下接口采用同步模式,任务执行完成后返回: | ||
| 11 | + - aclrtLaunchKernel | ||
| 12 | + - aclrtLaunchKernelV2 | ||
| 13 | + - aclrtLaunchKernelWithConfig | ||
| 14 | + - aclrtLaunchKernelWithHostArgs | ||
| 15 | + - aclrtLaunchKernelWithArgsArray | ||
| 16 | + - aclrtLaunchSIMTKernelWithArgsArray | ||
| 17 | + - aclrtLaunchSIMTKernelWithHostArgs | ||
| 18 | + - aclmdlRIExecuteAsync | ||
| 19 | +- 其他值:与配置为0时相同。 | ||
| 20 | + | ||
| 21 | +>**须知:** | ||
| 22 | +> | ||
| 23 | +>- 该环境变量默认关闭。未配置或配置为空时,与配置为0时相同。 | ||
| 24 | +>- 开启后,较早版本的算子可能未适配本功能。如果算子中已下发的任务依赖尚未下发的任务,接口同步等待会导致后续任务无法继续下发,可能发生死锁。 | ||
| 25 | +>- 上述场景可在存在依赖关系的任务下发前调用[aclrtNonBlockingLaunchBegin](../api_ref/06_stream_management.md#aclrtNonBlockingLaunchBegin),任务下发完成后调用[aclrtNonBlockingLaunchEnd](../api_ref/06_stream_management.md#aclrtNonBlockingLaunchEnd);也可调用[aclrtSetStreamAttribute](../api_ref/06_stream_management.md#aclrtSetStreamAttribute),将stmAttrType设置为ACL_STREAM_LAUNCH_BLOCKING_MODE,并将launchBlockingMode设置为ACL_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING。 | ||
| 26 | +>- 对于调用aclrtCreateStreamWithConfig接口,将flag设置为ACL_STREAM_PERSISTENT、ACL_STREAM_CPU_SCHEDULE或ACL_STREAM_DEVICE_USE_ONLY创建的Stream,本功能不生效。 | ||
| 27 | + | ||
| 28 | +## 配置示例 | ||
| 29 | + | ||
| 30 | +```bash | ||
| 31 | +export ASCEND_RT_LAUNCH_BLOCKING=1 | ||
| 32 | +``` | ||
| 33 | + | ||
| 34 | +## 使用约束 | ||
| 35 | + | ||
| 36 | +- 该环境变量不支持动态修改。调用任意Runtime接口前需完成配置,Runtime初始化后修改不生效。 | ||
| 37 | +- 开启该环境变量可能会影响业务性能,建议仅在算子调试场景下使用。 | ||
要提示配合老版本算子死锁的风险 ![]() ![]() | |||
| 38 | + | ||
| 39 | +<!-- npu="950,A3,910b" id1 --> | ||
| 40 | +## 支持的型号 | ||
| 41 | + | ||
| 42 | +<!-- npu="950" id2 --> | ||
| 43 | +Ascend 950PR/Ascend 950DT | ||
| 44 | +<!-- end id2 --> | ||
| 45 | + | ||
| 46 | +<!-- npu="A3" id3 --> | ||
| 47 | +Atlas A3 训练系列产品/Atlas A3 推理系列产品 | ||
| 48 | +<!-- end id3 --> | ||
| 49 | + | ||
| 50 | +<!-- npu="910b" id4 --> | ||
| 51 | +Atlas A2 训练系列产品/Atlas A2 推理系列产品 | ||
| 52 | +<!-- end id4 --> | ||
| 53 | +<!-- end id1 --> | ||
| @@ -0,0 +1,40 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +cmake_minimum_required(VERSION 3.16.0) | ||
| 12 | + | ||
| 13 | +project(Launch_Blocking_Sample) | ||
| 14 | + | ||
| 15 | +set(ASCENDC_CMAKE_DIR $ENV{ASCENDC_CMAKE_DIR}) | ||
| 16 | +set(SOC_VERSION $ENV{SOC_VERSION}) | ||
| 17 | +set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type Release/Debug (default Debug)" FORCE) | ||
| 18 | +set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/out" CACHE STRING "path for install()" FORCE) | ||
| 19 | + | ||
| 20 | +include(${ASCENDC_CMAKE_DIR}/ascendc.cmake) | ||
| 21 | +ascendc_fatbin_library(launch_blocking_kernel ../../../kernel_func/launch_blocking_kernel.cpp) | ||
| 22 | + | ||
| 23 | +find_package(Threads REQUIRED) | ||
| 24 | +add_executable(launch_blocking main.cpp) | ||
| 25 | +target_include_directories(launch_blocking PRIVATE | ||
| 26 | + ${ASCEND_CANN_PACKAGE_PATH}/include | ||
| 27 | +) | ||
| 28 | +target_compile_options(launch_blocking PRIVATE | ||
| 29 | + -O2 -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Werror | ||
| 30 | +) | ||
| 31 | +target_link_libraries(launch_blocking PRIVATE | ||
| 32 | + ${ASCEND_CANN_PACKAGE_PATH}/lib64/libacl_rt.so | ||
| 33 | + Threads::Threads | ||
| 34 | +) | ||
| 35 | + | ||
| 36 | +install(TARGETS launch_blocking | ||
| 37 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| 38 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| 39 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| 40 | +) | ||
| @@ -0,0 +1,82 @@ | |||
| 1 | +# 4_launch_blocking | ||
| 2 | + | ||
| 3 | +## 描述 | ||
| 4 | + | ||
| 5 | +本样例展示 Kernel Launch Blocking 功能的三类控制方式。样例通过 Notify 延迟释放目标流,并执行一个输出可校验的 Ascend C Kernel,检查 Kernel Launch 返回后的流状态和计算结果。 | ||
| 6 | + | ||
| 7 | +- 环境变量控制:分别以 `ASCEND_RT_LAUNCH_BLOCKING=0` 和 `ASCEND_RT_LAUNCH_BLOCKING=1` 启动进程,验证异步模式和同步模式。 | ||
| 8 | +- 流级三态控制:通过 `aclrtSetStreamAttribute` 设置 `DEFAULT`、`ASYNC` 和 `SYNC`,验证流属性对环境变量的继承或覆盖。 | ||
| 9 | +- 异步执行范围:在同步模式下嵌套调用 `aclrtNonBlockingLaunchBegin` 和 `aclrtNonBlockingLaunchEnd`。两个接口之间 Kernel 保持异步模式,内层 `End` 不执行同步等待,最外层 `End` 同步流并恢复后续 Kernel 的同步模式。 | ||
| 10 | + | ||
| 11 | +`run.sh` 会构建一次样例,并为不同环境变量配置分别启动新进程。 | ||
| 12 | + | ||
| 13 | +## 产品支持情况 | ||
| 14 | + | ||
| 15 | +本样例支持以下产品: | ||
| 16 | + | ||
| 17 | +| 产品 | 是否支持 | | ||
| 18 | +| --- | --- | | ||
| 19 | +| Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件 | √ | | ||
| 20 | +| Ascend 950PR/Ascend 950DT | √ | | ||
| 21 | + | ||
| 22 | +## 编译运行 | ||
| 23 | + | ||
| 24 | +1. 下载样例代码至安装 CANN 软件的环境,切换到样例目录。 | ||
| 25 | + | ||
| 26 | +```bash | ||
| 27 | +cd ${git_clone_path}/example/2_advanced_features/kernel/4_launch_blocking | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +2. 设置环境变量。 | ||
| 31 | + | ||
| 32 | +```bash | ||
| 33 | +# ${install_root} 替换为 CANN 安装根目录,默认安装在 /usr/local/Ascend 目录 | ||
| 34 | +source ${install_root}/cann/set_env.sh | ||
| 35 | +``` | ||
| 36 | + | ||
| 37 | +3. 执行以下命令构建并运行全部场景。 | ||
| 38 | + | ||
| 39 | +```bash | ||
| 40 | +bash run.sh | ||
| 41 | +``` | ||
| 42 | + | ||
| 43 | +环境变量在 Runtime 初始化时读取,因此不能在同一进程内切换。不要在执行 `run.sh` 前固定导出 `ASCEND_RT_LAUNCH_BLOCKING`,脚本会为每个场景单独设置该变量。 | ||
| 44 | + | ||
| 45 | +## 场景说明 | ||
| 46 | + | ||
| 47 | +| 场景 | 环境变量 | 预期行为 | | ||
| 48 | +| --- | --- | --- | | ||
| 49 | +| `env-control` | `0` | Kernel Launch 异步返回,显式同步后结果正确 | | ||
| 50 | +| `env-control` | `1` | Kernel Launch 等待流完成后返回,结果正确 | | ||
| 51 | +| `stream-mode` | `0` 和 `1` | `CTRL_BY_ENV` 跟随环境变量,`NON_BLOCKING` 强制异步,`BLOCKING` 强制同步 | | ||
| 52 | +| `non-blocking-section` | `1` | 嵌套范围内保持异步模式,最外层 `End` 同步,结束后恢复同步模式 | | ||
| 53 | + | ||
| 54 | +## CANN Runtime API | ||
| 55 | + | ||
| 56 | +- `aclrtSetStreamAttribute`、`aclrtGetStreamAttribute`:设置和查询 `ACL_STREAM_LAUNCH_BLOCKING_MODE` 流属性。 | ||
| 57 | +- `aclrtNonBlockingLaunchBegin`、`aclrtNonBlockingLaunchEnd`:标记指定流上相关接口异步执行的起始点和结束点。 | ||
| 58 | +- `aclrtLaunchKernel`:下发自定义 Kernel。 | ||
| 59 | +- `aclrtCreateNotify`、`aclrtWaitAndResetNotify`、`aclrtRecordNotify`:构造可控的流等待关系。 | ||
| 60 | +- `aclrtStreamQuery`:检查 Kernel Launch 或异步执行范围相关接口返回后的流状态。 | ||
| 61 | +- `aclrtSynchronizeStreamWithTimeout`:等待异步 Kernel 执行完成。 | ||
| 62 | + | ||
| 63 | +## 示例输出 | ||
| 64 | + | ||
| 65 | +```text | ||
| 66 | +========== ASCEND_RT_LAUNCH_BLOCKING=0, scenario=env-control ========== | ||
| 67 | +[ENV] ASCEND_RT_LAUNCH_BLOCKING=0 | ||
| 68 | +[STATUS] environment control: NOT_READY | ||
| 69 | +[PASS] environment control | ||
| 70 | +[SUCCESS] env-control | ||
| 71 | +... | ||
| 72 | +========== ASCEND_RT_LAUNCH_BLOCKING=1, scenario=non-blocking-section ========== | ||
| 73 | +[STATUS] inside nested section: NOT_READY | ||
| 74 | +[STATUS] after inner end: NOT_READY | ||
| 75 | +[STATUS] after outer end: COMPLETE | ||
| 76 | +[PASS] nested non-blocking section | ||
| 77 | +[STATUS] blocking restored after outer end: COMPLETE | ||
| 78 | +[SUCCESS] non-blocking-section | ||
| 79 | +All launch blocking scenarios passed. | ||
| 80 | +``` | ||
| 81 | + | ||
| 82 | +样例以 Notify 构造确定性的等待关系,并以流状态和输出结果作为通过条件,日志中的耗时仅用于观察。 | ||
| @@ -0,0 +1,82 @@ | |||
| 1 | +# 4_launch_blocking | ||
| 2 | + | ||
| 3 | +## Description | ||
| 4 | + | ||
| 5 | +This sample demonstrates three ways to control Kernel Launch Blocking. It delays the target stream with a Notify, runs an Ascend C kernel with verifiable output, and checks both the stream status and computation result after each launch. | ||
| 6 | + | ||
| 7 | +- Environment control: starts separate processes with `ASCEND_RT_LAUNCH_BLOCKING=0` and `ASCEND_RT_LAUNCH_BLOCKING=1` to verify asynchronous and synchronous launch modes. | ||
| 8 | +- Per-stream modes: sets `DEFAULT`, `ASYNC`, and `SYNC` through `aclrtSetStreamAttribute` to verify that a stream either inherits or overrides the environment setting. | ||
| 9 | +- Asynchronous execution range: nests `aclrtNonBlockingLaunchBegin` and `aclrtNonBlockingLaunchEnd` while synchronous mode is enabled. Kernel launches between the two APIs remain asynchronous, the inner `End` does not synchronize, and the outermost `End` synchronizes the stream and restores synchronous mode for subsequent launches. | ||
| 10 | + | ||
| 11 | +`run.sh` builds the sample once and starts a new process for each environment configuration. | ||
| 12 | + | ||
| 13 | +## Supported Products | ||
| 14 | + | ||
| 15 | +This sample supports the following products: | ||
| 16 | + | ||
| 17 | +| Product | Supported | | ||
| 18 | +| --- | --- | | ||
| 19 | +| Atlas A2 Training Series Products/Atlas 800I A2 Inference Products/A200I A2 Box Heterogeneous Components | Yes | | ||
| 20 | +| Ascend 950PR/Ascend 950DT | Yes | | ||
| 21 | + | ||
| 22 | +## Build and Run | ||
| 23 | + | ||
| 24 | +1. Download the sample to an environment where CANN is installed and switch to the sample directory. | ||
| 25 | + | ||
| 26 | +```bash | ||
| 27 | +cd ${git_clone_path}/example/2_advanced_features/kernel/4_launch_blocking | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +2. Set the environment variables. | ||
| 31 | + | ||
| 32 | +```bash | ||
| 33 | +# Replace ${install_root} with the CANN installation root. The default is /usr/local/Ascend. | ||
| 34 | +source ${install_root}/cann/set_env.sh | ||
| 35 | +``` | ||
| 36 | + | ||
| 37 | +3. Build and run all scenarios. | ||
| 38 | + | ||
| 39 | +```bash | ||
| 40 | +bash run.sh | ||
| 41 | +``` | ||
| 42 | + | ||
| 43 | +Runtime reads the environment variable during initialization, so it cannot be switched in one process. Do not export a fixed `ASCEND_RT_LAUNCH_BLOCKING` value before running `run.sh`; the script sets it separately for each scenario. | ||
| 44 | + | ||
| 45 | +## Scenarios | ||
| 46 | + | ||
| 47 | +| Scenario | Environment | Expected behavior | | ||
| 48 | +| --- | --- | --- | | ||
| 49 | +| `env-control` | `0` | Kernel Launch returns asynchronously; the result is correct after explicit synchronization | | ||
| 50 | +| `env-control` | `1` | Kernel Launch returns after the stream completes; the result is correct | | ||
| 51 | +| `stream-mode` | `0` and `1` | `CTRL_BY_ENV` follows the environment, `NON_BLOCKING` forces asynchronous launch, and `BLOCKING` forces synchronous launch | | ||
| 52 | +| `non-blocking-section` | `1` | Nested launches are asynchronous, the outermost `End` synchronizes, and synchronous mode is restored afterward | | ||
| 53 | + | ||
| 54 | +## CANN Runtime APIs | ||
| 55 | + | ||
| 56 | +- `aclrtSetStreamAttribute` and `aclrtGetStreamAttribute`: set and query the `ACL_STREAM_LAUNCH_BLOCKING_MODE` stream attribute. | ||
| 57 | +- `aclrtNonBlockingLaunchBegin` and `aclrtNonBlockingLaunchEnd`: mark the start and end points of asynchronous execution for the affected APIs on a stream. | ||
| 58 | +- `aclrtLaunchKernel`: launch the custom kernel. | ||
| 59 | +- `aclrtCreateNotify`, `aclrtWaitAndResetNotify`, and `aclrtRecordNotify`: create a controlled stream wait. | ||
| 60 | +- `aclrtStreamQuery`: inspect the stream status after a Kernel Launch or asynchronous execution range API returns. | ||
| 61 | +- `aclrtSynchronizeStreamWithTimeout`: wait for an asynchronous kernel to complete. | ||
| 62 | + | ||
| 63 | +## Sample Output | ||
| 64 | + | ||
| 65 | +```text | ||
| 66 | +========== ASCEND_RT_LAUNCH_BLOCKING=0, scenario=env-control ========== | ||
| 67 | +[ENV] ASCEND_RT_LAUNCH_BLOCKING=0 | ||
| 68 | +[STATUS] environment control: NOT_READY | ||
| 69 | +[PASS] environment control | ||
| 70 | +[SUCCESS] env-control | ||
| 71 | +... | ||
| 72 | +========== ASCEND_RT_LAUNCH_BLOCKING=1, scenario=non-blocking-section ========== | ||
| 73 | +[STATUS] inside nested section: NOT_READY | ||
| 74 | +[STATUS] after inner end: NOT_READY | ||
| 75 | +[STATUS] after outer end: COMPLETE | ||
| 76 | +[PASS] nested non-blocking section | ||
| 77 | +[STATUS] blocking restored after outer end: COMPLETE | ||
| 78 | +[SUCCESS] non-blocking-section | ||
| 79 | +All launch blocking scenarios passed. | ||
| 80 | +``` | ||
| 81 | + | ||
| 82 | +The sample uses a Notify to create a deterministic wait. Stream status and output data determine whether it passes; elapsed times in the logs are informational only. | ||
| @@ -0,0 +1,419 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <chrono> | ||
| 12 | +#include <cstdint> | ||
| 13 | +#include <cstdlib> | ||
| 14 | +#include <cstring> | ||
| 15 | +#include <iostream> | ||
| 16 | +#include <string> | ||
| 17 | +#include <thread> | ||
| 18 | +#include <vector> | ||
| 19 | + | ||
| 20 | +#include "acl/acl.h" | ||
| 21 | + | ||
| 22 | +namespace { | ||
| 23 | +constexpr int32_t kDeviceId = 0; | ||
| 24 | +constexpr uint32_t kBlockDim = 1; | ||
| 25 | +constexpr size_t kElementCount = 2048U; | ||
| 26 | +constexpr size_t kDataSize = kElementCount * sizeof(uint16_t); | ||
| 27 | +constexpr uint64_t kLoopSpin = 1ULL; | ||
| 28 | +constexpr int32_t kSyncTimeoutMs = 60000; | ||
| 29 | +constexpr int32_t kGateDelayMs = 1500; | ||
| 30 | +constexpr uint16_t kInputX = 0x3c00U; // half(1.0) | ||
| 31 | +constexpr uint16_t kInputY = 0x4000U; // half(2.0) | ||
| 32 | +constexpr uint16_t kExpected = 0x4200U; // half(3.0) | ||
| 33 | +constexpr char kKernelPath[] = "./out/fatbin/launch_blocking_kernel/launch_blocking_kernel.o"; | ||
| 34 | + | ||
| 35 | +struct KernelArgs { | ||
| 36 | + void* x; | ||
| 37 | + void* y; | ||
| 38 | + void* z; | ||
| 39 | + void* loop; | ||
| 40 | +}; | ||
| 41 | + | ||
| 42 | +struct LaunchResult { | ||
| 43 | + aclError ret; | ||
| 44 | + int64_t elapsedMs; | ||
| 45 | +}; | ||
| 46 | + | ||
| 47 | +int64_t NowMs() | ||
| 48 | +{ | ||
| 49 | + return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()) | ||
| 50 | + .count(); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +bool CheckAcl(aclError ret, const char* expression) | ||
| 54 | +{ | ||
| 55 | + if (ret == ACL_SUCCESS) { | ||
| 56 | + return true; | ||
| 57 | + } | ||
| 58 | + std::cerr << "[ERROR] " << expression << " failed, ret=" << ret << std::endl; | ||
| 59 | + return false; | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +bool IsLaunchBlockingEnabledByEnv() | ||
| 63 | +{ | ||
| 64 | + const char* value = std::getenv("ASCEND_RT_LAUNCH_BLOCKING"); | ||
| 65 | + return value != nullptr && std::strcmp(value, "1") == 0; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +class SampleContext { | ||
| 69 | +public: | ||
| 70 | + ~SampleContext() { Cleanup(); } | ||
| 71 | + | ||
| 72 | + bool Init() | ||
| 73 | + { | ||
| 74 | + if (!CheckAcl(aclInit(nullptr), "aclInit")) { | ||
| 75 | + return false; | ||
| 76 | + } | ||
| 77 | + aclInitialized_ = true; | ||
| 78 | + if (!CheckAcl(aclrtSetDevice(kDeviceId), "aclrtSetDevice")) { | ||
| 79 | + return false; | ||
| 80 | + } | ||
| 81 | + deviceSet_ = true; | ||
| 82 | + if (!CheckAcl(aclrtCreateStream(&stream_), "aclrtCreateStream")) { | ||
| 83 | + return false; | ||
| 84 | + } | ||
| 85 | + if (!CheckAcl(aclrtCreateStream(&gateStream_), "aclrtCreateStream(gate)")) { | ||
| 86 | + return false; | ||
| 87 | + } | ||
| 88 | + if (!CheckAcl(aclrtGetCurrentContext(&context_), "aclrtGetCurrentContext")) { | ||
| 89 | + return false; | ||
| 90 | + } | ||
| 91 | + if (!CheckAcl(aclrtCreateNotify(¬ify_, 0), "aclrtCreateNotify")) { | ||
| 92 | + return false; | ||
| 93 | + } | ||
| 94 | + if (!CheckAcl(aclrtBinaryLoadFromFile(kKernelPath, nullptr, &binary_), "aclrtBinaryLoadFromFile")) { | ||
| 95 | + return false; | ||
| 96 | + } | ||
| 97 | + if (!CheckAcl( | ||
| 98 | + aclrtBinaryGetFunction(binary_, "launch_blocking_kernel", &function_), "aclrtBinaryGetFunction")) { | ||
| 99 | + return false; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + if (!Allocate(&xDevice_, kDataSize, "x") || !Allocate(&yDevice_, kDataSize, "y") || | ||
| 103 | + !Allocate(&zDevice_, kDataSize, "z") || !Allocate(&loopDevice_, sizeof(kLoopSpin), "loop") || | ||
| 104 | + !Allocate(&argsDevice_, sizeof(KernelArgs), "args")) { | ||
| 105 | + return false; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + const std::vector<uint16_t> xHost(kElementCount, kInputX); | ||
| 109 | + const std::vector<uint16_t> yHost(kElementCount, kInputY); | ||
| 110 | + const KernelArgs args{xDevice_, yDevice_, zDevice_, loopDevice_}; | ||
| 111 | + return CopyToDevice(xDevice_, kDataSize, xHost.data(), kDataSize, "x") && | ||
| 112 | + CopyToDevice(yDevice_, kDataSize, yHost.data(), kDataSize, "y") && | ||
| 113 | + CopyToDevice(loopDevice_, sizeof(kLoopSpin), &kLoopSpin, sizeof(kLoopSpin), "loop") && | ||
| 114 | + CopyToDevice(argsDevice_, sizeof(args), &args, sizeof(args), "args"); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + aclrtStream Stream() const { return stream_; } | ||
| 118 | + | ||
| 119 | + bool ResetOutput() { return CheckAcl(aclrtMemset(zDevice_, kDataSize, 0, kDataSize), "aclrtMemset"); } | ||
| 120 | + | ||
| 121 | + LaunchResult Launch() | ||
| 122 | + { | ||
| 123 | + const int64_t begin = NowMs(); | ||
| 124 | + const aclError ret = aclrtLaunchKernel(function_, kBlockDim, argsDevice_, sizeof(KernelArgs), stream_); | ||
| 125 | + return {ret, NowMs() - begin}; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + bool CheckStreamStatus(aclrtStreamStatus expected, const std::string& tag) | ||
| 129 | + { | ||
| 130 | + aclrtStreamStatus actual = ACL_STREAM_STATUS_RESERVED; | ||
| 131 | + if (!CheckAcl(aclrtStreamQuery(stream_, &actual), "aclrtStreamQuery")) { | ||
| 132 | + return false; | ||
| 133 | + } | ||
| 134 | + std::cout << "[STATUS] " << tag << ": " << (actual == ACL_STREAM_STATUS_COMPLETE ? "COMPLETE" : "NOT_READY") | ||
| 135 | + << std::endl; | ||
| 136 | + if (actual != expected) { | ||
| 137 | + std::cerr << "[ERROR] " << tag << ": unexpected stream status, expected=" << expected | ||
| 138 | + << ", actual=" << actual << std::endl; | ||
| 139 | + return false; | ||
| 140 | + } | ||
| 141 | + return true; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + bool Synchronize() | ||
| 145 | + { | ||
| 146 | + return CheckAcl( | ||
| 147 | + aclrtSynchronizeStreamWithTimeout(stream_, kSyncTimeoutMs), "aclrtSynchronizeStreamWithTimeout"); | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + bool QueueGateWait() | ||
| 151 | + { | ||
| 152 | + return CheckAcl(aclrtWaitAndResetNotify(notify_, stream_, kSyncTimeoutMs), "aclrtWaitAndResetNotify"); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + aclError ReleaseGate() | ||
| 156 | + { | ||
| 157 | + aclError ret = aclrtSetCurrentContext(context_); | ||
| 158 | + if (ret != ACL_SUCCESS) { | ||
| 159 | + return ret; | ||
| 160 | + } | ||
| 161 | + ret = aclrtRecordNotify(notify_, gateStream_); | ||
| 162 | + if (ret != ACL_SUCCESS) { | ||
| 163 | + return ret; | ||
| 164 | + } | ||
| 165 | + return aclrtSynchronizeStreamWithTimeout(gateStream_, kSyncTimeoutMs); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + bool VerifyOutput() | ||
| 169 | + { | ||
| 170 | + std::vector<uint16_t> output(kElementCount); | ||
| 171 | + if (!CheckAcl( | ||
| 172 | + aclrtMemcpy(output.data(), kDataSize, zDevice_, kDataSize, ACL_MEMCPY_DEVICE_TO_HOST), | ||
| 173 | + "aclrtMemcpy(output)")) { | ||
| 174 | + return false; | ||
| 175 | + } | ||
| 176 | + for (size_t i = 0; i < output.size(); ++i) { | ||
| 177 | + if (output[i] != kExpected) { | ||
| 178 | + std::cerr << "[ERROR] output[" << i << "] expected=0x" << std::hex << kExpected << ", actual=0x" | ||
| 179 | + << output[i] << std::dec << std::endl; | ||
| 180 | + return false; | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + return true; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | +private: | ||
| 187 | + bool Allocate(void** address, size_t size, const char* name) | ||
| 188 | + { | ||
| 189 | + const aclError ret = aclrtMalloc(address, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 190 | + if (ret != ACL_SUCCESS) { | ||
| 191 | + std::cerr << "[ERROR] aclrtMalloc(" << name << ") failed, ret=" << ret << std::endl; | ||
| 192 | + return false; | ||
| 193 | + } | ||
| 194 | + return true; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + bool CopyToDevice(void* dst, size_t dstSize, const void* src, size_t size, const char* name) | ||
| 198 | + { | ||
| 199 | + const aclError ret = aclrtMemcpy(dst, dstSize, src, size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 200 | + if (ret != ACL_SUCCESS) { | ||
| 201 | + std::cerr << "[ERROR] aclrtMemcpy(" << name << ") failed, ret=" << ret << std::endl; | ||
| 202 | + return false; | ||
| 203 | + } | ||
| 204 | + return true; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + void Cleanup() | ||
| 208 | + { | ||
| 209 | + if (stream_ != nullptr) { | ||
| 210 | + (void)aclrtSynchronizeStreamWithTimeout(stream_, kSyncTimeoutMs); | ||
| 211 | + } | ||
| 212 | + if (gateStream_ != nullptr) { | ||
| 213 | + (void)aclrtSynchronizeStreamWithTimeout(gateStream_, kSyncTimeoutMs); | ||
| 214 | + } | ||
| 215 | + if (binary_ != nullptr) { | ||
| 216 | + (void)aclrtBinaryUnLoad(binary_); | ||
| 217 | + } | ||
| 218 | + Free(argsDevice_); | ||
| 219 | + Free(loopDevice_); | ||
| 220 | + Free(zDevice_); | ||
| 221 | + Free(yDevice_); | ||
| 222 | + Free(xDevice_); | ||
| 223 | + if (notify_ != nullptr) { | ||
| 224 | + (void)aclrtDestroyNotify(notify_); | ||
| 225 | + notify_ = nullptr; | ||
| 226 | + } | ||
| 227 | + if (gateStream_ != nullptr) { | ||
| 228 | + (void)aclrtDestroyStream(gateStream_); | ||
| 229 | + gateStream_ = nullptr; | ||
| 230 | + } | ||
| 231 | + if (stream_ != nullptr) { | ||
| 232 | + (void)aclrtDestroyStream(stream_); | ||
| 233 | + stream_ = nullptr; | ||
| 234 | + } | ||
| 235 | + if (deviceSet_) { | ||
| 236 | + (void)aclrtResetDevice(kDeviceId); | ||
| 237 | + deviceSet_ = false; | ||
| 238 | + } | ||
| 239 | + if (aclInitialized_) { | ||
| 240 | + (void)aclFinalize(); | ||
| 241 | + aclInitialized_ = false; | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + static void Free(void*& address) | ||
| 246 | + { | ||
| 247 | + if (address != nullptr) { | ||
| 248 | + (void)aclrtFree(address); | ||
| 249 | + address = nullptr; | ||
| 250 | + } | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + bool aclInitialized_ = false; | ||
| 254 | + bool deviceSet_ = false; | ||
| 255 | + aclrtContext context_ = nullptr; | ||
| 256 | + aclrtStream stream_ = nullptr; | ||
| 257 | + aclrtStream gateStream_ = nullptr; | ||
| 258 | + aclrtNotify notify_ = nullptr; | ||
| 259 | + aclrtBinHandle binary_ = nullptr; | ||
| 260 | + aclrtFuncHandle function_ = nullptr; | ||
| 261 | + void* xDevice_ = nullptr; | ||
| 262 | + void* yDevice_ = nullptr; | ||
| 263 | + void* zDevice_ = nullptr; | ||
| 264 | + void* loopDevice_ = nullptr; | ||
| 265 | + void* argsDevice_ = nullptr; | ||
| 266 | +}; | ||
| 267 | + | ||
| 268 | +bool SetAndCheckLaunchBlockingMode(SampleContext& context, uint32_t mode, const std::string& name) | ||
| 269 | +{ | ||
| 270 | + aclrtStreamAttrValue value{}; | ||
| 271 | + value.launchBlockingMode = mode; | ||
| 272 | + if (!CheckAcl( | ||
| 273 | + aclrtSetStreamAttribute(context.Stream(), ACL_STREAM_LAUNCH_BLOCKING_MODE, &value), | ||
| 274 | + "aclrtSetStreamAttribute")) { | ||
| 275 | + return false; | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + aclrtStreamAttrValue actual{}; | ||
| 279 | + if (!CheckAcl( | ||
| 280 | + aclrtGetStreamAttribute(context.Stream(), ACL_STREAM_LAUNCH_BLOCKING_MODE, &actual), | ||
| 281 | + "aclrtGetStreamAttribute")) { | ||
| 282 | + return false; | ||
| 283 | + } | ||
| 284 | + std::cout << "[MODE] " << name << ": value=" << static_cast<uint32_t>(actual.launchBlockingMode) << std::endl; | ||
| 285 | + if (actual.launchBlockingMode != mode) { | ||
| 286 | + std::cerr << "[ERROR] stream launch blocking mode mismatch" << std::endl; | ||
| 287 | + return false; | ||
| 288 | + } | ||
| 289 | + return true; | ||
| 290 | +} | ||
| 291 | + | ||
| 292 | +bool LaunchAndCheck(SampleContext& context, const std::string& tag, bool expectBlocking) | ||
| 293 | +{ | ||
| 294 | + if (!context.ResetOutput() || !context.QueueGateWait()) { | ||
| 295 | + return false; | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + aclError gateRet = ACL_SUCCESS; | ||
| 299 | + std::thread gateThread([&context, &gateRet]() { | ||
| 300 | + std::this_thread::sleep_for(std::chrono::milliseconds(kGateDelayMs)); | ||
| 301 | + gateRet = context.ReleaseGate(); | ||
| 302 | + }); | ||
| 303 | + const LaunchResult result = context.Launch(); | ||
| 304 | + std::cout << "[LAUNCH] " << tag << ": ret=" << result.ret << ", elapsed=" << result.elapsedMs << " ms" << std::endl; | ||
| 305 | + | ||
| 306 | + const aclrtStreamStatus expectedStatus = expectBlocking ? ACL_STREAM_STATUS_COMPLETE : ACL_STREAM_STATUS_NOT_READY; | ||
| 307 | + const bool statusOk = result.ret == ACL_SUCCESS && context.CheckStreamStatus(expectedStatus, tag); | ||
| 308 | + gateThread.join(); | ||
| 309 | + const bool gateOk = CheckAcl(gateRet, "release gate notify"); | ||
| 310 | + const bool syncOk = expectBlocking || context.Synchronize(); | ||
| 311 | + const bool outputOk = syncOk && context.VerifyOutput(); | ||
| 312 | + if (!statusOk || !gateOk || !syncOk || !outputOk) { | ||
| 313 | + return false; | ||
| 314 | + } | ||
| 315 | + std::cout << "[PASS] " << tag << std::endl; | ||
| 316 | + return true; | ||
| 317 | +} | ||
| 318 | + | ||
| 319 | +bool RunEnvControl(SampleContext& context) | ||
| 320 | +{ | ||
| 321 | + const bool envEnabled = IsLaunchBlockingEnabledByEnv(); | ||
| 322 | + std::cout << "[ENV] ASCEND_RT_LAUNCH_BLOCKING=" << (envEnabled ? "1" : "0") << std::endl; | ||
| 323 | + return SetAndCheckLaunchBlockingMode(context, ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV, "CTRL_BY_ENV") && | ||
| 324 | + LaunchAndCheck(context, "environment control", envEnabled); | ||
| 325 | +} | ||
| 326 | + | ||
| 327 | +bool RunStreamMode(SampleContext& context) | ||
| 328 | +{ | ||
| 329 | + const bool envEnabled = IsLaunchBlockingEnabledByEnv(); | ||
| 330 | + std::cout << "[ENV] ASCEND_RT_LAUNCH_BLOCKING=" << (envEnabled ? "1" : "0") << std::endl; | ||
| 331 | + return SetAndCheckLaunchBlockingMode(context, ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV, "CTRL_BY_ENV") && | ||
| 332 | + LaunchAndCheck(context, "CTRL_BY_ENV", envEnabled) && | ||
| 333 | + SetAndCheckLaunchBlockingMode(context, ACL_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING, "NON_BLOCKING") && | ||
| 334 | + LaunchAndCheck(context, "NON_BLOCKING overrides environment", false) && | ||
| 335 | + SetAndCheckLaunchBlockingMode(context, ACL_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING, "BLOCKING") && | ||
| 336 | + LaunchAndCheck(context, "BLOCKING overrides environment", true) && | ||
| 337 | + SetAndCheckLaunchBlockingMode(context, ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV, "restore CTRL_BY_ENV") && | ||
| 338 | + LaunchAndCheck(context, "restored environment control", envEnabled); | ||
| 339 | +} | ||
| 340 | + | ||
| 341 | +bool RunNonBlockingSection(SampleContext& context) | ||
| 342 | +{ | ||
| 343 | + if (!IsLaunchBlockingEnabledByEnv()) { | ||
| 344 | + std::cerr << "[ERROR] non-blocking-section must run with ASCEND_RT_LAUNCH_BLOCKING=1" << std::endl; | ||
| 345 | + return false; | ||
| 346 | + } | ||
| 347 | + if (!SetAndCheckLaunchBlockingMode(context, ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV, "CTRL_BY_ENV") || | ||
| 348 | + !context.ResetOutput() || | ||
| 349 | + !CheckAcl(aclrtNonBlockingLaunchBegin(context.Stream(), 0), "outer aclrtNonBlockingLaunchBegin") || | ||
| 350 | + !CheckAcl(aclrtNonBlockingLaunchBegin(context.Stream(), 0), "inner aclrtNonBlockingLaunchBegin")) { | ||
| 351 | + return false; | ||
| 352 | + } | ||
| 353 | + | ||
| 354 | + if (!context.QueueGateWait()) { | ||
| 355 | + (void)aclrtNonBlockingLaunchEnd(context.Stream(), 0); | ||
| 356 | + (void)aclrtNonBlockingLaunchEnd(context.Stream(), 0); | ||
| 357 | + return false; | ||
| 358 | + } | ||
| 359 | + aclError gateRet = ACL_SUCCESS; | ||
| 360 | + std::thread gateThread([&context, &gateRet]() { | ||
| 361 | + std::this_thread::sleep_for(std::chrono::milliseconds(kGateDelayMs)); | ||
| 362 | + gateRet = context.ReleaseGate(); | ||
| 363 | + }); | ||
| 364 | + | ||
| 365 | + const LaunchResult first = context.Launch(); | ||
| 366 | + const LaunchResult second = context.Launch(); | ||
| 367 | + std::cout << "[LAUNCH] nested section: first=" << first.elapsedMs << " ms, second=" << second.elapsedMs << " ms" | ||
| 368 | + << std::endl; | ||
| 369 | + bool passed = first.ret == ACL_SUCCESS && second.ret == ACL_SUCCESS && | ||
| 370 | + context.CheckStreamStatus(ACL_STREAM_STATUS_NOT_READY, "inside nested section"); | ||
| 371 | + passed = CheckAcl(aclrtNonBlockingLaunchEnd(context.Stream(), 0), "inner aclrtNonBlockingLaunchEnd") && passed; | ||
| 372 | + passed = context.CheckStreamStatus(ACL_STREAM_STATUS_NOT_READY, "after inner end") && passed; | ||
| 373 | + | ||
| 374 | + const int64_t begin = NowMs(); | ||
| 375 | + const aclError endRet = aclrtNonBlockingLaunchEnd(context.Stream(), 0); | ||
| 376 | + const int64_t elapsed = NowMs() - begin; | ||
| 377 | + std::cout << "[END] outer section: ret=" << endRet << ", elapsed=" << elapsed << " ms" << std::endl; | ||
| 378 | + gateThread.join(); | ||
| 379 | + passed = CheckAcl(gateRet, "release gate notify") && passed; | ||
| 380 | + passed = endRet == ACL_SUCCESS && passed; | ||
| 381 | + passed = context.CheckStreamStatus(ACL_STREAM_STATUS_COMPLETE, "after outer end") && passed; | ||
| 382 | + passed = context.VerifyOutput() && passed; | ||
| 383 | + if (!passed) { | ||
| 384 | + return false; | ||
| 385 | + } | ||
| 386 | + std::cout << "[PASS] nested non-blocking section" << std::endl; | ||
| 387 | + | ||
| 388 | + return LaunchAndCheck(context, "blocking restored after outer end", true); | ||
| 389 | +} | ||
| 390 | +} // namespace | ||
| 391 | + | ||
| 392 | +int main(int argc, char** argv) | ||
| 393 | +{ | ||
| 394 | + if (argc != 2) { | ||
| 395 | + std::cerr << "Usage: " << argv[0] << " <env-control|stream-mode|non-blocking-section>" << std::endl; | ||
| 396 | + return 1; | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + SampleContext context; | ||
| 400 | + if (!context.Init()) { | ||
| 401 | + return 1; | ||
| 402 | + } | ||
| 403 | + | ||
| 404 | + const std::string scenario = argv[1]; | ||
| 405 | + bool passed = false; | ||
| 406 | + if (scenario == "env-control") { | ||
| 407 | + passed = RunEnvControl(context); | ||
| 408 | + } else if (scenario == "stream-mode") { | ||
| 409 | + passed = RunStreamMode(context); | ||
| 410 | + } else if (scenario == "non-blocking-section") { | ||
| 411 | + passed = RunNonBlockingSection(context); | ||
| 412 | + } else { | ||
| 413 | + std::cerr << "[ERROR] unknown scenario: " << scenario << std::endl; | ||
| 414 | + return 1; | ||
| 415 | + } | ||
| 416 | + | ||
| 417 | + std::cout << (passed ? "[SUCCESS] " : "[FAILED] ") << scenario << std::endl; | ||
| 418 | + return passed ? 0 : 1; | ||
| 419 | +} | ||
| @@ -0,0 +1,80 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +set -euo pipefail | ||
| 13 | + | ||
| 14 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 15 | +EXAMPLE_DIR="$(cd "${SCRIPT_DIR}/../../.." && pwd)" | ||
| 16 | +BUILD_DIR="${SCRIPT_DIR}/build" | ||
| 17 | +OUTPUT_DIR="${SCRIPT_DIR}/out" | ||
| 18 | + | ||
| 19 | +source "${EXAMPLE_DIR}/common/resolve_cann_env.sh" | ||
| 20 | + | ||
| 21 | +detect_sample_env() { | ||
| 22 | + if [ -n "${SOC_VERSION:-}" ] && [ -n "${ASCENDC_CMAKE_DIR:-}" ]; then | ||
| 23 | + return 0 | ||
| 24 | + fi | ||
| 25 | + if [ ! -f "${EXAMPLE_DIR}/set_sample_env.sh" ]; then | ||
| 26 | + return 0 | ||
| 27 | + fi | ||
| 28 | + | ||
| 29 | + set +eu | ||
| 30 | + source "${EXAMPLE_DIR}/set_sample_env.sh" | ||
| 31 | + local ret=$? | ||
| 32 | + set -euo pipefail | ||
| 33 | + return "${ret}" | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +resolve_cann_env | ||
| 37 | + | ||
| 38 | +if ! detect_sample_env; then | ||
| 39 | + echo "[ERROR] Failed to detect SOC_VERSION or ASCENDC_CMAKE_DIR. Source ${EXAMPLE_DIR}/set_sample_env.sh first." | ||
| 40 | + exit 1 | ||
| 41 | +fi | ||
| 42 | +if [ -z "${ASCENDC_CMAKE_DIR:-}" ] || [ ! -f "${ASCENDC_CMAKE_DIR}/ascendc.cmake" ]; then | ||
| 43 | + echo "[ERROR] ASCENDC_CMAKE_DIR is invalid." | ||
| 44 | + exit 1 | ||
| 45 | +fi | ||
| 46 | +if [ -z "${SOC_VERSION:-}" ]; then | ||
| 47 | + echo "[ERROR] SOC_VERSION is not set." | ||
| 48 | + exit 1 | ||
| 49 | +fi | ||
| 50 | + | ||
| 51 | +cd "${SCRIPT_DIR}" | ||
| 52 | +export ASCEND_TOOLKIT_HOME="${ASCEND_INSTALL_PATH}" | ||
| 53 | +export ASCEND_HOME_PATH="${ASCEND_INSTALL_PATH}" | ||
| 54 | + | ||
| 55 | +rm -rf "${BUILD_DIR}" "${OUTPUT_DIR}" | ||
| 56 | + | ||
| 57 | +cmake -S "${SCRIPT_DIR}" -B "${BUILD_DIR}" \ | ||
| 58 | + -DSOC_VERSION="${SOC_VERSION}" \ | ||
| 59 | + -DCMAKE_BUILD_TYPE=Debug \ | ||
| 60 | + -DCMAKE_INSTALL_PREFIX="${OUTPUT_DIR}" \ | ||
| 61 | + -DASCEND_CANN_PACKAGE_PATH="${ASCEND_INSTALL_PATH}" | ||
| 62 | +cmake --build "${BUILD_DIR}" -j"$(nproc)" | ||
| 63 | +cmake --install "${BUILD_DIR}" | ||
| 64 | + | ||
| 65 | +export LD_LIBRARY_PATH="${OUTPUT_DIR}/lib:${OUTPUT_DIR}/lib64:${ASCEND_INSTALL_PATH}/lib64:${LD_LIBRARY_PATH:-}" | ||
| 66 | + | ||
| 67 | +run_case() { | ||
| 68 | + local env_value=$1 | ||
| 69 | + local scenario=$2 | ||
| 70 | + echo "========== ASCEND_RT_LAUNCH_BLOCKING=${env_value}, scenario=${scenario} ==========" | ||
| 71 | + env ASCEND_RT_LAUNCH_BLOCKING="${env_value}" "${OUTPUT_DIR}/bin/launch_blocking" "${scenario}" | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +run_case 0 env-control | ||
| 75 | +run_case 1 env-control | ||
| 76 | +run_case 0 stream-mode | ||
| 77 | +run_case 1 stream-mode | ||
| 78 | +run_case 1 non-blocking-section | ||
| 79 | + | ||
| 80 | +echo "All launch blocking scenarios passed." | ||
| @@ -8,3 +8,4 @@ | |||
| 8 | - [1_launch_kernel_with_reslimit](./1_launch_kernel_with_reslimit/README.md):演示在 Device 资源限制下的 Kernel 执行。 | 8 | - [1_launch_kernel_with_reslimit](./1_launch_kernel_with_reslimit/README.md):演示在 Device 资源限制下的 Kernel 执行。 |
| 9 | - [2_binary_enumerate_functions](./2_binary_enumerate_functions/README.md):演示枚举同一算子二进制中的多个核函数,并依次下发和校验计算结果。 | 9 | - [2_binary_enumerate_functions](./2_binary_enumerate_functions/README.md):演示枚举同一算子二进制中的多个核函数,并依次下发和校验计算结果。 |
| 10 | - [3_binary_get_function_count](./3_binary_get_function_count/README.md):演示查询 Kernel 二进制中的核函数数量。 | 10 | - [3_binary_get_function_count](./3_binary_get_function_count/README.md):演示查询 Kernel 二进制中的核函数数量。 |
| 11 | +- [4_launch_blocking](./4_launch_blocking/README.md):演示 Kernel Launch Blocking 的环境变量控制、流级三态及嵌套非阻塞区间。 | ||
| @@ -8,3 +8,4 @@ This directory focuses on Kernel loading, parameter organization, execution, and | |||
| 8 | - [1_launch_kernel_with_reslimit](./1_launch_kernel_with_reslimit/README_en.md): Demonstrates Kernel execution under Device resource limits. | 8 | - [1_launch_kernel_with_reslimit](./1_launch_kernel_with_reslimit/README_en.md): Demonstrates Kernel execution under Device resource limits. |
| 9 | - [2_binary_enumerate_functions](./2_binary_enumerate_functions/README_en.md): Demonstrates enumerating multiple kernel functions in the same operator binary, then launching them and verifying the results. | 9 | - [2_binary_enumerate_functions](./2_binary_enumerate_functions/README_en.md): Demonstrates enumerating multiple kernel functions in the same operator binary, then launching them and verifying the results. |
| 10 | - [3_binary_get_function_count](./3_binary_get_function_count/README_en.md): Demonstrates querying the number of kernel functions in a Kernel binary. | 10 | - [3_binary_get_function_count](./3_binary_get_function_count/README_en.md): Demonstrates querying the number of kernel functions in a Kernel binary. |
| 11 | +- [4_launch_blocking](./4_launch_blocking/README_en.md): Demonstrates environment control, per-stream modes, and nested non-blocking sections for Kernel Launch Blocking. | ||
| @@ -0,0 +1,95 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include "kernel_operator.h" | ||
| 12 | + | ||
| 13 | +using namespace AscendC; | ||
| 14 | + | ||
| 15 | +namespace { | ||
| 16 | +constexpr int32_t kTotalLength = 2048; | ||
| 17 | +constexpr int32_t kCoreNum = 1; | ||
| 18 | +constexpr int32_t kBlockLength = kTotalLength / kCoreNum; | ||
| 19 | +constexpr int32_t kTileNum = 8; | ||
| 20 | +constexpr int32_t kBufferNum = 2; | ||
| 21 | +constexpr int32_t kTileLength = kBlockLength / kTileNum / kBufferNum * kBufferNum; | ||
| 22 | +} // namespace | ||
| 23 | + | ||
| 24 | +class LaunchBlockingKernel { | ||
| 25 | +public: | ||
| 26 | + __aicore__ inline LaunchBlockingKernel() = default; | ||
| 27 | + | ||
| 28 | + __aicore__ inline void Init(GM_ADDR x, GM_ADDR y, GM_ADDR z, GM_ADDR loop) | ||
| 29 | + { | ||
| 30 | + xGm_.SetGlobalBuffer((__gm__ half*)x + kBlockLength * GetBlockIdx(), kBlockLength); | ||
| 31 | + yGm_.SetGlobalBuffer((__gm__ half*)y + kBlockLength * GetBlockIdx(), kBlockLength); | ||
| 32 | + zGm_.SetGlobalBuffer((__gm__ half*)z + kBlockLength * GetBlockIdx(), kBlockLength); | ||
| 33 | + loopGm_.SetGlobalBuffer((__gm__ uint64_t*)loop, 1); | ||
| 34 | + pipe_.InitBuffer(xQueue_, kBufferNum, kTileLength * sizeof(half)); | ||
| 35 | + pipe_.InitBuffer(yQueue_, kBufferNum, kTileLength * sizeof(half)); | ||
| 36 | + pipe_.InitBuffer(zQueue_, kBufferNum, kTileLength * sizeof(half)); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + __aicore__ inline void Process() | ||
| 40 | + { | ||
| 41 | + const uint64_t loopSpin = loopGm_.GetValue(0); | ||
| 42 | + for (int32_t tile = 0; tile < kTileNum; ++tile) { | ||
| 43 | + CopyIn(tile); | ||
| 44 | + Compute(loopSpin); | ||
| 45 | + CopyOut(tile); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | +private: | ||
| 50 | + __aicore__ inline void CopyIn(const int32_t tile) | ||
| 51 | + { | ||
| 52 | + LocalTensor<half> xLocal = xQueue_.AllocTensor<half>(); | ||
| 53 | + LocalTensor<half> yLocal = yQueue_.AllocTensor<half>(); | ||
| 54 | + DataCopy(xLocal, xGm_[tile * kTileLength], kTileLength); | ||
| 55 | + DataCopy(yLocal, yGm_[tile * kTileLength], kTileLength); | ||
| 56 | + xQueue_.EnQue(xLocal); | ||
| 57 | + yQueue_.EnQue(yLocal); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + __aicore__ inline void Compute(const uint64_t loopSpin) | ||
| 61 | + { | ||
| 62 | + LocalTensor<half> xLocal = xQueue_.DeQue<half>(); | ||
| 63 | + LocalTensor<half> yLocal = yQueue_.DeQue<half>(); | ||
| 64 | + LocalTensor<half> zLocal = zQueue_.AllocTensor<half>(); | ||
| 65 | + for (uint64_t i = 0; i < loopSpin; ++i) { | ||
| 66 | + Add(zLocal, xLocal, yLocal, kTileLength); | ||
| 67 | + } | ||
| 68 | + zQueue_.EnQue<half>(zLocal); | ||
| 69 | + xQueue_.FreeTensor(xLocal); | ||
| 70 | + yQueue_.FreeTensor(yLocal); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + __aicore__ inline void CopyOut(const int32_t tile) | ||
| 74 | + { | ||
| 75 | + LocalTensor<half> zLocal = zQueue_.DeQue<half>(); | ||
| 76 | + DataCopy(zGm_[tile * kTileLength], zLocal, kTileLength); | ||
| 77 | + zQueue_.FreeTensor(zLocal); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + TPipe pipe_; | ||
| 81 | + TQue<QuePosition::VECIN, kBufferNum> xQueue_; | ||
| 82 | + TQue<QuePosition::VECIN, kBufferNum> yQueue_; | ||
| 83 | + TQue<QuePosition::VECOUT, kBufferNum> zQueue_; | ||
| 84 | + GlobalTensor<half> xGm_; | ||
| 85 | + GlobalTensor<half> yGm_; | ||
| 86 | + GlobalTensor<half> zGm_; | ||
| 87 | + GlobalTensor<uint64_t> loopGm_; | ||
| 88 | +}; | ||
| 89 | + | ||
| 90 | +extern "C" __global__ __aicore__ void launch_blocking_kernel(GM_ADDR x, GM_ADDR y, GM_ADDR z, GM_ADDR loop) | ||
| 91 | +{ | ||
| 92 | + LaunchBlockingKernel kernel; | ||
| 93 | + kernel.Init(x, y, z, loop); | ||
| 94 | + kernel.Process(); | ||
| 95 | +} | ||
| @@ -48,6 +48,10 @@ extern "C" { | |||
| 48 | #define ACL_CONTINUE_ON_FAILURE 0x00000000U | 48 | #define ACL_CONTINUE_ON_FAILURE 0x00000000U |
| 49 | #define ACL_STOP_ON_FAILURE 0x00000001U | 49 | #define ACL_STOP_ON_FAILURE 0x00000001U |
| 50 | 50 | ||
| 51 | +#define ACL_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV 0x00000000U | ||
| 52 | +#define ACL_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING 0x00000001U | ||
| 53 | +#define ACL_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING 0x00000002U | ||
| 54 | + | ||
| 51 | // for notify | for create notify | 55 | // for notify | for create notify |
| 52 | #define ACL_NOTIFY_DEFAULT 0x00000000U | 56 | #define ACL_NOTIFY_DEFAULT 0x00000000U |
| 53 | #define ACL_NOTIFY_DEVICE_USE_ONLY 0x00000001U | 57 | #define ACL_NOTIFY_DEVICE_USE_ONLY 0x00000001U |
| @@ -575,6 +579,7 @@ typedef enum { | |||
| 575 | ACL_STREAM_ATTR_USER_CUSTOM_TAG = 3, | 579 | ACL_STREAM_ATTR_USER_CUSTOM_TAG = 3, |
| 576 | ACL_STREAM_ATTR_CACHE_OP_INFO = 4, | 580 | ACL_STREAM_ATTR_CACHE_OP_INFO = 4, |
| 577 | ACL_STREAM_ATTR_PRIORITY = 5, | 581 | ACL_STREAM_ATTR_PRIORITY = 5, |
| 582 | + ACL_STREAM_LAUNCH_BLOCKING_MODE = 6, | ||
| 578 | } aclrtStreamAttr; | 583 | } aclrtStreamAttr; |
| 579 | 584 | ||
| 580 | typedef union { | 585 | typedef union { |
| @@ -583,6 +588,7 @@ typedef union { | |||
| 583 | uint32_t userCustomTag; | 588 | uint32_t userCustomTag; |
| 584 | uint32_t cacheOpInfoSwitch; | 589 | uint32_t cacheOpInfoSwitch; |
| 585 | uint32_t streamPriority; | 590 | uint32_t streamPriority; |
| 591 | + uint32_t launchBlockingMode; | ||
| 586 | uint32_t reserve[4]; | 592 | uint32_t reserve[4]; |
| 587 | } aclrtStreamAttrValue; | 593 | } aclrtStreamAttrValue; |
| 588 | 594 | ||
| @@ -2822,6 +2828,30 @@ ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStream(aclrtStream stream); | |||
| 2822 | */ | 2828 | */ |
| 2823 | ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStreamWithTimeout(aclrtStream stream, int32_t timeout); | 2829 | ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStreamWithTimeout(aclrtStream stream, int32_t timeout); |
| 2824 | 2830 | ||
| 2831 | +/** | ||
| 2832 | + * @ingroup AscendCL | ||
| 2833 | + * @brief begin a non-blocking kernel launch section on the specified stream | ||
| 2834 | + * | ||
| 2835 | + * @param stream [IN] the stream used by subsequent kernel launches; NULL indicates the default stream | ||
| 2836 | + * @param flag [IN] reserved parameter, must be 0 | ||
| 2837 | + * | ||
| 2838 | + * @retval ACL_SUCCESS The function is successfully executed. | ||
| 2839 | + * @retval OtherValues Failure | ||
| 2840 | + */ | ||
| 2841 | +ACL_FUNC_VISIBILITY aclError aclrtNonBlockingLaunchBegin(aclrtStream stream, uint64_t flag); | ||
| 2842 | + | ||
| 2843 | +/** | ||
| 2844 | + * @ingroup AscendCL | ||
| 2845 | + * @brief end a non-blocking kernel launch section on the specified stream | ||
| 2846 | + * | ||
| 2847 | + * @param stream [IN] the stream used by previous kernel launches; NULL indicates the default stream | ||
| 2848 | + * @param flag [IN] reserved parameter, must be 0 | ||
| 2849 | + * | ||
| 2850 | + * @retval ACL_SUCCESS The function is successfully executed. | ||
| 2851 | + * @retval OtherValues Failure | ||
| 2852 | + */ | ||
| 2853 | +ACL_FUNC_VISIBILITY aclError aclrtNonBlockingLaunchEnd(aclrtStream stream, uint64_t flag); | ||
| 2854 | + | ||
| 2825 | /** | 2855 | /** |
| 2826 | * @ingroup AscendCL | 2856 | * @ingroup AscendCL |
| 2827 | * @brief Query a stream for completion status. | 2857 | * @brief Query a stream for completion status. |
| @@ -3856,8 +3886,9 @@ ACL_FUNC_VISIBILITY aclError aclrtGetStreamAvailableNum(uint32_t* streamCount); | |||
| 3856 | * @brief set stream attribute | 3886 | * @brief set stream attribute |
| 3857 | * @param [in] stream stream handle | 3887 | * @param [in] stream stream handle |
| 3858 | * @param [in] stmAttrType stream attribute type, which value can be: | 3888 | * @param [in] stmAttrType stream attribute type, which value can be: |
| 3859 | - * ACL_STREAM_ATTR_FAILURE_MODE, ACL_STREAM_ATTR_FLOAT_OVERFLOW_CHECK | 3889 | + * ACL_STREAM_ATTR_FAILURE_MODE, ACL_STREAM_ATTR_FLOAT_OVERFLOW_CHECK, |
| 3860 | - * or ACL_STREAM_ATTR_USER_CUSTOM_TAG, ACL_STREAM_ATTR_CACHE_OP_INFO | 3890 | + * ACL_STREAM_ATTR_USER_CUSTOM_TAG, ACL_STREAM_ATTR_CACHE_OP_INFO, |
| 3891 | + * ACL_STREAM_ATTR_PRIORITY or ACL_STREAM_LAUNCH_BLOCKING_MODE | ||
| 3861 | * @param [in] value stream attribute value | 3892 | * @param [in] value stream attribute value |
| 3862 | * @retval ACL_SUCCESS The function is successfully executed. | 3893 | * @retval ACL_SUCCESS The function is successfully executed. |
| 3863 | * @retval OtherValues Failure | 3894 | * @retval OtherValues Failure |
| @@ -3870,8 +3901,9 @@ ACL_FUNC_VISIBILITY aclError aclrtSetStreamAttribute( | |||
| 3870 | * @brief get stream attribute | 3901 | * @brief get stream attribute |
| 3871 | * @param [in] stream stream handle | 3902 | * @param [in] stream stream handle |
| 3872 | * @param [in] stmAttrType stream attribute type, which value can be: | 3903 | * @param [in] stmAttrType stream attribute type, which value can be: |
| 3873 | - * ACL_STREAM_ATTR_FAILURE_MODE, ACL_STREAM_ATTR_FLOAT_OVERFLOW_CHECK | 3904 | + * ACL_STREAM_ATTR_FAILURE_MODE, ACL_STREAM_ATTR_FLOAT_OVERFLOW_CHECK, |
| 3874 | - * or ACL_STREAM_ATTR_USER_CUSTOM_TAG, ACL_STREAM_ATTR_CACHE_OP_INFO | 3905 | + * ACL_STREAM_ATTR_USER_CUSTOM_TAG, ACL_STREAM_ATTR_CACHE_OP_INFO, |
| 3906 | + * ACL_STREAM_ATTR_PRIORITY or ACL_STREAM_LAUNCH_BLOCKING_MODE | ||
| 3875 | * @param [out] value stream attribute value | 3907 | * @param [out] value stream attribute value |
| 3876 | * @retval ACL_SUCCESS The function is successfully executed. | 3908 | * @retval ACL_SUCCESS The function is successfully executed. |
| 3877 | * @retval OtherValues Failure | 3909 | * @retval OtherValues Failure |
| @@ -29,13 +29,19 @@ RT_RUNTIME_DEPRECATED_DECLS_BEGIN | |||
| 29 | #define RT_STREAM_FAILURE_MODE_CONTINUE_ON_FAILURE (0x0U) // 默认值,task出错时,处理完异常后继续执行流上的任务 | 29 | #define RT_STREAM_FAILURE_MODE_CONTINUE_ON_FAILURE (0x0U) // 默认值,task出错时,处理完异常后继续执行流上的任务 |
| 30 | #define RT_STREAM_FAILURE_MODE_STOP_ON_FAILURE (0x1U) // 遇错即停 | 30 | #define RT_STREAM_FAILURE_MODE_STOP_ON_FAILURE (0x1U) // 遇错即停 |
| 31 | 31 | ||
| 32 | +// Launch blocking mode | ||
| 33 | +#define RT_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV (0x0U) | ||
| 34 | +#define RT_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING (0x1U) | ||
| 35 | +#define RT_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING (0x2U) | ||
| 36 | + | ||
| 32 | typedef enum { | 37 | typedef enum { |
| 33 | RT_STREAM_ATTR_FAILURE_MODE = 1, | 38 | RT_STREAM_ATTR_FAILURE_MODE = 1, |
| 34 | RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK = 2, | 39 | RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK = 2, |
| 35 | RT_STREAM_ATTR_USER_CUSTOM_TAG = 3, | 40 | RT_STREAM_ATTR_USER_CUSTOM_TAG = 3, |
| 36 | RT_STREAM_ATTR_CACHE_OP_INFO = 4, | 41 | RT_STREAM_ATTR_CACHE_OP_INFO = 4, |
| 37 | RT_STREAM_ATTR_PRIORITY = 5, | 42 | RT_STREAM_ATTR_PRIORITY = 5, |
| 38 | - RT_STREAM_ATTR_MAX = 6, | 43 | + RT_STREAM_ATTR_LAUNCH_BLOCKING_MODE = 6, |
| 44 | + RT_STREAM_ATTR_MAX = 7, | ||
| 39 | } rtStreamAttr; | 45 | } rtStreamAttr; |
| 40 | 46 | ||
| 41 | typedef union { | 47 | typedef union { |
| @@ -44,6 +50,7 @@ typedef union { | |||
| 44 | uint32_t userCustomTag; | 50 | uint32_t userCustomTag; |
| 45 | uint32_t cacheOpInfoSwitch; | 51 | uint32_t cacheOpInfoSwitch; |
| 46 | uint32_t streamPriority; | 52 | uint32_t streamPriority; |
| 53 | + uint32_t launchBlockingMode; | ||
| 47 | uint32_t rsv[4]; | 54 | uint32_t rsv[4]; |
| 48 | } rtStreamAttrValue_t; | 55 | } rtStreamAttrValue_t; |
| 49 | 56 | ||
| @@ -160,6 +160,8 @@ | |||
| 160 | _(aclError, aclrtDestroyStreamForce, (aclrtStream stream), (stream)) \ | 160 | _(aclError, aclrtDestroyStreamForce, (aclrtStream stream), (stream)) \ |
| 161 | _(aclError, aclrtSynchronizeStream, (aclrtStream stream), (stream)) \ | 161 | _(aclError, aclrtSynchronizeStream, (aclrtStream stream), (stream)) \ |
| 162 | _(aclError, aclrtSynchronizeStreamWithTimeout, (aclrtStream stream, int32_t timeout), (stream, timeout)) \ | 162 | _(aclError, aclrtSynchronizeStreamWithTimeout, (aclrtStream stream, int32_t timeout), (stream, timeout)) \ |
| 163 | + _(aclError, aclrtNonBlockingLaunchBegin, (aclrtStream stream, uint64_t flag), (stream, flag)) \ | ||
| 164 | + _(aclError, aclrtNonBlockingLaunchEnd, (aclrtStream stream, uint64_t flag), (stream, flag)) \ | ||
| 163 | _(aclError, aclrtStreamQuery, (aclrtStream stream, aclrtStreamStatus * status), (stream, status)) \ | 165 | _(aclError, aclrtStreamQuery, (aclrtStream stream, aclrtStreamStatus * status), (stream, status)) \ |
| 164 | _(aclError, aclrtStreamGetPriority, (aclrtStream stream, uint32_t * priority), (stream, priority)) \ | 166 | _(aclError, aclrtStreamGetPriority, (aclrtStream stream, uint32_t * priority), (stream, priority)) \ |
| 165 | _(aclError, aclrtStreamGetFlags, (aclrtStream stream, uint32_t * flags), (stream, flags)) \ | 167 | _(aclError, aclrtStreamGetFlags, (aclrtStream stream, uint32_t * flags), (stream, flags)) \ |
| @@ -164,6 +164,26 @@ aclError aclrtSynchronizeStreamWithTimeoutImpl(aclrtStream stream, int32_t timeo | |||
| 164 | return ACL_SUCCESS; | 164 | return ACL_SUCCESS; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | +aclError aclrtNonBlockingLaunchBeginImpl(aclrtStream stream, uint64_t flag) | ||
| 168 | +{ | ||
| 169 | + ACL_LOG_INFO("start to execute aclrtNonBlockingLaunchBegin"); | ||
| 170 | + ACL_CHECK_RESERVED_PARAM_REPORT_RET(flag, 0U, ACL_ERROR_INVALID_PARAM); | ||
| 171 | + | ||
| 172 | + ACL_REQUIRES_RTS_OK(rtNonBlockingLaunchBegin(static_cast<rtStream_t>(stream), flag)); | ||
| 173 | + ACL_LOG_INFO("successfully execute aclrtNonBlockingLaunchBegin"); | ||
| 174 | + return ACL_SUCCESS; | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +aclError aclrtNonBlockingLaunchEndImpl(aclrtStream stream, uint64_t flag) | ||
| 178 | +{ | ||
| 179 | + ACL_LOG_INFO("start to execute aclrtNonBlockingLaunchEnd"); | ||
| 180 | + ACL_CHECK_RESERVED_PARAM_REPORT_RET(flag, 0U, ACL_ERROR_INVALID_PARAM); | ||
| 181 | + | ||
| 182 | + ACL_REQUIRES_RTS_OK(rtNonBlockingLaunchEnd(static_cast<rtStream_t>(stream), flag)); | ||
| 183 | + ACL_LOG_INFO("successfully execute aclrtNonBlockingLaunchEnd"); | ||
| 184 | + return ACL_SUCCESS; | ||
| 185 | +} | ||
| 186 | + | ||
| 167 | aclError aclrtStreamQueryImpl(aclrtStream stream, aclrtStreamStatus* status) | 187 | aclError aclrtStreamQueryImpl(aclrtStream stream, aclrtStreamStatus* status) |
| 168 | { | 188 | { |
| 169 | ACL_PROFILING_REG(acl::AclProfType::AclrtStreamQuery); | 189 | ACL_PROFILING_REG(acl::AclProfType::AclrtStreamQuery); |
| @@ -535,6 +535,8 @@ const char* GetStreamAttrDesc(aclrtStreamAttr attr) | |||
| 535 | return "STREAM_ATTR_CACHE_OP_INFO(4)"; | 535 | return "STREAM_ATTR_CACHE_OP_INFO(4)"; |
| 536 | case ACL_STREAM_ATTR_PRIORITY: | 536 | case ACL_STREAM_ATTR_PRIORITY: |
| 537 | return "STREAM_ATTR_PRIORITY(5)"; | 537 | return "STREAM_ATTR_PRIORITY(5)"; |
| 538 | + case ACL_STREAM_LAUNCH_BLOCKING_MODE: | ||
| 539 | + return "STREAM_LAUNCH_BLOCKING_MODE(6)"; | ||
| 538 | default: | 540 | default: |
| 539 | break; | 541 | break; |
| 540 | } | 542 | } |
| @@ -43,7 +43,27 @@ RTS_API rtError_t rtStreamGetTasks(rtStream_t const stm, rtTask_t* tasks, uint32 | |||
| 43 | */ | 43 | */ |
| 44 | RTS_API rtError_t rtStreamWaitEventWithFlag(rtStream_t stm, rtEvent_t evt, uint32_t timeout, uint32_t flag); | 44 | RTS_API rtError_t rtStreamWaitEventWithFlag(rtStream_t stm, rtEvent_t evt, uint32_t timeout, uint32_t flag); |
| 45 | 45 | ||
| 46 | +/** | ||
| 47 | + * @ingroup dvrt_stream | ||
| 48 | + * @brief begin a non-blocking kernel launch section on a stream | ||
| 49 | + * @param [in] stream stream handle | ||
| 50 | + * @param [in] flag reserved parameter | ||
| 51 | + * @return RT_ERROR_NONE for ok | ||
| 52 | + * @return RT_ERROR_INVALID_VALUE for error input | ||
| 53 | + */ | ||
| 54 | +RTS_API rtError_t rtNonBlockingLaunchBegin(rtStream_t stream, uint64_t flag); | ||
| 55 | + | ||
| 56 | +/** | ||
| 57 | + * @ingroup dvrt_stream | ||
| 58 | + * @brief end a non-blocking kernel launch section on a stream | ||
| 59 | + * @param [in] stream stream handle | ||
| 60 | + * @param [in] flag reserved parameter | ||
| 61 | + * @return RT_ERROR_NONE for ok | ||
| 62 | + * @return RT_ERROR_INVALID_VALUE for error input | ||
| 63 | + */ | ||
| 64 | +RTS_API rtError_t rtNonBlockingLaunchEnd(rtStream_t stream, uint64_t flag); | ||
| 65 | + | ||
| 46 | #if defined(__cplusplus) | 66 | #if defined(__cplusplus) |
| 47 | } | 67 | } |
| 48 | #endif | 68 | #endif |
| 49 | -#endif // CCE_RUNTIME_RT_INNER_STREAM_H | 69 | +#endif // CCE_RUNTIME_RT_INNER_STREAM_H |
| @@ -241,6 +241,8 @@ public: | |||
| 241 | Stream* const stm, Event* const evt, const uint32_t timeout = 0U, | 241 | Stream* const stm, Event* const evt, const uint32_t timeout = 0U, |
| 242 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) = 0; | 242 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) = 0; |
| 243 | virtual rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout = -1) = 0; | 243 | virtual rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout = -1) = 0; |
| 244 | + virtual rtError_t NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) = 0; | ||
| 245 | + virtual rtError_t NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) = 0; | ||
| 244 | virtual rtError_t StreamQuery(Stream* const stm) = 0; | 246 | virtual rtError_t StreamQuery(Stream* const stm) = 0; |
| 245 | virtual rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) = 0; | 247 | virtual rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) = 0; |
| 246 | virtual rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) = 0; | 248 | virtual rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) = 0; |
| @@ -614,6 +616,10 @@ public: | |||
| 614 | virtual rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) = 0; | 616 | virtual rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) = 0; |
| 615 | virtual rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) = 0; | 617 | virtual rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) = 0; |
| 616 | virtual rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) = 0; | 618 | virtual rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) = 0; |
| 619 | + virtual rtError_t StreamSetAttribute( | ||
| 620 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) = 0; | ||
| 621 | + virtual rtError_t StreamGetAttribute( | ||
| 622 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) = 0; | ||
| 617 | virtual rtError_t SetExceptCallback(const rtErrorCallback callback) = 0; | 623 | virtual rtError_t SetExceptCallback(const rtErrorCallback callback) = 0; |
| 618 | virtual rtError_t SetTaskAbortCallBack( | 624 | virtual rtError_t SetTaskAbortCallBack( |
| 619 | const char_t* regName, void* callback, void* args, TaskAbortCallbackType type) = 0; | 625 | const char_t* regName, void* callback, void* args, TaskAbortCallbackType type) = 0; |
| @@ -1398,6 +1398,30 @@ rtError_t rtsPersistentTaskClean(rtStream_t stm) | |||
| 1398 | return ACL_RT_SUCCESS; | 1398 | return ACL_RT_SUCCESS; |
| 1399 | } | 1399 | } |
| 1400 | 1400 | ||
| 1401 | +VISIBILITY_DEFAULT | ||
| 1402 | +rtError_t rtNonBlockingLaunchBegin(rtStream_t stream, uint64_t flag) | ||
| 1403 | +{ | ||
| 1404 | + Api* const apiInstance = Api::Instance(); | ||
| 1405 | + NULL_RETURN_ERROR_WITH_EXT_ERRCODE(apiInstance); | ||
| 1406 | + RT_VALIDATE_AND_UNWRAP_OBJECT(stream, Stream, targetStream); | ||
这里先用 ![]() ![]() | |||
| 1407 | + const rtError_t error = apiInstance->NonBlockingLaunchBegin(targetStream, flag); | ||
| 1408 | + COND_RETURN_WITH_NOLOG(error == RT_ERROR_FEATURE_NOT_SUPPORT, ACL_ERROR_RT_FEATURE_NOT_SUPPORT); | ||
| 1409 | + ERROR_RETURN_WITH_EXT_ERRCODE(error); | ||
| 1410 | + return ACL_RT_SUCCESS; | ||
| 1411 | +} | ||
| 1412 | + | ||
| 1413 | +VISIBILITY_DEFAULT | ||
| 1414 | +rtError_t rtNonBlockingLaunchEnd(rtStream_t stream, uint64_t flag) | ||
| 1415 | +{ | ||
| 1416 | + Api* const apiInstance = Api::Instance(); | ||
| 1417 | + NULL_RETURN_ERROR_WITH_EXT_ERRCODE(apiInstance); | ||
| 1418 | + RT_VALIDATE_AND_UNWRAP_OBJECT(stream, Stream, targetStream); | ||
| 1419 | + const rtError_t error = apiInstance->NonBlockingLaunchEnd(targetStream, flag); | ||
| 1420 | + COND_RETURN_WITH_NOLOG(error == RT_ERROR_FEATURE_NOT_SUPPORT, ACL_ERROR_RT_FEATURE_NOT_SUPPORT); | ||
| 1421 | + ERROR_RETURN_WITH_EXT_ERRCODE(error); | ||
| 1422 | + return ACL_RT_SUCCESS; | ||
| 1423 | +} | ||
| 1424 | + | ||
| 1401 | VISIBILITY_DEFAULT | 1425 | VISIBILITY_DEFAULT |
| 1402 | rtError_t rtCacheLastTaskOpInfo(const void* const infoPtr, const size_t infoSize) | 1426 | rtError_t rtCacheLastTaskOpInfo(const void* const infoPtr, const size_t infoSize) |
| 1403 | { | 1427 | { |
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "profiler.hpp" | 19 | #include "profiler.hpp" |
| 20 | #include "thread_local_container.hpp" | 20 | #include "thread_local_container.hpp" |
| 21 | #include "global_state_manager.hpp" | 21 | #include "global_state_manager.hpp" |
| 22 | +#include "stream.hpp" | ||
| 22 | #include <vector> | 23 | #include <vector> |
| 23 | #define INVALID_UINT32 (0xFFFFFFFFU) | 24 | #define INVALID_UINT32 (0xFFFFFFFFU) |
| 24 | 25 | ||
| @@ -439,64 +440,24 @@ VISIBILITY_DEFAULT | |||
| 439 | rtError_t rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) | 440 | rtError_t rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) |
| 440 | { | 441 | { |
| 441 | PARAM_NULL_RETURN_ERROR_WITH_EXT_ERRCODE(attrValue, RT_ERROR_INVALID_VALUE); | 442 | PARAM_NULL_RETURN_ERROR_WITH_EXT_ERRCODE(attrValue, RT_ERROR_INVALID_VALUE); |
| 442 | - rtError_t error; | ||
| 443 | const Runtime* const rtInstance = Runtime::Instance(); | 443 | const Runtime* const rtInstance = Runtime::Instance(); |
| 444 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(rtInstance); | 444 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(rtInstance); |
| 445 | Api* const apiInstance = Api::Instance(); | 445 | Api* const apiInstance = Api::Instance(); |
| 446 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(apiInstance); | 446 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(apiInstance); |
| 447 | RT_VALIDATE_AND_UNWRAP_OBJECT(stm, Stream, exeStream); | 447 | RT_VALIDATE_AND_UNWRAP_OBJECT(stm, Stream, exeStream); |
| 448 | 448 | ||
| 449 | - switch (stmAttrId) { | 449 | + if ((stmAttrId < RT_STREAM_ATTR_FAILURE_MODE) || (stmAttrId >= RT_STREAM_ATTR_MAX)) { |
| 450 | - case RT_STREAM_ATTR_FAILURE_MODE: { | 450 | + RT_LOG_OUTER_MSG_WITH_FUNC( |
| 451 | - COND_RETURN_WARN( | 451 | + ErrorCode::EE1003, |
| 452 | - !IS_SUPPORT_CHIP_FEATURE( | 452 | + RtFmtMsg( |
| 453 | - rtInstance->GetChipType(), RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_FAILURE_MODE), | 453 | + "%s(%d)", (stmAttrId == RT_STREAM_ATTR_MAX) ? "STREAM_ATTR_MAX" : "UNKNOWN", |
| 454 | - ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "chip type(%d) does not support.", | 454 | + static_cast<int32_t>(stmAttrId)), |
| 455 | - static_cast<int32_t>(rtInstance->GetChipType())); | 455 | + "stmAttrId", |
| 456 | - error = apiInstance->StreamSetMode(exeStream, attrValue->failureMode); | 456 | + "[" + std::to_string(RT_STREAM_ATTR_FAILURE_MODE) + ", " + std::to_string(RT_STREAM_ATTR_MAX) + ")"); |
| 457 | - break; | 457 | + ERROR_RETURN_WITH_EXT_ERRCODE(RT_ERROR_INVALID_VALUE); |
| 458 | - } | ||
| 459 | - case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | ||
| 460 | - if (!IS_SUPPORT_CHIP_FEATURE( | ||
| 461 | - rtInstance->GetChipType(), RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_OVERFLOW_CHECK)) { | ||
| 462 | - RT_LOG( | ||
| 463 | - RT_LOG_WARNING, "chip type(%d) does not support, return success.", | ||
| 464 | - static_cast<int32_t>(rtInstance->GetChipType())); | ||
| 465 | - return ACL_RT_SUCCESS; | ||
| 466 | - } | ||
| 467 | - error = apiInstance->SetStreamOverflowSwitch(exeStream, attrValue->overflowSwitch); | ||
| 468 | - break; | ||
| 469 | - } | ||
| 470 | - case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 471 | - if (!IS_SUPPORT_CHIP_FEATURE( | ||
| 472 | - rtInstance->GetChipType(), RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_USER_CUSTOM_TAG)) { | ||
| 473 | - RT_LOG( | ||
| 474 | - RT_LOG_WARNING, "chip type(%d) does not support, return success.", | ||
| 475 | - static_cast<int32_t>(rtInstance->GetChipType())); | ||
| 476 | - return ACL_RT_SUCCESS; | ||
| 477 | - } | ||
| 478 | - error = apiInstance->SetStreamTag(exeStream, attrValue->userCustomTag); | ||
| 479 | - break; | ||
| 480 | - } | ||
| 481 | - case RT_STREAM_ATTR_CACHE_OP_INFO: { | ||
| 482 | - error = apiInstance->SetStreamCacheOpInfoSwitch(exeStream, attrValue->cacheOpInfoSwitch); | ||
| 483 | - break; | ||
| 484 | - } | ||
| 485 | - case RT_STREAM_ATTR_PRIORITY: { | ||
| 486 | - error = apiInstance->SetStreamPriorityValue(exeStream, attrValue->streamPriority); | ||
| 487 | - break; | ||
| 488 | - } | ||
| 489 | - default: | ||
| 490 | - RT_LOG_OUTER_MSG_WITH_FUNC( | ||
| 491 | - ErrorCode::EE1003, | ||
| 492 | - RtFmtMsg( | ||
| 493 | - "%s(%d)", (stmAttrId == RT_STREAM_ATTR_MAX) ? "STREAM_ATTR_MAX" : "UNKNOWN", | ||
| 494 | - static_cast<int32_t>(stmAttrId)), | ||
| 495 | - "stmAttrId", | ||
| 496 | - "[" + std::to_string(RT_STREAM_ATTR_FAILURE_MODE) + ", " + std::to_string(RT_STREAM_ATTR_MAX) + ")"); | ||
| 497 | - error = RT_ERROR_INVALID_VALUE; | ||
| 498 | - break; | ||
| 499 | } | 458 | } |
| 459 | + const rtError_t error = apiInstance->StreamSetAttribute(exeStream, stmAttrId, attrValue); | ||
| 460 | + COND_RETURN_WITH_NOLOG(error == RT_ERROR_FEATURE_NOT_SUPPORT, ACL_ERROR_RT_FEATURE_NOT_SUPPORT); | ||
| 500 | ERROR_RETURN_WITH_EXT_ERRCODE(error); | 461 | ERROR_RETURN_WITH_EXT_ERRCODE(error); |
| 501 | return ACL_RT_SUCCESS; | 462 | return ACL_RT_SUCCESS; |
| 502 | } | 463 | } |
| @@ -505,52 +466,24 @@ VISIBILITY_DEFAULT | |||
| 505 | rtError_t rtsStreamGetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) | 466 | rtError_t rtsStreamGetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) |
| 506 | { | 467 | { |
| 507 | PARAM_NULL_RETURN_ERROR_WITH_EXT_ERRCODE(attrValue, RT_ERROR_INVALID_VALUE); | 468 | PARAM_NULL_RETURN_ERROR_WITH_EXT_ERRCODE(attrValue, RT_ERROR_INVALID_VALUE); |
| 508 | - rtError_t error; | ||
| 509 | const Runtime* const rtInstance = Runtime::Instance(); | 469 | const Runtime* const rtInstance = Runtime::Instance(); |
| 510 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(rtInstance); | 470 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(rtInstance); |
| 511 | Api* const apiInstance = Api::Instance(); | 471 | Api* const apiInstance = Api::Instance(); |
| 512 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(apiInstance); | 472 | NULL_RETURN_ERROR_WITH_EXT_ERRCODE(apiInstance); |
| 513 | RT_VALIDATE_AND_UNWRAP_OBJECT(stm, Stream, exeStream); | 473 | RT_VALIDATE_AND_UNWRAP_OBJECT(stm, Stream, exeStream); |
| 514 | 474 | ||
| 515 | - switch (stmAttrId) { | 475 | + if ((stmAttrId < RT_STREAM_ATTR_FAILURE_MODE) || (stmAttrId >= RT_STREAM_ATTR_MAX)) { |
| 516 | - case RT_STREAM_ATTR_FAILURE_MODE: { | 476 | + RT_LOG_OUTER_MSG_WITH_FUNC( |
| 517 | - error = apiInstance->StreamGetMode(exeStream, &attrValue->failureMode); | 477 | + ErrorCode::EE1003, |
| 518 | - break; | 478 | + RtFmtMsg( |
| 519 | - } | 479 | + "%s(%d)", (stmAttrId == RT_STREAM_ATTR_MAX) ? "STREAM_ATTR_MAX" : "UNKNOWN", |
| 520 | - case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | 480 | + static_cast<int32_t>(stmAttrId)), |
| 521 | - error = apiInstance->GetStreamOverflowSwitch(exeStream, &attrValue->overflowSwitch); | 481 | + "stmAttrId", |
| 522 | - break; | 482 | + "[" + std::to_string(RT_STREAM_ATTR_FAILURE_MODE) + ", " + std::to_string(RT_STREAM_ATTR_MAX) + ")"); |
| 523 | - } | 483 | + ERROR_RETURN_WITH_EXT_ERRCODE(RT_ERROR_INVALID_VALUE); |
| 524 | - case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 525 | - if (!IS_SUPPORT_CHIP_FEATURE( | ||
| 526 | - rtInstance->GetChipType(), RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_USER_CUSTOM_TAG)) { | ||
| 527 | - RT_LOG( | ||
| 528 | - RT_LOG_WARNING, "chip type(%d) does not support, return success.", | ||
| 529 | - static_cast<int32_t>(rtInstance->GetChipType())); | ||
| 530 | - return ACL_RT_SUCCESS; | ||
| 531 | - } | ||
| 532 | - error = apiInstance->GetStreamTag(exeStream, &attrValue->userCustomTag); | ||
| 533 | - break; | ||
| 534 | - } | ||
| 535 | - case RT_STREAM_ATTR_CACHE_OP_INFO: { | ||
| 536 | - error = apiInstance->GetStreamCacheOpInfoSwitch(exeStream, &attrValue->cacheOpInfoSwitch); | ||
| 537 | - break; | ||
| 538 | - } | ||
| 539 | - case RT_STREAM_ATTR_PRIORITY: { | ||
| 540 | - error = apiInstance->GetStreamPriorityValue(exeStream, &attrValue->streamPriority); | ||
| 541 | - break; | ||
| 542 | - } | ||
| 543 | - default: | ||
| 544 | - RT_LOG_OUTER_MSG_WITH_FUNC( | ||
| 545 | - ErrorCode::EE1003, | ||
| 546 | - RtFmtMsg( | ||
| 547 | - "%s(%d)", (stmAttrId == RT_STREAM_ATTR_MAX) ? "STREAM_ATTR_MAX" : "UNKNOWN", | ||
| 548 | - static_cast<int32_t>(stmAttrId)), | ||
| 549 | - "stmAttrId", | ||
| 550 | - "[" + std::to_string(RT_STREAM_ATTR_FAILURE_MODE) + ", " + std::to_string(RT_STREAM_ATTR_MAX) + ")"); | ||
| 551 | - error = RT_ERROR_INVALID_VALUE; | ||
| 552 | - break; | ||
| 553 | } | 484 | } |
| 485 | + const rtError_t error = apiInstance->StreamGetAttribute(exeStream, stmAttrId, attrValue); | ||
| 486 | + COND_RETURN_WITH_NOLOG(error == RT_ERROR_FEATURE_NOT_SUPPORT, ACL_ERROR_RT_FEATURE_NOT_SUPPORT); | ||
| 554 | ERROR_RETURN_WITH_EXT_ERRCODE(error); | 487 | ERROR_RETURN_WITH_EXT_ERRCODE(error); |
| 555 | return ACL_RT_SUCCESS; | 488 | return ACL_RT_SUCCESS; |
| 556 | } | 489 | } |
| @@ -351,6 +351,16 @@ rtError_t ApiDecorator::StreamSynchronize(Stream* const stm, const int32_t timeo | |||
| 351 | return impl_->StreamSynchronize(stm, timeout); | 351 | return impl_->StreamSynchronize(stm, timeout); |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | +rtError_t ApiDecorator::NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) | ||
| 355 | +{ | ||
| 356 | + return impl_->NonBlockingLaunchBegin(stream, flag); | ||
| 357 | +} | ||
| 358 | + | ||
| 359 | +rtError_t ApiDecorator::NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) | ||
| 360 | +{ | ||
| 361 | + return impl_->NonBlockingLaunchEnd(stream, flag); | ||
| 362 | +} | ||
| 363 | + | ||
| 354 | rtError_t ApiDecorator::StreamQuery(Stream* const stm) { return impl_->StreamQuery(stm); } | 364 | rtError_t ApiDecorator::StreamQuery(Stream* const stm) { return impl_->StreamQuery(stm); } |
| 355 | 365 | ||
| 356 | rtError_t ApiDecorator::NopTask(Stream* const stm) { return impl_->NopTask(stm); } | 366 | rtError_t ApiDecorator::NopTask(Stream* const stm) { return impl_->NopTask(stm); } |
| @@ -1525,6 +1535,18 @@ rtError_t ApiDecorator::GetStreamPriorityValue(Stream* const stm, uint32_t* cons | |||
| 1525 | return impl_->GetStreamPriorityValue(stm, streamPriority); | 1535 | return impl_->GetStreamPriorityValue(stm, streamPriority); |
| 1526 | } | 1536 | } |
| 1527 | 1537 | ||
| 1538 | +rtError_t ApiDecorator::StreamSetAttribute( | ||
| 1539 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) | ||
| 1540 | +{ | ||
| 1541 | + return impl_->StreamSetAttribute(stm, stmAttrId, attrValue); | ||
| 1542 | +} | ||
| 1543 | + | ||
| 1544 | +rtError_t ApiDecorator::StreamGetAttribute( | ||
| 1545 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) | ||
| 1546 | +{ | ||
| 1547 | + return impl_->StreamGetAttribute(stm, stmAttrId, attrValue); | ||
| 1548 | +} | ||
| 1549 | + | ||
| 1528 | rtError_t ApiDecorator::DvppGroupCreate(DvppGrp** grp, const uint32_t flags) | 1550 | rtError_t ApiDecorator::DvppGroupCreate(DvppGrp** grp, const uint32_t flags) |
| 1529 | { | 1551 | { |
| 1530 | return impl_->DvppGroupCreate(grp, flags); | 1552 | return impl_->DvppGroupCreate(grp, flags); |
| @@ -142,6 +142,8 @@ public: | |||
| 142 | Stream* const stm, Event* const evt, const uint32_t timeout, | 142 | Stream* const stm, Event* const evt, const uint32_t timeout, |
| 143 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) override; | 143 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) override; |
| 144 | rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout) override; | 144 | rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout) override; |
| 145 | + rtError_t NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) override; | ||
| 146 | + rtError_t NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) override; | ||
| 145 | rtError_t StreamQuery(Stream* const stm) override; | 147 | rtError_t StreamQuery(Stream* const stm) override; |
| 146 | rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) override; | 148 | rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) override; |
| 147 | rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) override; | 149 | rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) override; |
| @@ -517,6 +519,10 @@ public: | |||
| 517 | rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) override; | 519 | rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) override; |
| 518 | rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) override; | 520 | rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) override; |
| 519 | rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) override; | 521 | rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) override; |
| 522 | + rtError_t StreamSetAttribute( | ||
| 523 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) override; | ||
| 524 | + rtError_t StreamGetAttribute( | ||
| 525 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) override; | ||
| 520 | rtError_t SetExceptCallback(const rtErrorCallback callback) override; | 526 | rtError_t SetExceptCallback(const rtErrorCallback callback) override; |
| 521 | rtError_t SetTaskAbortCallBack( | 527 | rtError_t SetTaskAbortCallBack( |
| 522 | const char_t* regName, void* callback, void* args, TaskAbortCallbackType type) override; | 528 | const char_t* regName, void* callback, void* args, TaskAbortCallbackType type) override; |
| @@ -1605,14 +1605,268 @@ rtError_t ApiErrorDecorator::SetDeviceFailureMode(uint64_t failureMode) | |||
| 1605 | return impl_->SetDeviceFailureMode(failureMode); | 1605 | return impl_->SetDeviceFailureMode(failureMode); |
| 1606 | } | 1606 | } |
| 1607 | 1607 | ||
| 1608 | +static rtError_t ValidateStreamFailureModeSet(Stream* const stm, Stream*& targetStm) | ||
| 1609 | +{ | ||
| 1610 | + targetStm = Runtime::Instance()->GetCurStream(stm); | ||
| 1611 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1612 | + targetStm, RT_ERROR_INVALID_VALUE, "Setting the error handling mode of a stream"); | ||
| 1613 | + COND_RETURN_WARN( | ||
| 1614 | + (targetStm->Flags() & RT_STREAM_CP_PROCESS_USE) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 1615 | + "Coprocessor stream flag=%u is not supported, stream_id=%d", targetStm->Flags(), targetStm->Id_()); | ||
| 1616 | + return RT_ERROR_NONE; | ||
| 1617 | +} | ||
| 1618 | + | ||
| 1619 | +static rtError_t ValidateStreamFailureModeGet(Stream* const stm, uint64_t* const stmMode, Stream*& targetStm) | ||
| 1620 | +{ | ||
| 1621 | + targetStm = Runtime::Instance()->GetCurStream(stm); | ||
| 1622 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1623 | + targetStm, RT_ERROR_INVALID_VALUE, "Obtaining the error handling mode of a stream"); | ||
| 1624 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1625 | + stmMode, RT_ERROR_INVALID_VALUE, "Obtaining the error handling mode of a stream"); | ||
| 1626 | + return RT_ERROR_NONE; | ||
| 1627 | +} | ||
| 1628 | + | ||
| 1629 | +static rtError_t ValidateStreamOverflowSwitchSet(const Stream* const stm, const uint32_t flags) | ||
| 1630 | +{ | ||
| 1631 | + COND_RETURN_AND_MSG_OUTER_WITH_PARAM_AND_FUNC_DESC( | ||
| 1632 | + flags >= static_cast<uint32_t>(RT_OVERFLOW_MODE_UNDEF), RT_ERROR_INVALID_VALUE, | ||
| 1633 | + "Setting the stream overflow/underflow detection switch", flags, | ||
| 1634 | + "[" + std::to_string(RT_OVERFLOW_MODE_SATURATION) + ", " + std::to_string(RT_OVERFLOW_MODE_UNDEF) + ")"); | ||
| 1635 | + COND_RETURN_AND_MSG_OUTER( | ||
| 1636 | + (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, | ||
| 1637 | + "Setting the stream overflow/underflow detection switch", | ||
| 1638 | + RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_())); | ||
| 1639 | + return RT_ERROR_NONE; | ||
| 1640 | +} | ||
| 1641 | + | ||
| 1642 | +static rtError_t ValidateStreamPrioritySet( | ||
| 1643 | + const Stream* const stm, const uint32_t streamPriority, uint32_t& targetPriority) | ||
| 1644 | +{ | ||
| 1645 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Setting the stream priority"); | ||
| 1646 | + COND_RETURN_ERROR( | ||
| 1647 | + (stm->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 1648 | + "The stream with flag %u does not support priority setting.", stm->Flags()); | ||
| 1649 | + COND_RETURN_AND_MSG_OUTER( | ||
| 1650 | + (stm->Flags() & RT_STREAM_AICPU) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006, | ||
| 1651 | + "Setting the stream priority", "Parameter stm->Flags() value " + std::to_string(stm->Flags()), | ||
| 1652 | + "The current stream is used to carry AI CPU scheduling tasks and does not support priority setting"); | ||
| 1653 | + const int32_t validPriority = static_cast<int32_t>(streamPriority); | ||
| 1654 | + targetPriority = streamPriority; | ||
| 1655 | + if (validPriority < RT_STREAM_GREATEST_PRIORITY) { | ||
| 1656 | + targetPriority = RT_STREAM_GREATEST_PRIORITY; | ||
| 1657 | + } else if (validPriority > RT_STREAM_LEAST_PRIORITY) { | ||
| 1658 | + targetPriority = RT_STREAM_LEAST_PRIORITY; | ||
| 1659 | + } else { | ||
| 1660 | + // no operation | ||
| 1661 | + } | ||
| 1662 | + if (targetPriority != streamPriority) { | ||
| 1663 | + RT_LOG( | ||
| 1664 | + RT_LOG_INFO, "Input priority=%d is out of range [%u, %u], adjusted to %u", validPriority, | ||
| 1665 | + RT_STREAM_GREATEST_PRIORITY, RT_STREAM_LEAST_PRIORITY, targetPriority); | ||
| 1666 | + } | ||
| 1667 | + return RT_ERROR_NONE; | ||
| 1668 | +} | ||
| 1669 | + | ||
| 1670 | +static rtError_t ValidateStreamPriorityGet(const Stream* const stm, uint32_t* const streamPriority) | ||
| 1671 | +{ | ||
| 1672 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(streamPriority, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority"); | ||
| 1673 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority"); | ||
| 1674 | + COND_RETURN_ERROR( | ||
| 1675 | + (stm->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 1676 | + "The stream with flag %u does not support priority setting.", stm->Flags()); | ||
| 1677 | + COND_RETURN_AND_MSG_OUTER( | ||
| 1678 | + (stm->Flags() & RT_STREAM_AICPU) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006, | ||
| 1679 | + "Obtaining the stream priority", "Parameter stm->Flags() value " + std::to_string(stm->Flags()), | ||
| 1680 | + "The current stream is used to carry AI CPU scheduling tasks and does not support priority getting"); | ||
| 1681 | + return RT_ERROR_NONE; | ||
| 1682 | +} | ||
| 1683 | + | ||
| 1684 | +static rtError_t ValidateStreamTagSet(const Stream* const stm) | ||
| 1685 | +{ | ||
| 1686 | + COND_RETURN_AND_MSG_OUTER( | ||
| 1687 | + (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Setting the stream tag", | ||
| 1688 | + RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_())); | ||
| 1689 | + return RT_ERROR_NONE; | ||
| 1690 | +} | ||
| 1691 | + | ||
| 1692 | +static rtError_t ValidateStreamCacheOpInfoSet( | ||
| 1693 | + const Stream* const stm, const uint32_t cacheOpInfoSwitch, Stream*& targetStm) | ||
| 1694 | +{ | ||
| 1695 | + targetStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm)); | ||
| 1696 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1697 | + targetStm, RT_ERROR_INVALID_VALUE, "Setting the switch for caching operator information in a stream"); | ||
| 1698 | + COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_AND_FUNC_DESC( | ||
| 1699 | + (cacheOpInfoSwitch != 0U) && (cacheOpInfoSwitch != 1U), RT_ERROR_INVALID_VALUE, | ||
| 1700 | + "Setting the switch for caching operator information in a stream", RtFmtMsg("%u", cacheOpInfoSwitch), | ||
| 1701 | + "cacheOpInfoSwitch", "0 or 1"); | ||
| 1702 | + return RT_ERROR_NONE; | ||
| 1703 | +} | ||
| 1704 | + | ||
| 1705 | +static rtError_t ValidateStreamCacheOpInfoGet( | ||
| 1706 | + const Stream* const stm, uint32_t* const cacheOpInfoSwitch, Stream*& targetStm) | ||
| 1707 | +{ | ||
| 1708 | + targetStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm)); | ||
| 1709 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1710 | + targetStm, RT_ERROR_INVALID_VALUE, "Querying whether the operator information is cached"); | ||
| 1711 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1712 | + cacheOpInfoSwitch, RT_ERROR_INVALID_VALUE, "Querying whether the operator information is cached"); | ||
| 1713 | + return RT_ERROR_NONE; | ||
| 1714 | +} | ||
| 1715 | + | ||
| 1716 | +rtError_t ApiErrorDecorator::StreamSetAttribute( | ||
| 1717 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) | ||
| 1718 | +{ | ||
| 1719 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrValue, RT_ERROR_INVALID_VALUE, "Setting a stream attribute"); | ||
| 1720 | + Stream* targetStm = stm; | ||
| 1721 | + rtStreamAttrValue_t normalizedValue = {}; | ||
| 1722 | + const rtStreamAttrValue_t* targetValue = attrValue; | ||
| 1723 | + rtError_t error; | ||
| 1724 | + switch (stmAttrId) { | ||
| 1725 | + case RT_STREAM_ATTR_FAILURE_MODE: { | ||
| 1726 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 1727 | + COND_RETURN_WARN( | ||
| 1728 | + !IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_FAILURE_MODE), | ||
| 1729 | + ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "chip type(%d) does not support.", static_cast<int32_t>(chipType)); | ||
| 1730 | + error = ValidateStreamFailureModeSet(stm, targetStm); | ||
| 1731 | +#ifndef CFG_DEV_PLATFORM_PC | ||
| 1732 | + if (error == RT_ERROR_NONE) { | ||
| 1733 | + error = impl_->StreamSetAttribute(targetStm, stmAttrId, targetValue); | ||
| 1734 | + ERROR_RETURN(error, "set stream mode failed."); | ||
| 1735 | + } | ||
| 1736 | +#else | ||
| 1737 | + if (error == RT_ERROR_NONE) { | ||
| 1738 | + RT_LOG(RT_LOG_DEBUG, "no need set stream mode."); | ||
| 1739 | + } | ||
| 1740 | +#endif | ||
| 1741 | + break; | ||
| 1742 | + } | ||
| 1743 | + case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | ||
| 1744 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 1745 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_OVERFLOW_CHECK)) { | ||
| 1746 | + RT_LOG( | ||
| 1747 | + RT_LOG_WARNING, "chip type(%d) does not support, return success.", static_cast<int32_t>(chipType)); | ||
| 1748 | + return RT_ERROR_NONE; | ||
| 1749 | + } | ||
| 1750 | + error = ValidateStreamOverflowSwitchSet(stm, attrValue->overflowSwitch); | ||
| 1751 | + if (error == RT_ERROR_NONE) { | ||
| 1752 | + error = impl_->StreamSetAttribute(targetStm, stmAttrId, targetValue); | ||
| 1753 | + } | ||
| 1754 | + break; | ||
| 1755 | + } | ||
| 1756 | + case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 1757 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 1758 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_USER_CUSTOM_TAG)) { | ||
| 1759 | + RT_LOG( | ||
| 1760 | + RT_LOG_WARNING, "chip type(%d) does not support, return success.", static_cast<int32_t>(chipType)); | ||
| 1761 | + return RT_ERROR_NONE; | ||
| 1762 | + } | ||
| 1763 | + error = ValidateStreamTagSet(stm); | ||
| 1764 | + if (error == RT_ERROR_NONE) { | ||
| 1765 | + error = impl_->StreamSetAttribute(targetStm, stmAttrId, targetValue); | ||
| 1766 | + ERROR_RETURN(error, "set stream geOpTag failed."); | ||
| 1767 | + } | ||
| 1768 | + break; | ||
| 1769 | + } | ||
| 1770 | + case RT_STREAM_ATTR_CACHE_OP_INFO: { | ||
| 1771 | + error = ValidateStreamCacheOpInfoSet(stm, attrValue->cacheOpInfoSwitch, targetStm); | ||
| 1772 | + if (error == RT_ERROR_NONE) { | ||
| 1773 | + error = impl_->StreamSetAttribute(targetStm, stmAttrId, targetValue); | ||
| 1774 | + } | ||
| 1775 | + break; | ||
| 1776 | + } | ||
| 1777 | + case RT_STREAM_ATTR_PRIORITY: { | ||
| 1778 | + normalizedValue.streamPriority = attrValue->streamPriority; | ||
| 1779 | + error = ValidateStreamPrioritySet(stm, attrValue->streamPriority, normalizedValue.streamPriority); | ||
| 1780 | + if (error == RT_ERROR_NONE) { | ||
| 1781 | + targetValue = &normalizedValue; | ||
| 1782 | + error = impl_->StreamSetAttribute(targetStm, stmAttrId, targetValue); | ||
| 1783 | + } | ||
| 1784 | + break; | ||
| 1785 | + } | ||
| 1786 | + case RT_STREAM_ATTR_LAUNCH_BLOCKING_MODE: { | ||
| 1787 | + error = ValidateStreamLaunchBlockingSet(stm, attrValue->launchBlockingMode); | ||
| 1788 | + if (error == RT_ERROR_NONE) { | ||
| 1789 | + error = impl_->StreamSetAttribute(targetStm, stmAttrId, targetValue); | ||
| 1790 | + } | ||
| 1791 | + break; | ||
| 1792 | + } | ||
| 1793 | + default: { | ||
| 1794 | + RT_LOG_OUTER_MSG_INVALID_PARAM( | ||
| 1795 | + stmAttrId, | ||
| 1796 | + "[" + std::to_string(RT_STREAM_ATTR_FAILURE_MODE) + ", " + std::to_string(RT_STREAM_ATTR_MAX) + ")"); | ||
| 1797 | + error = RT_ERROR_INVALID_VALUE; | ||
| 1798 | + break; | ||
| 1799 | + } | ||
| 1800 | + } | ||
| 1801 | + return error; | ||
| 1802 | +} | ||
| 1803 | + | ||
| 1804 | +rtError_t ApiErrorDecorator::StreamGetAttribute( | ||
| 1805 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) | ||
| 1806 | +{ | ||
| 1807 | + NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrValue, RT_ERROR_INVALID_VALUE, "Obtaining a stream attribute"); | ||
| 1808 | + Stream* targetStm = stm; | ||
| 1809 | + rtError_t error; | ||
| 1810 | + switch (stmAttrId) { | ||
| 1811 | + case RT_STREAM_ATTR_FAILURE_MODE: { | ||
| 1812 | + error = ValidateStreamFailureModeGet(stm, &attrValue->failureMode, targetStm); | ||
| 1813 | + if (error == RT_ERROR_NONE) { | ||
| 1814 | + error = impl_->StreamGetAttribute(targetStm, stmAttrId, attrValue); | ||
| 1815 | + } | ||
| 1816 | + break; | ||
| 1817 | + } | ||
| 1818 | + case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | ||
| 1819 | + error = impl_->StreamGetAttribute(targetStm, stmAttrId, attrValue); | ||
| 1820 | + break; | ||
| 1821 | + } | ||
| 1822 | + case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 1823 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 1824 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_STREAM_ATTR_USER_CUSTOM_TAG)) { | ||
| 1825 | + RT_LOG( | ||
| 1826 | + RT_LOG_WARNING, "chip type(%d) does not support, return success.", static_cast<int32_t>(chipType)); | ||
| 1827 | + return RT_ERROR_NONE; | ||
| 1828 | + } | ||
| 1829 | + error = impl_->StreamGetAttribute(targetStm, stmAttrId, attrValue); | ||
| 1830 | + ERROR_RETURN(error, "get stream geOpTag failed."); | ||
| 1831 | + break; | ||
| 1832 | + } | ||
| 1833 | + case RT_STREAM_ATTR_CACHE_OP_INFO: { | ||
| 1834 | + error = ValidateStreamCacheOpInfoGet(stm, &attrValue->cacheOpInfoSwitch, targetStm); | ||
| 1835 | + if (error == RT_ERROR_NONE) { | ||
| 1836 | + error = impl_->StreamGetAttribute(targetStm, stmAttrId, attrValue); | ||
| 1837 | + } | ||
| 1838 | + break; | ||
| 1839 | + } | ||
| 1840 | + case RT_STREAM_ATTR_PRIORITY: { | ||
| 1841 | + error = ValidateStreamPriorityGet(stm, &attrValue->streamPriority); | ||
| 1842 | + if (error == RT_ERROR_NONE) { | ||
| 1843 | + error = impl_->StreamGetAttribute(targetStm, stmAttrId, attrValue); | ||
| 1844 | + } | ||
| 1845 | + break; | ||
| 1846 | + } | ||
| 1847 | + case RT_STREAM_ATTR_LAUNCH_BLOCKING_MODE: { | ||
| 1848 | + error = ValidateStreamLaunchBlockingGet(stm); | ||
| 1849 | + if (error == RT_ERROR_NONE) { | ||
| 1850 | + error = impl_->StreamGetAttribute(targetStm, stmAttrId, attrValue); | ||
| 1851 | + } | ||
| 1852 | + break; | ||
| 1853 | + } | ||
| 1854 | + default: { | ||
| 1855 | + RT_LOG_OUTER_MSG_INVALID_PARAM( | ||
| 1856 | + stmAttrId, | ||
| 1857 | + "[" + std::to_string(RT_STREAM_ATTR_FAILURE_MODE) + ", " + std::to_string(RT_STREAM_ATTR_MAX) + ")"); | ||
| 1858 | + error = RT_ERROR_INVALID_VALUE; | ||
| 1859 | + break; | ||
| 1860 | + } | ||
| 1861 | + } | ||
| 1862 | + return error; | ||
| 1863 | +} | ||
| 1864 | + | ||
| 1608 | rtError_t ApiErrorDecorator::StreamSetMode(Stream* const stm, const uint64_t stmMode) | 1865 | rtError_t ApiErrorDecorator::StreamSetMode(Stream* const stm, const uint64_t stmMode) |
| 1609 | { | 1866 | { |
| 1610 | - Stream* curStm = Runtime::Instance()->GetCurStream(stm); | 1867 | + Stream* curStm = nullptr; |
| 1611 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | 1868 | + const rtError_t checkError = ValidateStreamFailureModeSet(stm, curStm); |
| 1612 | - curStm, RT_ERROR_INVALID_VALUE, "Setting the error handling mode of a stream"); | 1869 | + COND_RETURN_WITH_NOLOG(checkError != RT_ERROR_NONE, checkError); |
| 1613 | - COND_RETURN_WARN( | ||
| 1614 | - (curStm->Flags() & RT_STREAM_CP_PROCESS_USE) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 1615 | - "Coprocessor stream flag=%u is not supported, stream_id=%d", curStm->Flags(), curStm->Id_()); | ||
| 1616 | #ifndef CFG_DEV_PLATFORM_PC | 1870 | #ifndef CFG_DEV_PLATFORM_PC |
| 1617 | const rtError_t error = impl_->StreamSetMode(curStm, stmMode); | 1871 | const rtError_t error = impl_->StreamSetMode(curStm, stmMode); |
| 1618 | ERROR_RETURN(error, "set stream mode failed."); | 1872 | ERROR_RETURN(error, "set stream mode failed."); |
| @@ -1625,11 +1879,9 @@ rtError_t ApiErrorDecorator::StreamSetMode(Stream* const stm, const uint64_t stm | |||
| 1625 | 1879 | ||
| 1626 | rtError_t ApiErrorDecorator::StreamGetMode(const Stream* const stm, uint64_t* const stmMode) | 1880 | rtError_t ApiErrorDecorator::StreamGetMode(const Stream* const stm, uint64_t* const stmMode) |
| 1627 | { | 1881 | { |
| 1628 | - Stream* curStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm)); | 1882 | + Stream* curStm = nullptr; |
| 1629 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | 1883 | + const rtError_t error = ValidateStreamFailureModeGet(const_cast<Stream*>(stm), stmMode, curStm); |
| 1630 | - curStm, RT_ERROR_INVALID_VALUE, "Obtaining the error handling mode of a stream"); | 1884 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); |
| 1631 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 1632 | - stmMode, RT_ERROR_INVALID_VALUE, "Obtaining the error handling mode of a stream"); | ||
| 1633 | return impl_->StreamGetMode(curStm, stmMode); | 1885 | return impl_->StreamGetMode(curStm, stmMode); |
| 1634 | } | 1886 | } |
| 1635 | 1887 | ||
| @@ -2875,22 +3127,21 @@ rtMemcpyKind_t ApiErrorDecorator::GetMemCpyKind(const rtMemcpyKind_t kind, const | |||
| 2875 | return kind; | 3127 | return kind; |
| 2876 | } | 3128 | } |
| 2877 | 3129 | ||
| 2878 | - static const std::unordered_map<rtMemcpyKind, rtMemcpyKind_t> KIND_MAP = { | 3130 | + static constexpr rtMemcpyKind_t KIND_MAP[] = { |
| 2879 | - {RT_MEMCPY_KIND_HOST_TO_HOST, RT_MEMCPY_HOST_TO_HOST}, | 3131 | + RT_MEMCPY_HOST_TO_HOST, // RT_MEMCPY_KIND_HOST_TO_HOST |
| 2880 | - {RT_MEMCPY_KIND_HOST_TO_DEVICE, RT_MEMCPY_HOST_TO_DEVICE}, | 3132 | + RT_MEMCPY_HOST_TO_DEVICE, // RT_MEMCPY_KIND_HOST_TO_DEVICE |
| 2881 | - {RT_MEMCPY_KIND_DEVICE_TO_HOST, RT_MEMCPY_DEVICE_TO_HOST}, | 3133 | + RT_MEMCPY_DEVICE_TO_HOST, // RT_MEMCPY_KIND_DEVICE_TO_HOST |
| 2882 | - {RT_MEMCPY_KIND_DEVICE_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE}, | 3134 | + RT_MEMCPY_DEVICE_TO_DEVICE, // RT_MEMCPY_KIND_DEVICE_TO_DEVICE |
| 2883 | - {RT_MEMCPY_KIND_DEFAULT, RT_MEMCPY_DEFAULT}, | 3135 | + RT_MEMCPY_DEFAULT, // RT_MEMCPY_KIND_DEFAULT |
| 2884 | - {RT_MEMCPY_KIND_HOST_TO_BUF_TO_DEVICE, RT_MEMCPY_HOST_TO_DEVICE_EX}, | 3136 | + RT_MEMCPY_HOST_TO_DEVICE_EX, // RT_MEMCPY_KIND_HOST_TO_BUF_TO_DEVICE |
| 2885 | - {RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE}, | 3137 | + RT_MEMCPY_DEVICE_TO_DEVICE, // RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE |
| 2886 | - {RT_MEMCPY_KIND_INTER_DEVICE_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE}, | 3138 | + RT_MEMCPY_DEVICE_TO_DEVICE // RT_MEMCPY_KIND_INTER_DEVICE_TO_DEVICE |
| 2887 | - {RT_MEMCPY_KIND_MAX, RT_MEMCPY_RESERVED}}; | 3139 | + }; |
| 2888 | - const auto iter = KIND_MAP.find(newKind); | 3140 | + const size_t index = static_cast<size_t>(newKind); |
| 2889 | - if (iter != KIND_MAP.end()) { | 3141 | + if (index >= (sizeof(KIND_MAP) / sizeof(KIND_MAP[0]))) { |
| 2890 | - return iter->second; | ||
| 2891 | - } else { | ||
| 2892 | return RT_MEMCPY_RESERVED; | 3142 | return RT_MEMCPY_RESERVED; |
| 2893 | } | 3143 | } |
| 3144 | + return KIND_MAP[index]; | ||
| 2894 | } | 3145 | } |
| 2895 | 3146 | ||
| 2896 | rtError_t ApiErrorDecorator::MemCopy2DCheckParam( | 3147 | rtError_t ApiErrorDecorator::MemCopy2DCheckParam( |
| @@ -5783,14 +6034,8 @@ rtError_t ApiErrorDecorator::GetDeviceSatModeForStream( | |||
| 5783 | 6034 | ||
| 5784 | rtError_t ApiErrorDecorator::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) | 6035 | rtError_t ApiErrorDecorator::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) |
| 5785 | { | 6036 | { |
| 5786 | - COND_RETURN_AND_MSG_OUTER_WITH_PARAM_AND_FUNC_DESC( | 6037 | + const rtError_t error = ValidateStreamOverflowSwitchSet(stm, flags); |
| 5787 | - flags >= static_cast<uint32_t>(RT_OVERFLOW_MODE_UNDEF), RT_ERROR_INVALID_VALUE, | 6038 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); |
| 5788 | - "Setting the stream overflow/underflow detection switch", flags, | ||
| 5789 | - "[" + std::to_string(RT_OVERFLOW_MODE_SATURATION) + ", " + std::to_string(RT_OVERFLOW_MODE_UNDEF) + ")"); | ||
| 5790 | - COND_RETURN_AND_MSG_OUTER( | ||
| 5791 | - (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, | ||
| 5792 | - "Setting the stream overflow/underflow detection switch", | ||
| 5793 | - RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_())); | ||
| 5794 | return impl_->SetStreamOverflowSwitch(stm, flags); | 6039 | return impl_->SetStreamOverflowSwitch(stm, flags); |
| 5795 | } | 6040 | } |
| 5796 | rtError_t ApiErrorDecorator::GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) | 6041 | rtError_t ApiErrorDecorator::GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) |
| @@ -5802,42 +6047,16 @@ rtError_t ApiErrorDecorator::GetStreamOverflowSwitch(Stream* const stm, uint32_t | |||
| 5802 | 6047 | ||
| 5803 | rtError_t ApiErrorDecorator::SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) | 6048 | rtError_t ApiErrorDecorator::SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) |
| 5804 | { | 6049 | { |
| 5805 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Setting the stream priority"); | ||
| 5806 | - COND_RETURN_ERROR( | ||
| 5807 | - (stm->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 5808 | - "The stream with flag %u does not support priority setting.", stm->Flags()); | ||
| 5809 | - COND_RETURN_AND_MSG_OUTER( | ||
| 5810 | - (stm->Flags() & RT_STREAM_AICPU) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006, | ||
| 5811 | - "Setting the stream priority", "Parameter stm->Flags() value " + std::to_string(stm->Flags()), | ||
| 5812 | - "The current stream is used to carry AI CPU scheduling tasks and does not support priority setting"); | ||
| 5813 | - const int32_t validPriority = static_cast<int32_t>(streamPriority); | ||
| 5814 | uint32_t priority = streamPriority; | 6050 | uint32_t priority = streamPriority; |
| 5815 | - if (validPriority < RT_STREAM_GREATEST_PRIORITY) { | 6051 | + const rtError_t error = ValidateStreamPrioritySet(stm, streamPriority, priority); |
| 5816 | - priority = RT_STREAM_GREATEST_PRIORITY; | 6052 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); |
| 5817 | - } else if (validPriority > RT_STREAM_LEAST_PRIORITY) { | ||
| 5818 | - priority = RT_STREAM_LEAST_PRIORITY; | ||
| 5819 | - } else { | ||
| 5820 | - // no operation | ||
| 5821 | - } | ||
| 5822 | - if (priority != streamPriority) { | ||
| 5823 | - RT_LOG( | ||
| 5824 | - RT_LOG_INFO, "Input priority=%d is out of range [%u, %u], adjusted to %u", validPriority, | ||
| 5825 | - RT_STREAM_GREATEST_PRIORITY, RT_STREAM_LEAST_PRIORITY, priority); | ||
| 5826 | - } | ||
| 5827 | return impl_->SetStreamPriorityValue(stm, priority); | 6053 | return impl_->SetStreamPriorityValue(stm, priority); |
| 5828 | } | 6054 | } |
| 5829 | 6055 | ||
| 5830 | rtError_t ApiErrorDecorator::GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) | 6056 | rtError_t ApiErrorDecorator::GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) |
| 5831 | { | 6057 | { |
| 5832 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(streamPriority, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority"); | 6058 | + const rtError_t error = ValidateStreamPriorityGet(stm, streamPriority); |
| 5833 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority"); | 6059 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); |
| 5834 | - COND_RETURN_ERROR( | ||
| 5835 | - (stm->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, | ||
| 5836 | - "The stream with flag %u does not support priority setting.", stm->Flags()); | ||
| 5837 | - COND_RETURN_AND_MSG_OUTER( | ||
| 5838 | - (stm->Flags() & RT_STREAM_AICPU) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006, | ||
| 5839 | - "Obtaining the stream priority", "Parameter stm->Flags() value " + std::to_string(stm->Flags()), | ||
| 5840 | - "The current stream is used to carry AI CPU scheduling tasks and does not support priority getting"); | ||
| 5841 | return impl_->GetStreamPriorityValue(stm, streamPriority); | 6060 | return impl_->GetStreamPriorityValue(stm, streamPriority); |
| 5842 | } | 6061 | } |
| 5843 | 6062 | ||
| @@ -5884,9 +6103,8 @@ rtError_t ApiErrorDecorator::DvppWaitGroupReport( | |||
| 5884 | 6103 | ||
| 5885 | rtError_t ApiErrorDecorator::SetStreamTag(Stream* const stm, const uint32_t geOpTag) | 6104 | rtError_t ApiErrorDecorator::SetStreamTag(Stream* const stm, const uint32_t geOpTag) |
| 5886 | { | 6105 | { |
| 5887 | - COND_RETURN_AND_MSG_OUTER( | 6106 | + const rtError_t checkError = ValidateStreamTagSet(stm); |
| 5888 | - (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Setting the stream tag", | 6107 | + COND_RETURN_WITH_NOLOG(checkError != RT_ERROR_NONE, checkError); |
| 5889 | - RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_())); | ||
| 5890 | const rtError_t error = impl_->SetStreamTag(stm, geOpTag); | 6108 | const rtError_t error = impl_->SetStreamTag(stm, geOpTag); |
| 5891 | ERROR_RETURN(error, "set stream geOpTag failed."); | 6109 | ERROR_RETURN(error, "set stream geOpTag failed."); |
| 5892 | return error; | 6110 | return error; |
| @@ -6697,24 +6915,17 @@ rtError_t ApiErrorDecorator::GetDeviceUuid(const int32_t devId, rtUuid_t* uuid) | |||
| 6697 | 6915 | ||
| 6698 | rtError_t ApiErrorDecorator::SetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t cacheOpInfoSwitch) | 6916 | rtError_t ApiErrorDecorator::SetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t cacheOpInfoSwitch) |
| 6699 | { | 6917 | { |
| 6700 | - Stream* curStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm)); | 6918 | + Stream* curStm = nullptr; |
| 6701 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | 6919 | + const rtError_t error = ValidateStreamCacheOpInfoSet(stm, cacheOpInfoSwitch, curStm); |
| 6702 | - curStm, RT_ERROR_INVALID_VALUE, "Setting the switch for caching operator information in a stream"); | 6920 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); |
| 6703 | - if (cacheOpInfoSwitch != 0U && cacheOpInfoSwitch != 1U) { | ||
| 6704 | - return RT_ERROR_INVALID_VALUE; | ||
| 6705 | - } | ||
| 6706 | - | ||
| 6707 | return impl_->SetStreamCacheOpInfoSwitch(curStm, cacheOpInfoSwitch); | 6921 | return impl_->SetStreamCacheOpInfoSwitch(curStm, cacheOpInfoSwitch); |
| 6708 | } | 6922 | } |
| 6709 | 6923 | ||
| 6710 | rtError_t ApiErrorDecorator::GetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t* const cacheOpInfoSwitch) | 6924 | rtError_t ApiErrorDecorator::GetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t* const cacheOpInfoSwitch) |
| 6711 | { | 6925 | { |
| 6712 | - Stream* curStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm)); | 6926 | + Stream* curStm = nullptr; |
| 6713 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | 6927 | + const rtError_t error = ValidateStreamCacheOpInfoGet(stm, cacheOpInfoSwitch, curStm); |
| 6714 | - curStm, RT_ERROR_INVALID_VALUE, "Querying whether the operator information is cached"); | 6928 | + COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error); |
| 6715 | - NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | ||
| 6716 | - cacheOpInfoSwitch, RT_ERROR_INVALID_VALUE, "Querying whether the operator information is cached"); | ||
| 6717 | - | ||
| 6718 | return impl_->GetStreamCacheOpInfoSwitch(curStm, cacheOpInfoSwitch); | 6929 | return impl_->GetStreamCacheOpInfoSwitch(curStm, cacheOpInfoSwitch); |
| 6719 | } | 6930 | } |
| 6720 | 6931 | ||
| @@ -16,6 +16,11 @@ | |||
| 16 | 16 | ||
| 17 | namespace cce { | 17 | namespace cce { |
| 18 | namespace runtime { | 18 | namespace runtime { |
| 19 | + | ||
| 20 | +// Keep launch-blocking validation in the standard/tiny source split so tiny retains its unsupported stub. | ||
| 21 | +rtError_t ValidateStreamLaunchBlockingSet(const Stream* const stm, const uint32_t launchBlockingMode); | ||
| 22 | +rtError_t ValidateStreamLaunchBlockingGet(const Stream* const stm); | ||
| 23 | + | ||
| 19 | class ApiErrorDecorator : public ApiDecorator { | 24 | class ApiErrorDecorator : public ApiDecorator { |
| 20 | public: | 25 | public: |
| 21 | explicit ApiErrorDecorator(Api* const impl); | 26 | explicit ApiErrorDecorator(Api* const impl); |
| @@ -137,6 +142,8 @@ public: | |||
| 137 | Stream* const stm, Event* const evt, const uint32_t timeout, | 142 | Stream* const stm, Event* const evt, const uint32_t timeout, |
| 138 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) override; | 143 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) override; |
| 139 | rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout) override; | 144 | rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout) override; |
| 145 | + rtError_t NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) override; | ||
| 146 | + rtError_t NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) override; | ||
| 140 | rtError_t StreamQuery(Stream* const stm) override; | 147 | rtError_t StreamQuery(Stream* const stm) override; |
| 141 | rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) override; | 148 | rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) override; |
| 142 | rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) override; | 149 | rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) override; |
| @@ -474,6 +481,10 @@ public: | |||
| 474 | rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) override; | 481 | rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) override; |
| 475 | rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) override; | 482 | rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) override; |
| 476 | rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) override; | 483 | rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) override; |
| 484 | + rtError_t StreamSetAttribute( | ||
| 485 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) override; | ||
| 486 | + rtError_t StreamGetAttribute( | ||
| 487 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) override; | ||
| 477 | // model | 488 | // model |
| 478 | rtError_t ModelCreate(Model** const mdl, const uint32_t flag) override; | 489 | rtError_t ModelCreate(Model** const mdl, const uint32_t flag) override; |
| 479 | rtError_t ModelSetExtId(Model* const mdl, const uint32_t extId) override; | 490 | rtError_t ModelSetExtId(Model* const mdl, const uint32_t extId) override; |
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "event.hpp" | 18 | #include "event.hpp" |
| 19 | #include "elf.hpp" | 19 | #include "elf.hpp" |
| 20 | #include "runtime/kernel.h" | 20 | #include "runtime/kernel.h" |
| 21 | +#include "runtime/rts/rts_stream.h" | ||
| 21 | #include "error_message_manage.hpp" | 22 | #include "error_message_manage.hpp" |
| 22 | #include "capture_model_utils.hpp" | 23 | #include "capture_model_utils.hpp" |
| 23 | #include "npu_driver.hpp" | 24 | #include "npu_driver.hpp" |
| @@ -25,9 +26,109 @@ | |||
| 25 | namespace cce { | 26 | namespace cce { |
| 26 | namespace runtime { | 27 | namespace runtime { |
| 27 | constexpr uint32_t TASK_ABORT_TIMEOUT_MAX = (36 * 60 * 1000U); // 36min | 28 | constexpr uint32_t TASK_ABORT_TIMEOUT_MAX = (36 * 60 * 1000U); // 36min |
| 29 | +constexpr uint32_t LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS = | ||
| 30 | + RT_STREAM_PERSISTENT | RT_STREAM_AICPU | RT_STREAM_CP_PROCESS_USE; | ||
| 28 | static string g_fusionSubTypeStr[RT_FUSION_END] = {"HCOM", "AICPU", "AIC", "CCU"}; | 31 | static string g_fusionSubTypeStr[RT_FUSION_END] = {"HCOM", "AICPU", "AIC", "CCU"}; |
| 29 | static unordered_set<string> g_fusionAllowedList{"HCOMAIC", "AICPUAIC", "CCUAIC", "CCU"}; | 32 | static unordered_set<string> g_fusionAllowedList{"HCOMAIC", "AICPUAIC", "CCUAIC", "CCU"}; |
| 30 | 33 | ||
| 34 | +rtError_t ValidateStreamLaunchBlockingSet(const Stream* const stream, const uint32_t launchBlockingMode) | ||
| 35 | +{ | ||
| 36 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 37 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)) { | ||
| 38 | + RT_LOG(RT_LOG_WARNING, "chip type(%d) does not support.", static_cast<int32_t>(chipType)); | ||
| 39 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 40 | + } | ||
| 41 | + COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_AND_FUNC_DESC( | ||
| 42 | + launchBlockingMode > RT_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING, RT_ERROR_INVALID_VALUE, | ||
| 43 | + "Setting the stream launch blocking mode", RtFmtMsg("UNKNOWN(%u)", launchBlockingMode), "launchBlockingMode", | ||
| 44 | + "[0, 3)"); | ||
跟测试对齐,现在这种数字区间是否满足规范 ![]() ![]() | |||
| 45 | + if (stream != nullptr) { | ||
| 46 | + COND_RETURN_AND_MSG_OUTER( | ||
| 47 | + stream->IsModelStream() || stream->GetBindFlag() || | ||
| 48 | + ((stream->Flags() & LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS) != 0U), | ||
| 49 | + RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016, "Setting the stream launch blocking mode", | ||
| 50 | + RtFmtMsg( | ||
| 51 | + "Stream (stream_id=%d) does not support launch blocking control because it is a model stream, a bound " | ||
| 52 | + "stream, or has RT_STREAM_PERSISTENT, RT_STREAM_AICPU, or RT_STREAM_CP_PROCESS_USE set", | ||
| 53 | + stream->Id_())); | ||
| 54 | + COND_RETURN_AND_MSG_OUTER( | ||
| 55 | + stream->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, | ||
| 56 | + "Setting the stream launch blocking mode", | ||
| 57 | + RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stream->Id_())); | ||
| 58 | + } | ||
| 59 | + return RT_ERROR_NONE; | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +rtError_t ValidateStreamLaunchBlockingGet(const Stream* const stream) | ||
| 63 | +{ | ||
| 64 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 65 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)) { | ||
| 66 | + RT_LOG(RT_LOG_WARNING, "chip type(%d) does not support.", static_cast<int32_t>(chipType)); | ||
| 67 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 68 | + } | ||
| 69 | + if (stream != nullptr) { | ||
| 70 | + COND_RETURN_AND_MSG_OUTER( | ||
| 71 | + stream->IsModelStream() || stream->GetBindFlag() || | ||
| 72 | + ((stream->Flags() & LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS) != 0U), | ||
| 73 | + RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016, "Obtaining the stream launch blocking mode", | ||
| 74 | + RtFmtMsg( | ||
| 75 | + "Stream (stream_id=%d) does not support launch blocking control because it is a model stream, a bound " | ||
| 76 | + "stream, or has RT_STREAM_PERSISTENT, RT_STREAM_AICPU, or RT_STREAM_CP_PROCESS_USE set", | ||
| 77 | + stream->Id_())); | ||
| 78 | + COND_RETURN_AND_MSG_OUTER( | ||
| 79 | + stream->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, | ||
| 80 | + "Obtaining the stream launch blocking mode", | ||
| 81 | + RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stream->Id_())); | ||
| 82 | + } | ||
| 83 | + return RT_ERROR_NONE; | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +rtError_t ApiErrorDecorator::NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) | ||
| 87 | +{ | ||
| 88 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 89 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)) { | ||
| 90 | + RT_LOG(RT_LOG_WARNING, "chip type(%d) does not support.", static_cast<int32_t>(chipType)); | ||
| 91 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 92 | + } | ||
| 93 | + Stream* const targetStm = Runtime::Instance()->GetCurStream(stream); | ||
| 94 | + NULL_PTR_RETURN(targetStm, RT_ERROR_INVALID_VALUE); | ||
| 95 | + COND_RETURN_AND_MSG_OUTER( | ||
| 96 | + targetStm->IsModelStream() || targetStm->GetBindFlag() || | ||
| 97 | + ((targetStm->Flags() & LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS) != 0U), | ||
| 98 | + RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016, "Starting a non-blocking launch section", | ||
| 99 | + RtFmtMsg( | ||
| 100 | + "Stream (stream_id=%d) does not support launch blocking control because it is a model stream, a bound " | ||
| 101 | + "stream, or has RT_STREAM_PERSISTENT, RT_STREAM_AICPU, or RT_STREAM_CP_PROCESS_USE set", | ||
| 102 | + targetStm->Id_())); | ||
| 103 | + COND_RETURN_AND_MSG_OUTER( | ||
| 104 | + targetStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Starting a non-blocking launch section", | ||
| 105 | + RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", targetStm->Id_())); | ||
| 106 | + return impl_->NonBlockingLaunchBegin(targetStm, flag); | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +rtError_t ApiErrorDecorator::NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) | ||
| 110 | +{ | ||
| 111 | + const rtChipType_t chipType = Runtime::Instance()->GetChipType(); | ||
| 112 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)) { | ||
| 113 | + RT_LOG(RT_LOG_WARNING, "chip type(%d) does not support.", static_cast<int32_t>(chipType)); | ||
| 114 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 115 | + } | ||
| 116 | + Stream* const targetStm = Runtime::Instance()->GetCurStream(stream); | ||
| 117 | + NULL_PTR_RETURN(targetStm, RT_ERROR_INVALID_VALUE); | ||
| 118 | + COND_RETURN_AND_MSG_OUTER( | ||
| 119 | + targetStm->IsModelStream() || targetStm->GetBindFlag() || | ||
| 120 | + ((targetStm->Flags() & LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS) != 0U), | ||
| 121 | + RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016, "Ending a non-blocking launch section", | ||
| 122 | + RtFmtMsg( | ||
| 123 | + "Stream (stream_id=%d) does not support launch blocking control because it is a model stream, a bound " | ||
| 124 | + "stream, or has RT_STREAM_PERSISTENT, RT_STREAM_AICPU, or RT_STREAM_CP_PROCESS_USE set", | ||
| 125 | + targetStm->Id_())); | ||
| 126 | + COND_RETURN_AND_MSG_OUTER( | ||
| 127 | + targetStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Ending a non-blocking launch section", | ||
| 128 | + RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", targetStm->Id_())); | ||
| 129 | + return impl_->NonBlockingLaunchEnd(targetStm, flag); | ||
| 130 | +} | ||
| 131 | + | ||
| 31 | rtError_t ApiErrorDecorator::WriteValuePtr(void* const writeValueInfo, Stream* const stm, void* const pointedAddr) | 132 | rtError_t ApiErrorDecorator::WriteValuePtr(void* const writeValueInfo, Stream* const stm, void* const pointedAddr) |
| 32 | { | 133 | { |
| 33 | NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( | 134 | NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC( |
| @@ -12,6 +12,33 @@ | |||
| 12 | namespace cce { | 12 | namespace cce { |
| 13 | namespace runtime { | 13 | namespace runtime { |
| 14 | 14 | ||
| 15 | +rtError_t ValidateStreamLaunchBlockingSet(const Stream* const stm, const uint32_t launchBlockingMode) | ||
| 16 | +{ | ||
| 17 | + UNUSED(stm); | ||
| 18 | + UNUSED(launchBlockingMode); | ||
| 19 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +rtError_t ValidateStreamLaunchBlockingGet(const Stream* const stm) | ||
| 23 | +{ | ||
| 24 | + UNUSED(stm); | ||
| 25 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +rtError_t ApiErrorDecorator::NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) | ||
| 29 | +{ | ||
| 30 | + UNUSED(stream); | ||
| 31 | + UNUSED(flag); | ||
| 32 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +rtError_t ApiErrorDecorator::NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) | ||
| 36 | +{ | ||
| 37 | + UNUSED(stream); | ||
| 38 | + UNUSED(flag); | ||
| 39 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 40 | +} | ||
| 41 | + | ||
| 15 | rtError_t ApiErrorDecorator::WriteValuePtr(void* const writeValueInfo, Stream* const stm, void* const pointedAddr) | 42 | rtError_t ApiErrorDecorator::WriteValuePtr(void* const writeValueInfo, Stream* const stm, void* const pointedAddr) |
| 16 | { | 43 | { |
| 17 | UNUSED(writeValueInfo); | 44 | UNUSED(writeValueInfo); |
| @@ -55,6 +55,7 @@ | |||
| 55 | #include "stream_factory.hpp" | 55 | #include "stream_factory.hpp" |
| 56 | #include "device/device_error_proc.hpp" | 56 | #include "device/device_error_proc.hpp" |
| 57 | #include "stream_state_callback_manager.hpp" | 57 | #include "stream_state_callback_manager.hpp" |
| 58 | +#include "stream_launch_blocking.hpp" | ||
| 58 | #include "heterogenous.h" | 59 | #include "heterogenous.h" |
| 59 | #include "capture_model.hpp" | 60 | #include "capture_model.hpp" |
| 60 | #include "capture_model_enum_desc.hpp" | 61 | #include "capture_model_enum_desc.hpp" |
| @@ -1350,6 +1351,9 @@ rtError_t ApiImpl::LaunchKernelV2( | |||
| 1350 | break; | 1351 | break; |
| 1351 | } | 1352 | } |
| 1352 | 1353 | ||
| 1354 | + if ((error == RT_ERROR_NONE) && StreamLaunchBlocking::ShouldLaunchBlock(curStm)) { | ||
| 1355 | + return curStm->Synchronize(false); | ||
| 1356 | + } | ||
| 1353 | return error; | 1357 | return error; |
| 1354 | } | 1358 | } |
| 1355 | 1359 | ||
| @@ -1376,7 +1380,11 @@ rtError_t ApiImpl::LaunchKernel( | |||
| 1376 | rtStreamLaunchKernelV2ExtendArgs_t launchKernelExtendArgs = {}; | 1380 | rtStreamLaunchKernelV2ExtendArgs_t launchKernelExtendArgs = {}; |
| 1377 | launchKernelExtendArgs.argsInfo = argsInfo; | 1381 | launchKernelExtendArgs.argsInfo = argsInfo; |
| 1378 | launchKernelExtendArgs.taskCfg = &taskCfg; | 1382 | launchKernelExtendArgs.taskCfg = &taskCfg; |
| 1379 | - return StreamLaunchKernelV2(kernel, blockDim, curStm, &launchKernelExtendArgs); | 1383 | + const rtError_t error = StreamLaunchKernelV2(kernel, blockDim, curStm, &launchKernelExtendArgs); |
| 1384 | + if ((error == RT_ERROR_NONE) && StreamLaunchBlocking::ShouldLaunchBlock(curStm)) { | ||
| 1385 | + return curStm->Synchronize(false); | ||
| 1386 | + } | ||
| 1387 | + return error; | ||
| 1380 | } | 1388 | } |
| 1381 | 1389 | ||
| 1382 | rtError_t ApiImpl::DatadumpInfoLoad(const void* const dumpInfo, const uint32_t length, const uint32_t flag) | 1390 | rtError_t ApiImpl::DatadumpInfoLoad(const void* const dumpInfo, const uint32_t length, const uint32_t flag) |
| @@ -1957,10 +1965,10 @@ rtError_t ApiImpl::SetDeviceFailureMode(uint64_t failureMode) | |||
| 1957 | return RT_ERROR_NONE; | 1965 | return RT_ERROR_NONE; |
| 1958 | } | 1966 | } |
| 1959 | 1967 | ||
| 1960 | -rtError_t ApiImpl::StreamSetMode(Stream* const stm, const uint64_t stmMode) | 1968 | +static rtError_t SetStreamFailureModeInternal(Stream* const stm, const uint64_t stmMode) |
| 1961 | { | 1969 | { |
| 1962 | RT_LOG(RT_LOG_DEBUG, "set stream mode entry, stream_id=%d, mode=%llu.", stm->Id_(), stmMode); | 1970 | RT_LOG(RT_LOG_DEBUG, "set stream mode entry, stream_id=%d, mode=%llu.", stm->Id_(), stmMode); |
| 1963 | - Context* const curCtx = CurrentContext(); | 1971 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); |
| 1964 | CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | 1972 | CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); |
| 1965 | Device* const dev = curCtx->Device_(); | 1973 | Device* const dev = curCtx->Device_(); |
| 1966 | COND_RETURN_AND_MSG_OUTER( | 1974 | COND_RETURN_AND_MSG_OUTER( |
| @@ -2000,13 +2008,198 @@ rtError_t ApiImpl::StreamSetMode(Stream* const stm, const uint64_t stmMode) | |||
| 2000 | return curStm->SetFailMode(failmode); | 2008 | return curStm->SetFailMode(failmode); |
| 2001 | } | 2009 | } |
| 2002 | 2010 | ||
| 2003 | -rtError_t ApiImpl::StreamGetMode(const Stream* const stm, uint64_t* const stmMode) | 2011 | +static rtError_t GetStreamFailureModeInternal(const Stream* const stm, uint64_t* const stmMode) |
| 2004 | { | 2012 | { |
| 2005 | *stmMode = stm->GetMode(); | 2013 | *stmMode = stm->GetMode(); |
| 2006 | RT_LOG(RT_LOG_DEBUG, "get stream_id=%d mode entry, mode = %llu.", stm->Id_(), *stmMode); | 2014 | RT_LOG(RT_LOG_DEBUG, "get stream_id=%d mode entry, mode = %llu.", stm->Id_(), *stmMode); |
| 2007 | return RT_ERROR_NONE; | 2015 | return RT_ERROR_NONE; |
| 2008 | } | 2016 | } |
| 2009 | 2017 | ||
| 2018 | +static rtError_t SetStreamOverflowSwitchInternal(Stream* const stm, const uint32_t flags) | ||
| 2019 | +{ | ||
| 2020 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 2021 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 2022 | + | ||
| 2023 | + Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 2024 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 2025 | + COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 2026 | + targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Setting the stream overflow/underflow detection switch"); | ||
| 2027 | + return curCtx->SetStreamOverflowSwitch(targetStm, flags); | ||
| 2028 | +} | ||
| 2029 | + | ||
| 2030 | +static rtError_t GetStreamOverflowSwitchInternal(const Stream* const stm, uint32_t* const flags) | ||
| 2031 | +{ | ||
| 2032 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 2033 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 2034 | + const Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 2035 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 2036 | + COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 2037 | + targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, | ||
| 2038 | + "Obtaining the overflow/underflow detection flag of a specified stream"); | ||
| 2039 | + | ||
| 2040 | + *flags = Runtime::Instance()->ChipIsHaveStars() ? static_cast<uint32_t>(targetStm->GetOverflowSwtich()) : 1U; | ||
| 2041 | + return RT_ERROR_NONE; | ||
| 2042 | +} | ||
| 2043 | + | ||
| 2044 | +static rtError_t SetStreamPriorityInternal(Stream* const stm, const uint32_t streamPriority) | ||
| 2045 | +{ | ||
| 2046 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 2047 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 2048 | + | ||
| 2049 | + Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 2050 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 2051 | + return targetStm->Device_()->Driver_()->SetStreamPriorityValue(targetStm, streamPriority); | ||
| 2052 | +} | ||
| 2053 | + | ||
| 2054 | +static rtError_t GetStreamPriorityInternal(Stream* const stm, uint32_t* const streamPriority) | ||
| 2055 | +{ | ||
| 2056 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 2057 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 2058 | + | ||
| 2059 | + Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 2060 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 2061 | + return targetStm->Device_()->Driver_()->GetStreamPriorityValue(targetStm, streamPriority); | ||
| 2062 | +} | ||
| 2063 | + | ||
| 2064 | +static rtError_t SetStreamTagInternal(Stream* const stm, const uint32_t geOpTag) | ||
| 2065 | +{ | ||
| 2066 | + RT_LOG(RT_LOG_DEBUG, "geOpTag=%#x.", geOpTag); | ||
| 2067 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 2068 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 2069 | + | ||
| 2070 | + Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 2071 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 2072 | + COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 2073 | + targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Setting the stream tag"); | ||
| 2074 | + return curCtx->SetStreamTag(targetStm, geOpTag); | ||
| 2075 | +} | ||
| 2076 | + | ||
| 2077 | +static rtError_t GetStreamTagInternal(const Stream* const stm, uint32_t* const geOpTag) | ||
| 2078 | +{ | ||
| 2079 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 2080 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 2081 | + const Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 2082 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 2083 | + COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 2084 | + targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Obtaining the stream label"); | ||
| 2085 | + | ||
| 2086 | + *geOpTag = static_cast<uint32_t>(targetStm->GetStreamTag()); | ||
| 2087 | + return RT_ERROR_NONE; | ||
| 2088 | +} | ||
| 2089 | + | ||
| 2090 | +static rtError_t SetStreamCacheOpInfoInternal(const Stream* const stm, const uint32_t cacheOpInfoSwitch) | ||
| 2091 | +{ | ||
| 2092 | + // The ctx is not checked for performance. | ||
| 2093 | + stm->SetStreamCacheOpInfoOriginSwitch(cacheOpInfoSwitch); | ||
| 2094 | + RT_LOG( | ||
| 2095 | + RT_LOG_DEBUG, "device_id=%u, stream_id=%u, cacheOpInfoSwitch=%u.", stm->Device_()->Id_(), stm->Id_(), | ||
| 2096 | + cacheOpInfoSwitch); | ||
| 2097 | + | ||
| 2098 | + if (stm->IsCapturing() && stm->GetCaptureStream() != nullptr && stm->GetCaptureStream()->IsOrigCaptureStream()) { | ||
| 2099 | + CaptureModel* mdl = dynamic_cast<CaptureModel*>(stm->GetCaptureStream()->Model_()); | ||
| 2100 | + RT_LOG( | ||
| 2101 | + RT_LOG_INFO, "set cache op info switch status, model_id = %u, stream_id=%u, status=%u.", mdl->Id_(), | ||
| 2102 | + stm->Id_(), cacheOpInfoSwitch); | ||
| 2103 | + mdl->SetModelCacheOpInfoSwitch(cacheOpInfoSwitch); | ||
| 2104 | + } | ||
| 2105 | + | ||
| 2106 | + return RT_ERROR_NONE; | ||
| 2107 | +} | ||
| 2108 | + | ||
| 2109 | +static rtError_t GetStreamCacheOpInfoInternal(const Stream* const stm, uint32_t* const cacheOpInfoSwitch) | ||
| 2110 | +{ | ||
| 2111 | + // The ctx is not checked for performance. | ||
| 2112 | + // main stream is not closed & this stream is opened | ||
| 2113 | + *cacheOpInfoSwitch = stm->GetStreamCacheOpInfoSwitch(); | ||
| 2114 | + return RT_ERROR_NONE; | ||
| 2115 | +} | ||
| 2116 | + | ||
| 2117 | +rtError_t ApiImpl::StreamSetAttribute( | ||
| 2118 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) | ||
| 2119 | +{ | ||
| 2120 | + NULL_PTR_RETURN_MSG(attrValue, RT_ERROR_INVALID_VALUE); | ||
| 2121 | + rtError_t error; | ||
| 2122 | + switch (stmAttrId) { | ||
| 2123 | + case RT_STREAM_ATTR_FAILURE_MODE: { | ||
| 2124 | + error = SetStreamFailureModeInternal(stm, attrValue->failureMode); | ||
| 2125 | + break; | ||
| 2126 | + } | ||
| 2127 | + case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | ||
| 2128 | + error = SetStreamOverflowSwitchInternal(stm, attrValue->overflowSwitch); | ||
| 2129 | + break; | ||
| 2130 | + } | ||
| 2131 | + case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 2132 | + error = SetStreamTagInternal(stm, attrValue->userCustomTag); | ||
| 2133 | + break; | ||
| 2134 | + } | ||
| 2135 | + case RT_STREAM_ATTR_CACHE_OP_INFO: { | ||
| 2136 | + error = SetStreamCacheOpInfoInternal(stm, attrValue->cacheOpInfoSwitch); | ||
| 2137 | + break; | ||
| 2138 | + } | ||
| 2139 | + case RT_STREAM_ATTR_PRIORITY: { | ||
| 2140 | + error = SetStreamPriorityInternal(stm, attrValue->streamPriority); | ||
| 2141 | + break; | ||
| 2142 | + } | ||
| 2143 | + case RT_STREAM_ATTR_LAUNCH_BLOCKING_MODE: { | ||
| 2144 | + error = StreamLaunchBlocking::SetLaunchBlockingMode(stm, attrValue->launchBlockingMode); | ||
| 2145 | + break; | ||
| 2146 | + } | ||
| 2147 | + default: { | ||
| 2148 | + error = RT_ERROR_INVALID_VALUE; | ||
| 2149 | + break; | ||
| 2150 | + } | ||
| 2151 | + } | ||
| 2152 | + return error; | ||
| 2153 | +} | ||
| 2154 | + | ||
| 2155 | +rtError_t ApiImpl::StreamGetAttribute( | ||
| 2156 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) | ||
| 2157 | +{ | ||
| 2158 | + NULL_PTR_RETURN_MSG(attrValue, RT_ERROR_INVALID_VALUE); | ||
| 2159 | + rtError_t error; | ||
| 2160 | + switch (stmAttrId) { | ||
| 2161 | + case RT_STREAM_ATTR_FAILURE_MODE: { | ||
| 2162 | + error = GetStreamFailureModeInternal(stm, &attrValue->failureMode); | ||
| 2163 | + break; | ||
| 2164 | + } | ||
| 2165 | + case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | ||
| 2166 | + error = GetStreamOverflowSwitchInternal(stm, &attrValue->overflowSwitch); | ||
| 2167 | + break; | ||
| 2168 | + } | ||
| 2169 | + case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 2170 | + error = GetStreamTagInternal(stm, &attrValue->userCustomTag); | ||
| 2171 | + break; | ||
| 2172 | + } | ||
| 2173 | + case RT_STREAM_ATTR_CACHE_OP_INFO: { | ||
| 2174 | + error = GetStreamCacheOpInfoInternal(stm, &attrValue->cacheOpInfoSwitch); | ||
| 2175 | + break; | ||
| 2176 | + } | ||
| 2177 | + case RT_STREAM_ATTR_PRIORITY: { | ||
| 2178 | + error = GetStreamPriorityInternal(stm, &attrValue->streamPriority); | ||
| 2179 | + break; | ||
| 2180 | + } | ||
| 2181 | + case RT_STREAM_ATTR_LAUNCH_BLOCKING_MODE: { | ||
| 2182 | + error = StreamLaunchBlocking::GetLaunchBlockingMode(stm, &attrValue->launchBlockingMode); | ||
| 2183 | + break; | ||
| 2184 | + } | ||
| 2185 | + default: { | ||
| 2186 | + error = RT_ERROR_INVALID_VALUE; | ||
| 2187 | + break; | ||
| 2188 | + } | ||
| 2189 | + } | ||
| 2190 | + return error; | ||
| 2191 | +} | ||
| 2192 | + | ||
| 2193 | +rtError_t ApiImpl::StreamSetMode(Stream* const stm, const uint64_t stmMode) | ||
| 2194 | +{ | ||
| 2195 | + return SetStreamFailureModeInternal(stm, stmMode); | ||
| 2196 | +} | ||
| 2197 | + | ||
| 2198 | +rtError_t ApiImpl::StreamGetMode(const Stream* const stm, uint64_t* const stmMode) | ||
| 2199 | +{ | ||
| 2200 | + return GetStreamFailureModeInternal(stm, stmMode); | ||
| 2201 | +} | ||
| 2202 | + | ||
| 2010 | rtError_t ApiImpl::EventCreate(Event** const evt, const uint64_t flag) | 2203 | rtError_t ApiImpl::EventCreate(Event** const evt, const uint64_t flag) |
| 2011 | { | 2204 | { |
| 2012 | RT_LOG(RT_LOG_DEBUG, "flag=%" PRIu64 ".", flag); | 2205 | RT_LOG(RT_LOG_DEBUG, "flag=%" PRIu64 ".", flag); |
| @@ -5886,48 +6079,22 @@ rtError_t ApiImpl::GetDeviceSatModeForStream(Stream* const stm, rtFloatOverflowM | |||
| 5886 | 6079 | ||
| 5887 | rtError_t ApiImpl::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) | 6080 | rtError_t ApiImpl::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) |
| 5888 | { | 6081 | { |
| 5889 | - Context* const curCtx = CurrentContext(); | 6082 | + return SetStreamOverflowSwitchInternal(stm, flags); |
| 5890 | - CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 5891 | - | ||
| 5892 | - Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 5893 | - NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 5894 | - COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 5895 | - targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Setting the stream overflow/underflow detection switch"); | ||
| 5896 | - return curCtx->SetStreamOverflowSwitch(targetStm, flags); | ||
| 5897 | } | 6083 | } |
| 5898 | 6084 | ||
| 5899 | rtError_t ApiImpl::GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) | 6085 | rtError_t ApiImpl::GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) |
| 5900 | { | 6086 | { |
| 5901 | - Context* const curCtx = CurrentContext(); | 6087 | + return GetStreamOverflowSwitchInternal(stm, flags); |
| 5902 | - CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 5903 | - Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 5904 | - NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 5905 | - COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 5906 | - targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, | ||
| 5907 | - "Obtaining the overflow/underflow detection flag of a specified stream"); | ||
| 5908 | - | ||
| 5909 | - *flags = Runtime::Instance()->ChipIsHaveStars() ? static_cast<uint32_t>(targetStm->GetOverflowSwtich()) : 1U; | ||
| 5910 | - return RT_ERROR_NONE; | ||
| 5911 | } | 6088 | } |
| 5912 | 6089 | ||
| 5913 | rtError_t ApiImpl::SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) | 6090 | rtError_t ApiImpl::SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) |
| 5914 | { | 6091 | { |
| 5915 | - Context* const curCtx = CurrentContext(); | 6092 | + return SetStreamPriorityInternal(stm, streamPriority); |
| 5916 | - CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 5917 | - | ||
| 5918 | - Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 5919 | - NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 5920 | - return targetStm->Device_()->Driver_()->SetStreamPriorityValue(targetStm, streamPriority); | ||
| 5921 | } | 6093 | } |
| 5922 | 6094 | ||
| 5923 | rtError_t ApiImpl::GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) | 6095 | rtError_t ApiImpl::GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) |
| 5924 | { | 6096 | { |
| 5925 | - Context* const curCtx = CurrentContext(); | 6097 | + return GetStreamPriorityInternal(stm, streamPriority); |
| 5926 | - CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 5927 | - | ||
| 5928 | - Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 5929 | - NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 5930 | - return targetStm->Device_()->Driver_()->GetStreamPriorityValue(targetStm, streamPriority); | ||
| 5931 | } | 6098 | } |
| 5932 | 6099 | ||
| 5933 | rtError_t ApiImpl::DvppGroupCreate(DvppGrp** grp, const uint32_t flags) | 6100 | rtError_t ApiImpl::DvppGroupCreate(DvppGrp** grp, const uint32_t flags) |
| @@ -5955,28 +6122,12 @@ rtError_t ApiImpl::DvppWaitGroupReport(DvppGrp* const grp, const rtDvppGrpCallba | |||
| 5955 | 6122 | ||
| 5956 | rtError_t ApiImpl::SetStreamTag(Stream* const stm, const uint32_t geOpTag) | 6123 | rtError_t ApiImpl::SetStreamTag(Stream* const stm, const uint32_t geOpTag) |
| 5957 | { | 6124 | { |
| 5958 | - RT_LOG(RT_LOG_DEBUG, "geOpTag=%#x.", geOpTag); | 6125 | + return SetStreamTagInternal(stm, geOpTag); |
| 5959 | - Context* const curCtx = CurrentContext(); | ||
| 5960 | - CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 5961 | - | ||
| 5962 | - Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 5963 | - NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 5964 | - COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 5965 | - targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Setting the stream tag"); | ||
| 5966 | - return curCtx->SetStreamTag(targetStm, geOpTag); | ||
| 5967 | } | 6126 | } |
| 5968 | 6127 | ||
| 5969 | rtError_t ApiImpl::GetStreamTag(Stream* const stm, uint32_t* const geOpTag) | 6128 | rtError_t ApiImpl::GetStreamTag(Stream* const stm, uint32_t* const geOpTag) |
| 5970 | { | 6129 | { |
| 5971 | - Context* const curCtx = CurrentContext(); | 6130 | + return GetStreamTagInternal(stm, geOpTag); |
| 5972 | - CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 5973 | - Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 5974 | - NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 5975 | - COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 5976 | - targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Obtaining the stream label"); | ||
| 5977 | - | ||
| 5978 | - *geOpTag = static_cast<uint32_t>(targetStm->GetStreamTag()); | ||
| 5979 | - return RT_ERROR_NONE; | ||
| 5980 | } | 6131 | } |
| 5981 | 6132 | ||
| 5982 | rtError_t ApiImpl::GetVisibleDeviceIdByLogicDeviceId(const int32_t logicDeviceId, int32_t* const visibleDeviceId) | 6133 | rtError_t ApiImpl::GetVisibleDeviceIdByLogicDeviceId(const int32_t logicDeviceId, int32_t* const visibleDeviceId) |
| @@ -6796,30 +6947,12 @@ rtError_t ApiImpl::GetUserDevIdByLogicDevId(const int32_t logicDevId, int32_t* c | |||
| 6796 | 6947 | ||
| 6797 | rtError_t ApiImpl::SetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t cacheOpInfoSwitch) | 6948 | rtError_t ApiImpl::SetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t cacheOpInfoSwitch) |
| 6798 | { | 6949 | { |
| 6799 | - // The ctx is not checked for performance. | 6950 | + return SetStreamCacheOpInfoInternal(stm, cacheOpInfoSwitch); |
| 6800 | - stm->SetStreamCacheOpInfoOriginSwitch(cacheOpInfoSwitch); | ||
| 6801 | - RT_LOG( | ||
| 6802 | - RT_LOG_DEBUG, "device_id=%u, stream_id=%u, cacheOpInfoSwitch=%u.", stm->Device_()->Id_(), stm->Id_(), | ||
| 6803 | - cacheOpInfoSwitch); | ||
| 6804 | - | ||
| 6805 | - if (stm->IsCapturing() && stm->GetCaptureStream() != nullptr && stm->GetCaptureStream()->IsOrigCaptureStream()) { | ||
| 6806 | - CaptureModel* mdl = dynamic_cast<CaptureModel*>(stm->GetCaptureStream()->Model_()); | ||
| 6807 | - RT_LOG( | ||
| 6808 | - RT_LOG_INFO, "set cache op info switch status, model_id = %u, stream_id=%u, status=%u.", mdl->Id_(), | ||
| 6809 | - stm->Id_(), cacheOpInfoSwitch); | ||
| 6810 | - mdl->SetModelCacheOpInfoSwitch(cacheOpInfoSwitch); | ||
| 6811 | - } | ||
| 6812 | - | ||
| 6813 | - return RT_ERROR_NONE; | ||
| 6814 | } | 6951 | } |
| 6815 | 6952 | ||
| 6816 | rtError_t ApiImpl::GetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t* const cacheOpInfoSwitch) | 6953 | rtError_t ApiImpl::GetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t* const cacheOpInfoSwitch) |
| 6817 | { | 6954 | { |
| 6818 | - // The ctx is not checked for performance. | 6955 | + return GetStreamCacheOpInfoInternal(stm, cacheOpInfoSwitch); |
| 6819 | - // main stream is not closed & this stream is opened | ||
| 6820 | - *cacheOpInfoSwitch = stm->GetStreamCacheOpInfoSwitch(); | ||
| 6821 | - | ||
| 6822 | - return RT_ERROR_NONE; | ||
| 6823 | } | 6956 | } |
| 6824 | 6957 | ||
| 6825 | rtError_t ApiImpl::ModelDestroyRegisterCallback(Model* const mdl, const rtCallback_t fn, void* ptr) | 6958 | rtError_t ApiImpl::ModelDestroyRegisterCallback(Model* const mdl, const rtCallback_t fn, void* ptr) |
| @@ -150,6 +150,8 @@ public: | |||
| 150 | Stream* const stm, Event* const evt, const uint32_t timeout, | 150 | Stream* const stm, Event* const evt, const uint32_t timeout, |
| 151 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) override; | 151 | const uint32_t flag = RT_EVENT_WAIT_DEFAULT) override; |
| 152 | rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout) override; | 152 | rtError_t StreamSynchronize(Stream* const stm, const int32_t timeout) override; |
| 153 | + rtError_t NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) override; | ||
| 154 | + rtError_t NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) override; | ||
| 153 | rtError_t StreamQuery(Stream* const stm) override; | 155 | rtError_t StreamQuery(Stream* const stm) override; |
| 154 | rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) override; | 156 | rtError_t GetStreamId(Stream* const stm, int32_t* const streamId) override; |
| 155 | rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) override; | 157 | rtError_t GetSqId(Stream* const stm, uint32_t* const sqId) override; |
| @@ -527,6 +529,10 @@ public: | |||
| 527 | rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) override; | 529 | rtError_t GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags) override; |
| 528 | rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) override; | 530 | rtError_t SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority) override; |
| 529 | rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) override; | 531 | rtError_t GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority) override; |
| 532 | + rtError_t StreamSetAttribute( | ||
| 533 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) override; | ||
| 534 | + rtError_t StreamGetAttribute( | ||
| 535 | + Stream* const stm, const rtStreamAttr stmAttrId, rtStreamAttrValue_t* const attrValue) override; | ||
| 530 | 536 | ||
| 531 | rtError_t SetExceptCallback(const rtErrorCallback callback) override; | 537 | rtError_t SetExceptCallback(const rtErrorCallback callback) override; |
| 532 | rtError_t SetTaskAbortCallBack( | 538 | rtError_t SetTaskAbortCallBack( |
| @@ -14,6 +14,20 @@ | |||
| 14 | namespace cce { | 14 | namespace cce { |
| 15 | namespace runtime { | 15 | namespace runtime { |
| 16 | 16 | ||
| 17 | +rtError_t ApiImpl::NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) | ||
| 18 | +{ | ||
| 19 | + UNUSED(stream); | ||
| 20 | + UNUSED(flag); | ||
| 21 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +rtError_t ApiImpl::NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) | ||
| 25 | +{ | ||
| 26 | + UNUSED(stream); | ||
| 27 | + UNUSED(flag); | ||
| 28 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 29 | +} | ||
| 30 | + | ||
| 17 | rtError_t ApiImpl::FlushCache(const uint64_t base, const size_t len) | 31 | rtError_t ApiImpl::FlushCache(const uint64_t base, const size_t len) |
| 18 | { | 32 | { |
| 19 | RT_LOG(RT_LOG_INFO, "flush cache base=%" PRIu64 ", len=%zu.", base, len); | 33 | RT_LOG(RT_LOG_INFO, "flush cache base=%" PRIu64 ", len=%zu.", base, len); |
| @@ -53,6 +53,7 @@ | |||
| 53 | #include "utils.h" | 53 | #include "utils.h" |
| 54 | #include "api_handle_guard.h" | 54 | #include "api_handle_guard.h" |
| 55 | #include "error_message_manage.hpp" | 55 | #include "error_message_manage.hpp" |
| 56 | +#include "stream_launch_blocking.hpp" | ||
| 56 | #include "capability.hpp" | 57 | #include "capability.hpp" |
| 57 | #include "notify_enum_desc.hpp" | 58 | #include "notify_enum_desc.hpp" |
| 58 | #include "task.hpp" | 59 | #include "task.hpp" |
| @@ -143,7 +144,11 @@ rtError_t ApiImplDavid::LaunchKernel( | |||
| 143 | rtStreamLaunchKernelV2ExtendArgs_t launchKernelExtendArgs = {}; | 144 | rtStreamLaunchKernelV2ExtendArgs_t launchKernelExtendArgs = {}; |
| 144 | launchKernelExtendArgs.argsInfo = argsInfo; | 145 | launchKernelExtendArgs.argsInfo = argsInfo; |
| 145 | launchKernelExtendArgs.taskCfg = &taskCfg; | 146 | launchKernelExtendArgs.taskCfg = &taskCfg; |
| 146 | - return StreamLaunchKernelV2(kernel, blockDim, curStm, &launchKernelExtendArgs); | 147 | + const rtError_t error = StreamLaunchKernelV2(kernel, blockDim, curStm, &launchKernelExtendArgs); |
| 148 | + if ((error == RT_ERROR_NONE) && StreamLaunchBlocking::ShouldLaunchBlock(curStm)) { | ||
| 149 | + return curStm->Synchronize(false); | ||
| 150 | + } | ||
| 151 | + return error; | ||
| 147 | } | 152 | } |
| 148 | 153 | ||
| 149 | rtError_t ApiImplDavid::CpuKernelLaunchExAll( | 154 | rtError_t ApiImplDavid::CpuKernelLaunchExAll( |
| @@ -1406,9 +1411,9 @@ rtError_t ApiImplDavid::GetDeviceSatStatus(void* const outputAddrPtr, const uint | |||
| 1406 | return error; | 1411 | return error; |
| 1407 | } | 1412 | } |
| 1408 | 1413 | ||
| 1409 | -rtError_t ApiImplDavid::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) | 1414 | +static rtError_t SetStreamOverflowSwitchInternal(Stream* const stm, const uint32_t flags) |
| 1410 | { | 1415 | { |
| 1411 | - Context* const curCtx = CurrentContext(); | 1416 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); |
| 1412 | CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | 1417 | CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); |
| 1413 | 1418 | ||
| 1414 | Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | 1419 | Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; |
| @@ -1418,10 +1423,10 @@ rtError_t ApiImplDavid::SetStreamOverflowSwitch(Stream* const stm, const uint32_ | |||
| 1418 | return SetOverflowSwitchOnStream(targetStm, flags); | 1423 | return SetOverflowSwitchOnStream(targetStm, flags); |
| 1419 | } | 1424 | } |
| 1420 | 1425 | ||
| 1421 | -rtError_t ApiImplDavid::SetStreamTag(Stream* const stm, const uint32_t geOpTag) | 1426 | +static rtError_t SetStreamTagInternal(Stream* const stm, const uint32_t geOpTag) |
| 1422 | { | 1427 | { |
| 1423 | RT_LOG(RT_LOG_DEBUG, "geOpTag=%#x.", geOpTag); | 1428 | RT_LOG(RT_LOG_DEBUG, "geOpTag=%#x.", geOpTag); |
| 1424 | - Context* const curCtx = CurrentContext(); | 1429 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); |
| 1425 | CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | 1430 | CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); |
| 1426 | Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | 1431 | Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; |
| 1427 | NULL_STREAM_PTR_RETURN_MSG(targetStm); | 1432 | NULL_STREAM_PTR_RETURN_MSG(targetStm); |
| @@ -1430,6 +1435,39 @@ rtError_t ApiImplDavid::SetStreamTag(Stream* const stm, const uint32_t geOpTag) | |||
| 1430 | return SetTagOnStream(targetStm, geOpTag); | 1435 | return SetTagOnStream(targetStm, geOpTag); |
| 1431 | } | 1436 | } |
| 1432 | 1437 | ||
| 1438 | +rtError_t ApiImplDavid::StreamSetAttribute( | ||
| 1439 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) | ||
| 1440 | +{ | ||
| 1441 | + NULL_PTR_RETURN_MSG(attrValue, RT_ERROR_INVALID_VALUE); | ||
| 1442 | + rtError_t error; | ||
| 1443 | + // Overflow and stream tag use the David-specific task delivery path. | ||
| 1444 | + switch (stmAttrId) { | ||
| 1445 | + case RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK: { | ||
| 1446 | + error = SetStreamOverflowSwitchInternal(stm, attrValue->overflowSwitch); | ||
| 1447 | + break; | ||
| 1448 | + } | ||
| 1449 | + case RT_STREAM_ATTR_USER_CUSTOM_TAG: { | ||
| 1450 | + error = SetStreamTagInternal(stm, attrValue->userCustomTag); | ||
| 1451 | + break; | ||
| 1452 | + } | ||
| 1453 | + default: { | ||
| 1454 | + error = ApiImpl::StreamSetAttribute(stm, stmAttrId, attrValue); | ||
| 1455 | + break; | ||
| 1456 | + } | ||
| 1457 | + } | ||
| 1458 | + return error; | ||
| 1459 | +} | ||
| 1460 | + | ||
| 1461 | +rtError_t ApiImplDavid::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) | ||
| 1462 | +{ | ||
| 1463 | + return SetStreamOverflowSwitchInternal(stm, flags); | ||
| 1464 | +} | ||
| 1465 | + | ||
| 1466 | +rtError_t ApiImplDavid::SetStreamTag(Stream* const stm, const uint32_t geOpTag) | ||
| 1467 | +{ | ||
| 1468 | + return SetStreamTagInternal(stm, geOpTag); | ||
| 1469 | +} | ||
| 1470 | + | ||
| 1433 | rtError_t ApiImplDavid::UbDbSend(rtUbDbInfo_t* const dbInfo, Stream* const stm) | 1471 | rtError_t ApiImplDavid::UbDbSend(rtUbDbInfo_t* const dbInfo, Stream* const stm) |
| 1434 | { | 1472 | { |
| 1435 | Context* const curCtx = CurrentContext(); | 1473 | Context* const curCtx = CurrentContext(); |
| @@ -44,6 +44,7 @@ | |||
| 44 | #include "stream_factory.hpp" | 44 | #include "stream_factory.hpp" |
| 45 | #include "device/device_error_proc.hpp" | 45 | #include "device/device_error_proc.hpp" |
| 46 | #include "stream_state_callback_manager.hpp" | 46 | #include "stream_state_callback_manager.hpp" |
| 47 | +#include "stream_launch_blocking.hpp" | ||
| 47 | #include "heterogenous.h" | 48 | #include "heterogenous.h" |
| 48 | #include "capture_model.hpp" | 49 | #include "capture_model.hpp" |
| 49 | #include "capture_model_utils.hpp" | 50 | #include "capture_model_utils.hpp" |
| @@ -165,6 +166,22 @@ rtError_t ApiImpl::BinaryEnumerateFunctions( | |||
| 165 | return RT_ERROR_NONE; | 166 | return RT_ERROR_NONE; |
| 166 | } | 167 | } |
| 167 | 168 | ||
| 169 | +rtError_t ApiImpl::NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) | ||
| 170 | +{ | ||
| 171 | + UNUSED(flag); | ||
| 172 | + Stream* const targetStm = Runtime::Instance()->GetCurStream(stream); | ||
| 173 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 174 | + return StreamLaunchBlocking::NonBlockingLaunchBegin(targetStm); | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +rtError_t ApiImpl::NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) | ||
| 178 | +{ | ||
| 179 | + UNUSED(flag); | ||
| 180 | + Stream* const targetStm = Runtime::Instance()->GetCurStream(stream); | ||
| 181 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 182 | + return StreamLaunchBlocking::NonBlockingLaunchEnd(targetStm); | ||
| 183 | +} | ||
| 184 | + | ||
| 168 | rtError_t ApiImpl::CntNotifyCreate(const int32_t deviceId, CountNotify** const cntNotify, const uint32_t flag) | 185 | rtError_t ApiImpl::CntNotifyCreate(const int32_t deviceId, CountNotify** const cntNotify, const uint32_t flag) |
| 169 | { | 186 | { |
| 170 | UNUSED(deviceId); | 187 | UNUSED(deviceId); |
| @@ -14,6 +14,20 @@ | |||
| 14 | namespace cce { | 14 | namespace cce { |
| 15 | namespace runtime { | 15 | namespace runtime { |
| 16 | 16 | ||
| 17 | +rtError_t ApiImpl::NonBlockingLaunchBegin(Stream* const stream, const uint64_t flag) | ||
| 18 | +{ | ||
| 19 | + UNUSED(stream); | ||
| 20 | + UNUSED(flag); | ||
| 21 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +rtError_t ApiImpl::NonBlockingLaunchEnd(Stream* const stream, const uint64_t flag) | ||
| 25 | +{ | ||
| 26 | + UNUSED(stream); | ||
| 27 | + UNUSED(flag); | ||
| 28 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 29 | +} | ||
| 30 | + | ||
| 17 | rtError_t ApiImpl::FlushCache(const uint64_t base, const size_t len) | 31 | rtError_t ApiImpl::FlushCache(const uint64_t base, const size_t len) |
| 18 | { | 32 | { |
| 19 | RT_LOG(RT_LOG_INFO, "flush cache base=%" PRIu64 ", len=%zu.", base, len); | 33 | RT_LOG(RT_LOG_INFO, "flush cache base=%" PRIu64 ", len=%zu.", base, len); |
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "context.hpp" | 18 | #include "context.hpp" |
| 19 | #include "xpu_aicpu_c.hpp" | 19 | #include "xpu_aicpu_c.hpp" |
| 20 | #include "task_fail_callback_manager.hpp" | 20 | #include "task_fail_callback_manager.hpp" |
| 21 | +#include "stream_launch_blocking.hpp" | ||
| 21 | 22 | ||
| 22 | namespace cce { | 23 | namespace cce { |
| 23 | namespace runtime { | 24 | namespace runtime { |
| @@ -59,7 +60,11 @@ rtError_t ApiImplDavid::LaunchKernelV2( | |||
| 59 | } | 60 | } |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | - return LaunchKernelByArgsWithType(kernel, blockDim, curStm, argsWithType, taskCfg); | 63 | + error = LaunchKernelByArgsWithType(kernel, blockDim, curStm, argsWithType, taskCfg); |
| 64 | + if ((error == RT_ERROR_NONE) && StreamLaunchBlocking::ShouldLaunchBlock(curStm)) { | ||
| 65 | + return curStm->Synchronize(false); | ||
| 66 | + } | ||
| 67 | + return error; | ||
| 63 | } | 68 | } |
| 64 | 69 | ||
| 65 | rtError_t ApiImplDavid::XpuSetTaskFailCallback(const rtXpuDevType devType, const char_t* moduleName, void* callback) | 70 | rtError_t ApiImplDavid::XpuSetTaskFailCallback(const rtXpuDevType devType, const char_t* moduleName, void* callback) |
| @@ -23,6 +23,14 @@ RUNTIME_API(standard_soc, rtError_t, rtsPersistentTaskClean, | |||
| 23 | (rtStream_t stm), | 23 | (rtStream_t stm), |
| 24 | (stm), FEATURE_NOT_SUPPORT, EXPORT) | 24 | (stm), FEATURE_NOT_SUPPORT, EXPORT) |
| 25 | 25 | ||
| 26 | +RUNTIME_API(standard_soc, rtError_t, rtNonBlockingLaunchBegin, | ||
| 27 | + (rtStream_t stream, uint64_t flag), | ||
| 28 | + (stream, flag), FEATURE_NOT_SUPPORT, EXPORT) | ||
| 29 | + | ||
| 30 | +RUNTIME_API(standard_soc, rtError_t, rtNonBlockingLaunchEnd, | ||
| 31 | + (rtStream_t stream, uint64_t flag), | ||
| 32 | + (stream, flag), FEATURE_NOT_SUPPORT, EXPORT) | ||
| 33 | + | ||
| 26 | RUNTIME_API(standard_soc, rtError_t, rtMemcpyAsyncWithOffset, | 34 | RUNTIME_API(standard_soc, rtError_t, rtMemcpyAsyncWithOffset, |
| 27 | ( void** dst, uint64_t dstMax, uint64_t dstDataOffset, const void** src, uint64_t cnt, | 35 | ( void** dst, uint64_t dstMax, uint64_t dstDataOffset, const void** src, uint64_t cnt, |
| 28 | uint64_t srcDataOffset, rtMemcpyKind kind, rtStream_t stm), | 36 | uint64_t srcDataOffset, rtMemcpyKind kind, rtStream_t stm), |
| @@ -146,6 +146,7 @@ set(libruntime_stream_common_src_files | |||
| 146 | ${RUNTIME_CORE_DIR}/src/stream/dvpp_grp.cc | 146 | ${RUNTIME_CORE_DIR}/src/stream/dvpp_grp.cc |
| 147 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc | 147 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc |
| 148 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc | 148 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc |
| 149 | + ${RUNTIME_FEATURE_DIR}/launch_blocking/stream_launch_blocking.cc | ||
| 149 | ${RUNTIME_CORE_DIR}/src/stream/stream_factory.cc | 150 | ${RUNTIME_CORE_DIR}/src/stream/stream_factory.cc |
| 150 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc | 151 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc |
| 151 | ) | 152 | ) |
| @@ -370,6 +371,7 @@ set(RUNTIME_INC_DIR_ARCH5162 | |||
| 370 | ${RUNTIME_FEATURE_DIR}/soma | 371 | ${RUNTIME_FEATURE_DIR}/soma |
| 371 | ${RUNTIME_FEATURE_DIR}/cntnotify | 372 | ${RUNTIME_FEATURE_DIR}/cntnotify |
| 372 | ${RUNTIME_FEATURE_DIR}/snapshot | 373 | ${RUNTIME_FEATURE_DIR}/snapshot |
| 374 | + ${RUNTIME_FEATURE_DIR}/launch_blocking | ||
| 373 | ${RUNTIME_FEATURE_DIR}/ccu | 375 | ${RUNTIME_FEATURE_DIR}/ccu |
| 374 | ${RUNTIME_FEATURE_DIR}/ffts | 376 | ${RUNTIME_FEATURE_DIR}/ffts |
| 375 | ${RUNTIME_FEATURE_DIR}/xpu | 377 | ${RUNTIME_FEATURE_DIR}/xpu |
| @@ -242,6 +242,7 @@ set(libruntime_cmodel_stream_common_src_files | |||
| 242 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc | 242 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc |
| 243 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc | 243 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc |
| 244 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc | 244 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc |
| 245 | + ${RUNTIME_FEATURE_DIR}/launch_blocking/stream_launch_blocking.cc | ||
| 245 | ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc | 246 | ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc |
| 246 | ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc | 247 | ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc |
| 247 | ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc | 248 | ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc |
| @@ -745,6 +746,7 @@ set(RUNTIME_CMODEL_INC_DIR_COMMON | |||
| 745 | ${RUNTIME_FEATURE_DIR}/soma | 746 | ${RUNTIME_FEATURE_DIR}/soma |
| 746 | ${RUNTIME_FEATURE_DIR}/cntnotify | 747 | ${RUNTIME_FEATURE_DIR}/cntnotify |
| 747 | ${RUNTIME_FEATURE_DIR}/snapshot | 748 | ${RUNTIME_FEATURE_DIR}/snapshot |
| 749 | + ${RUNTIME_FEATURE_DIR}/launch_blocking | ||
| 748 | ${RUNTIME_FEATURE_DIR}/ccu | 750 | ${RUNTIME_FEATURE_DIR}/ccu |
| 749 | ${RUNTIME_FEATURE_DIR}/xpu | 751 | ${RUNTIME_FEATURE_DIR}/xpu |
| 750 | ${RUNTIME_CORE_DIR}/src/uvm | 752 | ${RUNTIME_CORE_DIR}/src/uvm |
| @@ -61,6 +61,7 @@ set(RUNTIME_INC_DIR_COMMON_PLATFORM | |||
| 61 | ${RUNTIME_CORE_DIR}/src/kernel/args | 61 | ${RUNTIME_CORE_DIR}/src/kernel/args |
| 62 | ${RUNTIME_CORE_DIR}/src/memory | 62 | ${RUNTIME_CORE_DIR}/src/memory |
| 63 | ${RUNTIME_FEATURE_DIR}/soma | 63 | ${RUNTIME_FEATURE_DIR}/soma |
| 64 | + ${RUNTIME_FEATURE_DIR}/launch_blocking | ||
| 64 | ${RUNTIME_FEATURE_DIR}/cntnotify | 65 | ${RUNTIME_FEATURE_DIR}/cntnotify |
| 65 | ${RUNTIME_FEATURE_DIR}/ccu | 66 | ${RUNTIME_FEATURE_DIR}/ccu |
| 66 | ${RUNTIME_CORE_DIR}/src/uvm | 67 | ${RUNTIME_CORE_DIR}/src/uvm |
| @@ -135,6 +135,7 @@ set(libruntime_stream_common_src_files | |||
| 135 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc | 135 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc |
| 136 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc | 136 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc |
| 137 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc | 137 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc |
| 138 | + ${RUNTIME_FEATURE_DIR}/launch_blocking/stream_launch_blocking.cc | ||
| 138 | ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc | 139 | ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc |
| 139 | ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc | 140 | ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc |
| 140 | ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc | 141 | ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc |
| @@ -490,6 +491,7 @@ set(RUNTIME_INC_DIR_OPEN | |||
| 490 | ${RUNTIME_FEATURE_DIR}/soma | 491 | ${RUNTIME_FEATURE_DIR}/soma |
| 491 | ${RUNTIME_FEATURE_DIR}/cntnotify | 492 | ${RUNTIME_FEATURE_DIR}/cntnotify |
| 492 | ${RUNTIME_FEATURE_DIR}/snapshot | 493 | ${RUNTIME_FEATURE_DIR}/snapshot |
| 494 | + ${RUNTIME_FEATURE_DIR}/launch_blocking | ||
| 493 | ${RUNTIME_FEATURE_DIR}/ccu | 495 | ${RUNTIME_FEATURE_DIR}/ccu |
| 494 | ${RUNTIME_FEATURE_DIR}/ffts | 496 | ${RUNTIME_FEATURE_DIR}/ffts |
| 495 | ${RUNTIME_FEATURE_DIR}/xpu | 497 | ${RUNTIME_FEATURE_DIR}/xpu |
| @@ -167,6 +167,7 @@ set(libruntime_stream_common_src_files | |||
| 167 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc | 167 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc |
| 168 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc | 168 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc |
| 169 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc | 169 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc |
| 170 | + ${RUNTIME_FEATURE_DIR}/launch_blocking/tiny/stream_launch_blocking_tiny_stub.cc | ||
| 170 | ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc | 171 | ${RUNTIME_CORE_DIR}/src/stream/ctrl_stream.cc |
| 171 | ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc | 172 | ${RUNTIME_CORE_DIR}/src/stream/coprocessor_stream.cc |
| 172 | ${RUNTIME_CORE_DIR}/src/stream/stream_factory.cc | 173 | ${RUNTIME_CORE_DIR}/src/stream/stream_factory.cc |
| @@ -576,6 +577,7 @@ set(RUNTIME_INC_DIR_TINY | |||
| 576 | ${RUNTIME_FEATURE_DIR}/soma | 577 | ${RUNTIME_FEATURE_DIR}/soma |
| 577 | ${RUNTIME_FEATURE_DIR}/cntnotify | 578 | ${RUNTIME_FEATURE_DIR}/cntnotify |
| 578 | ${RUNTIME_FEATURE_DIR}/snapshot | 579 | ${RUNTIME_FEATURE_DIR}/snapshot |
| 580 | + ${RUNTIME_FEATURE_DIR}/launch_blocking | ||
| 579 | ${RUNTIME_FEATURE_DIR}/aclgraph | 581 | ${RUNTIME_FEATURE_DIR}/aclgraph |
| 580 | ${RUNTIME_FEATURE_DIR}/ccu | 582 | ${RUNTIME_FEATURE_DIR}/ccu |
| 581 | ${RUNTIME_FEATURE_DIR}/xpu | 583 | ${RUNTIME_FEATURE_DIR}/xpu |
| @@ -13,6 +13,8 @@ RUNTIME_API_CATALOG_VERSION(1) | |||
| 13 | RUNTIME_API_STUB(rtCntNotifyCreate) | 13 | RUNTIME_API_STUB(rtCntNotifyCreate) |
| 14 | RUNTIME_API_STUB(rtCntNotifyCreateWithFlag) | 14 | RUNTIME_API_STUB(rtCntNotifyCreateWithFlag) |
| 15 | RUNTIME_API_STUB(rtsPersistentTaskClean) | 15 | RUNTIME_API_STUB(rtsPersistentTaskClean) |
| 16 | +RUNTIME_API_STUB(rtNonBlockingLaunchBegin) | ||
| 17 | +RUNTIME_API_STUB(rtNonBlockingLaunchEnd) | ||
| 16 | RUNTIME_API_STUB(rtMemcpyAsyncWithOffset) | 18 | RUNTIME_API_STUB(rtMemcpyAsyncWithOffset) |
| 17 | RUNTIME_API_STUB(rtMemsetD32) | 19 | RUNTIME_API_STUB(rtMemsetD32) |
| 18 | RUNTIME_API_STUB(rtMemsetD32Async) | 20 | RUNTIME_API_STUB(rtMemsetD32Async) |
| @@ -165,6 +165,7 @@ set(libruntime_v200_stream_common_src_files | |||
| 165 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc | 165 | ${RUNTIME_CORE_DIR}/src/stream/stream_sqcq_manage.cc |
| 166 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc | 166 | ${RUNTIME_CORE_DIR}/src/stream/engine_stream_observer.cc |
| 167 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc | 167 | ${RUNTIME_CORE_DIR}/src/stream/stream.cc |
| 168 | + ${RUNTIME_FEATURE_DIR}/launch_blocking/stream_launch_blocking.cc | ||
| 168 | ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc | 169 | ${RUNTIME_FEATURE_DIR}/aclgraph/stream_capture.cc |
| 169 | ${RUNTIME_FEATURE_DIR}/jetty/jetty_manager.cc | 170 | ${RUNTIME_FEATURE_DIR}/jetty/jetty_manager.cc |
| 170 | ${RUNTIME_FEATURE_DIR}/jetty/jetty_pool.cc | 171 | ${RUNTIME_FEATURE_DIR}/jetty/jetty_pool.cc |
| @@ -516,6 +517,7 @@ set(RUNTIME_INC_DIR_COMMON_V200 | |||
| 516 | ${RUNTIME_FEATURE_DIR}/ffts | 517 | ${RUNTIME_FEATURE_DIR}/ffts |
| 517 | ${RUNTIME_FEATURE_DIR}/cntnotify | 518 | ${RUNTIME_FEATURE_DIR}/cntnotify |
| 518 | ${RUNTIME_FEATURE_DIR}/snapshot | 519 | ${RUNTIME_FEATURE_DIR}/snapshot |
| 520 | + ${RUNTIME_FEATURE_DIR}/launch_blocking | ||
| 519 | ${RUNTIME_FEATURE_DIR}/ccu | 521 | ${RUNTIME_FEATURE_DIR}/ccu |
| 520 | ${RUNTIME_FEATURE_DIR}/xpu | 522 | ${RUNTIME_FEATURE_DIR}/xpu |
| 521 | ${RUNTIME_CORE_DIR}/src/uvm | 523 | ${RUNTIME_CORE_DIR}/src/uvm |
| @@ -27,7 +27,6 @@ const std::unordered_set<RtOptionalFeatureType> CHIP_610LITE_FEATURE{ | |||
| 27 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GROUP_THREAD_LOCAL, | 27 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GROUP_THREAD_LOCAL, |
| 28 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, | 28 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, |
| 29 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, | 29 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, |
| 30 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 31 | RtOptionalFeatureType::RT_FEATURE_MODEL_SCHED_GROUP, | 30 | RtOptionalFeatureType::RT_FEATURE_MODEL_SCHED_GROUP, |
| 32 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, | 31 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, |
| 33 | RtOptionalFeatureType::RT_FEATURE_PROFILING_ADC, | 32 | RtOptionalFeatureType::RT_FEATURE_PROFILING_ADC, |
| @@ -123,6 +123,7 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_CLOUD_V2_FEATURE{ | |||
| 123 | RtOptionalFeatureType::RT_FEATURE_MEM_WAIT_PROF, | 123 | RtOptionalFeatureType::RT_FEATURE_MEM_WAIT_PROF, |
| 124 | RtOptionalFeatureType::RT_FEATURE_DFX_ERR_GET_AND_REPAIR, | 124 | RtOptionalFeatureType::RT_FEATURE_DFX_ERR_GET_AND_REPAIR, |
| 125 | RtOptionalFeatureType::RT_FEATURE_STARS_MONITOR_AICPU_TIMEOUT, | 125 | RtOptionalFeatureType::RT_FEATURE_STARS_MONITOR_AICPU_TIMEOUT, |
| 126 | + RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING, | ||
| 126 | }; | 127 | }; |
| 127 | 128 | ||
| 128 | REGISTER_CHIP_FEATURE_SET(CHIP_910_B_93, CHIP_CLOUD_V2_FEATURE); | 129 | REGISTER_CHIP_FEATURE_SET(CHIP_910_B_93, CHIP_CLOUD_V2_FEATURE); |
| @@ -121,7 +121,9 @@ const std::unordered_set<RtOptionalFeatureType> CHIP_DAVID_FEATURE{ | |||
| 121 | RtOptionalFeatureType::RT_FEATURE_TASK_EXEC_TIMEOUT_SCALE_MODIFY, | 121 | RtOptionalFeatureType::RT_FEATURE_TASK_EXEC_TIMEOUT_SCALE_MODIFY, |
| 122 | RtOptionalFeatureType::RT_FEATURE_MEM_WAIT_PROF, | 122 | RtOptionalFeatureType::RT_FEATURE_MEM_WAIT_PROF, |
| 123 | RtOptionalFeatureType::RT_FEATURE_DFX_PROCESS_SNAPSHOT, | 123 | RtOptionalFeatureType::RT_FEATURE_DFX_PROCESS_SNAPSHOT, |
| 124 | - RtOptionalFeatureType::RT_FEATURE_STARS_MONITOR_AICPU_TIMEOUT}; | 124 | + RtOptionalFeatureType::RT_FEATURE_STARS_MONITOR_AICPU_TIMEOUT, |
| 125 | + RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING, | ||
| 126 | +}; | ||
| 125 | 127 | ||
| 126 | REGISTER_CHIP_FEATURE_SET(CHIP_DAVID, CHIP_DAVID_FEATURE); | 128 | REGISTER_CHIP_FEATURE_SET(CHIP_DAVID, CHIP_DAVID_FEATURE); |
| 127 | 129 | ||
| @@ -26,7 +26,6 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_ADC_FEATURE{ | |||
| 26 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GROUP_THREAD_LOCAL, | 26 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GROUP_THREAD_LOCAL, |
| 27 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, | 27 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, |
| 28 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, | 28 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, |
| 29 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 30 | RtOptionalFeatureType::RT_FEATURE_MODEL_SCHED_GROUP, | 29 | RtOptionalFeatureType::RT_FEATURE_MODEL_SCHED_GROUP, |
| 31 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, | 30 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, |
| 32 | RtOptionalFeatureType::RT_FEATURE_PROFILING_ADC, | 31 | RtOptionalFeatureType::RT_FEATURE_PROFILING_ADC, |
| @@ -33,7 +33,6 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_AS31XM1_FEATURE{ | |||
| 33 | RtOptionalFeatureType::RT_FEATURE_NOTIFY_WAIT_TIMEOUT, | 33 | RtOptionalFeatureType::RT_FEATURE_NOTIFY_WAIT_TIMEOUT, |
| 34 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, | 34 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, |
| 35 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, | 35 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, |
| 36 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 37 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GET_STARS_VERSION, | 36 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GET_STARS_VERSION, |
| 38 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, | 37 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, |
| 39 | RtOptionalFeatureType::RT_FEATURE_STREAM_LOCKABLE, | 38 | RtOptionalFeatureType::RT_FEATURE_STREAM_LOCKABLE, |
| @@ -38,7 +38,6 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_CLOUD_FEATURE{ | |||
| 38 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, | 38 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, |
| 39 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, | 39 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, |
| 40 | RtOptionalFeatureType::RT_FEATURE_DFX_HWTS_LOG, | 40 | RtOptionalFeatureType::RT_FEATURE_DFX_HWTS_LOG, |
| 41 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 42 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, | 41 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, |
| 43 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, | 42 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, |
| 44 | RtOptionalFeatureType::RT_FEATURE_TASK_RECYCLE_THREAD, | 43 | RtOptionalFeatureType::RT_FEATURE_TASK_RECYCLE_THREAD, |
| @@ -32,7 +32,6 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_MINI_V3_FEATURE{ | |||
| 32 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, | 32 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, |
| 33 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, | 33 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, |
| 34 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GET_STARS_VERSION, | 34 | RtOptionalFeatureType::RT_FEATURE_DEVICE_GET_STARS_VERSION, |
| 35 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 36 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, | 35 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, |
| 37 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, | 36 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, |
| 38 | RtOptionalFeatureType::RT_FEATURE_HOST_CPU_MODEL_INFO_FROM_FILE, | 37 | RtOptionalFeatureType::RT_FEATURE_HOST_CPU_MODEL_INFO_FROM_FILE, |
| @@ -28,7 +28,6 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_NANO_FEATURE{ | |||
| 28 | RtOptionalFeatureType::RT_FEATURE_TASK_TRY_RECYCLE_DISABLE_HWTS, | 28 | RtOptionalFeatureType::RT_FEATURE_TASK_TRY_RECYCLE_DISABLE_HWTS, |
| 29 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, | 29 | RtOptionalFeatureType::RT_FEATURE_TASK_MODEL_EXECUTE_COPY_ONCE, |
| 30 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, | 30 | RtOptionalFeatureType::RT_FEATURE_DEVICE_HAS_TS_DEAMON, |
| 31 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 32 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, | 31 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, |
| 33 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, | 32 | RtOptionalFeatureType::RT_FEATURE_PROFILING_AICPU, |
| 34 | RtOptionalFeatureType::RT_FEATURE_TASK_PRE_BUILD_SQE, | 33 | RtOptionalFeatureType::RT_FEATURE_TASK_PRE_BUILD_SQE, |
| @@ -26,7 +26,6 @@ static const std::unordered_set<RtOptionalFeatureType> CHIP_5612_FEATURE{ | |||
| 26 | RtOptionalFeatureType::RT_FEATURE_DEVICE_FAILURE_MODE_SET, | 26 | RtOptionalFeatureType::RT_FEATURE_DEVICE_FAILURE_MODE_SET, |
| 27 | RtOptionalFeatureType::RT_FEATURE_TASK_TRY_RECYCLE_DISABLE_HWTS, | 27 | RtOptionalFeatureType::RT_FEATURE_TASK_TRY_RECYCLE_DISABLE_HWTS, |
| 28 | RtOptionalFeatureType::RT_FEATURE_NOTIFY_WAIT_TIMEOUT, | 28 | RtOptionalFeatureType::RT_FEATURE_NOTIFY_WAIT_TIMEOUT, |
| 29 | - RtOptionalFeatureType::RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | ||
| 30 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, | 29 | RtOptionalFeatureType::RT_FEATURE_DEVICE_P2P, |
| 31 | RtOptionalFeatureType::RT_FEATURE_STREAM_HUGE_DEPTH, | 30 | RtOptionalFeatureType::RT_FEATURE_STREAM_HUGE_DEPTH, |
| 32 | RtOptionalFeatureType::RT_FEATURE_STREAM_ABORT, | 31 | RtOptionalFeatureType::RT_FEATURE_STREAM_ABORT, |
| @@ -404,6 +404,8 @@ public: | |||
| 404 | 404 | ||
| 405 | bool GetNpuCollectFlag() const { return isNpuCollect; } | 405 | bool GetNpuCollectFlag() const { return isNpuCollect; } |
| 406 | 406 | ||
| 407 | + bool IsLaunchBlockingEnvEnabled() const { return launchBlockingEnvEnabled_; } | ||
| 408 | + | ||
| 407 | void SetProfileEnableFlag(bool isEnable) | 409 | void SetProfileEnableFlag(bool isEnable) |
| 408 | { | 410 | { |
| 409 | if (isEnable) { | 411 | if (isEnable) { |
| @@ -687,6 +689,7 @@ private: | |||
| 687 | rtError_t InitLabelAllocator(); | 689 | rtError_t InitLabelAllocator(); |
| 688 | rtError_t InitSetRuntimeVersion(); | 690 | rtError_t InitSetRuntimeVersion(); |
| 689 | void InitNpuCollectPath(); | 691 | void InitNpuCollectPath(); |
| 692 | + void InitLaunchBlocking(); | ||
| 690 | void InitStreamSyncMode(); | 693 | void InitStreamSyncMode(); |
| 691 | void NotifyProcWhenNewDevice(const uint32_t devId); | 694 | void NotifyProcWhenNewDevice(const uint32_t devId); |
| 692 | void NotifyProcWhenReleaseDevice(const uint32_t devId) const; | 695 | void NotifyProcWhenReleaseDevice(const uint32_t devId) const; |
| @@ -858,6 +861,9 @@ private: | |||
| 858 | uint8_t profileEnabled_ = 0U; | 861 | uint8_t profileEnabled_ = 0U; |
| 859 | bool isNpuCollect = false; // Corresponding to the environment NPU_COLLECT_PATH | 862 | bool isNpuCollect = false; // Corresponding to the environment NPU_COLLECT_PATH |
| 860 | 863 | ||
| 864 | + // Corresponding to the environment ASCEND_RT_LAUNCH_BLOCKING | ||
| 865 | + bool launchBlockingEnvEnabled_ = false; | ||
| 866 | + | ||
| 861 | bool enableOstFlag_{true}; | 867 | bool enableOstFlag_{true}; |
| 862 | 868 | ||
| 863 | uint32_t grpID_ = UINT32_MAX; | 869 | uint32_t grpID_ = UINT32_MAX; |
| @@ -118,6 +118,8 @@ public: | |||
| 118 | void* const outputAddrPtr, const uint64_t outputSize, const uint32_t checkMode, Stream* const stm) override; | 118 | void* const outputAddrPtr, const uint64_t outputSize, const uint32_t checkMode, Stream* const stm) override; |
| 119 | rtError_t NpuClearFloatDebugStatus(const uint32_t checkMode, Stream* const stm) override; | 119 | rtError_t NpuClearFloatDebugStatus(const uint32_t checkMode, Stream* const stm) override; |
| 120 | rtError_t GetDeviceSatStatus(void* const outputAddrPtr, const uint64_t outputSize, Stream* const stm) override; | 120 | rtError_t GetDeviceSatStatus(void* const outputAddrPtr, const uint64_t outputSize, Stream* const stm) override; |
| 121 | + rtError_t StreamSetAttribute( | ||
| 122 | + Stream* const stm, const rtStreamAttr stmAttrId, const rtStreamAttrValue_t* const attrValue) override; | ||
| 121 | rtError_t SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) override; | 123 | rtError_t SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags) override; |
| 122 | rtError_t SetStreamTag(Stream* const stm, const uint32_t geOpTag) override; | 124 | rtError_t SetStreamTag(Stream* const stm, const uint32_t geOpTag) override; |
| 123 | rtError_t UbDbSend(rtUbDbInfo_t* const dbInfo, Stream* const stm) override; | 125 | rtError_t UbDbSend(rtUbDbInfo_t* const dbInfo, Stream* const stm) override; |
| @@ -68,6 +68,8 @@ | |||
| 68 | namespace cce { | 68 | namespace cce { |
| 69 | namespace runtime { | 69 | namespace runtime { |
| 70 | namespace { | 70 | namespace { |
| 71 | +// Launch blocking is enabled only when the environment variable is exactly "1". | ||
| 72 | +constexpr char_t LAUNCH_BLOCKING_ENABLE_VALUE[] = "1"; | ||
| 71 | constexpr uint32_t TSD_OK = 0U; | 73 | constexpr uint32_t TSD_OK = 0U; |
| 72 | constexpr int64_t RTS_INVALID_HARDWARE_VERSION = 0xFFFFFFFFFFFFFFFFLL; | 74 | constexpr int64_t RTS_INVALID_HARDWARE_VERSION = 0xFFFFFFFFFFFFFFFFLL; |
| 73 | constexpr uint32_t TSD_SUBPROCESS_NUM_EXCEED_THE_LIMIT = 100U; | 75 | constexpr uint32_t TSD_SUBPROCESS_NUM_EXCEED_THE_LIMIT = 100U; |
| @@ -1319,6 +1321,27 @@ void Runtime::InitNpuCollectPath() | |||
| 1319 | return; | 1321 | return; |
| 1320 | } | 1322 | } |
| 1321 | 1323 | ||
| 1324 | +void Runtime::InitLaunchBlocking() | ||
| 1325 | +{ | ||
| 1326 | + launchBlockingEnvEnabled_ = false; | ||
| 1327 | + if (!IS_SUPPORT_CHIP_FEATURE(chipType_, RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)) { | ||
| 1328 | + return; | ||
| 1329 | + } | ||
| 1330 | + | ||
| 1331 | + char_t launchBlockingEnv[sizeof(LAUNCH_BLOCKING_ENABLE_VALUE)] = {}; | ||
| 1332 | + launchBlockingEnvEnabled_ = | ||
| 1333 | + ((mmGetEnv("ASCEND_RT_LAUNCH_BLOCKING", launchBlockingEnv, sizeof(launchBlockingEnv)) == EN_OK) && | ||
| 1334 | + (strcmp(launchBlockingEnv, LAUNCH_BLOCKING_ENABLE_VALUE) == 0)); | ||
| 1335 | + if (launchBlockingEnvEnabled_) { | ||
| 1336 | + RT_LOG( | ||
| 1337 | + RT_LOG_EVENT, | ||
| 1338 | + "ASCEND_RT_LAUNCH_BLOCKING is enabled. Kernel and model launches may run synchronously for operator " | ||
| 1339 | + "debugging, which may significantly impact performance. Composite operators with task dependencies may " | ||
| 1340 | + "deadlock unless non-blocking launch APIs or stream attributes are used."); | ||
| 1341 | + } | ||
| 1342 | + return; | ||
| 1343 | +} | ||
| 1344 | + | ||
| 1322 | void Runtime::InitStreamSyncMode() | 1345 | void Runtime::InitStreamSyncMode() |
| 1323 | { | 1346 | { |
| 1324 | // StreamSyncEschedMode for 310P helper scene | 1347 | // StreamSyncEschedMode for 310P helper scene |
| @@ -1597,6 +1620,7 @@ rtError_t Runtime::Init() | |||
| 1597 | excptCallBack_ = nullptr; | 1620 | excptCallBack_ = nullptr; |
| 1598 | 1621 | ||
| 1599 | InitNpuCollectPath(); | 1622 | InitNpuCollectPath(); |
| 1623 | + InitLaunchBlocking(); | ||
| 1600 | InitStreamSyncMode(); | 1624 | InitStreamSyncMode(); |
| 1601 | 1625 | ||
| 1602 | FindDcacheLockOp(); | 1626 | FindDcacheLockOp(); |
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <cinttypes> | 10 | #include <cinttypes> |
| 11 | #include <iomanip> | 11 | #include <iomanip> |
| 12 | #include "stream.hpp" | 12 | #include "stream.hpp" |
| 13 | +#include "stream_launch_blocking.hpp" | ||
| 13 | #include "device_enum_desc.hpp" | 14 | #include "device_enum_desc.hpp" |
| 14 | #include "model_update_task.h" | 15 | #include "model_update_task.h" |
| 15 | #include "runtime_handle_guard.h" | 16 | #include "runtime_handle_guard.h" |
| @@ -162,6 +163,8 @@ Stream::Stream(const Context* const stmCtx, const uint32_t prio, const uint32_t | |||
| 162 | 163 | ||
| 163 | Stream::~Stream() | 164 | Stream::~Stream() |
| 164 | { | 165 | { |
| 166 | + // Release optional state before the process-exit and device-fault early returns below. | ||
| 167 | + StreamLaunchBlocking::ReleaseLaunchBlockingState(this); | ||
| 165 | ResetEmbeddedInnerHandle<Stream>(this); | 168 | ResetEmbeddedInnerHandle<Stream>(this); |
| 166 | Runtime* const rt = Runtime::Instance(); | 169 | Runtime* const rt = Runtime::Instance(); |
| 167 | if (Runtime::IsProcessExiting(rt)) { | 170 | if (Runtime::IsProcessExiting(rt)) { |
| @@ -80,6 +80,7 @@ class EngineStreamObserver; | |||
| 80 | class TaskAllocator; | 80 | class TaskAllocator; |
| 81 | class CaptureModel; | 81 | class CaptureModel; |
| 82 | class LogicSq; | 82 | class LogicSq; |
| 83 | +class StreamLaunchBlocking; | ||
| 83 | 84 | ||
| 84 | enum class TagtsSqAllocType : std::uint32_t { SQ_ALLOC_TYPE_RT_DEFAULT = 0U }; | 85 | enum class TagtsSqAllocType : std::uint32_t { SQ_ALLOC_TYPE_RT_DEFAULT = 0U }; |
| 85 | using RtSqAllocType = TagtsSqAllocType; | 86 | using RtSqAllocType = TagtsSqAllocType; |
| @@ -971,6 +972,7 @@ public: | |||
| 971 | 972 | ||
| 972 | private: | 973 | private: |
| 973 | friend class Context; | 974 | friend class Context; |
| 975 | + friend class StreamLaunchBlocking; | ||
| 974 | void SetDestroyTaskRecycledOnTearDownOutput(bool* const output) | 976 | void SetDestroyTaskRecycledOnTearDownOutput(bool* const output) |
| 975 | { | 977 | { |
| 976 | destroyTaskRecycledOnTearDownOutput_ = output; | 978 | destroyTaskRecycledOnTearDownOutput_ = output; |
| @@ -1136,6 +1138,9 @@ private: | |||
| 1136 | bool isLastLevelCaptureStream_{true}; | 1138 | bool isLastLevelCaptureStream_{true}; |
| 1137 | Stream* parentCaptureStream_{nullptr}; // 级联场景下的上级流 | 1139 | Stream* parentCaptureStream_{nullptr}; // 级联场景下的上级流 |
| 1138 | Stream* childCaptureStream_{nullptr}; // 级联场景下的下级流(与 parentCaptureStream_ 对称) | 1140 | Stream* childCaptureStream_{nullptr}; // 级联场景下的下级流(与 parentCaptureStream_ 对称) |
| 1141 | + | ||
| 1142 | + // Null means the default mode with no active non-blocking section. | ||
| 1143 | + Atomic<StreamLaunchBlocking*> launchBlockingState_{nullptr}; | ||
| 1139 | std::map<uint32_t, std::pair<uint32_t, uint32_t>> posToHwPos_; // pos -> (logicSqId, hwPos) | 1144 | std::map<uint32_t, std::pair<uint32_t, uint32_t>> posToHwPos_; // pos -> (logicSqId, hwPos) |
| 1140 | rtStreamCaptureMode streamCaptureMode_{RT_STREAM_CAPTURE_MODE_MAX}; | 1145 | rtStreamCaptureMode streamCaptureMode_{RT_STREAM_CAPTURE_MODE_MAX}; |
| 1141 | StreamTaskGroupStatus taskGroupStatus_{StreamTaskGroupStatus::NONE}; // only for single-operator stream | 1146 | StreamTaskGroupStatus taskGroupStatus_{StreamTaskGroupStatus::NONE}; // only for single-operator stream |
| @@ -11,21 +11,36 @@ | |||
| 11 | #include "stars_cond_isa_helper.hpp" | 11 | #include "stars_cond_isa_helper.hpp" |
| 12 | #include "enum_desc.hpp" | 12 | #include "enum_desc.hpp" |
| 13 | #include "runtime.hpp" | 13 | #include "runtime.hpp" |
| 14 | -#include <map> | ||
| 15 | 14 | ||
| 16 | namespace cce { | 15 | namespace cce { |
| 17 | namespace runtime { | 16 | namespace runtime { |
| 18 | 17 | ||
| 19 | rtCondition_t GetNotCondition(const rtCondition_t condition) | 18 | rtCondition_t GetNotCondition(const rtCondition_t condition) |
| 20 | { | 19 | { |
| 21 | - static const std::map<rtCondition_t, rtCondition_t> notConditions = { | 20 | + rtCondition_t notCondition = condition; |
仅解决tiny超限的问题,与本需求无关 ![]() ![]() | |||
| 22 | - {RT_EQUAL, RT_NOT_EQUAL}, {RT_NOT_EQUAL, RT_EQUAL}, {RT_GREATER, RT_LESS_OR_EQUAL}, | 21 | + switch (condition) { |
| 23 | - {RT_GREATER_OR_EQUAL, RT_LESS}, {RT_LESS, RT_GREATER_OR_EQUAL}, {RT_LESS_OR_EQUAL, RT_GREATER}}; | 22 | + case RT_EQUAL: |
| 24 | - const auto notCondition = notConditions.find(condition); | 23 | + notCondition = RT_NOT_EQUAL; |
| 25 | - if (notCondition == notConditions.end()) { | 24 | + break; |
| 26 | - return condition; | 25 | + case RT_NOT_EQUAL: |
| 26 | + notCondition = RT_EQUAL; | ||
| 27 | + break; | ||
| 28 | + case RT_GREATER: | ||
| 29 | + notCondition = RT_LESS_OR_EQUAL; | ||
| 30 | + break; | ||
| 31 | + case RT_GREATER_OR_EQUAL: | ||
| 32 | + notCondition = RT_LESS; | ||
| 33 | + break; | ||
| 34 | + case RT_LESS: | ||
| 35 | + notCondition = RT_GREATER_OR_EQUAL; | ||
| 36 | + break; | ||
| 37 | + case RT_LESS_OR_EQUAL: | ||
| 38 | + notCondition = RT_GREATER; | ||
| 39 | + break; | ||
| 40 | + default: | ||
| 41 | + break; | ||
| 27 | } | 42 | } |
| 28 | - return notCondition->second; | 43 | + return notCondition; |
| 29 | } | 44 | } |
| 30 | 45 | ||
| 31 | void ConvertConditionToBranchFunc3( | 46 | void ConvertConditionToBranchFunc3( |
| @@ -1134,31 +1134,35 @@ bool NpuDriver::CheckIsSupportFeature(uint32_t devId, int32_t featureType) | |||
| 1134 | return false; | 1134 | return false; |
| 1135 | } | 1135 | } |
| 1136 | 1136 | ||
| 1137 | - static std::map<drvFeature_t, std::string> featureNameMap = { | 1137 | + static constexpr const char_t* featureNameTable[] = { |
| 1138 | - {FEATURE_SVM_GET_USER_MALLOC_ATTR, "FEATURE_SVM_GET_USER_MALLOC_ATTR"}, | 1138 | + "FEATURE_TRSDRV_SQ_DEVICE_MEM_PRIORITY", |
| 1139 | - {FEATURE_MEMCPY_BATCH_ASYNC, "FEATURE_MEMCPY_BATCH_ASYNC"}, | 1139 | + nullptr, // FEATURE_PROF_AICPU_CHAN is not queried by Runtime. |
| 1140 | - {FEATURE_TRSDRV_SQ_DEVICE_MEM_PRIORITY, "FEATURE_TRSDRV_SQ_DEVICE_MEM_PRIORITY"}, | 1140 | + "FEATURE_SVM_GET_USER_MALLOC_ATTR", |
| 1141 | - {FEATURE_TRSDRV_SQ_SUPPORT_DYNAMIC_BIND, "FEATURE_TRSDRV_SQ_SUPPORT_DYNAMIC_BIND"}, | 1141 | + "FEATURE_MEMCPY_BATCH_ASYNC", |
| 1142 | - {FEATURE_HOST_PIN_REGISTER_SUPPORT_UVA, "FEATURE_HOST_PIN_REGISTER_SUPPORT_UVA"}, | 1142 | + "FEATURE_TRSDRV_SQ_SUPPORT_DYNAMIC_BIND", |
| 1143 | - {FEATURE_SVM_VMM_NORMAL_GRANULARITY, "FEATURE_SVM_VMM_NORMAL_GRANULARITY"}, | 1143 | + "FEATURE_HOST_PIN_REGISTER_SUPPORT_UVA", |
| 1144 | - {FEATURE_TRSDRV_IS_SQ_SUPPORT_DYNAMIC_BIND_VERSION, "FEATURE_TRSDRV_IS_SQ_SUPPORT_DYNAMIC_BIND_VERSION"}, | 1144 | + "FEATURE_SVM_VMM_NORMAL_GRANULARITY", |
| 1145 | - {FEATURE_SVM_MEM_HOST_UVA, "FEATURE_SVM_MEM_HOST_UVA"}, | 1145 | + "FEATURE_TRSDRV_IS_SQ_SUPPORT_DYNAMIC_BIND_VERSION", |
| 1146 | - {FEATURE_DMS_GET_QOS_MASTER_CONFIG, "FEATURE_DMS_GET_QOS_MASTER_CONFIG"}, | 1146 | + "FEATURE_SVM_MEM_HOST_UVA", |
| 1147 | - {FEATURE_DMS_QUERY_CHIP_DIE_ID, "FEATURE_DMS_QUERY_CHIP_DIE_ID"}, | 1147 | + "FEATURE_DMS_GET_QOS_MASTER_CONFIG", |
| 1148 | - {FEATURE_SVM_MEM_REGISTER_QUERY_AND_GET_ATTR, "FEATURE_SVM_MEM_REGISTER_QUERY_AND_GET_ATTR"}, | 1148 | + "FEATURE_DMS_QUERY_CHIP_DIE_ID", |
| 1149 | - {FEATURE_APM_RES_MAP_REMOTE, "FEATURE_APM_RES_MAP_REMOTE"}, | 1149 | + "FEATURE_SVM_MEM_REGISTER_QUERY_AND_GET_ATTR", |
| 1150 | - {FEATURE_SVM_MEM_REGISTER_HOST_PINNED, "FEATURE_SVM_MEM_REGISTER_HOST_PINNED"}, | 1150 | + "FEATURE_APM_RES_MAP_REMOTE", |
| 1151 | - {FEATURE_DMS_GET_BOARD_LOCATION, "FEATURE_DMS_GET_BOARD_LOCATION"}, | 1151 | + "FEATURE_SVM_MEM_REGISTER_HOST_PINNED", |
| 1152 | + "FEATURE_DMS_GET_BOARD_LOCATION", | ||
| 1152 | }; | 1153 | }; |
| 1154 | + static_assert( | ||
| 1155 | + (sizeof(featureNameTable) / sizeof(featureNameTable[0])) == static_cast<size_t>(FEATURE_MAX), | ||
| 1156 | + "featureNameTable must match drvFeature_t"); | ||
| 1153 | 1157 | ||
| 1154 | - auto iter = featureNameMap.find(static_cast<drvFeature_t>(featureType)); | 1158 | + const char_t* const featureName = featureNameTable[static_cast<size_t>(featureType)]; |
| 1155 | - if (iter == featureNameMap.end()) { | 1159 | + if (featureName == nullptr) { |
| 1156 | RT_LOG(RT_LOG_INFO, "featureType %d does not exist", featureType); | 1160 | RT_LOG(RT_LOG_INFO, "featureType %d does not exist", featureType); |
| 1157 | return false; | 1161 | return false; |
| 1158 | } | 1162 | } |
| 1159 | 1163 | ||
| 1160 | const bool isSupported = halSupportFeature(devId, static_cast<drvFeature_t>(featureType)); | 1164 | const bool isSupported = halSupportFeature(devId, static_cast<drvFeature_t>(featureType)); |
| 1161 | - RT_LOG(RT_LOG_INFO, "%s %s, drv devId=%u.", (isSupported ? "Support" : "Not support"), iter->second.c_str(), devId); | 1165 | + RT_LOG(RT_LOG_INFO, "%s %s, drv devId=%u.", (isSupported ? "Support" : "Not support"), featureName, devId); |
| 1162 | return isSupported; | 1166 | return isSupported; |
| 1163 | } | 1167 | } |
| 1164 | 1168 | ||
| @@ -541,15 +541,19 @@ rtError_t NpuDriver::GetAllocationGranularity( | |||
| 541 | 541 | ||
| 542 | static bool TransSharedHandleType(rtMemSharedHandleType handleType, drv_mem_handle_type& drvHandleType) | 542 | static bool TransSharedHandleType(rtMemSharedHandleType handleType, drv_mem_handle_type& drvHandleType) |
| 543 | { | 543 | { |
| 544 | - static const std::map<rtMemSharedHandleType, drv_mem_handle_type> typeMap = { | 544 | + bool isValid = true; |
| 545 | - {RT_MEM_SHARE_HANDLE_TYPE_DEFAULT, MEM_HANDLE_TYPE_NONE}, | 545 | + switch (handleType) { |
| 546 | - {RT_MEM_SHARE_HANDLE_TYPE_FABRIC, MEM_HANDLE_TYPE_FABRIC}}; | 546 | + case RT_MEM_SHARE_HANDLE_TYPE_DEFAULT: |
| 547 | - auto it = typeMap.find(handleType); | 547 | + drvHandleType = MEM_HANDLE_TYPE_NONE; |
| 548 | - if (it == typeMap.end()) { | 548 | + break; |
| 549 | - return false; | 549 | + case RT_MEM_SHARE_HANDLE_TYPE_FABRIC: |
| 550 | + drvHandleType = MEM_HANDLE_TYPE_FABRIC; | ||
| 551 | + break; | ||
| 552 | + default: | ||
| 553 | + isValid = false; | ||
| 554 | + break; | ||
| 550 | } | 555 | } |
| 551 | - drvHandleType = it->second; | 556 | + return isValid; |
| 552 | - return true; | ||
| 553 | } | 557 | } |
| 554 | 558 | ||
| 555 | rtError_t NpuDriver::ExportToShareableHandle( | 559 | rtError_t NpuDriver::ExportToShareableHandle( |
| @@ -1627,18 +1631,36 @@ void NpuDriver::FreeFastRingBuffer(void* const ptr, const uint64_t size, const u | |||
| 1627 | * Subcategory: Get Memory Info | 1631 | * Subcategory: Get Memory Info |
| 1628 | * ======================================================== */ | 1632 | * ======================================================== */ |
| 1629 | 1633 | ||
| 1630 | -std::map<rtMemInfoType_t, rtMemInfoType_t> g_memInfoTypeMap = { | 1634 | +static rtMemInfoType_t ConvertMemInfoType(const rtMemInfoType_t memInfoType) |
| 1631 | - {RT_MEMORYINFO_DDR, RT_MEMORYINFO_DDR}, | 1635 | +{ |
| 1632 | - {RT_MEMORYINFO_HBM, RT_MEMORYINFO_DDR}, | 1636 | + // Unmapped types use DDR on platforms that require memory information type conversion. |
| 1633 | - {RT_MEMORYINFO_DDR_HUGE, RT_MEMORYINFO_DDR_HUGE}, | 1637 | + rtMemInfoType_t targetType = RT_MEMORYINFO_DDR; |
| 1634 | - {RT_MEMORYINFO_DDR_NORMAL, RT_MEMORYINFO_DDR_NORMAL}, | 1638 | + switch (memInfoType) { |
| 1635 | - {RT_MEMORYINFO_HBM_HUGE, RT_MEMORYINFO_DDR_HUGE}, | 1639 | + case RT_MEMORYINFO_DDR: |
| 1636 | - {RT_MEMORYINFO_HBM_NORMAL, RT_MEMORYINFO_DDR_NORMAL}, | 1640 | + case RT_MEMORYINFO_HBM: |
| 1637 | - {RT_MEMORYINFO_DDR_P2P_HUGE, RT_MEMORYINFO_DDR_P2P_HUGE}, | 1641 | + targetType = RT_MEMORYINFO_DDR; |
| 1638 | - {RT_MEMORYINFO_DDR_P2P_NORMAL, RT_MEMORYINFO_DDR_P2P_NORMAL}, | 1642 | + break; |
| 1639 | - {RT_MEMORYINFO_HBM_P2P_HUGE, RT_MEMORYINFO_DDR_P2P_HUGE}, | 1643 | + case RT_MEMORYINFO_DDR_HUGE: |
| 1640 | - {RT_MEMORYINFO_HBM_P2P_NORMAL, RT_MEMORYINFO_DDR_P2P_NORMAL}, | 1644 | + case RT_MEMORYINFO_HBM_HUGE: |
| 1641 | -}; | 1645 | + targetType = RT_MEMORYINFO_DDR_HUGE; |
| 1646 | + break; | ||
| 1647 | + case RT_MEMORYINFO_DDR_NORMAL: | ||
| 1648 | + case RT_MEMORYINFO_HBM_NORMAL: | ||
| 1649 | + targetType = RT_MEMORYINFO_DDR_NORMAL; | ||
| 1650 | + break; | ||
| 1651 | + case RT_MEMORYINFO_DDR_P2P_HUGE: | ||
| 1652 | + case RT_MEMORYINFO_HBM_P2P_HUGE: | ||
| 1653 | + targetType = RT_MEMORYINFO_DDR_P2P_HUGE; | ||
| 1654 | + break; | ||
| 1655 | + case RT_MEMORYINFO_DDR_P2P_NORMAL: | ||
| 1656 | + case RT_MEMORYINFO_HBM_P2P_NORMAL: | ||
| 1657 | + targetType = RT_MEMORYINFO_DDR_P2P_NORMAL; | ||
| 1658 | + break; | ||
| 1659 | + default: | ||
| 1660 | + break; | ||
| 1661 | + } | ||
| 1662 | + return targetType; | ||
| 1663 | +} | ||
| 1642 | 1664 | ||
| 1643 | static rtError_t GetMemInfoType(const rtMemInfoType_t memInfoType, uint32_t* const type) | 1665 | static rtError_t GetMemInfoType(const rtMemInfoType_t memInfoType, uint32_t* const type) |
| 1644 | { | 1666 | { |
| @@ -1899,7 +1921,7 @@ rtError_t NpuDriver::MemGetInfoEx( | |||
| 1899 | uint32_t type = 0U; | 1921 | uint32_t type = 0U; |
| 1900 | rtMemInfoType_t curMemInfoType = memInfoType; | 1922 | rtMemInfoType_t curMemInfoType = memInfoType; |
| 1901 | if ((GetDevProperties().memInfoMapType & MAP_WHEN_GET_INFO) != 0) { | 1923 | if ((GetDevProperties().memInfoMapType & MAP_WHEN_GET_INFO) != 0) { |
| 1902 | - curMemInfoType = g_memInfoTypeMap[memInfoType]; | 1924 | + curMemInfoType = ConvertMemInfoType(memInfoType); |
| 1903 | RT_LOG( | 1925 | RT_LOG( |
| 1904 | RT_LOG_INFO, "memInfoType convert %s to %s.", MemInfoTypeToString(memInfoType).c_str(), | 1926 | RT_LOG_INFO, "memInfoType convert %s to %s.", MemInfoTypeToString(memInfoType).c_str(), |
| 1905 | MemInfoTypeToString(curMemInfoType).c_str()); | 1927 | MemInfoTypeToString(curMemInfoType).c_str()); |
| @@ -42,6 +42,7 @@ | |||
| 42 | #include <securec.h> | 42 | #include <securec.h> |
| 43 | #include <algorithm> | 43 | #include <algorithm> |
| 44 | #include "task.hpp" | 44 | #include "task.hpp" |
| 45 | +#include "stream_launch_blocking.hpp" | ||
| 45 | 46 | ||
| 46 | namespace cce { | 47 | namespace cce { |
| 47 | namespace runtime { | 48 | namespace runtime { |
| @@ -524,11 +525,32 @@ rtError_t CaptureModel::ExecuteCommon(Stream* const stm, int32_t timeout, const | |||
| 524 | } | 525 | } |
| 525 | rtError_t CaptureModel::Execute(Stream* const stm, int32_t timeout) | 526 | rtError_t CaptureModel::Execute(Stream* const stm, int32_t timeout) |
| 526 | { | 527 | { |
| 527 | - return ExecuteCommon(stm, timeout, RT_MODEL_CAPTURE_EXECUTE_DEFAULT); | 528 | + Context* const context = Context_(); |
| 529 | + NULL_PTR_RETURN_MSG(context, RT_ERROR_CONTEXT_NULL); | ||
| 530 | + Stream* const executeStream = (stm == nullptr) ? context->DefaultStream_() : stm; | ||
| 531 | + NULL_STREAM_PTR_RETURN_MSG(executeStream); | ||
| 532 | + | ||
| 533 | + rtError_t error = ExecuteCommon(executeStream, timeout, RT_MODEL_CAPTURE_EXECUTE_DEFAULT); | ||
| 534 | + const bool isSyncExecuteStream = ((executeStream->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U); | ||
| 535 | + if ((error == RT_ERROR_NONE) && !isSyncExecuteStream && StreamLaunchBlocking::ShouldLaunchBlock(executeStream)) { | ||
| 536 | + executeStream->SetSyncMdlId(Id_()); | ||
| 537 | + error = executeStream->Synchronize(false, timeout); | ||
| 538 | + executeStream->SetSyncMdlId(MODEL_ID_INVALID); | ||
| 539 | + ERROR_RETURN( | ||
| 540 | + error, "Capture model post execute synchronization failed, stream_id=%d, model_id=%u, retCode=%#x.", | ||
| 541 | + executeStream->Id_(), Id_(), error); | ||
| 542 | + } | ||
| 543 | + return error; | ||
| 528 | } | 544 | } |
| 545 | + | ||
| 529 | rtError_t CaptureModel::ExecuteAsync(Stream* const stm) | 546 | rtError_t CaptureModel::ExecuteAsync(Stream* const stm) |
| 530 | { | 547 | { |
| 531 | - return ExecuteCommon(stm, -1, RT_MODEL_CAPTURE_EXECUTE_ASYNC); | 548 | + Context* const context = Context_(); |
| 549 | + NULL_PTR_RETURN_MSG(context, RT_ERROR_CONTEXT_NULL); | ||
| 550 | + Stream* const executeStream = (stm == nullptr) ? context->DefaultStream_() : stm; | ||
| 551 | + NULL_STREAM_PTR_RETURN_MSG(executeStream); | ||
| 552 | + | ||
| 553 | + return ExecuteCommon(executeStream, -1, RT_MODEL_CAPTURE_EXECUTE_ASYNC); | ||
| 532 | } | 554 | } |
| 533 | 555 | ||
| 534 | void CaptureModel::ReleaseNotifyListOnDestroy(std::vector<Notify*>& notifyList) | 556 | void CaptureModel::ReleaseNotifyListOnDestroy(std::vector<Notify*>& notifyList) |
| @@ -0,0 +1,168 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | +#include "stream_launch_blocking.hpp" | ||
| 11 | + | ||
| 12 | +#include <new> | ||
是否可以不使用new ![]() ![]() | |||
| 13 | +#include "context.hpp" | ||
| 14 | +#include "error_message_manage.hpp" | ||
| 15 | +#include "runtime.hpp" | ||
| 16 | +#include "runtime/rts/rts_stream.h" | ||
| 17 | +#include "stream.hpp" | ||
| 18 | + | ||
| 19 | +namespace cce { | ||
| 20 | +namespace runtime { | ||
| 21 | +constexpr uint32_t LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS = | ||
| 22 | + RT_STREAM_PERSISTENT | RT_STREAM_AICPU | RT_STREAM_CP_PROCESS_USE; | ||
| 23 | + | ||
| 24 | +StreamLaunchBlocking::StreamLaunchBlocking() : mode_(RT_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV), nonBlockingDepth_(0U) | ||
| 25 | +{} | ||
| 26 | + | ||
| 27 | +bool StreamLaunchBlocking::End(bool& isNonBlockingSectionClosed) | ||
| 28 | +{ | ||
| 29 | + uint32_t depth = nonBlockingDepth_.Value(); | ||
| 30 | + while (depth > 0U) { | ||
| 31 | + if (nonBlockingDepth_.CompareExchange(depth, depth - 1U)) { | ||
| 32 | + // A depth transition from 1 to 0 closes the outermost non-blocking section. | ||
| 33 | + isNonBlockingSectionClosed = (depth == 1U); | ||
| 34 | + return true; | ||
| 35 | + } | ||
| 36 | + depth = nonBlockingDepth_.Value(); | ||
| 37 | + } | ||
| 38 | + return false; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +rtError_t StreamLaunchBlocking::GetLaunchBlockingState(Stream* const stm, StreamLaunchBlocking*& launchBlockingState) | ||
| 42 | +{ | ||
| 43 | + launchBlockingState = stm->launchBlockingState_.Value(); | ||
| 44 | + if (launchBlockingState != nullptr) { | ||
| 45 | + return RT_ERROR_NONE; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + // Concurrent first callers may allocate together; only the CAS winner installs its state. | ||
| 49 | + StreamLaunchBlocking* const candidate = new (std::nothrow) StreamLaunchBlocking(); | ||
| 50 | + COND_RETURN_AND_MSG_OUTER( | ||
| 51 | + candidate == nullptr, RT_ERROR_MEMORY_ALLOCATION, ErrorCode::EE1013, sizeof(StreamLaunchBlocking), "new"); | ||
| 52 | + if (stm->launchBlockingState_.CompareExchange(nullptr, candidate)) { | ||
| 53 | + launchBlockingState = candidate; | ||
| 54 | + } else { | ||
| 55 | + delete candidate; | ||
| 56 | + launchBlockingState = stm->launchBlockingState_.Value(); | ||
| 57 | + } | ||
| 58 | + return RT_ERROR_NONE; | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +void StreamLaunchBlocking::ReleaseLaunchBlockingState(Stream* const stm) | ||
| 62 | +{ | ||
| 63 | + StreamLaunchBlocking* launchBlockingState = stm->launchBlockingState_.Exchange(nullptr); | ||
| 64 | + DELETE_O(launchBlockingState); | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +rtError_t StreamLaunchBlocking::SetLaunchBlockingMode(Stream* const stm, const uint32_t mode) | ||
| 68 | +{ | ||
| 69 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 70 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 71 | + | ||
| 72 | + Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 73 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 74 | + COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 75 | + targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Setting the stream launch blocking mode"); | ||
| 76 | + | ||
| 77 | + StreamLaunchBlocking* launchBlockingState = targetStm->launchBlockingState_.Value(); | ||
| 78 | + if ((launchBlockingState == nullptr) && (mode == RT_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV)) { | ||
| 79 | + // The null state already represents the default mode, so no allocation is needed. | ||
| 80 | + return RT_ERROR_NONE; | ||
| 81 | + } | ||
| 82 | + if (launchBlockingState == nullptr) { | ||
| 83 | + const rtError_t error = GetLaunchBlockingState(targetStm, launchBlockingState); | ||
| 84 | + if (error != RT_ERROR_NONE) { | ||
| 85 | + return error; | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + launchBlockingState->SetMode(mode); | ||
| 89 | + return RT_ERROR_NONE; | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +rtError_t StreamLaunchBlocking::GetLaunchBlockingMode(const Stream* const stm, uint32_t* const mode) | ||
| 93 | +{ | ||
| 94 | + Context* const curCtx = Runtime::Instance()->CurrentContext(true, DEFAULT_DEVICE_ID); | ||
| 95 | + CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL); | ||
| 96 | + | ||
| 97 | + const Stream* const targetStm = (stm == nullptr) ? curCtx->DefaultStream_() : stm; | ||
| 98 | + NULL_STREAM_PTR_RETURN_MSG(targetStm); | ||
| 99 | + COND_RETURN_AND_MSG_INVALID_CONTEXT_STREAM_WITH_FUNC_DESC( | ||
| 100 | + targetStm, curCtx, RT_ERROR_STREAM_CONTEXT, "Obtaining the stream launch blocking mode"); | ||
| 101 | + const StreamLaunchBlocking* const launchBlockingState = targetStm->launchBlockingState_.Value(); | ||
| 102 | + *mode = | ||
| 103 | + (launchBlockingState == nullptr) ? RT_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV : launchBlockingState->GetMode(); | ||
| 104 | + return RT_ERROR_NONE; | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +rtError_t StreamLaunchBlocking::NonBlockingLaunchBegin(Stream* const stream) | ||
| 108 | +{ | ||
| 109 | + StreamLaunchBlocking* launchBlockingState = nullptr; | ||
| 110 | + const rtError_t error = GetLaunchBlockingState(stream, launchBlockingState); | ||
| 111 | + if (error != RT_ERROR_NONE) { | ||
| 112 | + return error; | ||
| 113 | + } | ||
| 114 | + launchBlockingState->Begin(); | ||
| 115 | + return RT_ERROR_NONE; | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +rtError_t StreamLaunchBlocking::NonBlockingLaunchEnd(Stream* const stream) | ||
| 119 | +{ | ||
| 120 | + bool isNonBlockingSectionClosed = false; | ||
| 121 | + StreamLaunchBlocking* const launchBlockingState = stream->launchBlockingState_.Value(); | ||
| 122 | + if ((launchBlockingState == nullptr) || !launchBlockingState->End(isNonBlockingSectionClosed)) { | ||
| 123 | + RT_LOG_OUTER_MSG_IMPL( | ||
| 124 | + ErrorCode::EE1018, "Ending a non-blocking launch section", | ||
| 125 | + RtFmtMsg( | ||
| 126 | + "The stream (stream_id=%d) is not in a non-blocking launch section. Call the " | ||
| 127 | + "aclrtNonBlockingLaunchBegin API first", | ||
| 128 | + stream->Id_())); | ||
| 129 | + return RT_ERROR_INVALID_VALUE; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + if (isNonBlockingSectionClosed && ShouldLaunchBlock(stream)) { | ||
| 133 | + return stream->Synchronize(false); | ||
| 134 | + } | ||
| 135 | + return RT_ERROR_NONE; | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | +bool StreamLaunchBlocking::IsNonBlockingLaunchActive(const Stream* const stm) | ||
| 139 | +{ | ||
| 140 | + const StreamLaunchBlocking* const launchBlockingState = stm->launchBlockingState_.Value(); | ||
| 141 | + return (launchBlockingState != nullptr) && (launchBlockingState->nonBlockingDepth_.Value() > 0U); | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +bool StreamLaunchBlocking::ShouldLaunchBlock(const Stream* const stm) | ||
| 145 | +{ | ||
| 146 | + if ((stm == nullptr) || !stm->Device_()->IsSupportFeature(RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING) || | ||
| 147 | + stm->IsModelStream() || stm->GetBindFlag() || stm->IsCapturing() || | ||
| 148 | + ((stm->Flags() & LAUNCH_BLOCKING_UNSUPPORTED_STREAM_FLAGS) != 0U)) { | ||
| 149 | + return false; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + if (IsNonBlockingLaunchActive(stm)) { | ||
| 153 | + return false; | ||
| 154 | + } | ||
| 155 | + const StreamLaunchBlocking* const launchBlockingState = stm->launchBlockingState_.Value(); | ||
| 156 | + const uint32_t mode = | ||
| 157 | + (launchBlockingState == nullptr) ? RT_STREAM_LAUNCH_BLOCKING_MODE_CTRL_BY_ENV : launchBlockingState->GetMode(); | ||
| 158 | + if (mode == RT_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING) { | ||
| 159 | + return false; | ||
| 160 | + } | ||
| 161 | + if (mode == RT_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING) { | ||
| 162 | + return true; | ||
| 163 | + } | ||
| 164 | + return Runtime::Instance()->IsLaunchBlockingEnvEnabled(); | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +} // namespace runtime | ||
| 168 | +} // namespace cce | ||
| @@ -0,0 +1,50 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | +#ifndef CCE_RUNTIME_STREAM_LAUNCH_BLOCKING_HPP | ||
| 11 | +#define CCE_RUNTIME_STREAM_LAUNCH_BLOCKING_HPP | ||
| 12 | + | ||
| 13 | +#include <cstdint> | ||
| 14 | +#include "base.hpp" | ||
| 15 | +#include "osal.hpp" | ||
| 16 | + | ||
| 17 | +namespace cce { | ||
| 18 | +namespace runtime { | ||
| 19 | + | ||
| 20 | +class Stream; | ||
| 21 | + | ||
| 22 | +class StreamLaunchBlocking { | ||
| 23 | +public: | ||
| 24 | + static rtError_t SetLaunchBlockingMode(Stream* stm, uint32_t mode); | ||
| 25 | + static rtError_t GetLaunchBlockingMode(const Stream* stm, uint32_t* mode); | ||
| 26 | + static rtError_t NonBlockingLaunchBegin(Stream* stream); | ||
| 27 | + static rtError_t NonBlockingLaunchEnd(Stream* stream); | ||
| 28 | + static bool IsNonBlockingLaunchActive(const Stream* stm); | ||
| 29 | + static bool ShouldLaunchBlock(const Stream* stm); | ||
| 30 | + | ||
| 31 | +private: | ||
| 32 | + friend class Stream; | ||
| 33 | + StreamLaunchBlocking(); | ||
| 34 | + | ||
| 35 | + void SetMode(uint32_t mode) { mode_.Set(mode); } | ||
| 36 | + uint32_t GetMode() const { return mode_.Value(); } | ||
| 37 | + void Begin() { nonBlockingDepth_.Add(1U); } | ||
| 38 | + bool End(bool& isNonBlockingSectionClosed); | ||
| 39 | + | ||
| 40 | + static rtError_t GetLaunchBlockingState(Stream* stm, StreamLaunchBlocking*& launchBlockingState); | ||
| 41 | + static void ReleaseLaunchBlockingState(Stream* stm); | ||
| 42 | + | ||
| 43 | + Atomic<uint32_t> mode_; | ||
| 44 | + Atomic<uint32_t> nonBlockingDepth_; | ||
| 45 | +}; | ||
| 46 | + | ||
| 47 | +} // namespace runtime | ||
| 48 | +} // namespace cce | ||
| 49 | + | ||
| 50 | +#endif // CCE_RUNTIME_STREAM_LAUNCH_BLOCKING_HPP | ||
| @@ -0,0 +1,56 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | +#include "stream_launch_blocking.hpp" | ||
| 11 | + | ||
| 12 | +namespace cce { | ||
| 13 | +namespace runtime { | ||
| 14 | + | ||
| 15 | +void StreamLaunchBlocking::ReleaseLaunchBlockingState(Stream* const stm) { UNUSED(stm); } | ||
| 16 | + | ||
| 17 | +rtError_t StreamLaunchBlocking::SetLaunchBlockingMode(Stream* const stm, const uint32_t mode) | ||
| 18 | +{ | ||
| 19 | + UNUSED(stm); | ||
| 20 | + UNUSED(mode); | ||
| 21 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +rtError_t StreamLaunchBlocking::GetLaunchBlockingMode(const Stream* const stm, uint32_t* const mode) | ||
| 25 | +{ | ||
| 26 | + UNUSED(stm); | ||
| 27 | + UNUSED(mode); | ||
| 28 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +rtError_t StreamLaunchBlocking::NonBlockingLaunchBegin(Stream* const stream) | ||
| 32 | +{ | ||
| 33 | + UNUSED(stream); | ||
| 34 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +rtError_t StreamLaunchBlocking::NonBlockingLaunchEnd(Stream* const stream) | ||
| 38 | +{ | ||
| 39 | + UNUSED(stream); | ||
| 40 | + return RT_ERROR_FEATURE_NOT_SUPPORT; | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +bool StreamLaunchBlocking::IsNonBlockingLaunchActive(const Stream* const stm) | ||
| 44 | +{ | ||
| 45 | + UNUSED(stm); | ||
| 46 | + return false; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +bool StreamLaunchBlocking::ShouldLaunchBlock(const Stream* const stm) | ||
| 50 | +{ | ||
| 51 | + UNUSED(stm); | ||
| 52 | + return false; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +} // namespace runtime | ||
| 56 | +} // namespace cce | ||
| @@ -42,6 +42,7 @@ | |||
| 42 | #include "task_david.hpp" | 42 | #include "task_david.hpp" |
| 43 | #include "capture_model.hpp" | 43 | #include "capture_model.hpp" |
| 44 | #include "logic_sq.hpp" | 44 | #include "logic_sq.hpp" |
| 45 | +#include "stream_launch_blocking.hpp" | ||
| 45 | 46 | ||
| 46 | namespace cce { | 47 | namespace cce { |
| 47 | namespace runtime { | 48 | namespace runtime { |
| @@ -1376,6 +1377,15 @@ rtError_t Model::GetStreamToAsyncExecute(Stream* stm) | |||
| 1376 | ERROR_RETURN_MSG_INNER(error, "Model serial sched post proc failed, stream_id=%d.", stm->Id_()); | 1377 | ERROR_RETURN_MSG_INNER(error, "Model serial sched post proc failed, stream_id=%d.", stm->Id_()); |
| 1377 | } | 1378 | } |
| 1378 | 1379 | ||
| 1380 | + if ((modelType_ != RT_MODEL_CAPTURE_MODEL) && StreamLaunchBlocking::ShouldLaunchBlock(stm)) { | ||
| 1381 | + stm->SetSyncMdlId(id_); | ||
同步成功之后清除状态 ![]() ![]() | |||
| 1382 | + error = stm->Synchronize(false); | ||
| 1383 | + stm->SetSyncMdlId(MODEL_ID_INVALID); | ||
| 1384 | + ERROR_GOTO_MSG_INNER( | ||
| 1385 | + error, ERROR_RELEASE, "Model blocking execute synchronization failed, stream_id=%d, retCode=%#x.", | ||
| 1386 | + stm->Id_(), static_cast<uint32_t>(error)); | ||
| 1387 | + } | ||
| 1388 | + | ||
| 1379 | if (isDelTmpStream) { | 1389 | if (isDelTmpStream) { |
| 1380 | error = context_->StreamDestroy(stm); | 1390 | error = context_->StreamDestroy(stm); |
| 1381 | COND_PROC_RETURN_ERROR(error != RT_ERROR_NONE, error, SetExeStream(nullptr); | 1391 | COND_PROC_RETURN_ERROR(error != RT_ERROR_NONE, error, SetExeStream(nullptr); |
| @@ -108,7 +108,9 @@ enum class RtOptionalFeatureType : std::uint32_t { | |||
| 108 | RT_FEATURE_KERNEL_META_TYPE_SU_STACK_SIZE, | 108 | RT_FEATURE_KERNEL_META_TYPE_SU_STACK_SIZE, |
| 109 | RT_FEATURE_KERNEL_DOT_PROGRAM_ALLOCATOR, | 109 | RT_FEATURE_KERNEL_DOT_PROGRAM_ALLOCATOR, |
| 110 | RT_FEATURE_KERNEL_TILING_TABLE_PHY_CONTIGUOUS, | 110 | RT_FEATURE_KERNEL_TILING_TABLE_PHY_CONTIGUOUS, |
| 111 | - RT_FEATURE_KERNEL_NO_MIX_DOT_REGISTER, | 111 | + // Legacy products do not adapt operators to avoid launch-blocking deadlocks. |
| 112 | + // Runtime uses this feature to gate the behavior. | ||
| 113 | + RT_FEATURE_LAUNCH_BLOCKING, | ||
增加说明加这个特性开关背景,存量芯片的OPS不投入修改死锁问题,因此Runtime利用此开关拦截 ![]() ![]() | |||
| 112 | RT_FEATURE_KERNEL_TASK_RATION, | 114 | RT_FEATURE_KERNEL_TASK_RATION, |
| 113 | RT_FEATURE_KERNEL_ELF_AICPU_MACHINE, | 115 | RT_FEATURE_KERNEL_ELF_AICPU_MACHINE, |
| 114 | RT_FEATURE_KERNEL_ELF_16K_STACK, | 116 | RT_FEATURE_KERNEL_ELF_16K_STACK, |
| @@ -453,6 +453,8 @@ public: | |||
| 453 | const void* const devAddr, const uint64_t value, const uint32_t flag, rtStream_t stm); | 453 | const void* const devAddr, const uint64_t value, const uint32_t flag, rtStream_t stm); |
| 454 | 454 | ||
| 455 | virtual rtError_t rtsStreamGetAvailableNum(uint32_t* streamCount); | 455 | virtual rtError_t rtsStreamGetAvailableNum(uint32_t* streamCount); |
| 456 | + virtual rtError_t rtNonBlockingLaunchBegin(rtStream_t stream, uint64_t flag); | ||
| 457 | + virtual rtError_t rtNonBlockingLaunchEnd(rtStream_t stream, uint64_t flag); | ||
| 456 | virtual rtError_t rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue); | 458 | virtual rtError_t rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue); |
| 457 | virtual rtError_t rtsStreamGetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue); | 459 | virtual rtError_t rtsStreamGetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue); |
| 458 | 460 | ||
| @@ -1083,6 +1085,8 @@ public: | |||
| 1083 | rtsValueWait, rtError_t(const void* const devAddr, const uint64_t value, const uint32_t flag, rtStream_t stm)); | 1085 | rtsValueWait, rtError_t(const void* const devAddr, const uint64_t value, const uint32_t flag, rtStream_t stm)); |
| 1084 | 1086 | ||
| 1085 | MOCK_METHOD1(rtsStreamGetAvailableNum, rtError_t(uint32_t* streamCount)); | 1087 | MOCK_METHOD1(rtsStreamGetAvailableNum, rtError_t(uint32_t* streamCount)); |
| 1088 | + MOCK_METHOD2(rtNonBlockingLaunchBegin, rtError_t(rtStream_t stream, uint64_t flag)); | ||
| 1089 | + MOCK_METHOD2(rtNonBlockingLaunchEnd, rtError_t(rtStream_t stream, uint64_t flag)); | ||
| 1086 | MOCK_METHOD3( | 1090 | MOCK_METHOD3( |
| 1087 | rtsStreamSetAttribute, rtError_t(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue)); | 1091 | rtsStreamSetAttribute, rtError_t(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue)); |
| 1088 | MOCK_METHOD3( | 1092 | MOCK_METHOD3( |
| @@ -1553,6 +1553,20 @@ rtError_t aclStub::rtsStreamGetAvailableNum(uint32_t* streamCount) | |||
| 1553 | return RT_ERROR_NONE; | 1553 | return RT_ERROR_NONE; |
| 1554 | } | 1554 | } |
| 1555 | 1555 | ||
| 1556 | +rtError_t aclStub::rtNonBlockingLaunchBegin(rtStream_t stream, uint64_t flag) | ||
| 1557 | +{ | ||
| 1558 | + (void)stream; | ||
| 1559 | + (void)flag; | ||
| 1560 | + return RT_ERROR_NONE; | ||
| 1561 | +} | ||
| 1562 | + | ||
| 1563 | +rtError_t aclStub::rtNonBlockingLaunchEnd(rtStream_t stream, uint64_t flag) | ||
| 1564 | +{ | ||
| 1565 | + (void)stream; | ||
| 1566 | + (void)flag; | ||
| 1567 | + return RT_ERROR_NONE; | ||
| 1568 | +} | ||
| 1569 | + | ||
| 1556 | rtError_t aclStub::rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) | 1570 | rtError_t aclStub::rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) |
| 1557 | { | 1571 | { |
| 1558 | (void)stm; | 1572 | (void)stm; |
| @@ -3890,6 +3904,16 @@ rtError_t rtsStreamGetAvailableNum(uint32_t* streamCount) | |||
| 3890 | return MockFunctionTest::aclStubInstance().rtsStreamGetAvailableNum(streamCount); | 3904 | return MockFunctionTest::aclStubInstance().rtsStreamGetAvailableNum(streamCount); |
| 3891 | } | 3905 | } |
| 3892 | 3906 | ||
| 3907 | +rtError_t rtNonBlockingLaunchBegin(rtStream_t stream, uint64_t flag) | ||
| 3908 | +{ | ||
| 3909 | + return MockFunctionTest::aclStubInstance().rtNonBlockingLaunchBegin(stream, flag); | ||
| 3910 | +} | ||
| 3911 | + | ||
| 3912 | +rtError_t rtNonBlockingLaunchEnd(rtStream_t stream, uint64_t flag) | ||
| 3913 | +{ | ||
| 3914 | + return MockFunctionTest::aclStubInstance().rtNonBlockingLaunchEnd(stream, flag); | ||
| 3915 | +} | ||
| 3916 | + | ||
| 3893 | rtError_t rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) | 3917 | rtError_t rtsStreamSetAttribute(rtStream_t stm, rtStreamAttr stmAttrId, rtStreamAttrValue_t* attrValue) |
| 3894 | { | 3918 | { |
| 3895 | return MockFunctionTest::aclStubInstance().rtsStreamSetAttribute(stm, stmAttrId, attrValue); | 3919 | return MockFunctionTest::aclStubInstance().rtsStreamSetAttribute(stm, stmAttrId, attrValue); |
| @@ -744,6 +744,45 @@ TEST_F(UTEST_ACL_Runtime, aclrtSynchronizeStreamWithTimeoutTest) | |||
| 744 | EXPECT_EQ(ret, ACL_ERROR_RT_END_OF_SEQUENCE); | 744 | EXPECT_EQ(ret, ACL_ERROR_RT_END_OF_SEQUENCE); |
| 745 | } | 745 | } |
| 746 | 746 | ||
| 747 | +TEST_F(UTEST_ACL_Runtime, aclrtNonBlockingLaunchTest) | ||
| 748 | +{ | ||
| 749 | + aclrtStream stream = (aclrtStream)0x01; | ||
| 750 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtNonBlockingLaunchBegin(nullptr, 0U)) | ||
| 751 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 752 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtNonBlockingLaunchEnd(nullptr, 0U)) | ||
| 753 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 754 | + aclError ret = aclrtNonBlockingLaunchBegin(nullptr, 0U); | ||
| 755 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 756 | + | ||
| 757 | + ret = aclrtNonBlockingLaunchEnd(nullptr, 0U); | ||
| 758 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 759 | + | ||
| 760 | + ret = aclrtNonBlockingLaunchBegin(stream, 1U); | ||
| 761 | + EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM); | ||
| 762 | + | ||
| 763 | + ret = aclrtNonBlockingLaunchEnd(stream, 1U); | ||
| 764 | + EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM); | ||
| 765 | + | ||
| 766 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtNonBlockingLaunchBegin(_, _)) | ||
| 767 | + .WillOnce(Return(ACL_ERROR_RT_PARAM_INVALID)) | ||
| 768 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 769 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtNonBlockingLaunchEnd(_, _)) | ||
| 770 | + .WillOnce(Return(ACL_ERROR_RT_PARAM_INVALID)) | ||
| 771 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 772 | + | ||
| 773 | + ret = aclrtNonBlockingLaunchBegin(stream, 0U); | ||
| 774 | + EXPECT_EQ(ret, ACL_ERROR_RT_PARAM_INVALID); | ||
| 775 | + | ||
| 776 | + ret = aclrtNonBlockingLaunchEnd(stream, 0U); | ||
| 777 | + EXPECT_EQ(ret, ACL_ERROR_RT_PARAM_INVALID); | ||
| 778 | + | ||
| 779 | + ret = aclrtNonBlockingLaunchBegin(stream, 0U); | ||
| 780 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 781 | + | ||
| 782 | + ret = aclrtNonBlockingLaunchEnd(stream, 0U); | ||
| 783 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 784 | +} | ||
| 785 | + | ||
| 747 | TEST_F(UTEST_ACL_Runtime, aclrtStreamQueryTest) | 786 | TEST_F(UTEST_ACL_Runtime, aclrtStreamQueryTest) |
| 748 | { | 787 | { |
| 749 | // test aclrtStreamQuery | 788 | // test aclrtStreamQuery |
| @@ -5762,6 +5801,23 @@ TEST_F(UTEST_ACL_Runtime, aclrtSetStreamAttribute_success) | |||
| 5762 | EXPECT_EQ(ret, ACL_SUCCESS); | 5801 | EXPECT_EQ(ret, ACL_SUCCESS); |
| 5763 | } | 5802 | } |
| 5764 | 5803 | ||
| 5804 | +TEST_F(UTEST_ACL_Runtime, aclrtSetStreamAttribute_launchBlocking_success) | ||
| 5805 | +{ | ||
| 5806 | + aclrtStream stream = (aclrtStream)0x01; | ||
| 5807 | + aclrtStreamAttrValue value = {}; | ||
| 5808 | + value.launchBlockingMode = ACL_STREAM_LAUNCH_BLOCKING_MODE_NON_BLOCKING; | ||
| 5809 | + | ||
| 5810 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtsStreamSetAttribute(stream, _, _)) | ||
| 5811 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 5812 | + auto ret = aclrtSetStreamAttribute(stream, ACL_STREAM_LAUNCH_BLOCKING_MODE, &value); | ||
| 5813 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 5814 | + | ||
| 5815 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtsStreamSetAttribute(nullptr, _, _)) | ||
| 5816 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 5817 | + ret = aclrtSetStreamAttribute(nullptr, ACL_STREAM_LAUNCH_BLOCKING_MODE, &value); | ||
| 5818 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 5819 | +} | ||
| 5820 | + | ||
| 5765 | TEST_F(UTEST_ACL_Runtime, aclrtGetStreamAttribute_failed_with_invalid_args) | 5821 | TEST_F(UTEST_ACL_Runtime, aclrtGetStreamAttribute_failed_with_invalid_args) |
| 5766 | { | 5822 | { |
| 5767 | aclrtStreamAttr stmAttrType = ACL_STREAM_ATTR_FAILURE_MODE; | 5823 | aclrtStreamAttr stmAttrType = ACL_STREAM_ATTR_FAILURE_MODE; |
| @@ -5789,6 +5845,22 @@ TEST_F(UTEST_ACL_Runtime, aclrtGetStreamAttribute_success) | |||
| 5789 | EXPECT_EQ(ret, ACL_SUCCESS); | 5845 | EXPECT_EQ(ret, ACL_SUCCESS); |
| 5790 | } | 5846 | } |
| 5791 | 5847 | ||
| 5848 | +TEST_F(UTEST_ACL_Runtime, aclrtGetStreamAttribute_launchBlocking_success) | ||
| 5849 | +{ | ||
| 5850 | + aclrtStream stream = (aclrtStream)0x01; | ||
| 5851 | + aclrtStreamAttrValue value = {}; | ||
| 5852 | + | ||
| 5853 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtsStreamGetAttribute(stream, _, _)) | ||
| 5854 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 5855 | + auto ret = aclrtGetStreamAttribute(stream, ACL_STREAM_LAUNCH_BLOCKING_MODE, &value); | ||
| 5856 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 5857 | + | ||
| 5858 | + EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtsStreamGetAttribute(nullptr, _, _)) | ||
| 5859 | + .WillOnce(Return(RT_ERROR_NONE)); | ||
| 5860 | + ret = aclrtGetStreamAttribute(nullptr, ACL_STREAM_LAUNCH_BLOCKING_MODE, &value); | ||
| 5861 | + EXPECT_EQ(ret, ACL_SUCCESS); | ||
| 5862 | +} | ||
| 5863 | + | ||
| 5792 | TEST_F(UTEST_ACL_Runtime, aclrtCreateNotify_failed_with_invalid_args) | 5864 | TEST_F(UTEST_ACL_Runtime, aclrtCreateNotify_failed_with_invalid_args) |
| 5793 | { | 5865 | { |
| 5794 | auto ret = aclrtCreateNotify(nullptr, 0); | 5866 | auto ret = aclrtCreateNotify(nullptr, 0); |
| @@ -313,6 +313,8 @@ TEST_F(UTEST_ACL_compatibility_cast_check, aclrtStreamAttr) | |||
| 313 | EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_FLOAT_OVERFLOW_CHECK, (uint64_t)RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK); | 313 | EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_FLOAT_OVERFLOW_CHECK, (uint64_t)RT_STREAM_ATTR_FLOAT_OVERFLOW_CHECK); |
| 314 | EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_USER_CUSTOM_TAG, (uint64_t)RT_STREAM_ATTR_USER_CUSTOM_TAG); | 314 | EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_USER_CUSTOM_TAG, (uint64_t)RT_STREAM_ATTR_USER_CUSTOM_TAG); |
| 315 | EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_CACHE_OP_INFO, (uint64_t)RT_STREAM_ATTR_CACHE_OP_INFO); | 315 | EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_CACHE_OP_INFO, (uint64_t)RT_STREAM_ATTR_CACHE_OP_INFO); |
| 316 | + EXPECT_EQ((uint64_t)ACL_STREAM_ATTR_PRIORITY, (uint64_t)RT_STREAM_ATTR_PRIORITY); | ||
| 317 | + EXPECT_EQ((uint64_t)ACL_STREAM_LAUNCH_BLOCKING_MODE, (uint64_t)RT_STREAM_ATTR_LAUNCH_BLOCKING_MODE); | ||
| 316 | 318 | ||
| 317 | // check total size | 319 | // check total size |
| 318 | EXPECT_EQ(sizeof(aclrtStreamAttr), sizeof(rtStreamAttr)); | 320 | EXPECT_EQ(sizeof(aclrtStreamAttr), sizeof(rtStreamAttr)); |
| @@ -795,6 +795,12 @@ TEST_F(UTEST_ACL_compatibility_enum_check, aclrtStreamAttr) | |||
| 795 | value = (aclrtStreamAttr)4; | 795 | value = (aclrtStreamAttr)4; |
| 796 | EXPECT_EQ(value, ACL_STREAM_ATTR_CACHE_OP_INFO); | 796 | EXPECT_EQ(value, ACL_STREAM_ATTR_CACHE_OP_INFO); |
| 797 | 797 | ||
| 798 | + value = (aclrtStreamAttr)5; | ||
| 799 | + EXPECT_EQ(value, ACL_STREAM_ATTR_PRIORITY); | ||
| 800 | + | ||
| 801 | + value = (aclrtStreamAttr)6; | ||
| 802 | + EXPECT_EQ(value, ACL_STREAM_LAUNCH_BLOCKING_MODE); | ||
| 803 | + | ||
| 798 | EXPECT_EQ(sizeof(aclrtStreamAttr), 4); | 804 | EXPECT_EQ(sizeof(aclrtStreamAttr), 4); |
| 799 | } | 805 | } |
| 800 | 806 | ||
| @@ -317,6 +317,7 @@ set(runtimeut_common_src_stream_list | |||
| 317 | ${TOP_DIR}/src/runtime/core/src/stream/stream_sqcq_manage.cc | 317 | ${TOP_DIR}/src/runtime/core/src/stream/stream_sqcq_manage.cc |
| 318 | ${TOP_DIR}/src/runtime/core/src/stream/engine_stream_observer.cc | 318 | ${TOP_DIR}/src/runtime/core/src/stream/engine_stream_observer.cc |
| 319 | ${TOP_DIR}/src/runtime/core/src/stream/stream.cc | 319 | ${TOP_DIR}/src/runtime/core/src/stream/stream.cc |
| 320 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/stream_launch_blocking.cc | ||
| 320 | ${TOP_DIR}/src/runtime/core/src/stream/ctrl_stream.cc | 321 | ${TOP_DIR}/src/runtime/core/src/stream/ctrl_stream.cc |
| 321 | ${TOP_DIR}/src/runtime/core/src/stream/coprocessor_stream.cc | 322 | ${TOP_DIR}/src/runtime/core/src/stream/coprocessor_stream.cc |
| 322 | ${TOP_DIR}/src/runtime/core/src/stream/stream_factory.cc | 323 | ${TOP_DIR}/src/runtime/core/src/stream/stream_factory.cc |
| @@ -422,6 +423,7 @@ set(runtimeut_src_tiny_exclude_list | |||
| 422 | ${TOP_DIR}/src/runtime/feature/aclgraph/v100/capture_adapt_v100.cc | 423 | ${TOP_DIR}/src/runtime/feature/aclgraph/v100/capture_adapt_v100.cc |
| 423 | ${TOP_DIR}/src/runtime/feature/aclgraph/v100/capture_model_adapt_v100.cc | 424 | ${TOP_DIR}/src/runtime/feature/aclgraph/v100/capture_model_adapt_v100.cc |
| 424 | ${TOP_DIR}/src/runtime/feature/model/v100/capture_adapt.cc | 425 | ${TOP_DIR}/src/runtime/feature/model/v100/capture_adapt.cc |
| 426 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/stream_launch_blocking.cc | ||
| 425 | ${TOP_DIR}/src/runtime/feature/snapshot/device_snapshot.cc | 427 | ${TOP_DIR}/src/runtime/feature/snapshot/device_snapshot.cc |
| 426 | ${TOP_DIR}/src/runtime/feature/snapshot/snapshot_process_helper.cc | 428 | ${TOP_DIR}/src/runtime/feature/snapshot/snapshot_process_helper.cc |
| 427 | ${TOP_DIR}/src/runtime/feature/snapshot/snapshot_callback_manager.cc | 429 | ${TOP_DIR}/src/runtime/feature/snapshot/snapshot_callback_manager.cc |
| @@ -491,6 +493,7 @@ set(runtimeut_src_tiny_include_list | |||
| 491 | ${TOP_DIR}/src/runtime/feature/aclgraph/tiny/event_capture_stub.cc | 493 | ${TOP_DIR}/src/runtime/feature/aclgraph/tiny/event_capture_stub.cc |
| 492 | ${TOP_DIR}/src/runtime/feature/aclgraph/tiny/stream_capture_stub.cc | 494 | ${TOP_DIR}/src/runtime/feature/aclgraph/tiny/stream_capture_stub.cc |
| 493 | ${TOP_DIR}/src/runtime/feature/model/tiny/model_aclgraph_stub.cc | 495 | ${TOP_DIR}/src/runtime/feature/model/tiny/model_aclgraph_stub.cc |
| 496 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/tiny/stream_launch_blocking_tiny_stub.cc | ||
| 494 | ${TOP_DIR}/src/runtime/feature/snapshot/tiny/device_snapshot_stub.cc | 497 | ${TOP_DIR}/src/runtime/feature/snapshot/tiny/device_snapshot_stub.cc |
| 495 | ${TOP_DIR}/src/runtime/feature/snapshot/tiny/snapshot_process_helper_stub.cc | 498 | ${TOP_DIR}/src/runtime/feature/snapshot/tiny/snapshot_process_helper_stub.cc |
| 496 | ${TOP_DIR}/src/runtime/feature/snapshot/tiny/snapshot_callback_manager_stub.cc | 499 | ${TOP_DIR}/src/runtime/feature/snapshot/tiny/snapshot_callback_manager_stub.cc |
| @@ -980,6 +983,7 @@ add_executable(runtime_utest | |||
| 980 | test/rt_utest_agent.cc | 983 | test/rt_utest_agent.cc |
| 981 | test/rt_utest_aicpu_err_msg.cc | 984 | test/rt_utest_aicpu_err_msg.cc |
| 982 | test/rt_utest_aicpu_timeout.cc | 985 | test/rt_utest_aicpu_timeout.cc |
| 986 | + test/rt_utest_launch_blocking.cc | ||
| 983 | test/rt_utest_aicpu_scheduler_agent.cc | 987 | test/rt_utest_aicpu_scheduler_agent.cc |
| 984 | test/rt_utest_enum_to_string_utils.cc | 988 | test/rt_utest_enum_to_string_utils.cc |
| 985 | test/rt_utest_ttlv.cc | 989 | test/rt_utest_ttlv.cc |
| @@ -1484,6 +1488,7 @@ set(RUNTIME_TEST_INC_DIR_COMMON | |||
| 1484 | ${TOP_DIR}/src/runtime/feature/soma/ | 1488 | ${TOP_DIR}/src/runtime/feature/soma/ |
| 1485 | ${TOP_DIR}/src/runtime/feature/cntnotify/ | 1489 | ${TOP_DIR}/src/runtime/feature/cntnotify/ |
| 1486 | ${TOP_DIR}/src/runtime/feature/snapshot/ | 1490 | ${TOP_DIR}/src/runtime/feature/snapshot/ |
| 1491 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/ | ||
| 1487 | ${TOP_DIR}/src/runtime/feature/xpu/ | 1492 | ${TOP_DIR}/src/runtime/feature/xpu/ |
| 1488 | ${TOP_DIR}/src/runtime/core/src/uvm | 1493 | ${TOP_DIR}/src/runtime/core/src/uvm |
| 1489 | ${TOP_DIR}/src/runtime/core/src/event | 1494 | ${TOP_DIR}/src/runtime/core/src/event |
| @@ -136,9 +136,9 @@ RUNTIME_API_STUB(rtNoop) | |||
| 136 | self.assertEqual(catalog_version, product_version) | 136 | self.assertEqual(catalog_version, product_version) |
| 137 | self.assertFalse(set(names) - set(catalog)) | 137 | self.assertFalse(set(names) - set(catalog)) |
| 138 | self.assertEqual(names, sorted(names)) | 138 | self.assertEqual(names, sorted(names)) |
| 139 | - self.assertEqual(len(catalog), 784) | 139 | + self.assertEqual(len(catalog), 786) |
| 140 | self.assertEqual(len(names), 654) | 140 | self.assertEqual(len(names), 654) |
| 141 | - self.assertEqual(len(set(catalog) - set(names)), 130) | 141 | + self.assertEqual(len(set(catalog) - set(names)), 132) |
| 142 | self.assertEqual( | 142 | self.assertEqual( |
| 143 | sum(catalog[name].policy == "FEATURE_NOT_SUPPORT" for name in names), | 143 | sum(catalog[name].policy == "FEATURE_NOT_SUPPORT" for name in names), |
| 144 | 650, | 144 | 650, |
| @@ -142,6 +142,7 @@ set(runtimeut_src_aclgraph_list | |||
| 142 | ) | 142 | ) |
| 143 | 143 | ||
| 144 | set(runtimeut_common_src_stream_list | 144 | set(runtimeut_common_src_stream_list |
| 145 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/stream_launch_blocking.cc | ||
| 145 | ${TOP_DIR}/src/runtime/core/src/stream/stream_sqcq_manage.cc | 146 | ${TOP_DIR}/src/runtime/core/src/stream/stream_sqcq_manage.cc |
| 146 | ${TOP_DIR}/src/runtime/core/src/stream/engine_stream_observer.cc | 147 | ${TOP_DIR}/src/runtime/core/src/stream/engine_stream_observer.cc |
| 147 | ${TOP_DIR}/src/runtime/core/src/stream/stream.cc | 148 | ${TOP_DIR}/src/runtime/core/src/stream/stream.cc |
| @@ -551,6 +552,7 @@ set(RUNTIME_TEST_INC_DIR_COMMON | |||
| 551 | ${TOP_DIR}/src/runtime/core/src/memory/ | 552 | ${TOP_DIR}/src/runtime/core/src/memory/ |
| 552 | ${TOP_DIR}/src/runtime/feature/soma/ | 553 | ${TOP_DIR}/src/runtime/feature/soma/ |
| 553 | ${TOP_DIR}/src/runtime/feature/snapshot/ | 554 | ${TOP_DIR}/src/runtime/feature/snapshot/ |
| 555 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/ | ||
| 554 | ${TOP_DIR}/src/runtime/feature/xpu/ | 556 | ${TOP_DIR}/src/runtime/feature/xpu/ |
| 555 | ${TOP_DIR}/src/runtime/core/src/event | 557 | ${TOP_DIR}/src/runtime/core/src/event |
| 556 | ${C_SEC_INCLUDE} | 558 | ${C_SEC_INCLUDE} |
| @@ -1061,6 +1061,32 @@ TEST_F(CloudV2CaptureModelTest, capture_mode_api_hardsq) | |||
| 1061 | EXPECT_EQ(error, RT_ERROR_NONE); | 1061 | EXPECT_EQ(error, RT_ERROR_NONE); |
| 1062 | } | 1062 | } |
| 1063 | 1063 | ||
| 1064 | +TEST_F(CloudV2CaptureModelTest, capture_model_execute_with_null_stream) | ||
| 1065 | +{ | ||
| 1066 | + rtStream_t captureStream; | ||
| 1067 | + rtModel_t model; | ||
| 1068 | + void* devPtr; | ||
| 1069 | + | ||
| 1070 | + rtError_t error = rtMalloc(&devPtr, 64U, RT_MEMORY_HBM, DEFAULT_MODULEID); | ||
| 1071 | + ASSERT_EQ(error, RT_ERROR_NONE); | ||
| 1072 | + error = rtStreamCreate(&captureStream, 0); | ||
| 1073 | + ASSERT_EQ(error, RT_ERROR_NONE); | ||
| 1074 | + error = rtStreamBeginCapture(captureStream, RT_STREAM_CAPTURE_MODE_GLOBAL); | ||
| 1075 | + ASSERT_EQ(error, RT_ERROR_NONE); | ||
| 1076 | + error = rtsValueWrite(devPtr, 0U, 0U, captureStream); | ||
| 1077 | + ASSERT_EQ(error, RT_ERROR_NONE); | ||
| 1078 | + error = rtStreamEndCapture(captureStream, &model); | ||
| 1079 | + ASSERT_EQ(error, RT_ERROR_NONE); | ||
| 1080 | + | ||
| 1081 | + EXPECT_EQ(rtModelExecute(model, nullptr, 0U), RT_ERROR_NONE); | ||
| 1082 | + | ||
| 1083 | + CaptureModel* captureModel = static_cast<CaptureModel*>(rt_ut::UnwrapOrNull<Model>(model)); | ||
| 1084 | + captureModel->CaptureModelExecuteFinish(RT_ERROR_NONE); | ||
| 1085 | + EXPECT_EQ(rtModelDestroy(model), RT_ERROR_NONE); | ||
| 1086 | + EXPECT_EQ(rtStreamDestroy(captureStream), RT_ERROR_NONE); | ||
| 1087 | + EXPECT_EQ(rtFree(devPtr), RT_ERROR_NONE); | ||
| 1088 | +} | ||
| 1089 | + | ||
| 1064 | TEST_F(CloudV2CaptureModelTest, capture_mode_api_normal) | 1090 | TEST_F(CloudV2CaptureModelTest, capture_mode_api_normal) |
| 1065 | { | 1091 | { |
| 1066 | rtError_t error; | 1092 | rtError_t error; |
| @@ -13,6 +13,8 @@ | |||
| 13 | #include "securec.h" | 13 | #include "securec.h" |
| 14 | #include "runtime/rt.h" | 14 | #include "runtime/rt.h" |
| 15 | #include "runtime/event.h" | 15 | #include "runtime/event.h" |
| 16 | +#include "runtime/rts/rts_stream.h" | ||
| 17 | +#include "stream_launch_blocking.hpp" | ||
| 16 | #define private public | 18 | #define private public |
| 17 | #define protected public | 19 | #define protected public |
| 18 | #include "runtime.hpp" | 20 | #include "runtime.hpp" |
| @@ -8789,6 +8791,89 @@ TEST_F(ApiDavidTest, TestLaunchKernelV2) | |||
| 8789 | delete device; | 8791 | delete device; |
| 8790 | delete k1; | 8792 | delete k1; |
| 8791 | } | 8793 | } |
| 8794 | + | ||
| 8795 | +TEST_F(ApiDavidTest, LaunchKernelV2StandardAicpuBlocks) | ||
| 8796 | +{ | ||
| 8797 | + constexpr uint32_t testKernelId = 10U; | ||
| 8798 | + PlainProgram program(RT_KERNEL_ATTR_TYPE_AICPU); | ||
| 8799 | + Kernel kernel("aicpu", 0ULL, &program, RT_KERNEL_ATTR_TYPE_AICPU, testKernelId); | ||
| 8800 | + kernel.userParaNum_ = 0U; | ||
| 8801 | + kernel.systemParaNum_ = 0U; | ||
| 8802 | + kernel.isSupportOverFlow_ = false; | ||
| 8803 | + kernel.isNeedSetFftsAddrInArg_ = false; | ||
| 8804 | + kernel.SetKernelRegisterType(RT_KERNEL_REG_TYPE_CPU); | ||
| 8805 | + | ||
| 8806 | + RtArgsWithType argsWithType = {}; | ||
| 8807 | + argsWithType.type = RT_ARGS_CPU_EX; | ||
| 8808 | + ASSERT_EQ( | ||
| 8809 | + StreamLaunchBlocking::SetLaunchBlockingMode(stream_, RT_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING), RT_ERROR_NONE); | ||
| 8810 | + static_cast<RawDevice*>(device_) | ||
| 8811 | + ->featureSet_[static_cast<size_t>(RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)] = true; | ||
| 8812 | + | ||
| 8813 | + MOCKER_CPP(&ApiImplDavid::CpuKernelLaunchExAll).stubs().will(returnValue(RT_ERROR_NONE)); | ||
| 8814 | + MOCKER_CPP_VIRTUAL(stream_, &Stream::Synchronize) | ||
| 8815 | + .expects(once()) | ||
| 8816 | + .with(eq(false), eq(-1)) | ||
| 8817 | + .will(returnValue(RT_ERROR_NONE)); | ||
| 8818 | + | ||
| 8819 | + ApiImplDavid apiImpl; | ||
| 8820 | + EXPECT_EQ(apiImpl.LaunchKernelV2(&kernel, 1U, &argsWithType, stream_, nullptr), RT_ERROR_NONE); | ||
| 8821 | + GlobalMockObject::verify(); | ||
| 8822 | +} | ||
| 8823 | + | ||
| 8824 | +TEST_F(ApiDavidTest, LaunchKernelV2AllArgumentTypesBlockAtEntry) | ||
| 8825 | +{ | ||
| 8826 | + constexpr uint32_t testKernelId = 10U; | ||
| 8827 | + PlainProgram program(RT_KERNEL_ATTR_TYPE_AICPU); | ||
| 8828 | + Kernel kernel("kernel", 0ULL, &program, RT_KERNEL_ATTR_TYPE_AICPU, testKernelId); | ||
| 8829 | + const ArgsType argsTypes[] = {RT_ARGS_NON_CPU_EX, RT_ARGS_CPU_EX, RT_ARGS_HANDLE, | ||
| 8830 | + RT_ARGS_ARRAY, RT_SIMT_ARGS_ARRAY, RT_SIMT_ARGS_HOST}; | ||
| 8831 | + constexpr uint32_t argsTypeCount = sizeof(argsTypes) / sizeof(argsTypes[0]); | ||
| 8832 | + | ||
| 8833 | + ASSERT_EQ( | ||
| 8834 | + StreamLaunchBlocking::SetLaunchBlockingMode(stream_, RT_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING), RT_ERROR_NONE); | ||
| 8835 | + static_cast<RawDevice*>(device_) | ||
| 8836 | + ->featureSet_[static_cast<size_t>(RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)] = true; | ||
| 8837 | + MOCKER_CPP(&ApiImplDavid::LaunchKernelByArgsWithType) | ||
| 8838 | + .expects(exactly(argsTypeCount)) | ||
| 8839 | + .will(returnValue(RT_ERROR_NONE)); | ||
| 8840 | + MOCKER_CPP_VIRTUAL(stream_, &Stream::Synchronize) | ||
| 8841 | + .expects(exactly(argsTypeCount)) | ||
| 8842 | + .with(eq(false), eq(-1)) | ||
| 8843 | + .will(returnValue(RT_ERROR_NONE)); | ||
| 8844 | + | ||
| 8845 | + ApiImplDavid apiImpl; | ||
| 8846 | + for (const ArgsType argsType : argsTypes) { | ||
| 8847 | + RtArgsWithType argsWithType = {}; | ||
| 8848 | + argsWithType.type = argsType; | ||
| 8849 | + EXPECT_EQ(apiImpl.LaunchKernelV2(&kernel, 1U, &argsWithType, stream_, nullptr), RT_ERROR_NONE); | ||
| 8850 | + } | ||
| 8851 | + GlobalMockObject::verify(); | ||
| 8852 | +} | ||
| 8853 | + | ||
| 8854 | +TEST_F(ApiDavidTest, LaunchKernelV2ReturnsLaunchBlockingSyncError) | ||
| 8855 | +{ | ||
| 8856 | + constexpr uint32_t testKernelId = 10U; | ||
| 8857 | + PlainProgram program(RT_KERNEL_ATTR_TYPE_AICPU); | ||
| 8858 | + Kernel kernel("aicpu", 0ULL, &program, RT_KERNEL_ATTR_TYPE_AICPU, testKernelId); | ||
| 8859 | + RtArgsWithType argsWithType = {}; | ||
| 8860 | + argsWithType.type = RT_ARGS_CPU_EX; | ||
| 8861 | + | ||
| 8862 | + ASSERT_EQ( | ||
| 8863 | + StreamLaunchBlocking::SetLaunchBlockingMode(stream_, RT_STREAM_LAUNCH_BLOCKING_MODE_BLOCKING), RT_ERROR_NONE); | ||
| 8864 | + static_cast<RawDevice*>(device_) | ||
| 8865 | + ->featureSet_[static_cast<size_t>(RtOptionalFeatureType::RT_FEATURE_LAUNCH_BLOCKING)] = true; | ||
| 8866 | + MOCKER_CPP(&ApiImplDavid::LaunchKernelByArgsWithType).expects(once()).will(returnValue(RT_ERROR_NONE)); | ||
| 8867 | + MOCKER_CPP_VIRTUAL(stream_, &Stream::Synchronize) | ||
| 8868 | + .expects(once()) | ||
| 8869 | + .with(eq(false), eq(-1)) | ||
| 8870 | + .will(returnValue(RT_ERROR_STREAM_SYNC_TIMEOUT)); | ||
| 8871 | + | ||
| 8872 | + ApiImplDavid apiImpl; | ||
| 8873 | + EXPECT_EQ(apiImpl.LaunchKernelV2(&kernel, 1U, &argsWithType, stream_, nullptr), RT_ERROR_STREAM_SYNC_TIMEOUT); | ||
| 8874 | + GlobalMockObject::verify(); | ||
| 8875 | +} | ||
| 8876 | + | ||
| 8792 | TEST_F(ApiDavidTest, rtsCntNotify_0002) | 8877 | TEST_F(ApiDavidTest, rtsCntNotify_0002) |
| 8793 | { | 8878 | { |
| 8794 | rtCntNotify_t inNotify; | 8879 | rtCntNotify_t inNotify; |
| @@ -156,6 +156,7 @@ set(runtimeut_common_src_stream_list | |||
| 156 | ${TOP_DIR}/src/runtime/core/src/stream/dvpp_grp.cc | 156 | ${TOP_DIR}/src/runtime/core/src/stream/dvpp_grp.cc |
| 157 | ${TOP_DIR}/src/runtime/core/src/stream/engine_stream_observer.cc | 157 | ${TOP_DIR}/src/runtime/core/src/stream/engine_stream_observer.cc |
| 158 | ${TOP_DIR}/src/runtime/core/src/stream/stream.cc | 158 | ${TOP_DIR}/src/runtime/core/src/stream/stream.cc |
| 159 | + ${TOP_DIR}/src/runtime/feature/launch_blocking/stream_launch_blocking.cc | ||
| 159 | ${TOP_DIR}/src/runtime/core/src/stream/stream_factory.cc | 160 | ${TOP_DIR}/src/runtime/core/src/stream/stream_factory.cc |
| 160 | ${TOP_DIR}/src/runtime/core/src/stream/stream_sqcq_manage.cc | 161 | ${TOP_DIR}/src/runtime/core/src/stream/stream_sqcq_manage.cc |
| 161 | ) | 162 | ) |
| @@ -449,6 +450,7 @@ set(RUNTIME_TEST_INC_DIR_COMMON | |||
| 449 | ${TOP_DIR}/src/runtime/core/inc/launch | 450 | ${TOP_DIR}/src/runtime/core/inc/launch |
| 450 | ${TOP_DIR}/src/runtime/core/inc/model | 451 | ${TOP_DIR}/src/runtime/core/inc/model |
| 451 | ${TOP_DIR}/src/runtime/feature/jetty | 452 | ${TOP_DIR}/src/runtime/feature/jetty |
| 453 | + ${TOP_DIR}/src/runtime/feature/launch_blocking | ||
| 452 | ${TOP_DIR}/src/runtime/core/inc/event | 454 | ${TOP_DIR}/src/runtime/core/inc/event |
| 453 | ${TOP_DIR}/src/runtime/core/inc/arg_loader | 455 | ${TOP_DIR}/src/runtime/core/inc/arg_loader |
| 454 | ${TOP_DIR}/src/runtime/core/inc/notify | 456 | ${TOP_DIR}/src/runtime/core/inc/notify |
| @@ -3876,6 +3876,10 @@ TEST_F(NpuDriverTest, CheckIsSupportFeature_invalid) | |||
| 3876 | ret = rawDrv->CheckIsSupportFeature(0, feature); | 3876 | ret = rawDrv->CheckIsSupportFeature(0, feature); |
| 3877 | EXPECT_FALSE(ret); | 3877 | EXPECT_FALSE(ret); |
| 3878 | 3878 | ||
| 3879 | + feature = static_cast<int32_t>(FEATURE_PROF_AICPU_CHAN); | ||
| 3880 | + ret = rawDrv->CheckIsSupportFeature(0, feature); | ||
| 3881 | + EXPECT_FALSE(ret); | ||
| 3882 | + | ||
| 3879 | delete rawDrv; | 3883 | delete rawDrv; |
| 3880 | } | 3884 | } |
| 3881 | 3885 | ||


缺其他产品型号