Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
newling committed Aug 20, 2024
1 parent efc9461 commit fbf482e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 64 deletions.
112 changes: 59 additions & 53 deletions compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/XCLBinGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -1131,21 +1134,24 @@ static LogicalResult generateUnifiedObject(
FailureOr<ArrayRef<uint32_t>> 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<DenseUI32ResourceElementsAttr>(maybeNpuInstructions);
if (!npuInstructions)
if (!npuInstructions) {
return emitError(
UnknownLoc::get(ctx),
"Failed to cast npu_instructions to DenseUI32ResourceElementsAttr");
}
std::optional<ArrayRef<uint32_t>> 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();
}

Expand Down
29 changes: 18 additions & 11 deletions compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,21 +786,28 @@ void addMLIRAIRLoweringPasses(OpPassManager &passManager, AMDAIEDevice device) {
}

void addMLIRAIELoweringPasses(OpPassManager &passManager) {
OpPassManager &devicePM = passManager.nest<xilinx::AIE::DeviceOp>();
devicePM.addPass(createAMDAIEObjectFifoStatefulTransformPass());
devicePM.addPass(createAMDAIEDmaToNpuPass());
{
OpPassManager &devicePM = passManager.nest<xilinx::AIE::DeviceOp>();
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<xilinx::AIE::DeviceOp>(
createAMDAIELocalizeLocksPass());
passManager.addNestedPass<xilinx::AIE::DeviceOp>(
createAMDAIENormalizeAddressSpacesPass());

{
OpPassManager &devicePM = passManager.nest<xilinx::AIE::DeviceOp>();
devicePM.addPass(createAMDAIELocalizeLocksPass());
devicePM.addPass(createAMDAIENormalizeAddressSpacesPass());
devicePM.addPass(createCanonicalizerPass());
}
}

// NOTE: this runs on the top-level program module containing all hal.executable
Expand Down

0 comments on commit fbf482e

Please sign in to comment.