Merged
feat(opdev): add external op task framework integration #962
feat(opdev): add external op task framework integration #962
Merged
su-yuemingAdd on Sep 29
Total: 10 files changed+1448-3
@@ -0,0 +1,49 @@
1+# AddDirectInvokeTask
2+ 
3+通过三个生命周期回调将计算任务加入 executor。头文件为 `opdev/direct_invoke_task.h`。
4+ 
5+```cpp
6+aclnnStatus op::AddDirectInvokeTask(
7+ const char* l0Name, uint32_t opType,
8+ DirectInvokePrepareFn prepare,
9+ DirectInvokeLaunchFn launch,
10+ DirectInvokeDestroyFn destroy,
11+ aclOpExecutor* executor, OpArgContext* args);
12+```
13+ 
14+## 回调与生命周期
15+ 
16+- `prepare(args, workspaceRequest, launchState)` 在注册时同步执行。实现选择、tiling、工作区大小等每次调用的输入均来自 `args`。算子专属回调可以引用不可变的实现元数据。
17+- `launch(launchState, args, stream)` 在执行时提交计算,可包含多个设备任务。最终输入、输出和工作区地址从本次 `args` 读取。
18+- `destroy(launchState)` 在注册失败或 launcher 销毁时释放非空状态,包含 prepare 失败返回的部分状态;每个状态恰好释放一次。无状态任务可返回空状态,此时不调用 destroy。
19+ 
20+三个回调都必须非空且为 `noexcept`。opbase 将 workspace 请求初始化为 `{nullptr, 0, 0}`、状态初始化为空。
21+`DirectInvokeWorkspaceRequest` 的每个大小对应一个 executor 分配的工作区 tensor,由 opbase 负责对齐和内存复用。
22+大小数组必须在注册返回前保持有效,例如由 launchState 持有,不能指向 prepare 栈变量。
23+ 
24+`args` 必须由 `GetOpArgContext` 创建,所有注册返回路径都由 opbase 消费。
25+允许空的可选输入 tensor,输出不能空;入口的 workspace 参数列表必须为空或不存在。
26+回调模块应覆盖 executor 的生命周期,异步设备任务使用的代码和资源还必须存活到设备执行完成;destroy 不是设备完成通知。
27+ 
28+## 计算、缓存与 DFX 契约
29+ 
30+任务统一为计算任务,内部使用与设备引擎无关的 `DIRECT_INVOKE` 分类,不声明 AiCore/AiCpu/Dvpp。
31+opbase 保留输入输出 dump、适用的 overflow 检查,不在回调边界上报 profiling;具体设备任务 profiling 由实际下发路径处理。
32+ 
33+DirectInvoke 使用准备状态复用:同一 executor 设置为 repeatable 后,prepare 只执行一次,
34+每次执行都调用 producer 的 launch,传入同一 launchState、本次 args 和 stream。
35+创建新的 executor 会重新 prepare,不提供跨 executor 的 prepare 结果缓存。
36+ 
37+opbase 内部禁止包含 DirectInvoke 的 executor 使用设备任务缓存重放。producer 的直接 runtime
38+下发不填充 OpExecCache 任务队列,不能通过重放该队列绕过 launch;producer 无需提供额外缓存接口。
39+ 
40+- 每次执行的 tensor/workspace 地址从 args 读取,launchState 不保存待重绑定的地址。
41+- 固定实现和执行环境下,准备结果只依赖 args;静态元数据在 executor 存活期间保持不变。
42+- 动态输出形状及现有框架限制仍可禁止 repeat,注册不会重新启用已禁止的复用。
43+- destroy 在 executor 销毁时释放状态,不能假设每次 launch 后立即执行。
44+ 
45+## 接口迁移
46+ 
47+原任务描述结构、taskConfig、引擎类型和 producer 缓存策略已移除。
48+调用方直接传入三个回调,原先通过 taskConfig 传入的静态 descriptor 可由算子专属 prepare 回调引用;每次调用变化的数据应编码为常规 `args` 参数。
49+本次为不兼容接口变更,调用方及 opbase 必须一起重新编译,不保留旧接口别名。
@@ -1,5 +1,7 @@
1# 常用宏和类1# 常用宏和类
2 2 
3+- **[AddDirectInvokeTask](AddDirectInvokeTask.md)**
4+ 
3- **[ADD\_TO\_LAUNCHER\_LIST\_AICORE](ADD_TO_LAUNCHER_LIST_AICORE.md)** 5- **[ADD\_TO\_LAUNCHER\_LIST\_AICORE](ADD_TO_LAUNCHER_LIST_AICORE.md)**
4 6 
5- **[ADD\_TO\_LAUNCHER\_LIST\_AICPU](ADD_TO_LAUNCHER_LIST_AICPU.md)** 7- **[ADD\_TO\_LAUNCHER\_LIST\_AICPU](ADD_TO_LAUNCHER_LIST_AICPU.md)**
@@ -0,0 +1,103 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#ifndef OP_API_COMMON_INC_OPDEV_DIRECT_INVOKE_TASK_H_
12+#define OP_API_COMMON_INC_OPDEV_DIRECT_INVOKE_TASK_H_
13+ 
14+#include <cstdint>
15+#include "acl/acl_base_rt.h"
16+#include "aclnn/acl_meta.h"
17+ 
18+struct aclOpExecutor;
19+ 
20+namespace op {
21+struct OpArgContext;
22+ 
23+/**
24+ * One executor-allocated workspace tensor per byte size. opbase handles
25+ * alignment and memory reuse. sizes must remain valid until AddDirectInvokeTask
26+ * returns (for example, owned by launchState); opbase consumes it synchronously
27+ * after prepare returns and does not retain the pointer.
28+ */
29+struct DirectInvokeWorkspaceRequest {
30+ const uint64_t* sizes;
31+ uint32_t count;
32+ uint32_t reserved;
33+};
34+ 
35+/**
36+ * Prepare one executor-local compute task in ACLNN phase 1.
37+ * All per-call inputs to implementation selection, tiling and workspace sizing
38+ * must come from args. An operator-specific callback may reference immutable
39+ * implementation metadata. For a fixed implementation and execution environment,
40+ * equivalent args must yield equivalent preparation results. Do not hide dynamic
41+ * configuration in globals, opaque pointer attributes or tensor device contents.
42+ *
43+ * opbase initializes workspaceRequest to {nullptr, 0, 0} and launchState to null.
44+ * A non-null state returned on success or failure is destroyed exactly once.
45+ * State must be address-independent: obtain final tensor/workspace addresses from
46+ * launch's args. Stateless tasks may return null; destroy is then not called.
47+ */
48+using DirectInvokePrepareFn = aclnnStatus (*)(const OpArgContext* args, DirectInvokeWorkspaceRequest* workspaceRequest,
49+ void** launchState) noexcept;
50+ 
51+/**
52+ * Submit compute work in ACLNN phase 2 using the caller's stream. Multiple device
53+ * dispatches are allowed, with producer-managed dependencies for any other stream.
54+ * On an explicitly repeatable executor, prepare runs once and the same launchState
55+ * is reused, but this callback is invoked on every execution. Read all current
56+ * tensor/workspace addresses from args and use the stream supplied for that run.
57+ * DirectInvoke does not use OpExecCache device-task replay or cross-executor cache
58+ * hits: producers need not record their runtime dispatches into a replay queue.
59+ *
60+ * opbase dumps inputs/outputs and performs applicable overflow checks around
61+ * the callback. It reports no profiling at the callback boundary, does not
62+ * infer device engine types, and does not report device-task profiling on
63+ * behalf of the actual dispatches.
64+ */
65+using DirectInvokeLaunchFn = aclnnStatus (*)(void* launchState, const OpArgContext* args, aclrtStream stream) noexcept;
66+ 
67+/**
68+ * Destroy a non-null state on registration failure or launcher teardown, including
69+ * partially prepared state. This is not a device-completion notification: producers
70+ * must retain code images and resources until submitted asynchronous work finishes,
71+ * even when launch reports an error. opbase does not synchronize or unload modules.
72+ */
73+using DirectInvokeDestroyFn = void (*)(void* launchState) noexcept;
74+ 
75+/**
76+ * Attach a compute task by registering three required, non-throwing callbacks.
77+ * prepare runs synchronously; launch/destroy and their modules must remain valid
78+ * for the executor's lifetime (and submitted work's lifetime where applicable).
79+ *
80+ * args is consumed on every return path and must be created by GetOpArgContext.
81+ * Optional input tensors may be null; outputs must be non-null. The entry workspace
82+ * list must be absent or empty; prepare requests buffers that opbase appends to args.
83+ *
84+ * Profiling and dump attribution comes from opType and the enclosing DFX
85+ * context captured at registration time, same as the AI Core path. l0Name is
86+ * reserved and currently unused, mirroring CreatAiCoreKernelLauncher; callers
87+ * wanting attributed profiling must register under the framework DFX macros
88+ * (L2_DFX_PHASE_1/L0_DFX).
89+ *
90+ * opbase disables device-task caching for any executor containing DirectInvoke.
91+ * Explicit executor repeat retains the prepared state and calls launch each time;
92+ * it remains subject to argument rebinding checks, dynamic output shape limits
93+ * and existing framework restrictions. A new executor performs prepare again.
94+ * This API replaces the former descriptor-based interface; rebuild callers and
95+ * opbase together. No compatibility alias is provided for the old ABI.
96+ */
97+aclnnStatus AddDirectInvokeTask([[maybe_unused]] const char* l0Name, uint32_t opType, DirectInvokePrepareFn prepare,
98+ DirectInvokeLaunchFn launch, DirectInvokeDestroyFn destroy, aclOpExecutor* executor,
99+ OpArgContext* args);
100+ 
101+} // namespace op
102+ 
103+#endif // OP_API_COMMON_INC_OPDEV_DIRECT_INVOKE_TASK_H_
@@ -321,7 +321,15 @@ struct OpArgContext {
321 return nullptr;321 return nullptr;
322 }322 }
323 323 
324- inline bool ContainsOpArgType(OpArgDef type)324+ inline const OpArgList* GetOpArg(OpArgDef type) const
325+ {
326+ if (type >= OP_INPUT_ARG && type <= OP_EXEC_MODE_ARG) {
327+ return &argLists[type];
328+ }
329+ return nullptr;
330+ }
331+ 
332+ inline bool ContainsOpArgType(OpArgDef type) const
325 {333 {
326 if (type >= OP_INPUT_ARG && type <= OP_EXEC_MODE_ARG) {334 if (type >= OP_INPUT_ARG && type <= OP_EXEC_MODE_ARG) {
327 return argLists[type].args && argLists[type].count;335 return argLists[type].args && argLists[type].count;
@@ -21,7 +21,8 @@
21 21 
22namespace op {22namespace op {
23 23 
24-enum CoreType { AI_CORE = 0, AI_CPU, DVPP, NO_CALC };24+// DIRECT_INVOKE is an engine-neutral compute task, not a device engine identity.
25+enum CoreType { AI_CORE = 0, AI_CPU, DVPP, NO_CALC, DIRECT_INVOKE };
25 26 
26enum OpIOType { OpInputType, OpOutputType, OpWorkspaceType };27enum OpIOType { OpInputType, OpOutputType, OpWorkspaceType };
27 28 
@@ -187,6 +187,7 @@
187 <file_info copy_type="source" src_path="" dst_path="$(TARGET_ENV)/include/aclnn/opdev" install_path="$(TARGET_ENV)/include/aclnn/opdev" install_type="all">187 <file_info copy_type="source" src_path="" dst_path="$(TARGET_ENV)/include/aclnn/opdev" install_path="$(TARGET_ENV)/include/aclnn/opdev" install_type="all">
188 <file value="bfloat16.h" install_mod="550"/>188 <file value="bfloat16.h" install_mod="550"/>
189 <file value="common_types.h" install_mod="550"/>189 <file value="common_types.h" install_mod="550"/>
190+ <file value="direct_invoke_task.h" install_mod="550"/>
190 <file value="data_type_utils.h" install_mod="550"/>191 <file value="data_type_utils.h" install_mod="550"/>
191 <file value="fast_vector.h" install_mod="550"/>192 <file value="fast_vector.h" install_mod="550"/>
192 <file value="float4_e1m2.h" install_mod="550"/>193 <file value="float4_e1m2.h" install_mod="550"/>
@@ -0,0 +1,330 @@
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 "opdev/direct_invoke_task.h"
12+ 
13+#include <limits>
14+#include <new>
15+ 
16+#include "bridge_graph.h"
17+#include "kernel_launcher.h"
18+#include "op_dfx_internal.h"
19+#include "opdev/op_arg_def.h"
20+#include "opdev/op_def.h"
21+#include "opdev/op_dfx.h"
22+#include "opdev/op_executor.h"
23+#include "opdev/op_log.h"
24+ 
25+namespace op {
26+ 
27+namespace {
28+ 
29+// GetOpArg never returns null for the arg kinds used here; a malformed list
30+// is one that claims entries without backing storage.
31+bool IsWellFormedArgList(const OpArgList* list)
32+{
33+ return list != nullptr && (list->count == 0U || list->args != nullptr);
34+}
35+ 
36+// launcher must own args. This function consumes launcher and args on every
37+// return path: failure deletes launcher, success transfers it to executor.
38+aclnnStatus RegisterKernelLauncher(uint32_t opType, aclOpExecutor* executor, OpArgContext* args,
39+ KernelLauncher* launcher, bool includeOutShape = false)
40+{
41+ if (launcher == nullptr) {
42+ DestroyOpArgContext(args);
43+ OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Kernel launcher must not be null.");
44+ return ACLNN_ERR_PARAM_NULLPTR;
45+ }
46+ if (executor == nullptr || args == nullptr) {
47+ delete launcher;
48+ OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "Executor and launcher arguments must not be null.");
49+ return ACLNN_ERR_PARAM_NULLPTR;
50+ }
51+ 
52+ OpArgList* inputs = args->GetOpArg(OP_INPUT_ARG);
53+ OpArgList* outputs = args->GetOpArg(OP_OUTPUT_ARG);
54+ OpArgList* workspaces = args->GetOpArg(OP_WORKSPACE_ARG);
55+ OpArgList* outShapes = args->GetOpArg(OP_OUTSHAPE_ARG);
56+ if (!IsWellFormedArgList(inputs) || !IsWellFormedArgList(outputs) || !IsWellFormedArgList(workspaces) ||
57+ (includeOutShape && !IsWellFormedArgList(outShapes))) {
58+ delete launcher;
59+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Launcher graph arguments are malformed.");
60+ return ACLNN_ERR_PARAM_INVALID;
61+ }
62+ 
63+ aclnnStatus status = includeOutShape ?
64+ internal::BuildGraph(executor->GetGraph(), opType, *inputs, *outputs, *workspaces,
65+ *outShapes) :
66+ internal::BuildGraph(executor->GetGraph(), opType, *inputs, *outputs, *workspaces);
67+ if (status != ACLNN_SUCCESS) {
68+ delete launcher;
69+ return status;
70+ }
71+ executor->AddToKernelLauncherList(launcher);
72+ return ACLNN_SUCCESS;
73+}
74+ 
75+// Matches the framework graph builder: a null input tensor means an absent
76+// optional input and is tolerated; outputs must be present.
77+enum class TensorRequirement : uint32_t {
78+ OptionalInput = 0U,
79+ Required = 1U,
80+};
81+ 
82+bool IsValidTensor(const aclTensor* tensor, TensorRequirement requirement)
83+{
84+ if (tensor == nullptr) {
85+ return requirement == TensorRequirement::OptionalInput;
86+ }
87+ return true;
88+}
89+ 
90+bool IsValidTensorArg(const OpArg& arg, TensorRequirement requirement)
91+{
92+ if (arg.type == OpArgType::OPARG_ACLTENSOR) {
93+ return IsValidTensor(static_cast<const aclTensor*>(arg.value.data.pointer), requirement);
94+ }
95+ if (arg.type != OpArgType::OPARG_ACLTENSOR_LIST) {
96+ return false;
97+ }
98+ const auto* tensors = static_cast<const aclTensorList*>(arg.value.data.pointer);
99+ if (tensors == nullptr) {
100+ return false;
101+ }
102+ for (uint64_t index = 0U; index < tensors->Size(); ++index) {
103+ if (!IsValidTensor((*tensors)[index], requirement)) {
104+ return false;
105+ }
106+ }
107+ return true;
108+}
109+ 
110+bool IsValidTensorList(const OpArgList& args, TensorRequirement requirement)
111+{
112+ if (args.count != 0U && args.args == nullptr) {
113+ return false;
114+ }
115+ for (size_t index = 0U; index < args.count; ++index) {
116+ if (!IsValidTensorArg(args.args[index], requirement)) {
117+ return false;
118+ }
119+ }
120+ return true;
121+}
122+ 
123+bool IsValidArgs(const OpArgContext& args)
124+{
125+ const OpArgList* inputs = args.GetOpArg(OP_INPUT_ARG);
126+ const OpArgList* outputs = args.GetOpArg(OP_OUTPUT_ARG);
127+ const OpArgList* attributes = args.GetOpArg(OP_ATTR_ARG);
128+ const OpArgList* workspaces = args.GetOpArg(OP_WORKSPACE_ARG);
129+ // Workspace buffers are requested through the prepare callback and
130+ // allocated by opbase; the entry workspace list must be absent or empty.
131+ return inputs != nullptr && outputs != nullptr && attributes != nullptr &&
132+ (attributes->count == 0U || attributes->args != nullptr) &&
133+ IsValidTensorList(*inputs, TensorRequirement::OptionalInput) &&
134+ IsValidTensorList(*outputs, TensorRequirement::Required) &&
135+ (workspaces == nullptr || workspaces->count == 0U);
136+}
137+ 
138+// Mirrors the AI Core GetWorkspace flow: one DT_UINT8 tensor per requested
139+// size, allocated from the executor so the memory planner applies its
140+// alignment and lifetime reuse, then appended as the workspace argument.
141+aclnnStatus AppendRequestedWorkspaces(aclOpExecutor* executor, const DirectInvokeWorkspaceRequest& request,
142+ OpArgContext* args)
143+{
144+ if (request.count == 0U) {
145+ return ACLNN_SUCCESS;
146+ }
147+ if (request.sizes == nullptr) {
148+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Workspace request count is non-zero but sizes is null.");
149+ return ACLNN_ERR_PARAM_INVALID;
150+ }
151+ FVector<aclTensor*> workspaces;
152+ for (uint32_t index = 0U; index < request.count; ++index) {
153+ const uint64_t size = request.sizes[index];
154+ if (size == 0U || size > static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
155+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Workspace request contains an invalid size %llu at index %u.",
156+ static_cast<unsigned long long>(size), index);
157+ return ACLNN_ERR_PARAM_INVALID;
158+ }
159+ aclTensor* tensor = executor->AllocTensor(Shape({static_cast<int64_t>(size)}), DataType::DT_UINT8);
160+ if (tensor == nullptr) {
161+ OP_LOGE(ACLNN_ERR_INNER, "Failed to allocate requested workspace of %llu bytes.",
162+ static_cast<unsigned long long>(size));
163+ return ACLNN_ERR_INNER;
164+ }
165+ workspaces.push_back(tensor);
166+ }
167+ aclTensorList* workspaceList = executor->AllocTensorList(workspaces.data(), workspaces.size());
168+ if (workspaceList == nullptr) {
169+ OP_LOGE(ACLNN_ERR_INNER, "Failed to allocate requested workspace list.");
170+ return ACLNN_ERR_INNER;
171+ }
172+ args->AppendOpWorkspaceArg(workspaceList);
173+ return ACLNN_SUCCESS;
174+}
175+ 
176+class DirectInvokeKernelLauncher final : public KernelLauncher {
177+public:
178+ DirectInvokeKernelLauncher(uint32_t opType, const aclOpExecutor* executor, DirectInvokeLaunchFn launch,
179+ DirectInvokeDestroyFn destroy, void* launchState, OpArgContext* args)
180+ : KernelLauncher(opType, DIRECT_INVOKE, executor, internal::ProfilingInfoId{}),
181+ launch_(launch),
182+ destroy_(destroy),
183+ launchState_(launchState),
184+ args_(args)
185+ {
186+ // Attribution comes from the enclosing DFX context captured by the
187+ // base class (TLS names are macro stringification literals) and from
188+ // opType, same as the AI Core path; no name override is accepted.
189+ }
190+ 
191+ ~DirectInvokeKernelLauncher() override
192+ {
193+ if (launchState_ != nullptr) {
194+ destroy_(launchState_);
195+ launchState_ = nullptr;
196+ }
197+ DestroyOpArgContext(args_);
198+ args_ = nullptr;
199+ }
200+ 
201+ aclnnStatus Launch() override
202+ {
203+ if (launch_ == nullptr || args_ == nullptr) {
204+ OP_LOGE(ACLNN_ERR_INNER, "DirectInvoke task launcher is not initialized.");
205+ return ACLNN_ERR_INNER;
206+ }
207+ // Same TLS discipline as the AI Core path: phase 2 entry already
208+ // restored the L2 context (InitL2Phase2Context), so the launcher only
209+ // fills in the l0Name captured at registration time.
210+ auto& threadLocalCtx = op::internal::GetThreadLocalContext();
211+ threadLocalCtx.logInfo_.l0Name = opLogInfo_.l0Name;
212+ threadLocalCtx.profilingInfoId_ = profilingInfoId_;
213+ 
214+ // DirectInvoke callbacks always submit compute tasks.
215+ if (threadLocalCtx.opConfigInfo_.isOpDumpEnable_) {
216+ op::internal::DumpL0(*args_->GetOpArg(op::OP_INPUT_ARG), opLogInfo_, OpInputType, executor_->GetStream());
217+ }
218+ 
219+ const aclnnStatus ret = launch_(launchState_, args_, executor_->GetStream());
220+ 
221+ if (threadLocalCtx.opConfigInfo_.isOpDumpEnable_) {
222+ op::internal::DumpL0(*args_->GetOpArg(op::OP_OUTPUT_ARG), opLogInfo_, OpOutputType, executor_->GetStream());
223+ }
224+ if (ret == ACLNN_SUCCESS && op::internal::IsOverflowDumpEnable()) {
225+ CheckOverflowDump();
226+ }
227+ return ret;
228+ }
229+ 
230+ internal::OpKernelBin* GetBin() override { return nullptr; }
231+ 
232+ // The task contract requires launchState to be address-independent, so
233+ // repeatability only depends on the argument storages, same as the AI CPU
234+ // path.
235+ bool CheckRepeatable(const std::unordered_map<const aclStorage*, const aclStorage*>& relation,
236+ const std::vector<const aclStorage*>& oriStorage) override
237+ {
238+ if (args_ == nullptr) {
239+ return false;
240+ }
241+ LauncherRepeatableChecker checker(relation, oriStorage);
242+ return checker.CheckLauncherRepeatable(args_);
243+ }
244+ 
245+private:
246+ void CheckOverflowDump()
247+ {
248+ aclmdlRICaptureStatus status;
249+ aclmdlRI captureMdl;
250+ if ((aclmdlRICaptureGetInfo(executor_->GetStream(), &status, &captureMdl) == ACL_SUCCESS) &&
251+ (status == ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE)) {
252+ OP_LOGI("No need to perform overflow check in the capture scenario.");
253+ return;
254+ }
255+ (void)op::internal::OverflowDumpProcess(args_, const_cast<aclOpExecutor*>(executor_), executor_->GetStream(),
256+ opLogInfo_);
257+ }
258+ 
259+ DirectInvokeLaunchFn launch_;
260+ DirectInvokeDestroyFn destroy_;
261+ void* launchState_;
262+ OpArgContext* args_;
263+};
264+ 
265+} // namespace
266+ 
267+aclnnStatus AddDirectInvokeTask([[maybe_unused]] const char* l0Name, uint32_t opType, DirectInvokePrepareFn prepare,
268+ DirectInvokeLaunchFn launch, DirectInvokeDestroyFn destroy, aclOpExecutor* executor,
269+ OpArgContext* args)
270+{
271+ if (prepare == nullptr || launch == nullptr || destroy == nullptr || executor == nullptr || args == nullptr) {
272+ DestroyOpArgContext(args);
273+ OP_LOGE(ACLNN_ERR_PARAM_NULLPTR, "DirectInvoke callbacks, executor and arguments must not be null.");
274+ return ACLNN_ERR_PARAM_NULLPTR;
275+ }
276+ 
277+ if (opType == 0U || opType >= OpTypeDict::GetAllOpTypeSize() || !IsValidArgs(*args)) {
278+ DestroyOpArgContext(args);
279+ OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Invalid DirectInvoke task or arguments.");
280+ return ACLNN_ERR_PARAM_INVALID;
281+ }
282+ 
283+ DirectInvokeWorkspaceRequest workspaceRequest{nullptr, 0U, 0U};
284+ void* launchState = nullptr;
285+ aclnnStatus status = prepare(args, &workspaceRequest, &launchState);
286+ if (status != ACLNN_SUCCESS) {
287+ if (launchState != nullptr) {
288+ destroy(launchState);
289+ }
290+ DestroyOpArgContext(args);
291+ return status;
292+ }
293+ 
294+ status = AppendRequestedWorkspaces(executor, workspaceRequest, args);
295+ if (status != ACLNN_SUCCESS) {
296+ if (launchState != nullptr) {
297+ destroy(launchState);
298+ }
299+ DestroyOpArgContext(args);
300+ return status;
301+ }
302+ 
303+ // The constructor only stores pointers and cannot throw, so nothrow new
304+ // fully covers launcher creation failures.
305+ auto* launcher = new (std::nothrow)
306+ DirectInvokeKernelLauncher(opType, executor, launch, destroy, launchState, args);
307+ if (launcher == nullptr) {
308+ if (launchState != nullptr) {
309+ destroy(launchState);
310+ }
311+ DestroyOpArgContext(args);
312+ return ACLNN_ERR_INNER;
313+ }
314+ 
315+ // Tasks with dynamic output shapes must not be cached, same as the AI
316+ // Core path (CreatAiCoreKernelLauncher abandons the cache for them).
317+ const bool includeOutShape = args->ContainsOpArgType(OP_OUTSHAPE_ARG);
318+ status = RegisterKernelLauncher(opType, executor, args, launcher, includeOutShape);
319+ if (status != ACLNN_SUCCESS) {
320+ return status;
321+ }
322+ // Reuse the prepared state through explicit executor repeat, but execute
323+ // the producer callback on every run. Direct runtime dispatches do not
324+ // populate OpExecCache's task queue, so device-task replay must not bypass
325+ // Launch(). Dynamic output shapes still prohibit repeat altogether.
326+ executor->AbandonCache(includeOutShape);
327+ return ACLNN_SUCCESS;
328+}
329+ 
330+} // namespace op
@@ -10,6 +10,7 @@
10set(STUB_SRC_LIST10set(STUB_SRC_LIST
11 ${CMAKE_CURRENT_BINARY_DIR}/stub_aicpu_task.cc11 ${CMAKE_CURRENT_BINARY_DIR}/stub_aicpu_task.cc
12 ${CMAKE_CURRENT_BINARY_DIR}/stub_common_types.cc12 ${CMAKE_CURRENT_BINARY_DIR}/stub_common_types.cc
13+ ${CMAKE_CURRENT_BINARY_DIR}/stub_direct_invoke_task.cc
13 ${CMAKE_CURRENT_BINARY_DIR}/stub_data_type_utils.cc14 ${CMAKE_CURRENT_BINARY_DIR}/stub_data_type_utils.cc
14 ${CMAKE_CURRENT_BINARY_DIR}/stub_format_utils.cc15 ${CMAKE_CURRENT_BINARY_DIR}/stub_format_utils.cc
15 ${CMAKE_CURRENT_BINARY_DIR}/stub_framework_op.cc16 ${CMAKE_CURRENT_BINARY_DIR}/stub_framework_op.cc
@@ -43,7 +44,7 @@ add_custom_command(
43 OUTPUT ${STUB_SRC_LIST}44 OUTPUT ${STUB_SRC_LIST}
44 COMMAND echo "Generating nnopbase stub files."45 COMMAND echo "Generating nnopbase stub files."
45 && ${HI_PYTHON} ${CMAKE_CURRENT_LIST_DIR}/gen_stubapi.py ${OPS_BASE_PATH} ${CMAKE_CURRENT_BINARY_DIR} > /dev/null 2>&146 && ${HI_PYTHON} ${CMAKE_CURRENT_LIST_DIR}/gen_stubapi.py ${OPS_BASE_PATH} ${CMAKE_CURRENT_BINARY_DIR} > /dev/null 2>&1
46- && echo "Generating nnopbase stub files end." 47+ && echo "Generating nnopbase stub files end."
47)48)
48 49 
49 50 
@@ -78,6 +78,7 @@ white_list_for_debug = [
78 "format_utils.h",78 "format_utils.h",
79 "data_type_utils.h",79 "data_type_utils.h",
80 "common_types.h",80 "common_types.h",
81+ "direct_invoke_task.h",
81 "aicpu/aicpu_task.h", # aicpu82 "aicpu/aicpu_task.h", # aicpu
82 "individual_op_api.h", # nnopbase83 "individual_op_api.h", # nnopbase
83 "aclnn/acl_meta.h",84 "aclnn/acl_meta.h",