Skip to content

Commit

Permalink
Improve CMake and code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeratec committed Dec 11, 2024
1 parent 4825e1b commit 8b2418c
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 112 deletions.
60 changes: 8 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,62 +44,18 @@ endif()

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

################################################################################
# Host Runtime Library #
################################################################################
add_library(runtime_host STATIC)

target_compile_options(runtime_host
PRIVATE
-O2
)

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

# WIESEP: Expose common link option
target_link_options(runtime_host
PUBLIC
-march=${ISA_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_cluster_snitch
PUBLIC
-march=${ISA_CLUSTER_SNITCH}
-mabi=${ABI}
-nostartfiles
-ffreestanding
)

################################################################################
# Add subdirectories #
################################################################################
add_subdirectory(hal)
# WIESEP: Targets have to be included before the other folders to make them available
# Depending on the target, the following static libraries have to added by the targets:
# - runtime_host
# - runtime_cluster_snitch
add_subdirectory(targets)

# Include other subdirectories
add_subdirectory(hal)
add_subdirectory(devices)
add_subdirectory(drivers)

################################################################################
Expand Down
49 changes: 49 additions & 0 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,52 @@ macro(add_target_source name)
message(WARNING "Path ${CMAKE_CURRENT_LIST_DIR}/${name} does not exist")
endif()
endmacro()

# Define a reusable macro for handling folder mappings
macro(add_chimera_subdirectories target_platform category mappings)
# Initialize included folders
set(included_folders "")

# Process mappings
foreach(mapping IN LISTS ${mappings})
string(FIND "${mapping}" ":" delim_pos)
if(delim_pos EQUAL -1)
message(WARNING "[CHIMERA-SDK] Invalid mapping entry: '${mapping}'. Skipping.")
continue()
endif()


# Extract key and value
string(SUBSTRING "${mapping}" 0 ${delim_pos} key)
math(EXPR value_start "${delim_pos} + 1")
string(SUBSTRING "${mapping}" ${value_start} -1 value)

if(key STREQUAL "${target_platform}")
list(APPEND included_folders ${value})
break()
endif()
endforeach()

string(REPLACE "," ";" included_folders "${included_folders}")

# Align output with padding
string(LENGTH "[CHIMERA-SDK] Enabled ${category}s" category_prefix_length)
math(EXPR padding_length "36 - ${category_prefix_length}")
if(padding_length GREATER 0)
string(REPEAT " " ${padding_length} padding)
else()
set(padding "")
endif()

# Debug: Print the folders being included
message(STATUS "[CHIMERA-SDK] Enabled ${category}s${padding}: ${included_folders}")

# Add subdirectories, checking for a valid CMakeLists.txt
foreach(folder IN LISTS included_folders)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${folder}/CMakeLists.txt)
add_subdirectory(${folder})
else()
message(WARNING "[CHIMERA-SDK] ${category} folder '${folder}' does not contain a valid CMakeLists.txt. Skipping.")
endif()
endforeach()
endmacro()
41 changes: 41 additions & 0 deletions devices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Philip Wiese <[email protected]>

# Define mappings directly using lists for each target
# set(CHIMERA_DEVICE_CONVOLVE_FOLDERS snitch_cluster)
# set(CHIMERA_DEVICE_OPEN_FOLDERS snitch_cluster)
# set(CHIMERA_DEVICE_HOST_FOLDERS)

# # Determine which folders to include based on TARGET_PLATFORM
# if(TARGET_PLATFORM STREQUAL "chimera-convolve")
# set(INCLUDED_FOLDERS ${CHIMERA_DEVICE_CONVOLVE_FOLDERS})
# elseif(TARGET_PLATFORM STREQUAL "chimera-open")
# set(INCLUDED_FOLDERS ${CHIMERA_DEVICE_OPEN_FOLDERS})
# elseif(TARGET_PLATFORM STREQUAL "chimera-host")
# set(INCLUDED_FOLDERS ${CHIMERA_DEVICE_HOST_FOLDERS})
# endif()

# # WIESEP: Print the folders being included
# message(STATUS "[CHIMERA-SDK] Enabled Devices : ${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] Device folder '${folder}' does not contain a valid CMakeLists.txt. Skipping.")
# endif()
# endforeach()

# Define mappings for devices
set(DEVICE_MAPPINGS
chimera-convolve:snitch_cluster
chimera-open:snitch_cluster
chimera-host:
)

# Call the macro
add_chimera_subdirectories(${TARGET_PLATFORM} "Device" DEVICE_MAPPINGS)
15 changes: 15 additions & 0 deletions devices/snitch_cluster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Philip Wiese <[email protected]>


