The Astaroth Code Compiler (acc) is now built with cmake. Additionally, make is now used to generate the CUDA headers from DSL sources. The headers are also properly regenerated whenever a DSL file has been changed. With this commit, the DSL is now seamlessly integrated to the library and we no longer need complicated scripts to figure out the correct files. The current workflow for using custom DSL sources is to pass the DSL module directory to cmake, f.ex. cmake -DDSL_MODULE_DIR=/acc/mhd_solver. Note that the path must be absolute or then given relative to the CMakeLists.txt directory. f.ex cd build && cmake -DDSL_MODULE_DIR=../acc/mhd_solver does not work. CMake then takes all DSL files in that directory and handles the rest.

This commit is contained in:
jpekkila
2019-09-18 17:28:29 +03:00
parent bce3e4de03
commit 3bb6ca1712
7 changed files with 55 additions and 13 deletions

View File

@@ -29,6 +29,35 @@ option(DOUBLE_PRECISION "Generates double precision code"
option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON) option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON)
option(ALTER_CONF "If enabled, loads astaroth.conf from the build directory" OFF) option(ALTER_CONF "If enabled, loads astaroth.conf from the build directory" OFF)
## Compile the Astaroth Code compiler
find_package(FLEX)
find_package(BISON)
execute_process (
COMMAND ./build_acc.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/acc
)
# NOTE: Manually defined DSL_MODULE_DIR must be set relative to the project root, not the actual
# build directory!
# NO! ../acc/mhd_solver
# YES! acc/mhd_solver
if (NOT DEFINED DSL_MODULE_DIR)
set(DSL_MODULE_DIR ${CMAKE_SOURCE_DIR}/acc/mhd_solver)
endif ()
get_filename_component(DSL_MODULE_DIR ${DSL_MODULE_DIR} REALPATH)
message(STATUS "DSL module dir: ${DSL_MODULE_DIR}")
set(DSL_SOURCES ${DSL_MODULE_DIR}/*)
set(DSL_HEADERS "${PROJECT_BINARY_DIR}/stencil_assembly.cuh"
"${PROJECT_BINARY_DIR}/stencil_process.cuh"
"${PROJECT_BINARY_DIR}/stencil_defines.h")
add_custom_command (
COMMENT "Building AC objects ${DSL_MODULE_DIR}"
COMMAND ${CMAKE_SOURCE_DIR}/scripts/compile_acc_module.sh ${DSL_MODULE_DIR}
DEPENDS ${DSL_SOURCES}
OUTPUT ${DSL_HEADERS}
)
add_custom_target(dsl_headers ALL DEPENDS ${DSL_HEADERS})
## Build types ## Build types
# Available types (case-sensitive): # Available types (case-sensitive):
# RELEASE (best performance) # RELEASE (best performance)

View File

@@ -6,14 +6,14 @@ COMPILER_NAME="acc"
SRC_DIR=${PWD}/src SRC_DIR=${PWD}/src
BUILD_DIR=${PWD}/build BUILD_DIR=${PWD}/build
echo "Created" ${BUILD_DIR} echo "-- Compiling acc:" ${BUILD_DIR}
mkdir -p ${BUILD_DIR} mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR} cd ${BUILD_DIR}
echo ${BASE_DIR} #echo ${BASE_DIR}
echo ${SRC_DIR} #echo ${SRC_DIR}
echo ${BUILD_DIR} #echo ${BUILD_DIR}
# Generate Bison headers # Generate Bison headers
bison --verbose -d ${SRC_DIR}/${COMPILER_NAME}.y bison --verbose -d ${SRC_DIR}/${COMPILER_NAME}.y

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Usage ./compile <source file> # Usage ./compile <source file> <gcc preprocessor flags, f.ex. -I some/path>
ACC_DIR=`dirname $0` ACC_DIR=`dirname $0`
@@ -10,19 +10,19 @@ EXTENSION="${FULL_NAME##*.}"
if [ "${EXTENSION}" = "sas" ]; then if [ "${EXTENSION}" = "sas" ]; then
COMPILE_FLAGS="-sas" # Generate stencil assembly stage COMPILE_FLAGS="-sas" # Generate stencil assembly stage
CUH_FILENAME="stencil_assembly.cuh" CUH_FILENAME="stencil_assembly.cuh"
echo "Generating stencil assembly stage ${FILENAME}.sas -> ${CUH_FILENAME}" echo "-- Generating stencil assembly stage: ${FILENAME}.sas -> ${CUH_FILENAME}"
elif [ "${EXTENSION}" = "sps" ]; then elif [ "${EXTENSION}" = "sps" ]; then
COMPILE_FLAGS="-sps" # Generate stencil processing stage COMPILE_FLAGS="-sps" # Generate stencil processing stage
CUH_FILENAME="stencil_process.cuh" CUH_FILENAME="stencil_process.cuh"
echo "Generating stencil processing stage: ${FILENAME}.sps -> ${CUH_FILENAME}" echo "-- Generating stencil processing stage: ${FILENAME}.sps -> ${CUH_FILENAME}"
elif [ "${EXTENSION}" = "sdh" ]; then elif [ "${EXTENSION}" = "sdh" ]; then
COMPILE_FLAGS="-sdh" # Generate stencil definition header COMPILE_FLAGS="-sdh" # Generate stencil definition header
CUH_FILENAME="stencil_defines.h" CUH_FILENAME="stencil_defines.h"
echo "Generating stencil definition header: ${FILENAME}.sdh -> ${CUH_FILENAME}" echo "-- Generating stencil definition header: ${FILENAME}.sdh -> ${CUH_FILENAME}"
else else
echo "Error: unknown extension" ${EXTENSION} "of file" ${FULL_NAME} echo "-- Error: unknown extension" ${EXTENSION} "of file" ${FULL_NAME}
echo "Extension should be either .sas, .sps or .sdh" echo "-- Extension should be either .sas, .sps or .sdh"
exit exit
fi fi
${ACC_DIR}/preprocess.sh $1 | ${ACC_DIR}/build/acc ${COMPILE_FLAGS} > ${CUH_FILENAME} ${ACC_DIR}/preprocess.sh $@ | ${ACC_DIR}/build/acc ${COMPILE_FLAGS} > ${CUH_FILENAME}

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
# Preprocesses the give file using GCC. This script is usually automatically called in # Preprocesses the give file using GCC. This script is usually automatically called in
# ./compile.sh, but may be called also individually for debugging purposes. # ./compile.sh, but may be called also individually for debugging purposes.
cat ${@} | gcc -x c -E - | sed "s/#.*//g" cat $1 | gcc ${@:2} -x c -E - | sed "s/#.*//g"

View File

@@ -650,8 +650,10 @@ main(int argc, char** argv)
compilation_type = STENCIL_PROCESS; compilation_type = STENCIL_PROCESS;
else if (!strcmp(argv[1], "-sdh")) else if (!strcmp(argv[1], "-sdh"))
compilation_type = STENCIL_HEADER; compilation_type = STENCIL_HEADER;
else else {
printf("Unknown flag %s. Generating stencil assembly.\n", argv[1]); printf("Unknown flag %s. Generating stencil assembly.\n", argv[1]);
return EXIT_FAILURE;
}
} }
else { else {
printf("Usage: ./acc [flags]\n" printf("Usage: ./acc [flags]\n"
@@ -685,4 +687,5 @@ main(int argc, char** argv)
// Cleanup // Cleanup
astnode_destroy(root); astnode_destroy(root);
// printf("COMPILATION SUCCESS\n"); // printf("COMPILATION SUCCESS\n");
return EXIT_SUCCESS;
} }

9
scripts/compile_acc_module.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
ACC_DIR=$(realpath $(dirname $0)/../acc)
MODULE_DIR=$(realpath $1)
echo "-- Compiling project in "${MODULE_DIR}
for source in ${MODULE_DIR}/*.sas ${MODULE_DIR}/*.sps ${MODULE_DIR}/*.sdh
do
${ACC_DIR}/compile.sh $source -I ${MODULE_DIR}
done

View File

@@ -37,3 +37,4 @@ endif ()
cuda_add_library(astaroth_core STATIC astaroth.cu device.cu node.cu) cuda_add_library(astaroth_core STATIC astaroth.cu device.cu node.cu)
target_include_directories(astaroth_core PRIVATE .) target_include_directories(astaroth_core PRIVATE .)
target_link_libraries(astaroth_core m) target_link_libraries(astaroth_core m)
add_dependencies(astaroth_core dsl_headers)