Skip to content

Commit

Permalink
[codegen][runtime] Use bender and pulp from docker image (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
zero9178 authored May 19, 2024
1 parent f066d70 commit 1fbaede
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 64 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ jobs:
sudo apt-get update
sudo apt-get install lld clang cargo
- name: Install Pulp Toolchain
run: |
mkdir ${{github.workspace}}/pulp-toolchain
wget -qO- https://github.com/pulp-platform/llvm-project/releases/download/0.12.0/riscv32-pulp-llvm-ubuntu2004-0.12.0.tar.gz \
| tar --strip-components=1 -xzv -C ${{github.workspace}}/pulp-toolchain
- name: Install Quidditch Toolchain
run: |
mkdir ./toolchain
Expand All @@ -60,7 +54,6 @@ jobs:
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DPULP_CLANG_PATH=${{github.workspace}}/pulp-toolchain/bin/clang \
-DQUIDDITCH_TOOLCHAIN_FILE=${{github.workspace}}/toolchain/ToolchainFile.cmake \
-DOVERRIDE_VENV=ON \
-S ${{github.workspace}}
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
[submodule "xdsl"]
path = xdsl
url = https://github.com/xdslproject/xdsl
[submodule "bender"]
path = bender
url = https://github.com/pulp-platform/bender
23 changes: 3 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.21)
project(Quidditch C CXX)

set(QUIDDITCH_TOOLCHAIN_FILE "" CACHE STRING "Path to the quidditch toolchain's toolchain file")
set(PULP_CLANG_PATH "" CACHE STRING "Path to clang within the pulp toolchain")
set(OVERRIDE_VENV OFF CACHE BOOL "")
cmake_path(REMOVE_FILENAME QUIDDITCH_TOOLCHAIN_FILE OUTPUT_VARIABLE QUIDDITCH_TOOLCHAIN_ROOT)