################################################################################
# Snitch Cluster Runtime Library #
################################################################################
file(GLOB_RECURSE C_SOURCES_SNITCH
"trampoline_snitchCluster.c"
)

target_sources(runtime_cluster_snitch PRIVATE ${C_SOURCES_SNITCH})
File renamed without changes.
11 changes: 9 additions & 2 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
#
# Philip Wiese <[email protected]>

# Define mappings for drivers
set(DRIVER_MAPPINGS
chimera-convolve:cluster
chimera-open:cluster
chimera-host:
)

# Call the macro
add_chimera_subdirectories(${TARGET_PLATFORM} "Driver" DRIVER_MAPPINGS)

# WIESEP: Add all runtime drivers
add_subdirectory(cluster)

# WIESEP: Export this directory as root include directory for the drivers
target_include_directories(runtime_host PUBLIC ${CMAKE_CURRENT_LIST_DIR})
12 changes: 0 additions & 12 deletions drivers/cluster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,3 @@ file(GLOB_RECURSE C_SOURCES
)

target_sources(runtime_host PRIVATE ${C_SOURCES})

################################################################################
# Snitch Cluster Runtime Library #
################################################################################
file(GLOB_RECURSE C_SOURCES_SNITCH
"trampoline_snitchCluster.c"
)

target_sources(runtime_cluster_snitch PRIVATE ${C_SOURCES_SNITCH})



56 changes: 51 additions & 5 deletions targets/chimera-convolve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# Viviane Potocnik <[email protected]>
# Philip Wiese <[email protected]>

################################################################################
# Host Runtime Library #
################################################################################
add_library(runtime_host STATIC)

file(GLOB_RECURSE ASM_SOURCES
"src/crt0.S"
)
Expand All @@ -22,21 +27,62 @@ target_sources(runtime_host
${C_SOURCES}
)

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

target_compile_options(runtime_host
PRIVATE
-O2
)

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

# WIESEP: Export the target specific linkerscript
target_link_options(runtime_host
PUBLIC
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
-march=${ISA_HOST}
-mabi=${ABI}
-nostartfiles
-ffreestanding
)

# WIESEP: Export the target specific include directory
target_include_directories(runtime_host
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)
################################################################################
# Snitch Cluster Runtime Library #
################################################################################
add_library(runtime_cluster_snitch STATIC)

# WIESEP: Export the headers also to the cluster runtime
target_include_directories(runtime_cluster_snitch
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)

# 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_cluster_snitch
PUBLIC
-march=${ISA_CLUSTER_SNITCH}
-mabi=${ABI}
-nostartfiles
-ffreestanding
)
39 changes: 29 additions & 10 deletions targets/chimera-host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# Viviane Potocnik <[email protected]>
# Philip Wiese <[email protected]>

################################################################################
# Host Runtime Library #
################################################################################
add_library(runtime_host STATIC)

file(GLOB_RECURSE ASM_SOURCES
"src/crt0.S"
)
Expand All @@ -22,21 +27,35 @@ target_sources(runtime_host
${C_SOURCES}
)

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

# WIESEP: Export the target specific include directory
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
target_compile_options(runtime_host
PRIVATE
-O2
)

target_compile_options(runtime_host
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
-march=${ISA_HOST}
-mabi=${ABI}
)

# WIESEP: Export the target specific linkerscript
target_link_options(runtime_host
PUBLIC
-L${CMAKE_CURRENT_LIST_DIR}
-Tlink.ld
-march=${ISA_HOST}
-mabi=${ABI}
-nostartfiles
-ffreestanding
)

################################################################################
# Snitch Cluster Runtime Library #
################################################################################
# WIESEP: There is no Snitch cluster present in this target
25 changes: 25 additions & 0 deletions targets/chimera-host/include/addr_maps/soc_addr_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Moritz Scherer <[email protected]>

#ifndef _SOC_ADDR_MAP_INCLUDE_GUARD_
#define _SOC_ADDR_MAP_INCLUDE_GUARD_

#include <stdint.h>

#define CLINT_CTRL_BASE 0x02040000

#define SOC_CTRL_BASE 0x30001000

#define NUM_CLUSTER_CORES 0

static uint8_t _chimera_numCores[] = {0};

#define _chimera_numClusters 0

#define CHIMERA_PADFRAME_BASE_ADDRESS 0x30002000
#define FLL_BASE_ADDR 0x30003000

#endif
Loading

0 comments on commit 8b2418c

Please sign in to comment.