- Notifications
You must be signed in to change notification settings - Fork161
[proposal][wip] Add event trace configuration to mlir-aie#2705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
fifield wants to merge41 commits intoXilinx:mainChoose a base branch fromfifield:events_proposal
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes from1 commit
Commits
Show all changes
41 commits Select commitHold shift + click to select a range
80a48e3 Add a callable library function to parse_trace.py
fifield733652a Apply suggestions from code review
fifieldedee5a6 Generate trace_events package with CMake instead of checking into git
fifield7a7e694 Apply suggestions from code review
fifielda1cb4cf Make duplicate event number detection fail the build (#2697)
Copilote1bfbde Generate and include tablegen event enums in AIE dialect
fifield543bedb Commit 1: Add TableGen definitions for trace operations
fifieldc5e52d5 Commit 2: Add verification tests for trace operations
fifield7034d74 Commit 3: Implement standalone JSON register database loader
fifield6c506c6 Commit 4: Implement AIETraceToConfigPass
fifieldc7c734c Commit 5: Implement AIEInlineTraceConfigPass
fifieldc4c8b5e Commit 6: Add AIEConfigToNPUPass stub implementation
fifielda25c6fe Commit 7: Add end-to-end trace pipeline test
fifieldb4f5660 Complete Pass 3 implementation with RegisterDatabase integration
fifieldb611636 Refactor: Fix design issue with col/row preservation
fifield248af1c Move trace NPU passes to AIEX dialect (fixes AIEX loading issue)
fifield9a4ff28 Move and update trace tests to AIEX dialect
fifield184c25d Update AIEX tests to use runtime_sequence
fifield10449f3 checkpoint
fifield4a4e41f start a test
fifield300908f format
fifield6b591cc checkpoint
fifield97007eb updates, fixes, formatting
fifieldcaaf7f4 clang-format
fifieldb58edf2 remove aie-config-to-npu placeholder
fifield6556d01 fixes for core mem events
fifield1635816 fix test location
fifieldaa79764 Add stream switch port event monitoring to AIE trace infrastructure
fifield41ba2c7 update example to use aie.trace.port
fifieldbb18de2 Replace BoolAttr with DMAChannelDir for trace port direction
fifieldebfab0d Add test.py for trace example
fifield6095f3a implement trace and combo event op tablegen
fifield7907894 Update lower pass for combo and edge events
fifield01c9a32 Update dialect to use generated enums for events
fifielda2433db fix aie1 suffix
fifielde6a6457 checkpoint
fifield2532c8a fixes, format, refactor, cleanup
fifield2e0fc12 checkpoint
fifieldef6c53e wip
fifieldcc56b4d cleanup, fixes, refactor
fifieldfc99d49 implement AIETargetModel getStreamSwitchPortIndex
fifieldFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Move trace NPU passes to AIEX dialect (fixes AIEX loading issue)
PROBLEM: AIEX dialect couldn't be loaded during AIE pass executionSOLUTION: Move NPU-generating passes to AIEX dialect where they belong- Moved AIEInlineTraceConfig.cpp to lib/Dialect/AIEX/Transforms/- Moved AIEConfigToNPU.cpp to lib/Dialect/AIEX/Transforms/- Updated pass definitions in AIEXPasses.td- Removed from AIEPasses.td- Updated CMakeLists for both dialects- Updated pass registration headers- Fixed namespaces (AIEX, not AIE)RESULT: npu.write32 generation now works!- Pass renamed: aie-inline-trace-config → aiex-inline-trace-config- Pass renamed: aie-config-to-npu → aiex-config-to-npu- Col/row preserved in npu.write32 operations- RegisterDatabase integration functional- Bitfield merging workingExample output:aiex.npu.write32 {address=0xB40D0, column=0, row=2, value=0x1E2E0001}This is the correct architectural placement: AIEX depends on AIE.- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit248af1c01c3a0c713503985e901242379e0f4723
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletionslib/Dialect/AIEX/Transforms/AIEConfigToNPU.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //===- AIEConfigToNPU.cpp ---------------------------------------*- C++ -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // Copyright (C) 2025, Advanced Micro Devices, Inc. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // Pass to lower trace.reg to aiex.npu.write32 | ||
| // NOTE: This pass is now a stub. NPU generation moved to AIEInlineTraceConfig. | ||
| //===----------------------------------------------------------------------===// | ||
| #include "aie/Dialect/AIE/IR/AIEDialect.h" | ||
| #include "aie/Dialect/AIEX/Transforms/AIEXPasses.h" | ||
| #include "mlir/Pass/Pass.h" | ||
| using namespace mlir; | ||
| using namespace xilinx; | ||
| using namespace xilinx::AIEX; | ||
| struct AIEConfigToNPUPass : AIEXConfigToNPUBase<AIEConfigToNPUPass> { | ||
| void runOnOperation() override { | ||
| // This pass is now a no-op. | ||
| // NPU write generation happens in AIEInlineTraceConfig (Pass 2). | ||
| // Keeping this pass for future extensibility. | ||
| return; | ||
| } | ||
| }; | ||
| std::unique_ptr<OperationPass<AIE::DeviceOp>> | ||
| xilinx::AIEX::createAIEXConfigToNPUPass() { | ||
| return std::make_unique<AIEConfigToNPUPass>(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| //===- AIEInlineTraceConfig.cpp ---------------------------------*- C++ -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // Copyright (C) 2025, Advanced Micro Devices, Inc. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // Pass to inline trace.start_config and generate npu.write32 | ||
| //===----------------------------------------------------------------------===// | ||
| #include "aie/Dialect/AIE/IR/AIEDialect.h" | ||
| #include "aie/Dialect/AIE/IR/AIERegisterDatabase.h" | ||
| #include "aie/Dialect/AIEX/IR/AIEXDialect.h" | ||
| #include "aie/Dialect/AIEX/Transforms/AIEXPasses.h" | ||
| #include "mlir/IR/Attributes.h" | ||
| #include "mlir/Pass/Pass.h" | ||
| using namespace mlir; | ||
| using namespace xilinx; | ||
| using namespace xilinx::AIE; | ||
| using namespace xilinx::AIEX; | ||
| struct AIEInlineTraceConfigPass : AIEXInlineTraceConfigBase<AIEInlineTraceConfigPass> { | ||
| void runOnOperation() override { | ||
| AIE::DeviceOp device = getOperation(); | ||
| // Load RegisterDatabase for AIE2 | ||
| auto regDb = RegisterDatabase::loadAIE2(); | ||
| if (!regDb) { | ||
| device.emitError("Failed to load register database"); | ||
| return signalPassFailure(); | ||
| } | ||
| // // Load AIEX dialect (it's registered in aie-opt) | ||
| // device->getContext()->getOrLoadDialect<AIEX::AIEXDialect>(); | ||
| // Collect all trace.start_config operations | ||
| SmallVector<TraceStartConfigOp> startConfigs; | ||
| device.walk([&](TraceStartConfigOp startConfig) { | ||
| startConfigs.push_back(startConfig); | ||
| }); | ||
| for (auto startConfig : startConfigs) { | ||
| OpBuilder builder(startConfig); | ||
| // Lookup the trace config symbol | ||
| auto configSymbolName = startConfig.getTraceConfig(); | ||
| auto configOp = dyn_cast_or_null<TraceConfigOp>( | ||
| SymbolTable::lookupNearestSymbolFrom(device, | ||
| builder.getStringAttr(configSymbolName)) | ||
| ); | ||
| if (!configOp) { | ||
| startConfig.emitError("trace config symbol '") | ||
| << configSymbolName << "' not found"; | ||
| return signalPassFailure(); | ||
| } | ||
| // Get tile and extract col/row | ||
| auto tile = configOp.getTile(); | ||
| auto tileOp = dyn_cast<TileOp>(tile.getDefiningOp()); | ||
| if (!tileOp) { | ||
| startConfig.emitError("tile operand must be a TileOp"); | ||
| return signalPassFailure(); | ||
| } | ||
| int col = tileOp.getCol(); | ||
| int row = tileOp.getRow(); | ||
| // Determine module based on tile row | ||
| std::string module = "CORE_MODULE"; | ||
| if (row == 0) module = "PL_MODULE"; | ||
| else if (row == 1) module = "MEM_TILE_MODULE"; | ||
| // Group register writes by offset for merging | ||
| std::map<uint32_t, uint32_t> mergedValues; | ||
| std::map<uint32_t, TraceRegOp> firstRegOp; | ||
| // Process all trace.reg operations in the config | ||
| for (auto &op : configOp.getBody().getOps()) { | ||
| auto regOp = dyn_cast<TraceRegOp>(op); | ||
| if (!regOp) continue; | ||
| // Look up register | ||
| auto regName = regOp.getRegName().str(); | ||
| auto* regInfo = regDb->lookupRegister(regName, module); | ||
| if (!regInfo) { | ||
| regOp.emitWarning("Register '") << regName << "' not found in module " << module; | ||
| continue; | ||
| } | ||
| // Look up field | ||
| auto fieldName = regOp.getField().str(); | ||
| auto* fieldInfo = regInfo->getField(fieldName); | ||
| if (!fieldInfo) { | ||
| regOp.emitWarning("Field '") << fieldName << "' not found in register " << regName; | ||
| continue; | ||
| } | ||
| // Encode value | ||
| uint32_t encodedValue = 0; | ||
| auto value = regOp.getValue(); | ||
| if (auto intAttr = llvm::dyn_cast<IntegerAttr>(value)) { | ||
| // Integer value | ||
| encodedValue = regDb->encodeFieldValue(*fieldInfo, intAttr.getInt()); | ||
| } else if (auto strAttr = llvm::dyn_cast<StringAttr>(value)) { | ||
| // String value - resolve as event | ||
| std::string strVal = strAttr.getValue().str(); | ||
| auto eventCode = regDb->lookupEvent(strVal, "core"); | ||
| if (eventCode) { | ||
| encodedValue = regDb->encodeFieldValue(*fieldInfo, *eventCode); | ||
| } | ||
| } | ||
| // Merge into accumulated value | ||
| mergedValues[regInfo->offset] |= encodedValue; | ||
| if (firstRegOp.find(regInfo->offset) == firstRegOp.end()) { | ||
| firstRegOp[regInfo->offset] = regOp; | ||
| } | ||
| } | ||
| // Generate aiex.npu.write32 operations with col/row | ||
| for (auto& [offset, value] : mergedValues) { | ||
| builder.create<AIEX::NpuWrite32Op>( | ||
| firstRegOp[offset].getLoc(), | ||
| builder.getUI32IntegerAttr(offset), | ||
| builder.getUI32IntegerAttr(value), | ||
| nullptr, // buffer | ||
| builder.getI32IntegerAttr(col), // column | ||
| builder.getI32IntegerAttr(row) // row | ||
| ); | ||
| } | ||
| // Remove the start_config invocation | ||
| startConfig.erase(); | ||
| } | ||
| } | ||
| }; | ||
| std::unique_ptr<OperationPass<AIE::DeviceOp>> | ||
| xilinx::AIEX::createAIEXInlineTraceConfigPass() { | ||
| return std::make_unique<AIEInlineTraceConfigPass>(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.