Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions runtime/cmake/FindSNAX.cmake
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions runtime/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include(quidditch_module)
add_subdirectory(nsnet2)
add_subdirectory(util)
add_subdirectory(vec_multiply)
add_subdirectory(snax-helloworld)
29 changes: 29 additions & 0 deletions runtime/samples/snax-helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)

53 changes: 53 additions & 0 deletions runtime/samples/snax-helloworld/Snakefile
Original file line number Diff line number Diff line change
@@ -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}"
12 changes: 12 additions & 0 deletions runtime/samples/snax-helloworld/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*#include <stdio.h>*/
/*#include <team_decls.h>*/
/*#include "snax_rt.h"*/
#include <snrt.h>

int main() {
if (!snrt_is_dm_core())
return 0;

printf("Hello SNAX World\n");
return 0;
}
Loading