Skip to content

Commit

Permalink
Implemented feedback for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeratec committed Dec 10, 2024
1 parent 6392cc1 commit 5dc3247
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 99 deletions.
74 changes: 53 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,82 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
project(chimera-sdk LANGUAGES C ASM)

# WIESEP: It is important to set the ISA and ABI for the host and the cluster snitch
set(ISA_HOST rv32imc)
set(ABI_HOST ilp32)
set(ABI ilp32)
set(ISA_CLUSTER_SNITCH rv32im)
set(ABI_CLUSTER_SNITCH ilp32)
set(ISA_HOST rv32imc)

message(STATUS "[CHIMERA-SDK] ISA_HOST : ${ISA_HOST}")
message(STATUS "[CHIMERA-SDK] ABI_HOST : ${ABI_HOST}")
message(STATUS "[CHIMERA-SDK] ISA_CLUSTER_SNITCH : ${ISA_CLUSTER_SNITCH}")
message(STATUS "[CHIMERA-SDK] ABI_CLUSTER_SNITCH : ${ABI_CLUSTER_SNITCH}")
message(STATUS "[CHIMERA-SDK] ABI : ${ABI}")
message(STATUS "[CHIMERA-SDK] ISA_HOST : ${ISA_HOST}")
message(STATUS "[CHIMERA-SDK] ISA_CLUSTER_SNITCH : ${ISA_CLUSTER_SNITCH}")
if (${DISASSEMBLE_LIBRARIES})
message(STATUS "[CHIMERA-SDK] DISASSEMBLE_LIBRARIES : ON")
else()
message(STATUS "[CHIMERA-SDK] DISASSEMBLE_LIBRARIES : OFF")
endif()

include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils.cmake)

# WIESEP: Add a object library to collect all runtime sources
add_library(runtime STATIC)
################################################################################
# Host Runtime Library #
################################################################################
add_library(runtime_host STATIC)

