Skip to content

Commit

Permalink
refactor chess interface (#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenneuendorffer committed Sep 18, 2024
1 parent 6191459 commit e90b275
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 112 deletions.
21 changes: 11 additions & 10 deletions python/compiler/aiecc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,20 +430,25 @@ async def chesshack(self, task, llvmir, aie_target):
llvmir_chesslinked_path = llvmir + "chesslinked.ll"
if not self.opts.execute:
return llvmir_chesslinked_path
llvmir = await read_file_async(llvmir)

install_path = aie.compiler.aiecc.configure.install_path()
runtime_lib_path = os.path.join(install_path, "aie_runtime_lib")
chess_intrinsic_wrapper_ll_path = os.path.join(
runtime_lib_path, aie_target.upper(), "chess_intrinsic_wrapper.ll"
)

await write_file_async(llvmir, llvmir_chesshack)
llvmir_ir = await read_file_async(llvmir)
llvmir_hacked_ir = downgrade_ir_for_chess(llvmir_ir)
await write_file_async(llvmir_hacked_ir, llvmir_chesshack)

assert os.path.exists(llvmir_chesshack)
await self.do_call(
task,
[
"llvm-link",
# The path below is cheating a bit since it refers directly to the AIE1
# version of llvm-link, rather than calling the architecture-specific
# tool version.
opts.aietools_path + "/tps/lnx64/target/bin/LNa64bin/chess-llvm-link",
llvmir_chesshack,
chess_intrinsic_wrapper_ll_path,
"-S",
Expand All @@ -452,10 +457,6 @@ async def chesshack(self, task, llvmir, aie_target):
],
)

llvmir_chesslinked_ir = await read_file_async(llvmir_chesslinked_path)
llvmir_chesslinked_ir = downgrade_ir_for_chess(llvmir_chesslinked_ir)
await write_file_async(llvmir_chesslinked_ir, llvmir_chesslinked_path)

return llvmir_chesslinked_path

async def process_core(
Expand Down Expand Up @@ -513,9 +514,9 @@ async def process_core(
file_core_llvmir_chesslinked = await self.chesshack(task, file_core_llvmir, aie_target)
if self.opts.link and self.opts.xbridge:
link_with_obj = await extract_input_files(file_core_bcf)
await self.do_call(task, ["xchesscc_wrapper", aie_target.lower(), "+w", self.prepend_tmp("work"), "-d", "-f", "+P", "4", file_core_llvmir_chesslinked, link_with_obj, "+l", file_core_bcf, "-o", file_core_elf])
await self.do_call(task, ["xchesscc_wrapper", aie_target.lower(), "+w", self.prepend_tmp("work"), "-d", "+Wclang,-xir", "-f", 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", aie_target.lower(), "+w", self.prepend_tmp("work"), "-c", "-d", "-f", "+P", "4", file_core_llvmir_chesslinked, "-o", file_core_obj])
await self.do_call(task, ["xchesscc_wrapper", aie_target.lower(), "+w", self.prepend_tmp("work"), "-c", "-d", "+Wclang,-xir", "-f", file_core_llvmir_chesslinked, "-o", file_core_obj])
await self.do_call(task, [self.peano_clang_path, "-O2", "--target=" + aie_peano_target, file_core_obj, *clang_link_args, "-Wl,-T," + file_core_ldscript, "-o", file_core_elf])
else:
file_core_obj = self.unified_file_core_obj
Expand Down Expand Up @@ -1113,7 +1114,7 @@ async def run_flow(self):
self.unified_file_core_obj = self.prepend_tmp("input.o")
if opts.compile and opts.xchesscc:
file_llvmir_hacked = await self.chesshack(progress_bar.task, file_llvmir, aie_target)
await self.do_call(progress_bar.task, ["xchesscc_wrapper", aie_target.lower(), "+w", self.prepend_tmp("work"), "-c", "-d", "-f", "+P", "4", file_llvmir_hacked, "-o", self.unified_file_core_obj])
await self.do_call(progress_bar.task, ["xchesscc_wrapper", aie_target.lower(), "+w", self.prepend_tmp("work"), "-c", "-d", "+Wclang,-xir", "-f", file_llvmir_hacked, "-o", self.unified_file_core_obj])
elif opts.compile:
file_llvmir_opt = self.prepend_tmp("input.opt.ll")
await self.do_call(progress_bar.task, [self.peano_opt_path, "--passes=default<O2>", "-inline-threshold=10", "-S", file_llvmir, "-o", file_llvmir_opt])
Expand Down
20 changes: 0 additions & 20 deletions tools/chess-clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,4 @@ if(NOT DEFINED CMAKE_CROSSCOMPILE)
# These files are only useful on host x86 compiles.
install(PROGRAMS xchesscc_wrapper DESTINATION ${PROJECT_BINARY_DIR}/bin)
install(PROGRAMS xchesscc_wrapper DESTINATION ${SCRIPT_INSTALL_PATH})

set(FILES
chess-clang)

set(TARGETS ${FILES})
list(TRANSFORM TARGETS PREPEND ${PROJECT_BINARY_DIR}/bin/)

# stuff into the build directory
add_custom_target(copy-scripts ALL DEPENDS ${TARGETS})
foreach(file ${FILES})
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/bin/${file}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file}
${PROJECT_BINARY_DIR}/bin/${file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
endforeach()

# install too!
foreach(file ${FILES})
install(PROGRAMS ${file} DESTINATION ${SCRIPT_INSTALL_PATH})
endforeach()
endif()
64 changes: 0 additions & 64 deletions tools/chess-clang/chess-clang

This file was deleted.

23 changes: 5 additions & 18 deletions tools/chess-clang/xchesscc_wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# (c) Copyright 2021 Xilinx Inc.
# (c) Copyright 2022-2023 Advanced Micro Devices, Inc.
# (c) Copyright 2022-2024 Advanced Micro Devices, Inc.

AIETOOLS=`realpath $(dirname $(which xchesscc))/../`

TARGET_AIE_LIBDIR=$AIETOOLS/data/versal_prod/lib
TARGET_AIE2_LIBDIR=$AIETOOLS/data/aie_ml/lib

TARGET=${1^^}
shift

Expand All @@ -23,29 +20,19 @@ fi
if [ $TARGET == "AIE" ]
then
EXTRA_DEFS="-D__AIE_ARCH__=10 -D__AIEARCH__=10"
AIEARCH=versal_prod
elif [ $TARGET == "AIE2" ]
then
EXTRA_DEFS="-D__AIE_ARCH__=20 -D__AIEARCH__=20"
AIEARCH=aie_ml
fi
if [ -z "$AIETOOLS" ]
then
echo "xchesscc_wrapper needs a valid Vitis installation"
exit 1
fi

if [ -z "$AIETOOLS" ]
then
echo "xchesscc_wrapper needs a valid Vitis installation"
exit 1
fi

TARGETVAR=TARGET_${TARGET}_LIBDIR
LIBDIR=${!TARGETVAR}
LIBDIR=${AIETOOLS}/data/${AIEARCH}/lib

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
export RDI_DATADIR=$AIETOOLS/data
export UNWRAPPED_XCHESSCC=$AIETOOLS/bin/unwrapped/lnx64.o/xchesscc
export LD_LIBRARY_PATH=$AIETOOLS/lib/lnx64.o:$AIETOOLS/lnx64/tools/dot/lib:$LD_LIBRARY_PATH
# Carefully crafted path so that we can inject other scripts into the chess path, namely chess-clang
export PATH=$DIR:$AIETOOLS/bin/unwrapped/lnx64.o:$AIETOOLS/tps/lnx64/target/bin/LNa64bin
$UNWRAPPED_XCHESSCC -p me -C Release_LLVM -D__AIENGINE__ $EXTRA_DEFS -Y clang=$DIR/chess-clang -P $LIBDIR -d -f $@
xchesscc --aiearch ${AIEARCH} -p me -C Release_LLVM -D__AIENGINE__ $EXTRA_DEFS -P $LIBDIR -d -f $@

0 comments on commit e90b275

Please sign in to comment.