From 725f19cda78fe67870b000a641bd53012a4102e3 Mon Sep 17 00:00:00 2001 From: Chris Vasiladiotis Date: Fri, 27 Jun 2025 13:31:55 +0100 Subject: [PATCH 1/6] Add dummy SNAX hello world kernel program --- runtime/samples/snax-helloworld/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 runtime/samples/snax-helloworld/main.c 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; +} From 3dbc8531d88d5fb4833d90548f78c583f6ffa0ad Mon Sep 17 00:00:00 2001 From: Chris Vasiladiotis Date: Fri, 27 Jun 2025 13:31:55 +0100 Subject: [PATCH 2/6] Add snakemake file --- runtime/samples/snax-helloworld/Snakefile | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 runtime/samples/snax-helloworld/Snakefile 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}" From afb5ffec515df34fb54140eb38e22164e3a435ae Mon Sep 17 00:00:00 2001 From: Chris Vasiladiotis Date: Mon, 30 Jun 2025 22:05:17 +0100 Subject: [PATCH 3/6] Add CMake file for SNAX hello world kernel --- runtime/samples/snax-helloworld/CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 runtime/samples/snax-helloworld/CMakeLists.txt diff --git a/runtime/samples/snax-helloworld/CMakeLists.txt b/runtime/samples/snax-helloworld/CMakeLists.txt new file mode 100644 index 00000000..34ab87cf --- /dev/null +++ b/runtime/samples/snax-helloworld/CMakeLists.txt @@ -0,0 +1,16 @@ + +# "${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 +) + From ce8b85a0a39cda87d65091ecb5e5776bb9b9f245 Mon Sep 17 00:00:00 2001 From: Chris Vasiladiotis Date: Tue, 1 Jul 2025 11:12:19 +0100 Subject: [PATCH 4/6] Add FindSNAX CMake module --- runtime/cmake/FindSNAX.cmake | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 runtime/cmake/FindSNAX.cmake 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) From a1ae2c8cd6bb05cc7767bd34295a0c702d6ac2e2 Mon Sep 17 00:00:00 2001 From: Chris Vasiladiotis Date: Wed, 2 Jul 2025 15:44:05 +0100 Subject: [PATCH 5/6] Hook up SNAX hello world dummy kernel --- runtime/samples/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) 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) From 4343d831f1f9047a6f40fe62dc147be2e3267b1b Mon Sep 17 00:00:00 2001 From: Chris Vasiladiotis Date: Fri, 11 Jul 2025 11:46:59 +0100 Subject: [PATCH 6/6] Add guard in CMake file for snax kernels --- runtime/samples/snax-helloworld/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runtime/samples/snax-helloworld/CMakeLists.txt b/runtime/samples/snax-helloworld/CMakeLists.txt index 34ab87cf..d003351f 100644 --- a/runtime/samples/snax-helloworld/CMakeLists.txt +++ b/runtime/samples/snax-helloworld/CMakeLists.txt @@ -1,4 +1,17 @@ +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/")