if (NOT DEFINED ENV{VIRTUAL_ENV} AND NOT ${OVERRIDE_VENV})
message(FATAL_ERROR [[
Expand Down Expand Up @@ -39,7 +39,7 @@ append_if_defined(host_cmake_args CMAKE_CXX_COMPILER_LAUNCHER)
ExternalProject_Add(codegen
CMAKE_ARGS
-DIREE_ENABLE_LLD=ON
-DPULP_CLANG_PATH=${PULP_CLANG_PATH}
-DQUIDDITCH_TOOLCHAIN_ROOT=${QUIDDITCH_TOOLCHAIN_ROOT}
${host_cmake_args}
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/codegen
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/codegen
Expand All @@ -53,31 +53,14 @@ ExternalProject_Add(codegen
USES_TERMINAL_TEST ON
)

ExternalProject_Add(bender
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/bender
CONFIGURE_COMMAND ""
BUILD_COMMAND
${CARGO_PATH} build
--release
--target-dir=${CMAKE_CURRENT_BINARY_DIR}/bender
--manifest-path=${CMAKE_CURRENT_LIST_DIR}/bender/Cargo.toml
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bender
INSTALL_COMMAND ""
USES_TERMINAL_CONFIGURE ON
USES_TERMINAL_BUILD ON
USES_TERMINAL_TEST ON
)

set(runtime_cmake_args)
append_if_defined(runtime_cmake_args CMAKE_BUILD_TYPE)
append_if_defined(runtime_cmake_args CMAKE_C_COMPILER_LAUNCHER)
append_if_defined(runtime_cmake_args CMAKE_CXX_COMPILER_LAUNCHER)
ExternalProject_Add(runtime
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${QUIDDITCH_TOOLCHAIN_FILE}
-DPULP_CLANG_PATH=${PULP_CLANG_PATH}
-DQUIDDITCH_CODEGEN_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}/codegen
-DBENDER_PATH=${CMAKE_CURRENT_BINARY_DIR}/bender/release/bender
${runtime_cmake_args}
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/runtime
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/runtime
Expand All @@ -87,7 +70,7 @@ ExternalProject_Add(runtime
USES_TERMINAL_BUILD ON
USES_TERMINAL_TEST ON
)
add_dependencies(runtime codegen bender)
add_dependencies(runtime codegen)

enable_testing()
include(ProcessorCount)
Expand Down
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,24 @@ Only linux is currently supported as a build environment
Building Quidditch requires the following tools to be installed:
* CMake 3.21 or newer
* A C++17 compiler
* Cargo
* Python 3
* Ninja (ideally)
* the Quidditch toolchain
* the Pulp toolchain
* Docker to install the Quidditch toolchain. See [the toolchain directory for more details](runtime/toolchain/README.md)

`docker` is required to install the Quidditch toolchain using:
```shell
docker run --rm ghcr.io/opencompl/Quidditch/toolchain:main tar -cC /opt/quidditch-toolchain .\
| tar -xC $INSTALL_DIR/quidditch-toolchain
```
See [the toolchain directory for more details](runtime/toolchain/README.md).

To get the pulp toolchain, you can run:
```shell
mkdir $INSTALL_DIR/pulp-toolchain
wget -qO- https://github.com/pulp-platform/llvm-project/releases/download/0.12.0/riscv32-pulp-llvm-ubuntu2004-0.12.0.tar.gz \
| tar --strip-components=1 -xzv -C $INSTALL_DIR/pulp-toolchain
```
or similar if your system is binary compatible with Ubuntu 22.04.
See [the toolchain directory for more details](runtime/toolchain/README.md).

Afterward, you can perform a mega build using:
```shell
git clone --recursive https://github.com/opencompl/quidditch
cd quidditch

docker run --rm ghcr.io/opencompl/Quidditch/toolchain:main tar -cC /opt/quidditch-toolchain .\
| tar -xC ./toolchain

python -m venv venv
source ./venv/bin/activate

Expand All @@ -44,9 +36,8 @@ cmake .. -GNinja \
# Optional for improved caching, requires ccache to be installed.
# -DCMAKE_C_COMPILER_LAUNCHER=ccache \
# -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DPULP_CLANG_PATH=$INSTALL_DIR/pulp-toolchain/bin/clang \
-DQUIDDITCH_TOOLCHAIN_FILE=$INSTALL_DIR/quidditch-toolchain/ToolchainFile.cmake

-DQUIDDITCH_TOOLCHAIN_FILE=../toolchain/ToolchainFile.cmake

# Build and Test everything.
cmake --build . --target test
```
Expand Down
1 change: 0 additions & 1 deletion bender
Submodule bender deleted from 818a77
1 change: 1 addition & 0 deletions codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.21)
project(QuidditchCompiler LANGUAGES CXX C)

set(IREE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../iree" CACHE STRING "IREE source code path")
set(QUIDDITCH_TOOLCHAIN_ROOT "" CACHE STRING "Path to the Quidditch toolchain")

add_subdirectory(iree-configuration)

Expand Down
25 changes: 12 additions & 13 deletions codegen/compiler/src/Quidditch/QuidditchTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QuidditchTargetDevice final : public IREE::HAL::TargetDevice {
struct QuidditchTargetOptions {
std::string staticLibraryOutputPath;
std::string xDSLOptPath;
std::string pulpClangPath;
std::string toolChainRoot;

void bindOptions(OptionsBinder &binder) {
LLVMInitializeRISCVTarget();
Expand All @@ -83,10 +83,9 @@ struct QuidditchTargetOptions {
llvm::cl::desc("Path to the 'xdsl-opt' executable "
"to use for kernel compilation."));
binder.opt<std::string>(
"iree-quidditch-pulp-clang-path", pulpClangPath,
llvm::cl::cat(category),
llvm::cl::desc("Path to the 'clang' executable "
"that is part of the pulp toolchain."));
"iree-quidditch-toolchain-root", toolChainRoot, llvm::cl::cat(category),
llvm::cl::desc("Path to the root directory of the Quidditch toolchain "
"(containing the toolchain file)"));
}
};

Expand Down Expand Up @@ -179,11 +178,11 @@ class QuidditchTargetBackend final : public IREE::HAL::TargetBackend {

auto &objectFile = objectFiles.emplace_back(
IREE::HAL::Artifact::createTemporary("xdsl-out", "o"));
ret = llvm::sys::ExecuteAndWait(targetOptions.pulpClangPath,
{targetOptions.pulpClangPath, "-c",
stdoutFile.str(), "-o", objectFile.path,
"-menable-experimental-extensions",
"-mcpu=snitch", "-mabi=ilp32d"});
ret = llvm::sys::ExecuteAndWait(
targetOptions.toolChainRoot + "/bin/pulp-as",
{targetOptions.toolChainRoot + "/bin/pulp-as", "--filetype=obj",
"--target-abi=ilp32d", stdoutFile.str(), "-o", objectFile.path,
"--mcpu=snitch", "-g"});
if (ret != 0)
return failure();

Expand Down Expand Up @@ -375,8 +374,7 @@ class QuidditchTargetBackend final : public IREE::HAL::TargetBackend {

objectFiles.push_back(std::move(*objectFileOrFailure));

SmallVector<StringRef> arguments = {
targetOptions.pulpClangPath, "-fuse-ld=lld", "-nostartfiles", "-Wl,-r"};
SmallVector<StringRef> arguments = {"ld.lld", "-r"};
llvm::append_range(
arguments,
llvm::map_range(objectFiles,
Expand All @@ -389,7 +387,8 @@ class QuidditchTargetBackend final : public IREE::HAL::TargetBackend {
auto linkedObject = IREE::HAL::Artifact::createTemporary(libraryName, "o");
arguments.push_back("-o");
arguments.push_back(linkedObject.path);
int ret = llvm::sys::ExecuteAndWait(targetOptions.pulpClangPath, arguments);
int ret = llvm::sys::ExecuteAndWait(
targetOptions.toolChainRoot + "/bin/ld.lld", arguments);
if (ret != 0)
return failure();

Expand Down
2 changes: 1 addition & 1 deletion codegen/tests/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

config.substitutions.append(("%PATH%", config.environment["PATH"]))
config.substitutions.append(("%xdsl-opt", config.xdsl_opt))
config.substitutions.append(("%pulp-clang", config.pulp_clang))
config.substitutions.append(("%quidditch-toolchain-root", config.quidditch_toolchain_root))

# FileCheck -enable-var-scope is enabled by default in MLIR test
# This option avoids to accidentally reuse variable across -LABEL match,
Expand Down
2 changes: 1 addition & 1 deletion codegen/tests/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config.python_executable = "@Python3_EXECUTABLE@"
config.native_target = "@LLVM_NATIVE_ARCH@"
config.llvm_host_triple = '@LLVM_HOST_TRIPLE@'
config.binary_dir = "@CMAKE_BINARY_DIR@"
config.pulp_clang = "@PULP_CLANG_PATH@"
config.quidditch_toolchain_root = "@QUIDDITCH_TOOLCHAIN_ROOT@"
config.xdsl_opt = "@XDSL_OPT_PATH@"

# Support substitution of the tools_dir with user parameters. This is
Expand Down
2 changes: 1 addition & 1 deletion codegen/tests/smoketest.mlir
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: iree-compile %s --iree-hal-target-backends=quidditch --iree-opt-demote-f64-to-f32=0 \
// RUN: --iree-quidditch-static-library-output-path=%t.o \
// RUN: --iree-quidditch-xdsl-opt-path=%xdsl-opt \
// RUN: --iree-quidditch-pulp-clang-path=%pulp-clang \
// RUN: --iree-quidditch-toolchain-root=%quidditch-toolchain-root \
// RUN: --output-format=vm-c \
// RUN: --iree-vm-target-index-bits=32 \
// RUN: -o /dev/null
Expand Down
2 changes: 1 addition & 1 deletion runtime/cmake/quidditch_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function(quidditch_module)
list(APPEND _COMPILER_ARGS "--iree-hal-target-backends=quidditch")
list(APPEND _COMPILER_ARGS "--iree-quidditch-static-library-output-path=${_O_FILE_NAME}")
list(APPEND _COMPILER_ARGS "--iree-quidditch-xdsl-opt-path=${XDSL_OPT_PATH}")
list(APPEND _COMPILER_ARGS "--iree-quidditch-pulp-clang-path=${PULP_CLANG_PATH}")
list(APPEND _COMPILER_ARGS "--iree-quidditch-toolchain-root=${QUIDDITCH_TOOLCHAIN_ROOT}")
endif ()

list(APPEND _COMPILER_ARGS "--output-format=vm-c")
Expand Down

0 comments on commit 1fbaede

Please sign in to comment.