diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp index 204bf1100..e7285642f 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp @@ -673,57 +673,56 @@ static LogicalResult generateCDO(MLIRContext *context, AIE::DeviceOp deviceOp, static json::Object makeKernelJSON(const std::string &name, const std::string &id, const std::string &instance) { - using json::Object; - - return Object{ + return json::Object{ {"name", name}, {"type", "dpu"}, {"extended-data", - Object{{"subtype", "DPU"}, {"functional", "0"}, {"dpu_kernel_id", id}}}, - {"arguments", json::Array{Object{{"name", "opcode"}, - {"address-qualifier", "SCALAR"}, - {"type", "uint64_t"}, - {"offset", "0x00"}}, - Object{{"name", "instr"}, - {"memory-connection", "SRAM"}, - {"address-qualifier", "GLOBAL"}, - {"type", "char *"}, - {"offset", "0x08"}}, - Object{{"name", "ninstr"}, - {"address-qualifier", "SCALAR"}, - {"type", "uint32_t"}, - {"offset", "0x10"}}, - Object{{"name", "bo0"}, - {"memory-connection", "HOST"}, - {"address-qualifier", "GLOBAL"}, - {"type", "void*"}, - {"offset", "0x14"}}, - Object{{"name", "bo1"}, - {"memory-connection", "HOST"}, - {"address-qualifier", "GLOBAL"}, - {"type", "void*"}, - {"offset", "0x1c"}}, - Object{{"name", "bo2"}, - {"memory-connection", "HOST"}, - {"address-qualifier", "GLOBAL"}, - {"type", "void*"}, - {"offset", "0x24"}}, - Object{{"name", "bo3"}, - {"memory-connection", "HOST"}, - {"address-qualifier", "GLOBAL"}, - {"type", "void*"}, - {"offset", "0x2c"}}, - Object{{"name", "bo4"}, - {"memory-connection", "HOST"}, - {"address-qualifier", "GLOBAL"}, - {"type", "void*"}, - {"offset", "0x34"}}, - Object{{"name", "bo5"}, - {"memory-connection", "HOST"}, - {"address-qualifier", "GLOBAL"}, - {"type", "void*"}, - {"offset", "0x3c"}}}}, - {"instances", json::Array{Object{{"name", instance}}}}}; + json::Object{ + {"subtype", "DPU"}, {"functional", "0"}, {"dpu_kernel_id", id}}}, + {"arguments", json::Array{json::Object{{"name", "opcode"}, + {"address-qualifier", "SCALAR"}, + {"type", "uint64_t"}, + {"offset", "0x00"}}, + json::Object{{"name", "instr"}, + {"memory-connection", "SRAM"}, + {"address-qualifier", "GLOBAL"}, + {"type", "char *"}, + {"offset", "0x08"}}, + json::Object{{"name", "ninstr"}, + {"address-qualifier", "SCALAR"}, + {"type", "uint32_t"}, + {"offset", "0x10"}}, + json::Object{{"name", "bo0"}, + {"memory-connection", "HOST"}, + {"address-qualifier", "GLOBAL"}, + {"type", "void*"}, + {"offset", "0x14"}}, + json::Object{{"name", "bo1"}, + {"memory-connection", "HOST"}, + {"address-qualifier", "GLOBAL"}, + {"type", "void*"}, + {"offset", "0x1c"}}, + json::Object{{"name", "bo2"}, + {"memory-connection", "HOST"}, + {"address-qualifier", "GLOBAL"}, + {"type", "void*"}, + {"offset", "0x24"}}, + json::Object{{"name", "bo3"}, + {"memory-connection", "HOST"}, + {"address-qualifier", "GLOBAL"}, + {"type", "void*"}, + {"offset", "0x2c"}}, + json::Object{{"name", "bo4"}, + {"memory-connection", "HOST"}, + {"address-qualifier", "GLOBAL"}, + {"type", "void*"}, + {"offset", "0x34"}}, + json::Object{{"name", "bo5"}, + {"memory-connection", "HOST"}, + {"address-qualifier", "GLOBAL"}, + {"type", "void*"}, + {"offset", "0x3c"}}}}, + {"instances", json::Array{json::Object{{"name", instance}}}}}; } static LogicalResult generateXCLBin( @@ -1066,8 +1065,10 @@ static LogicalResult generateUnifiedObject( llvm::LLVMContext llvmContext; auto llvmModule = translateModuleToLLVMIR(moduleWithOneDevice, llvmContext); - if (!llvmModule) + if (!llvmModule) { return deviceOp.emitOpError("Failed to translate module to LLVMIR"); + } + std::string inputLLStr; { llvm::raw_string_ostream rso(inputLLStr); @@ -1089,7 +1090,9 @@ static LogicalResult generateUnifiedObject( /*workDir=*/tempDir, /*vitisDir=*/*maybeVitisDir, /*verbose=*/verbose); - if (failed(chessIntrinsicsObjFile)) return failure(); + if (failed(chessIntrinsicsObjFile)) { + return failure(); + } } else { Path LLVMIRFile = tempDir / "input.ll"; if (auto maybeErr = dumpStrToDisk(inputLLStr, LLVMIRFile.string()); @@ -1131,21 +1134,24 @@ static LogicalResult generateUnifiedObject( FailureOr> getNpuInstructions(AIE::DeviceOp deviceOp) { MLIRContext *ctx = deviceOp.getContext(); mlir::Attribute maybeNpuInstructions = deviceOp->getAttr("npu_instructions"); - if (!maybeNpuInstructions) + if (!maybeNpuInstructions) { return emitError(UnknownLoc::get(ctx), "Expected npu_instructions attribute on aie.device"); + } auto npuInstructions = dyn_cast(maybeNpuInstructions); - if (!npuInstructions) + if (!npuInstructions) { return emitError( UnknownLoc::get(ctx), "Failed to cast npu_instructions to DenseUI32ResourceElementsAttr"); + } std::optional> maybeArrayRef = npuInstructions.tryGetAsArrayRef(); - if (!maybeArrayRef.has_value()) + if (!maybeArrayRef.has_value()) { return emitError( UnknownLoc::get(ctx), "Failed getting values for npu_instructions in tryGetAsArrayRef"); + } return maybeArrayRef.value(); } diff --git a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/Passes.cpp b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/Passes.cpp index fdaab084b..a1bd27d91 100644 --- a/compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/Passes.cpp +++ b/compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/Passes.cpp @@ -786,21 +786,28 @@ void addMLIRAIRLoweringPasses(OpPassManager &passManager, AMDAIEDevice device) { } void addMLIRAIELoweringPasses(OpPassManager &passManager) { - OpPassManager &devicePM = passManager.nest(); - devicePM.addPass(createAMDAIEObjectFifoStatefulTransformPass()); - devicePM.addPass(createAMDAIEDmaToNpuPass()); + { + OpPassManager &devicePM = passManager.nest(); + devicePM.addPass(createAMDAIEObjectFifoStatefulTransformPass()); + devicePM.addPass(createCanonicalizerPass()); + devicePM.addPass(createAMDAIEDmaToNpuPass()); + devicePM.addPass(createAMDAIEAssignLockIDsPass()); + devicePM.addPass(createAMDAIEAssignBufferDescriptorIDsPass()); + devicePM.addPass(createAMDAIEAssignBufferAddressesBasicPass()); + devicePM.addPass(createAMDAIEPathfinderPass()); + } + passManager.addPass(createCanonicalizerPass()); passManager.addPass(createConvertLinalgToLoopsPass()); passManager.addPass(createLowerAffinePass()); - devicePM.addPass(createAMDAIEAssignLockIDsPass()); - devicePM.addPass(createAMDAIEAssignBufferDescriptorIDsPass()); - devicePM.addPass(createAMDAIEAssignBufferAddressesBasicPass()); - devicePM.addPass(createAMDAIEPathfinderPass()); passManager.addPass(createConvertSCFToCFPass()); - passManager.addNestedPass( - createAMDAIELocalizeLocksPass()); - passManager.addNestedPass( - createAMDAIENormalizeAddressSpacesPass()); + + { + OpPassManager &devicePM = passManager.nest(); + devicePM.addPass(createAMDAIELocalizeLocksPass()); + devicePM.addPass(createAMDAIENormalizeAddressSpacesPass()); + devicePM.addPass(createCanonicalizerPass()); + } } // NOTE: this runs on the top-level program module containing all hal.executable