Skip to content

Commit

Permalink
[runtime] Add basic xDSL kernel compilation example
Browse files Browse the repository at this point in the history
This PR implements a basic sample running an xDSL generated kernel in a snitch cluster. The code currently has to be executed by a compute core (as the kernels are executed by the same caller core) and the memory allocated in L1 as that is required by streaming registers.
The quidditch device was reverted to just be a fork of the `local-sync` device as the current plan is to leverage parallelism inside one cluster within a kernel for now.
  • Loading branch information
zero9178 committed May 17, 2024
1 parent bfd8b7d commit e749937
Show file tree
Hide file tree
Showing 14 changed files with 1,217 additions and 166 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ jobs:

- name: Test Runtime
working-directory: ${{github.workspace}}/quidditch-runtime-build
# TODO: This should run a proper test suite once we are no longer using verilator.
run: ctest --extra-verbose -j$(nproc) -R HelloWorld
run: ctest --extra-verbose -j$(nproc)
2 changes: 2 additions & 0 deletions codegen/compiler/src/Quidditch/HoistHALOpsToFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void HoistHALOpsToFunc::runOnOperation() {
continue;

func->setAttr("xdsl_generated", builder.getUnitAttr());
// xDSL only supports barepointer lowering right now.
func->setAttr("llvm.bareptr", builder.getUnitAttr());

// Find all HAL operations that need to be hoisted and any other operations
// they depend on.
Expand Down
95 changes: 58 additions & 37 deletions runtime/cmake/quidditch_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,78 @@ find_program(IREE_COMPILE_PATH iree-compile
)
message(STATUS "Using iree-compile at ${IREE_COMPILE_PATH}")

find_package(Python3 REQUIRED)
cmake_path(GET Python3_EXECUTABLE PARENT_PATH python_bin_dir)
cmake_path(GET python_bin_dir PARENT_PATH python_bin_dir)
find_program(XDSL_OPT_PATH xdsl-opt
PATHS ${python_bin_dir}
PATH_SUFFIXES "bin"
NO_DEFAULT_PATH
DOC "Path of the xdsl-opt file"
REQUIRED
)

function(quidditch_module)
cmake_parse_arguments(_RULE "" "SRC" "FLAGS;DEPENDS" ${ARGN})
cmake_parse_arguments(_RULE "LLVM" "SRC" "FLAGS;DEPENDS" ${ARGN})

set(_MLIR_SRC "${_RULE_SRC}")

set(_MLIR_SRC "${_RULE_SRC}")
cmake_path(GET _MLIR_SRC STEM filename)

cmake_path(GET _MLIR_SRC STEM filename)
get_filename_component(_MLIR_SRC "${_MLIR_SRC}" REALPATH)
set(_O_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${filename}/${filename}.o")
set(_H_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${filename}/${filename}_module.h")
set(_MODULE_NAME "${filename}_module")

set(_COMPILER_ARGS ${_RULE_FLAGS})
set(_COMPILER_ARGS ${_RULE_FLAGS})
list(APPEND _COMPILER_ARGS "--iree-vm-bytecode-module-strip-source-map=true")
list(APPEND _COMPILER_ARGS "--iree-vm-emit-polyglot-zip=false")
list(APPEND _COMPILER_ARGS "--iree-input-type=auto")
# TODO: xDSL cannot deal with anything but f64 right now.
list(APPEND _COMPILER_ARGS "--iree-opt-demote-f64-to-f32=0")

if (_RULE_LLVM)
list(APPEND _COMPILER_ARGS "--iree-hal-target-backends=llvm-cpu")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-debug-symbols=false")
list(APPEND _COMPILER_ARGS "--iree-vm-bytecode-module-strip-source-map=true")
list(APPEND _COMPILER_ARGS "--iree-vm-emit-polyglot-zip=false")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-target-triple=riscv32-unknown-elf")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-target-cpu=generic-rv32")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-target-cpu-features=+m,+f,+d,+zfh")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-target-abi=ilp32d")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-link-embedded=false")
list(APPEND _COMPILER_ARGS "--iree-input-type=auto")

set(_O_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${filename}/${filename}.o")
set(_H_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${filename}/${filename}_module.h")
set(_MODULE_NAME "${filename}_module")

get_filename_component(_MLIR_SRC "${_MLIR_SRC}" REALPATH)
list(APPEND _COMPILER_ARGS "--output-format=vm-c")
list(APPEND _COMPILER_ARGS "--iree-vm-target-index-bits=32")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-link-static")
list(APPEND _COMPILER_ARGS "--iree-llvmcpu-static-library-output-path=${_O_FILE_NAME}")
list(APPEND _COMPILER_ARGS "${_MLIR_SRC}")
list(APPEND _COMPILER_ARGS "-o")
list(APPEND _COMPILER_ARGS "${_H_FILE_NAME}")
else ()
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}")
endif ()

list(APPEND _COMPILER_ARGS "--output-format=vm-c")
list(APPEND _COMPILER_ARGS "--iree-vm-target-index-bits=32")
list(APPEND _COMPILER_ARGS "${_MLIR_SRC}")
list(APPEND _COMPILER_ARGS "-o")
list(APPEND _COMPILER_ARGS "${_H_FILE_NAME}")

set(_OUTPUT_FILES "${_H_FILE_NAME}")
string(REPLACE ".o" ".h" _STATIC_HDR_PATH "${_O_FILE_NAME}")
list(APPEND _OUTPUT_FILES "${_O_FILE_NAME}" "${_STATIC_HDR_PATH}")
set(_OUTPUT_FILES "${_H_FILE_NAME}")
string(REPLACE ".o" ".h" _STATIC_HDR_PATH "${_O_FILE_NAME}")
list(APPEND _OUTPUT_FILES "${_O_FILE_NAME}" "${_STATIC_HDR_PATH}")

add_custom_command(
OUTPUT ${_OUTPUT_FILES}
COMMAND ${IREE_COMPILE_PATH} ${_COMPILER_ARGS}
DEPENDS ${IREE_COMPILE_PATH} ${_MLIR_SRC}
)
add_custom_command(
OUTPUT ${_OUTPUT_FILES}
COMMAND ${IREE_COMPILE_PATH} ${_COMPILER_ARGS}
DEPENDS ${IREE_COMPILE_PATH} ${_MLIR_SRC}
)

add_library(${_MODULE_NAME}
STATIC
${_H_FILE_NAME} ${_O_FILE_NAME}
)
target_include_directories(${_MODULE_NAME} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/${filename})
target_compile_definitions(${_MODULE_NAME} PUBLIC EMITC_IMPLEMENTATION=\"${_H_FILE_NAME}\")
set_target_properties(
${_MODULE_NAME}
PROPERTIES
LINKER_LANGUAGE C
)
add_library(${_MODULE_NAME}
STATIC
${_H_FILE_NAME} ${_O_FILE_NAME}
)
target_include_directories(${_MODULE_NAME} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/${filename})
target_compile_definitions(${_MODULE_NAME} PUBLIC EMITC_IMPLEMENTATION=\"${_H_FILE_NAME}\")
set_target_properties(
${_MODULE_NAME}
PROPERTIES
LINKER_LANGUAGE C
)
endfunction()
24 changes: 17 additions & 7 deletions runtime/runtime/src/Quidditch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
add_subdirectory(registration)

iree_cc_library(
NAME
device
SRCS
device.c
DEPS
iree::base
PUBLIC
NAME
device
SRCS
device.c
event.c
semaphore.c
DEPS
snRuntime
iree::base
iree::base::internal
iree::base::internal::arena
iree::base::internal::synchronization
iree::hal::utils::deferred_command_buffer
iree::hal::utils::file_transfer
iree::hal::utils::memory_file
iree::hal::utils::semaphore_base
PUBLIC
)
Loading

0 comments on commit e749937

Please sign in to comment.