target_compile_options(runtime
target_compile_options(runtime_host
PRIVATE
-O2
)

target_compile_options(runtime_host
PUBLIC
-march=${ISA_HOST}
-mabi=${ABI_HOST}
-mabi=${ABI}
)

target_link_options(runtime
PRIVATE
# WIESEP: Expose common link option
target_link_options(runtime_host
PUBLIC
-march=${ISA_HOST}
-mabi=${ABI_HOST}
-mabi=${ABI}
-nostartfiles
-ffreestanding
)

################################################################################
# Snitch Cluster Runtime Library #
################################################################################
add_library(runtime_cluster_snitch STATIC)

# WIESEP: Do not export optimization flags
target_compile_options(runtime_cluster_snitch
PRIVATE
-O2
)

target_compile_options(runtime_cluster_snitch
PUBLIC
-march=${ISA_CLUSTER_SNITCH}
-mabi=${ABI}
)

# WIESEP: Expose common link option
target_link_options(runtime
target_link_options(runtime_cluster_snitch
PUBLIC
-march=${ISA_CLUSTER_SNITCH}
-mabi=${ABI}
-nostartfiles
-nostdlib
-ffreestanding
)

################################################################################
# Add subdirectories #
################################################################################
add_subdirectory(hal)
add_subdirectory(targets)
add_subdirectory(drivers)

# WIESEP: Interface library to link against all components of the SDK
add_library(chimera-sdk INTERFACE)
target_link_libraries(chimera-sdk INTERFACE hal)
target_link_libraries(chimera-sdk INTERFACE runtime)

################################################################################
# Testing #
################################################################################
enable_testing()

add_subdirectory(tests)
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ The resulting binaries will be stored in `build/bin`, and can be used within the

To format all source files, run
```
python scripts/run_clang_format.py -ir hal/ targets/ tests/ driver/
python scripts/run_clang_format.py -ir hal/ targets/ tests/ drivers/
```

Our CI uses llvm-12 for clang-format, so on IIS machines you may run
```
python scripts/run_clang_format.py -ir tests/ hal/ targets/ driver/ --clang-format-executable=/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin/clang-format
python scripts/run_clang_format.py -ir tests/ hal/ targets/ drivers/ --clang-format-executable=/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin/clang-format
```

Expand All @@ -77,12 +77,13 @@ To enable automatic configuration of the C/C++ extension and support for the int
}
}
```
If you are not on an IIS system, you need to adjust the paths according to your local installation.

## Technical Details

### Mixed ISA Compilation
The current approach compiles all code for both the host and cluster cores into a single library. This requires precise handling to ensure compatibility between the different instruction set architectures (ISAs) and application binary interfaces (ABIs).
This requires careful handling to avoid invalid instructions caused by mismatched ISAs or ABIs between the host and cluster cores. Hence, we define four CMake variables,`ISA_HOST`, `ABI_HOST`, `ISA_CLUSTER_SNITCH`, and `ABI_CLUSTER_SNITCH` to specify the appropriate ISA and ABI for each core type.
This requires careful handling to avoid invalid instructions caused by mismatched ISAs between the host and cluster cores. Hence, we define four CMake variables,`ABI`, `ISA_HOST`, and `ISA_CLUSTER_SNITCH`, to specify the appropriate ISA for each core type. The ABI has to be identical to ensure correct function calls.
Furthermore, the tests are split into `src_host` and `src_cluster` directories to clearly separate code executed on the host and cluster cores.

### cMake Build Flow
Expand Down
6 changes: 1 addition & 5 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@
add_subdirectory(cluster)

# WIESEP: Export this directory as root include directory for the drivers
target_include_directories(runtime PUBLIC ${CMAKE_CURRENT_LIST_DIR})




target_include_directories(runtime_host PUBLIC ${CMAKE_CURRENT_LIST_DIR})
33 changes: 11 additions & 22 deletions drivers/cluster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,24 @@
#
# Philip Wiese <[email protected]>

file(GLOB_RECURSE C_SOURCES_SNTICH
"trampoline_snitchCluster.c"
)

################################################################################
# Host Runtime Library #
################################################################################
file(GLOB_RECURSE C_SOURCES
"*.c"
"offload_snitchCluster.c"
)

# WIESEP: Remove the C_SOURCES_SNTICH from the list of sources
list(REMOVE_ITEM C_SOURCES ${C_SOURCES_SNTICH})

# WIESEP: Create an object library for the snitch cluster trampoline to compile it with the correct ISA and ABI
add_library(cluster_snitch OBJECT ${C_SOURCES_SNTICH})
target_sources(runtime_host PRIVATE ${C_SOURCES})

target_compile_options(cluster_snitch
PRIVATE
-O2
-march=${ISA_CLUSTER_SNITCH}
-mabi=${ABI_CLUSTER_SNITCH}
)

# Add include directories from runtime to cluster_snitch
target_include_directories(cluster_snitch
PRIVATE
$<TARGET_PROPERTY:runtime,INTERFACE_INCLUDE_DIRECTORIES>
################################################################################
# Snitch Cluster Runtime Library #
################################################################################
file(GLOB_RECURSE C_SOURCES_SNTICH
"trampoline_snitchCluster.c"
)

target_sources(runtime INTERFACE $<TARGET_OBJECTS:cluster_snitch>)
target_sources(runtime PRIVATE ${C_SOURCES})
target_sources(runtime_cluster_snitch PRIVATE ${C_SOURCES_SNTICH})



8 changes: 3 additions & 5 deletions drivers/cluster/trampoline_snitchCluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
//
// Philip Wiese <[email protected]>

#include "soc.h"

#include <stdint.h>

// Persistent trampoline function pointer for each core
extern void (*_trampoline_function[NUM_CLUSTER_CORES])(void *);
extern void (*_trampoline_function)(void *);

// Peristent argument storage for the trampoline function
extern void *_trampoline_args[NUM_CLUSTER_CORES];
extern void *_trampoline_args;

// Persistant stack pointer storage for each core
extern void *_trampoline_stack[NUM_CLUSTER_CORES];
extern void *_trampoline_stack;

/**
* @brief Trampoline function for the cluster core.
Expand Down
4 changes: 2 additions & 2 deletions hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ file(GLOB_RECURSE SOURCES
"src/*"
)

add_library(hal STATIC ${SOURCES})
add_library(hal_host STATIC ${SOURCES})

target_include_directories(hal
target_include_directories(hal_host
PUBLIC
"inc/"
)
2 changes: 2 additions & 0 deletions targets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ if(NOT TARGET_PLATFORM IN_LIST AVAILABLE_TARGETS)
message(FATAL_ERROR "Wrong value for TARGET_PLATFORM: Got ${TARGET_PLATFORM}. Available targets are: ${AVAILABLE_TARGETS}")
endif()

message(STATUS "[CHIMERA-SDK] TARGET_PLATFORM : ${TARGET_PLATFORM}")

if (TARGET_PLATFORM STREQUAL "chimera-host")
add_subdirectory(chimera-host)
endif()
Expand Down
12 changes: 8 additions & 4 deletions targets/chimera-convolve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ file(GLOB_RECURSE C_SOURCES

set_property(SOURCE ${ASM_SOURCES} PROPERTY LANGUAGE ASM)

target_sources(runtime
target_sources(runtime_host
PRIVATE
${ASM_SOURCES}
${C_SOURCES}
)

# WIESEP: Export the target specific linkerscript
target_link_options(runtime
target_link_options(runtime_host
PUBLIC
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
)

# WIESEP: Export the target specific include directory
target_include_directories(runtime
target_include_directories(runtime_host
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)


# WIESEP: Export the headers also to the cluster runtime
target_include_directories(runtime_cluster_snitch
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)
33 changes: 17 additions & 16 deletions targets/chimera-host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# Moritz Scherer <[email protected]>
# Viviane Potocnik <[email protected]>
# Philip Wiese <[email protected]>

file(GLOB_RECURSE ASM_SOURCES
"src/crt0.S"
Expand All @@ -14,28 +15,28 @@ file(GLOB_RECURSE C_SOURCES
)

set_property(SOURCE ${ASM_SOURCES} PROPERTY LANGUAGE ASM)
add_library(runtime OBJECT ${ASM_SOURCES} ${C_SOURCES})

target_include_directories(runtime
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
target_sources(runtime_host
PRIVATE
${ASM_SOURCES}
${C_SOURCES}
)

set(ISA rv32imc)
set(ABI ilp32)
# WIESEP: Export the target specific linkerscript
target_link_options(runtime_host
PUBLIC
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
)

target_compile_options(runtime
# WIESEP: Export the target specific include directory
target_include_directories(runtime_host
PUBLIC
-march=${ISA}
-mabi=${ABI}
${CMAKE_CURRENT_LIST_DIR}/include
)

target_link_options(runtime
# WIESEP: Export the headers also to the cluster runtime
target_include_directories(runtime_cluster_snitch
PUBLIC
-march=${ISA}
-mabi=${ABI}
-nostartfiles
-nostdlib
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
${CMAKE_CURRENT_LIST_DIR}/include
)
13 changes: 9 additions & 4 deletions targets/chimera-open/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# Moritz Scherer <[email protected]>
# Viviane Potocnik <[email protected]>
# Philip Wiese <[email protected]>

file(GLOB_RECURSE ASM_SOURCES
"src/crt0.S"
Expand All @@ -15,23 +16,27 @@ file(GLOB_RECURSE C_SOURCES

set_property(SOURCE ${ASM_SOURCES} PROPERTY LANGUAGE ASM)

target_sources(runtime
target_sources(runtime_host
PRIVATE
${ASM_SOURCES}
${C_SOURCES}
)

# WIESEP: Export the target specific linkerscript
target_link_options(runtime
target_link_options(runtime_host
PUBLIC
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
)

# WIESEP: Export the target specific include directory
target_include_directories(runtime
target_include_directories(runtime_host
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)


# WIESEP: Export the headers also to the cluster runtime
target_include_directories(runtime_cluster_snitch
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)
30 changes: 26 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@
# SPDX-License-Identifier: Apache-2.0
#
# Moritz Scherer <[email protected]>
# Philip Wiese <[email protected]>

add_subdirectory(generic)
# Define mappings directly using lists for each target
set(CHIMERA_CONVOLVE_FOLDERS chimera-convolve chimera-open chimera-host)
set(CHIMERA_OPEN_FOLDERS chimera-open chimera-host)
set(CHIMERA_HOST_FOLDERS chimera-host)

# Check if folder has a CMakeLists.txt file
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${TARGET_PLATFORM}/CMakeLists.txt)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${TARGET_PLATFORM})
# Determine which folders to include based on TARGET_PLATFORM
if(TARGET_PLATFORM STREQUAL "chimera-convolve")
set(INCLUDED_FOLDERS ${CHIMERA_CONVOLVE_FOLDERS})
elseif(TARGET_PLATFORM STREQUAL "chimera-open")
set(INCLUDED_FOLDERS ${CHIMERA_OPEN_FOLDERS})
elseif(TARGET_PLATFORM STREQUAL "chimera-host")
set(INCLUDED_FOLDERS ${CHIMERA_HOST_FOLDERS})
else()
message(FATAL_ERROR "[CHIMERA-SDK] Unknown TARGET_PLATFORM: '${TARGET_PLATFORM}'. Valid options are chimera-convolve, chimera-open, or chimera-host.")
endif()

# WIESEP: Print the folders being included
message(STATUS "[CHIMERA-SDK] Including test folders: ${INCLUDED_FOLDERS}")

# Add subdirectories, checking for a valid CMakeLists.txt in each folder
foreach(folder IN LISTS INCLUDED_FOLDERS)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${folder}/CMakeLists.txt)
add_subdirectory(${folder})
else()
message(WARNING "[CHIMERA-SDK] Folder '${folder}' does not contain a valid CMakeLists.txt. Skipping.")
endif()
endforeach()
Loading

0 comments on commit 5dc3247

Please sign in to comment.