Skip to content

Commit

Permalink
Simplify CDO code generation (#1501)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
  • Loading branch information
stephenneuendorffer and makslevental authored May 21, 2024
1 parent 92c6ed9 commit f507a5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
8 changes: 5 additions & 3 deletions lib/Targets/AIETargetCDODirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ LogicalResult generateCDOBinary(const StringRef outputPath,
const std::function<LogicalResult()> &cb) {
startCDOFileStream(outputPath.str().c_str());
FileHeader();
// Never generate a completely empty CDO file. If the file only contains a
// header, then bootgen flags it as invalid.
insertNoOpCommand(4);
if (failed(cb()))
return failure();
configureHeader();
Expand All @@ -717,8 +720,7 @@ LogicalResult generateCDOBinariesSeparately(AIEControl &ctl,
DeviceOp &targetOp, bool aieSim,
bool enableCores) {

if (!targetOp.getOps<CoreOp>().empty() &&
failed(generateCDOBinary(
if (failed(generateCDOBinary(
(llvm::Twine(workDirPath) + std::string(1, ps) + "aie_cdo_elfs.bin")
.str(),
[&ctl, &targetOp, &workDirPath, &aieSim] {
Expand All @@ -732,7 +734,7 @@ LogicalResult generateCDOBinariesSeparately(AIEControl &ctl,
[&ctl, &targetOp] { return ctl.addInitConfigToCDO(targetOp); })))
return failure();

if (enableCores && !targetOp.getOps<CoreOp>().empty() &&
if (enableCores &&
failed(generateCDOBinary(
(llvm::Twine(workDirPath) + std::string(1, ps) + "aie_cdo_enable.bin")
.str(),
Expand Down
22 changes: 11 additions & 11 deletions python/compiler/aiecc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ def emit_partition(mlir_module_str, kernel_id="0x901", start_columns=None):
module.operation,
lambda o: isinstance(o.operation.opview, aiedialect.TileOp),
)
min_col = min([t.col.value for t in tiles])
max_col = max([t.col.value for t in tiles])

min_col = min([t.col.value for t in tiles], default=0)
max_col = max([t.col.value for t in tiles], default=0)
num_cols = max_col - min_col + 1
device = find_ops(
module.operation,
Expand Down Expand Up @@ -255,8 +254,9 @@ def generate_cores_list(mlir_module_str):


def emit_design_bif(root_path, has_cores=True, enable_cores=True):
elf_file = f"file={root_path}/aie_cdo_elfs.bin" if has_cores else ""
enable_file = f"file={root_path}/aie_cdo_enable.bin" if enable_cores else ""
cdo_elfs_file = f"file={root_path}/aie_cdo_elfs.bin"
cdo_init_file = f"file={root_path}/aie_cdo_init.bin"
cdo_enable_file = f"file={root_path}/aie_cdo_enable.bin" if enable_cores else ""
return dedent(
f"""\
all:
Expand All @@ -267,9 +267,9 @@ def emit_design_bif(root_path, has_cores=True, enable_cores=True):
{{
name=aie_image, id=0x1c000000
{{ type=cdo
{elf_file}
file={root_path}/aie_cdo_init.bin
{enable_file}
{cdo_elfs_file}
{cdo_init_file}
{cdo_enable_file}
}}
}}
}}
Expand Down Expand Up @@ -550,7 +550,7 @@ async def process_cdo(self):
)
generate_cdo(input_physical.operation, self.tmpdirname)

async def process_xclbin_gen(self, has_cores):
async def process_xclbin_gen(self):
if opts.progress:
task = self.progress_bar.add_task(
"[yellow] XCLBIN generation ", total=10, command="starting"
Expand Down Expand Up @@ -583,7 +583,7 @@ async def process_xclbin_gen(self, has_cores):
)

await write_file_async(
emit_design_bif(self.tmpdirname, has_cores),
emit_design_bif(self.tmpdirname),
self.prepend_tmp("design.bif"),
)

Expand Down Expand Up @@ -1075,7 +1075,7 @@ async def run_flow(self):
if opts.cdo and opts.execute:
await self.process_cdo()
if opts.cdo or opts.xcl:
await self.process_xclbin_gen(bool(len(cores)))
await self.process_xclbin_gen()

def dumpprofile(self):
sortedruntimes = sorted(
Expand Down

0 comments on commit f507a5f

Please sign in to comment.