Merged
fix(codegen): Null-check taskStat before OPEN_MIX_PERF sys_cnt access #6187
anyangleAdd on Sep 11
fix(codegen): Null-check taskStat before OPEN_MIX_PERF sys_cnt access #6187
Merged
anyangleAdd on Sep 11
Total: 3 files changed+6-4
@@ -63,7 +63,7 @@ PyPTO提供了丰富的示例代码,涵盖从基础操作到复杂模型实现
63## 📖文档资源63## 📖文档资源
64 64 
65若您希望深入体验项目功能并修改源码,请访问如下文档获取详细教程。65若您希望深入体验项目功能并修改源码,请访问如下文档获取详细教程。
66-- [文档中心](https://pypto.gitcode.com):当前发布版本的详细文档,包括PyPTO算子开发、PyPTO API参考等66+- [文档中心](https://pypto.gitcode.com):当前发布版本的详细文档,包含PyPTO算子开发、PyPTO API参考等
67- [示例代码](https://gitcode.com/cann/pypto/blob/master/examples/):丰富的示例代码,从基础到高级应用67- [示例代码](https://gitcode.com/cann/pypto/blob/master/examples/):丰富的示例代码,从基础到高级应用
68 68 
69## 🔍目录结构69## 🔍目录结构
@@ -64,7 +64,7 @@ If you want to quickly experience the usage and development process of PyPTO, re
64## Documentation Resources64## Documentation Resources
65 65 
66If you want to deeply experience the project features and modify the source code, refer to the following documents for detailed tutorials.66If you want to deeply experience the project features and modify the source code, refer to the following documents for detailed tutorials.
67-- [Documentation Center](https://pypto.gitcode.com): Detailed documentation for the current release version, including programming guides (with debugging and tuning tools), API references, and more.67+- [Documentation Center](https://pypto.gitcode.com): Detailed documentation for the current release version, including PyPTO Operator Development, PyPTO API references, and more.
68- [Sample Code](https://gitcode.com/cann/pypto/blob/master/examples/): Rich sample code from basic to advanced applications.68- [Sample Code](https://gitcode.com/cann/pypto/blob/master/examples/): Rich sample code from basic to advanced applications.
69 69 
70## Directory Structure70## Directory Structure
@@ -45,8 +45,9 @@ std::string CodeGenOpNPU::GenSyncWaitOp() const { return PrintSyncInSingleKernel
45 45 
46void InsertSetSysCnt(std::ostringstream& oss)46void InsertSetSysCnt(std::ostringstream& oss)
47{47{
48+ // Capture may leave taskStat null; guard to avoid AICore OOB.
48 oss << "#ifdef OPEN_MIX_PERF\n";49 oss << "#ifdef OPEN_MIX_PERF\n";
49- oss << "{\n";50+ oss << "if (taskStat != nullptr) {\n";
50 oss << " __gm__ uint64_t* setEventBase = reinterpret_cast<__gm__ uint64_t*>(taskStat->perfDataBaseAddr + "51 oss << " __gm__ uint64_t* setEventBase = reinterpret_cast<__gm__ uint64_t*>(taskStat->perfDataBaseAddr + "
51 "taskStat->setEventAddr);\n";52 "taskStat->setEventAddr);\n";
52 oss << " setEventBase[taskStat->setEventNum++] = get_sys_cnt();\n";53 oss << " setEventBase[taskStat->setEventNum++] = get_sys_cnt();\n";
@@ -65,8 +66,9 @@ std::string CodeGenOpNPU::GenCVSyncSetOp() const
65 66 
66void InsertWaitSysCnt(std::ostringstream& oss)67void InsertWaitSysCnt(std::ostringstream& oss)
67{68{
69+ // Capture may leave taskStat null; guard to avoid AICore OOB.
68 oss << "#ifdef OPEN_MIX_PERF\n";70 oss << "#ifdef OPEN_MIX_PERF\n";
69- oss << "{\n";71+ oss << "if (taskStat != nullptr) {\n";
70 oss << " __gm__ uint64_t* waitEventBase = reinterpret_cast<__gm__ uint64_t*>(taskStat->perfDataBaseAddr + "72 oss << " __gm__ uint64_t* waitEventBase = reinterpret_cast<__gm__ uint64_t*>(taskStat->perfDataBaseAddr + "
71 "taskStat->waitEventAddr);\n";73 "taskStat->waitEventAddr);\n";
72 oss << " waitEventBase[taskStat->waitEventNum++] = get_sys_cnt();\n";74 oss << " waitEventBase[taskStat->waitEventNum++] = get_sys_cnt();\n";