Skip to content

Commit

Permalink
[aiecc] Be explicit about peano path (#794)
Browse files Browse the repository at this point in the history
Historically, we assumed that peano was primarily accessed from the
user's path, which causes some issues where peano binaries conflict
with other LLVMs on the user path.  This patch removes this use
of the path in favor of referencing peano using explicit paths.
These explicit paths are discovered when aiecc runs, relative to
the location of the python code.  This replaces the (bogus)
compile-time setting of peano_install_dir, which was completely wrong
when distributing a packaged build.
  • Loading branch information
stephenneuendorffer authored Nov 30, 2023
1 parent 3fe300a commit 5b84241
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
10 changes: 10 additions & 0 deletions python/compiler/aiecc/cl_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@

from aie.compiler.aiecc.configure import *

aie_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
peano_install_dir = ""
# The expected location in an install area
peano_install_dir = os.path.join(aie_dir, "peano")
if(not os.path.exists(peano_install_dir)):
# The expected location in a build area
peano_install_dir = os.path.realpath(os.path.join(aie_dir, "..", "peano"))
if(not os.path.exists(peano_install_dir)):
peano_install_dir = "peano_not_found"

def parse_args(args=None):
if (args is None):
args = sys.argv[1:]
Expand Down
22 changes: 15 additions & 7 deletions python/compiler/aiecc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ async def prepare_for_chesshack(self, task):


async def process_core(self, core):
peano_path = os.path.join(opts.peano_install_dir, 'bin')
peano_clang_path = os.path.join(peano_path, 'clang')
peano_opt_path = os.path.join(peano_path, 'opt')
peano_llc_path = os.path.join(peano_path, 'llc')
async with self.limit:
if(self.stopall):
return
Expand Down Expand Up @@ -230,29 +234,29 @@ async def process_core(self, core):
await self.do_call(task, ['xchesscc_wrapper', self.aie_target.lower(), '+w', os.path.join(self.tmpdirname, 'work'), '-d', '-f', '+P', '4', file_core_llvmir_chesslinked, link_with_obj, '+l', file_core_bcf, '-o', file_core_elf])
elif(self.opts.link):
await self.do_call(task, ['xchesscc_wrapper', self.aie_target.lower(), '+w', os.path.join(self.tmpdirname, 'work'), '-c', '-d', '-f', '+P', '4', file_core_llvmir_chesslinked, '-o', file_core_obj])
await self.do_call(task, ['clang', '-O2', '--target=' + self.aie_peano_target, file_core_obj, *clang_link_args,
await self.do_call(task, [peano_clang_path, '-O2', '--target=' + self.aie_peano_target, file_core_obj, *clang_link_args,
'-Wl,-T,'+file_core_ldscript, '-o', file_core_elf])
else:
file_core_obj = self.file_obj
if(opts.link and opts.xbridge):
link_with_obj = self.extract_input_files(file_core_bcf)
await self.do_call(task, ['xchesscc_wrapper', self.aie_target.lower(), '+w', os.path.join(self.tmpdirname, 'work'), '-d', '-f', file_core_obj, link_with_obj, '+l', file_core_bcf, '-o', file_core_elf])
elif(opts.link):
await self.do_call(task, ['clang', '-O2', '--target=' + self.aie_peano_target, file_core_obj, *clang_link_args,
await self.do_call(task, [peano_clang_path, '-O2', '--target=' + self.aie_peano_target, file_core_obj, *clang_link_args,
'-Wl,-T,'+file_core_ldscript, '-o', file_core_elf])

elif(opts.compile):
if(not opts.unified):
file_core_llvmir_stripped = self.tmpcorefile(core, "stripped.ll")
await self.do_call(task, ['opt', '--passes=default<O2>,strip', '-S', file_core_llvmir, '-o', file_core_llvmir_stripped])
await self.do_call(task, ['llc', file_core_llvmir_stripped, '-O2', '--march=%s' % self.aie_target.lower(), '--function-sections', '--filetype=obj', '-o', file_core_obj])
await self.do_call(task, [peano_opt_path, '--passes=default<O2>,strip', '-S', file_core_llvmir, '-o', file_core_llvmir_stripped])
await self.do_call(task, [peano_llc_path, file_core_llvmir_stripped, '-O2', '--march=%s' % self.aie_target.lower(), '--function-sections', '--filetype=obj', '-o', file_core_obj])
else:
file_core_obj = self.file_obj
if(opts.link and opts.xbridge):
link_with_obj = self.extract_input_files(file_core_bcf)
await self.do_call(task, ['xchesscc_wrapper', self.aie_target.lower(), '+w', os.path.join(self.tmpdirname, 'work'), '-d', '-f', file_core_obj, link_with_obj, '+l', file_core_bcf, '-o', file_core_elf])
elif(opts.link):
await self.do_call(task, ['clang', '-O2', '--target=' + self.aie_peano_target, file_core_obj, *clang_link_args,
await self.do_call(task, [peano_clang_path, '-O2', '--target=' + self.aie_peano_target, file_core_obj, *clang_link_args,
'-Wl,-T,'+file_core_ldscript, '-o', file_core_elf])

self.progress_bar.update(self.progress_bar.task_completed,advance=1)
Expand Down Expand Up @@ -634,6 +638,10 @@ def make_sim_dir(x):
print("To run simulation: " + sim_script)

async def run_flow(self):
peano_path = os.path.join(opts.peano_install_dir, 'bin')
peano_clang_path = os.path.join(peano_path, 'clang')
peano_opt_path = os.path.join(peano_path, 'opt')
peano_llc_path = os.path.join(peano_path, 'llc')
nworkers = int(opts.nthreads)
if(nworkers == 0):
nworkers = os.cpu_count()
Expand Down Expand Up @@ -700,9 +708,9 @@ async def run_flow(self):
await self.do_call(progress_bar.task, ['xchesscc_wrapper', self.aie_target.lower(), '+w', os.path.join(self.tmpdirname, 'work'), '-c', '-d', '-f', '+P', '4', file_llvmir_hacked, '-o', self.file_obj])
elif(opts.compile):
self.file_llvmir_opt= os.path.join(self.tmpdirname, 'input.opt.ll')
await self.do_call(progress_bar.task, ['opt', '--passes=default<O2>', '-inline-threshold=10', '-S', self.file_llvmir, '-o', self.file_llvmir_opt])
await self.do_call(progress_bar.task, [peano_opt_path, '--passes=default<O2>', '-inline-threshold=10', '-S', self.file_llvmir, '-o', self.file_llvmir_opt])

await self.do_call(progress_bar.task, ['llc', self.file_llvmir_opt, '-O2', '--march=%s' % self.aie_target.lower(), '--function-sections', '--filetype=obj', '-o', self.file_obj])
await self.do_call(progress_bar.task, [peano_llc_path, self.file_llvmir_opt, '-O2', '--march=%s' % self.aie_target.lower(), '--function-sections', '--filetype=obj', '-o', self.file_obj])

progress_bar.update(progress_bar.task,advance=0,visible=False)
progress_bar.task_completed = progress_bar.add_task("[green] AIE Compilation:", total=len(cores)+1, command="%d Workers" % nworkers)
Expand Down
8 changes: 4 additions & 4 deletions test/aiecc/simple.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

// Note that llc determines the architecture from the llvm IR.

// XCHESSCC-NOT: {{^llc}}
// XCHESSCC-NOT: {{^[^ ]*llc}}
// XCHESSCC: xchesscc_wrapper aie
// XCHESSCC-NOT: {{^llc}}
// XCHESSCC-NOT: {{^[^ ]*llc}}
// PEANO-NOT: xchesscc_wrapper
// PEANO: {{^llc}}
// PEANO: {{^[^ ]*llc}}
// PEANO-SAME: --march=aie
// PEANO-NOT: xchesscc_wrapper
// NOCOMPILE-NOT: xchesscc_wrapper
// NOCOMPILE-NOT: {{^llc}}
// NOCOMPILE-NOT: {{^[^ ]*llc}}

module {
%12 = AIE.tile(1, 2)
Expand Down
8 changes: 4 additions & 4 deletions test/aiecc/simple_aie2.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
// RUN: %PYTHON aiecc.py --no-unified --no-compile --no-link -nv --sysroot=%VITIS_SYSROOT% --host-target=aarch64-linux-gnu %s -I%host_runtime_lib% %host_runtime_lib%/test_library.cpp %S/test.cpp -o test.elf | FileCheck %s --check-prefix=NOCOMPILE

// Note that llc determines the architecture from the llvm IR.
// XCHESSCC-NOT: {{^llc}}
// XCHESSCC-NOT: {{^[^ ]*llc}}
// XCHESSCC: xchesscc_wrapper aie2
// XCHESSCC-NOT: {{^llc}}
// XCHESSCC-NOT: {{^[^ ]*llc}}
// PEANO-NOT: xchesscc_wrapper
// PEANO: {{^llc}}
// PEANO: {{^[^ ]*llc}}
// PEANO-SAME: --march=aie2
// PEANO-NOT: xchesscc_wrapper
// NOCOMPILE-NOT: xchesscc_wrapper
// NOCOMPILE-NOT: {{^llc}}
// NOCOMPILE-NOT: {{^[^ ]*llc}}

module {
AIE.device(xcve2302) {
Expand Down
1 change: 0 additions & 1 deletion tools/aiecc/aiecc/configure.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ aie_disable_link = @CONFIG_DISABLE_LINK@
aie_disable_compile = @CONFIG_DISABLE_COMPILE@
aie_unified_compile = True
host_disable_compile = @CONFIG_DISABLE_HOST_COMPILE@
peano_install_dir = "@CONFIG_PEANO_INSTALL_DIR@"
host_architecture = "@LLVM_HOST_TRIPLE@"

def install_path():
Expand Down

0 comments on commit 5b84241

Please sign in to comment.