diff --git a/runtime/cmake/FindSNAX.cmake b/runtime/cmake/FindSNAX.cmake new file mode 100644 index 00000000..60c7fcf4 --- /dev/null +++ b/runtime/cmake/FindSNAX.cmake @@ -0,0 +1,89 @@ +# - Find SNAX library +# This module creates an imported target for the SNAX library +# +# Variables that can be set to guide the search: +# SNAX_ROOT_DIR - Root directory where SNAX is installed +# SNAX_INCLUDE_DIR - Directory containing SNAX headers +# SNAX_LIBRARY - Full path to SNAX static library +# +# Output variables: +# SNAX_FOUND - True if SNAX was found +# SNAX_INCLUDE_DIRS - SNAX include directories +# SNAX_LIBRARIES - SNAX library to link against +# +# Creates target: +# SNAX::SNAX - Imported target for SNAX library + +include(FindPackageHandleStandardArgs) + +# Search for header files +find_path(SNAX_INCLUDE_DIR + NAMES snrt.h + HINTS ${SNAX_ROOT_DIR}/target/snitch_cluster/sw/runtime/rtl/src/ + ${SNAX_INCLUDE_DIR} + DOC "Path to SNAX include directory" +) + +find_path(SNAX_COMMON_INCLUDE_DIR + NAMES snitch_cluster_defs.h + HINTS ${SNAX_ROOT_DIR}/target/snitch_cluster/sw/runtime/common/ + ${SNAX_COMMON_INCLUDE_DIR} + DOC "Path to SNAX common include directory" +) + +find_path(SNAX_SW_INCLUDE_DIR + NAMES alloc.h + HINTS ${SNAX_ROOT_DIR}/sw/snRuntime/src/ + ${SNAX_SW_INCLUDE_DIR} + DOC "Path to SNAX sw include directory" +) + +find_path(SNAX_OMP_INCLUDE_DIR + NAMES eu.h + HINTS ${SNAX_ROOT_DIR}/sw/snRuntime/src/omp/ + ${SNAX_OMP_INCLUDE_DIR} + DOC "Path to SNAX OMP include directory" +) + +find_path(SNAX_API_OMP_INCLUDE_DIR + NAMES eu_decls.h + HINTS ${SNAX_ROOT_DIR}/sw/snRuntime/api/omp/ + ${SNAX_API_OMP_INCLUDE_DIR} + DOC "Path to SNAX API OMP include directory" +) + +# Search for library +find_library(SNAX_LIBRARY + NAMES libsnRuntime.a + HINTS ${SNAX_ROOT_DIR}/rtl-generic/build/ + ${SNAX_LIBRARY} + DOC "Path to SNAX static library" +) + +# Handle standard arguments +find_package_handle_standard_args(SNAX + REQUIRED_VARS SNAX_LIBRARY SNAX_INCLUDE_DIR SNAX_COMMON_INCLUDE_DIR SNAX_SW_INCLUDE_DIR SNAX_OMP_INCLUDE_DIR SNAX_API_OMP_INCLUDE_DIR +) + +if(SNAX_FOUND) + set(SNAX_INCLUDE_DIRS ${SNAX_INCLUDE_DIR} ${SNAX_COMMON_INCLUDE_DIR} ${SNAX_SW_INCLUDE_DIR} ${SNAX_OMP_INCLUDE_DIR} ${SNAX_API_OMP_INCLUDE_DIR}) + set(SNAX_LIBRARIES ${SNAX_LIBRARY}) + + set(SNAX_LINKER_SCRIPT "${SNAX_ROOT_DIR}/sw/snRuntime/base.ld") + + #if(SNAX_LINKER_SCRIPT AND NOT EXISTS "${SNAX_LINKER_SCRIPT}") + #message(FATAL_ERROR "Linker script not found: ${SNAX_LINKER_SCRIPT}") + #endif() + + if(NOT TARGET SNAX::SNAX) + add_library(SNAX::SNAX STATIC IMPORTED) + set_target_properties(SNAX::SNAX PROPERTIES + IMPORTED_LOCATION "${SNAX_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SNAX_API_OMP_INCLUDE_DIR};${SNAX_OMP_INCLUDE_DIR};${SNAX_SW_INCLUDE_DIR};${SNAX_COMMON_INCLUDE_DIR};${SNAX_INCLUDE_DIR}" + INTERFACE_LINK_DIRECTORIES "${SNAX_ROOT_DIR}/target/snitch_cluster/sw/runtime/rtl-generic/" + INTERFACE_LINK_OPTIONS "-T${SNAX_LINKER_SCRIPT}" + ) + endif() +endif() + +mark_as_advanced(SNAX_INCLUDE_DIR SNAX_LIBRARY) diff --git a/runtime/samples/CMakeLists.txt b/runtime/samples/CMakeLists.txt index d64669d5..1721b83a 100644 --- a/runtime/samples/CMakeLists.txt +++ b/runtime/samples/CMakeLists.txt @@ -3,3 +3,4 @@ include(quidditch_module) add_subdirectory(nsnet2) add_subdirectory(util) add_subdirectory(vec_multiply) +add_subdirectory(snax-helloworld) diff --git a/runtime/samples/snax-helloworld/CMakeLists.txt b/runtime/samples/snax-helloworld/CMakeLists.txt new file mode 100644 index 00000000..d003351f --- /dev/null +++ b/runtime/samples/snax-helloworld/CMakeLists.txt @@ -0,0 +1,29 @@ + +find_program( + SNAX_MLIR_EXECUTABLE + NAMES snax-mlir + DOC "Path to snax-mlir executable" +) + +if(NOT SNAX_MLIR_EXECUTABLE) + message(WARNING "snax-mlir executable not found. Skipping directory: ${CMAKE_CURRENT_SOURCE_DIR}") + return() +else() + message(STATUS "Found snax-mlir: ${SNAX_MLIR_EXECUTABLE}") +endif() + +# "${CONDA_PREFIX}"/snax-utils/snax-mac/target/snitch_cluster +set(SNAX_ROOT_DIR "/home/vasich/wb/snax-mlir/.pixi/envs/default/snax-utils/snax-mac/") + +find_package(SNAX REQUIRED) + +add_executable(snax-helloworld main.c) + +target_link_libraries( + snax-helloworld + PRIVATE + samples_util + SNAX::SNAX + Quidditch::dispatch::dispatch +) + diff --git a/runtime/samples/snax-helloworld/Snakefile b/runtime/samples/snax-helloworld/Snakefile new file mode 100644 index 00000000..5eca2928 --- /dev/null +++ b/runtime/samples/snax-helloworld/Snakefile @@ -0,0 +1,53 @@ +from util.snake.configs import get_snax_mac_config + +config = get_snax_mac_config() +config["snaxoptflags"] = ",".join( + [ + "dispatch-kernels", + "set-memory-space", + "set-memory-layout", + "realize-memref-casts", + "reuse-memref-allocs", + "insert-sync-barrier", + "dispatch-regions", + "snax-copy-to-dma", + "memref-to-snax", + "snax-to-func", + "clear-memory-space", + "postprocess", + ] +) + + +module snax_rules: + snakefile: + "../../util/snake/snax.smk" + config: + config + + +use rule * from snax_rules as snax_* + + +# Rules +rule all: + input: + "hello_world_traces.json", + + +rule compile_main: + input: + "main.c", + output: + "main.o", + shell: + "{config[cc]} {config[cflags]} -c {input[0]}" + + +rule link_snax_binary: + input: + "main.o", + output: + "hello_world.x", + shell: + "{config[ld]} {config[ldflags]} {input} -o {output}" diff --git a/runtime/samples/snax-helloworld/main.c b/runtime/samples/snax-helloworld/main.c new file mode 100644 index 00000000..384af0ba --- /dev/null +++ b/runtime/samples/snax-helloworld/main.c @@ -0,0 +1,12 @@ +/*#include */ +/*#include */ +/*#include "snax_rt.h"*/ +#include + +int main() { + if (!snrt_is_dm_core()) + return 0; + + printf("Hello SNAX World\n"); + return 0; +}