From f1d1a9eba39519532621b89bf298a0c037e9cf0c Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Thu, 3 Apr 2025 13:47:46 +0200 Subject: [PATCH 01/11] add overarching CMakeLists for native CMake integration --- .gitignore | 5 +++ CMakeLists.txt | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index e4a9790f4..51fe45bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,14 @@ astra-sim-alibabacloud/build/simai_analytical/build/ astra-sim-alibabacloud/build/astra_ns3/build/ astra-sim-alibabacloud/extern/ +astra-sim-alibabacloud/inputs/config/ +!astra-sim-alibabacloud/inputs/config/SimAI.conf bin/ results/ test/log/ *.log .cur* .DS_Store + +**/build +**/cmake-cache diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..73fbebfcc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,88 @@ +# CMake requirement +cmake_minimum_required(VERSION 3.15) + +# C++ requirement +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) +add_definitions("-Wall -g") +SET(CMAKE_BUILD_TYPE "Debug") + +# Compiler requirement +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) + message(FATAL_ERROR "g++ (GNU) version should be greater than 5.3, but found ${CMAKE_CXX_COMPILER_VERSION}") + endif() +endif() + +set(NS3_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ns-3-alibabacloud/simulation") +set(ASTRA_SIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/astra-sim") +set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") +set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}}/result") + +# Create required directories +file(MAKE_DIRECTORY ${BUILD_DIR}) +file(MAKE_DIRECTORY ${RESULT_DIR}) + +# Option to clean build and result directories +option(CLEAN_BUILD "Clean build directory" OFF) +option(CLEAN_RESULT "Clean result directory" OFF) +option(BUILD_SIM "Build NS3 simulation" ON) +option(BUILD_ANALYTICAL "Build analytical" OFF) +option(BUILD_PHY "Build physical" OFF) + +if(CLEAN_BUILD) + message(STATUS "Cleaning build directory: ${BUILD_DIR}") + file(REMOVE_RECURSE ${BUILD_DIR}) + file(REMOVE_RECURSE "${NS3_DIR}/simulation/build") + file(REMOVE_RECURSE "${NS3_DIR}/simulation/cmake-cache") + file(MAKE_DIRECTORY ${BUILD_DIR}) +endif() + +if(CLEAN_RESULT) + message(STATUS "Cleaning result directory: ${RESULT_DIR}") + file(REMOVE_RECURSE ${RESULT_DIR}) + file(MAKE_DIRECTORY ${RESULT_DIR}) +endif() + +if(BUILD_SIM) + # AstraSim + add_subdirectory(astra-sim-alibabacloud/build/astra_ns3) + + file(GLOB_RECURSE astra_sim_files CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/*") + foreach(file ${astra_sim_files}) + string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path ${file}) + get_filename_component(output_dir ${NS3_SRC_DIR}/src/applications/${relative_path} DIRECTORY) + file(MAKE_DIRECTORY ${output_dir}) + configure_file(${file} ${NS3_SRC_DIR}/src/applications/${relative_path} COPYONLY) + endforeach() + + file(GLOB scratch_files + CONFIGURE_DEPENDS + ${ASTRA_SIM_DIR}/network_frontend/ns3/*) + foreach(file ${scratch_files}) + get_filename_component(filename ${file} NAME) + configure_file(${file} ${NS3_SRC_DIR}/scratch/${filename} COPYONLY) + endforeach() + + # NS3 + add_subdirectory(${NS3_SRC_DIR} ${NS3_SRC_DIR}/cmake-cache) + + # Link binaries + string(TOLOWER ${CMAKE_BUILD_TYPE} profile) + add_custom_target(create_ns3_symlink + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "${NS3_SRC_DIR}/build/scratch/ns3.36.1-AstraSimNetwork-${profile}" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator2" + DEPENDS scratch_AstraSimNetwork + COMMENT "Creating simulator symlink..." + ) +endif() + +if(BUILD_ANALYTICAL) + add_subdirectory(astra-sim-alibabacloud/build/simai_analytical) +endif() + +if(BUILD_PHY) + add_subdirectory(astra-sim-alibabacloud/build/simai_phy) +endif() From 5f92c6fc7a5117d633c964af309320b46700b1b6 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Thu, 3 Apr 2025 15:17:35 +0200 Subject: [PATCH 02/11] update ns3 submodule --- ns-3-alibabacloud | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ns-3-alibabacloud b/ns-3-alibabacloud index 781b7d804..29c45258d 160000 --- a/ns-3-alibabacloud +++ b/ns-3-alibabacloud @@ -1 +1 @@ -Subproject commit 781b7d804736bdbbc184254636d6a3c8cfea9ab4 +Subproject commit 29c45258d9ffcd9ebf4fe384450c2c0d97a34833 From ac053d6b9f184ff7e6c723306eb4916adfeab902 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Fri, 4 Apr 2025 16:07:57 +0200 Subject: [PATCH 03/11] integrate ns3 build options and build profile in root project --- .gitignore | 1 + CMakeLists.txt | 24 +++++++++++++++---- .../build/astra_ns3/CMakeLists.txt | 4 +++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 51fe45bf0..b63af361c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ test/log/ **/build **/cmake-cache +!astra-sim-alibabacloud/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 73fbebfcc..38cf0c18b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,10 @@ cmake_minimum_required(VERSION 3.15) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) add_definitions("-Wall -g") -SET(CMAKE_BUILD_TYPE "Debug") + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE) +endif() # Compiler requirement if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") @@ -14,6 +17,8 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() endif() +project(SimAI) + set(NS3_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ns-3-alibabacloud/simulation") set(ASTRA_SIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/astra-sim") set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") @@ -49,6 +54,7 @@ if(BUILD_SIM) add_subdirectory(astra-sim-alibabacloud/build/astra_ns3) file(GLOB_RECURSE astra_sim_files CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/*") + list(FILTER astra_sim_files EXCLUDE REGEX "/network_frontend/") foreach(file ${astra_sim_files}) string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path ${file}) get_filename_component(output_dir ${NS3_SRC_DIR}/src/applications/${relative_path} DIRECTORY) @@ -65,15 +71,25 @@ if(BUILD_SIM) endforeach() # NS3 + string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) + if (build_type STREQUAL "release") + set(NS3_ASSERT OFF CACHE BOOL "Override NS3_ASSERT" FORCE) + set(NS3_LOG OFF CACHE BOOL "Override NS3_LOG" FORCE) + endif () + if (NOT DEFINED NS3_WARNINGS_AS_ERRORS) + set(NS3_WARNINGS_AS_ERRORS OFF CACHE BOOL "Override NS3_WARNINGS_AS_ERRORS" FORCE) + endif () + if (NOT DEFINED NS3_MTP) + set(NS3_MTP ON CACHE BOOL "Override NS3_MTP" FORCE) + endif () add_subdirectory(${NS3_SRC_DIR} ${NS3_SRC_DIR}/cmake-cache) # Link binaries - string(TOLOWER ${CMAKE_BUILD_TYPE} profile) add_custom_target(create_ns3_symlink COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin" COMMAND ${CMAKE_COMMAND} -E create_symlink - "${NS3_SRC_DIR}/build/scratch/ns3.36.1-AstraSimNetwork-${profile}" - "${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator2" + "$" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator" DEPENDS scratch_AstraSimNetwork COMMENT "Creating simulator symlink..." ) diff --git a/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt b/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt index 903403921..1c467487f 100644 --- a/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt +++ b/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt @@ -5,7 +5,9 @@ cmake_minimum_required(VERSION 3.15) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) add_definitions("-Wall -g") -SET(CMAKE_BUILD_TYPE "Debug") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE) +endif() # Compiler requirement if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") From 47c1482dbe8c0be2bf8941e867c4f45c973905f3 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 12:17:37 +0200 Subject: [PATCH 04/11] Apply fix from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38cf0c18b..561f438e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,8 @@ option(BUILD_PHY "Build physical" OFF) if(CLEAN_BUILD) message(STATUS "Cleaning build directory: ${BUILD_DIR}") file(REMOVE_RECURSE ${BUILD_DIR}) - file(REMOVE_RECURSE "${NS3_DIR}/simulation/build") - file(REMOVE_RECURSE "${NS3_DIR}/simulation/cmake-cache") + file(REMOVE_RECURSE "${NS3_SRC_DIR}/build") + file(REMOVE_RECURSE "${NS3_SRC_DIR}/cmake-cache") file(MAKE_DIRECTORY ${BUILD_DIR}) endif() From 012be77b9294c221e021fabea34bdf8b607806d5 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 12:24:03 +0200 Subject: [PATCH 05/11] remove stray bracket in result path --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 561f438e5..5e4b5350f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ project(SimAI) set(NS3_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ns-3-alibabacloud/simulation") set(ASTRA_SIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/astra-sim") set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") -set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}}/result") +set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/result") # Create required directories file(MAKE_DIRECTORY ${BUILD_DIR}) From 8ae8a9615f96c1a3b9498e54b4fb782f173cc794 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 16:20:56 +0200 Subject: [PATCH 06/11] avoid duplicate source files in the ns3 folder and uniform behavior to symlink/stubs generation for native ns3 headers --- CMakeLists.txt | 103 ++++++++++++++++++++++++++++++++++++++-------- ns-3-alibabacloud | 2 +- 2 files changed, 87 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e4b5350f..937b73b01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(ASTRA_SIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/astra-sim" set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/result") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # Create required directories file(MAKE_DIRECTORY ${BUILD_DIR}) file(MAKE_DIRECTORY ${RESULT_DIR}) @@ -31,16 +33,62 @@ file(MAKE_DIRECTORY ${RESULT_DIR}) # Option to clean build and result directories option(CLEAN_BUILD "Clean build directory" OFF) option(CLEAN_RESULT "Clean result directory" OFF) -option(BUILD_SIM "Build NS3 simulation" ON) + +# Build types +option(BUILD_SIM "Build NS3 simulation" OFF) option(BUILD_ANALYTICAL "Build analytical" OFF) option(BUILD_PHY "Build physical" OFF) +# Other options +option(SYS_ASSERTS "Enable assert() in all profile with -UNDEBUG" OFF) + +get_filename_component(BUILD_DIR_NAME ${BUILD_DIR} NAME) + +function(ns3_export_file src dst) + get_filename_component(_dst_abs "${dst}" ABSOLUTE) + get_filename_component(dst_dir "${dst}" DIRECTORY) + file(MAKE_DIRECTORY "${dst_dir}") + + if(NS3_USE_RELATIVE_PATHS_SYMLINKS) + # Compute a relative path from destination directory to source file. + file(RELATIVE_PATH src_path "${dst_dir}" "${src}") + # Ensure forward slashes for the preprocessor include + file(TO_CMAKE_PATH "${src_path}" src_path) + else() + set(src_path "${src}") + endif() + + if(NS3_EXPORT_HEADERS_AS_STUBS) + # Remove destination file if it is a symlink + if(IS_SYMLINK "${_dst_abs}") + file(REMOVE "${dst}") + endif() + if("${src_path}" MATCHES "\\.(h|hh)$") + file(GENERATE OUTPUT "${dst}" CONTENT "#include \"${src_path}\"\n") + else() + # Source files are just copied + configure_file(${src} ${dst} COPYONLY) + endif() + else() + if(NOT IS_SYMLINK "${_dst_abs}") + # Create/overwrite a symbolic link. + file(CREATE_LINK "${src_path}" "${dst}" SYMBOLIC) + endif() + endif() +endfunction() + if(CLEAN_BUILD) message(STATUS "Cleaning build directory: ${BUILD_DIR}") - file(REMOVE_RECURSE ${BUILD_DIR}) - file(REMOVE_RECURSE "${NS3_SRC_DIR}/build") - file(REMOVE_RECURSE "${NS3_SRC_DIR}/cmake-cache") + file(REMOVE_RECURSE "${BUILD_DIR}") file(MAKE_DIRECTORY ${BUILD_DIR}) + message(STATUS "Cleaning output directory: ${NS3_SRC_DIR}/build") + file(REMOVE "${NS3_SRC_DIR}/.lock-ns3_linux_build") + file(REMOVE_RECURSE "${NS3_SRC_DIR}/build") + message(STATUS "Cleaning build directory: ${NS3_SRC_DIR}/${BUILD_DIR_NAME}") + file(REMOVE_RECURSE "${NS3_SRC_DIR}/${BUILD_DIR_NAME}") + message(STATUS "Cleaning bin directory: ${CMAKE_CURRENT_SOURCE_DIR}/bin") + file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/bin") + file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin") endif() if(CLEAN_RESULT) @@ -49,6 +97,11 @@ if(CLEAN_RESULT) file(MAKE_DIRECTORY ${RESULT_DIR}) endif() +if(SYS_ASSERTS) + add_compile_options(-UNDEBUG) + message(STATUS "Asserts enabled for all profiles.") +endif() + if(BUILD_SIM) # AstraSim add_subdirectory(astra-sim-alibabacloud/build/astra_ns3) @@ -57,23 +110,27 @@ if(BUILD_SIM) list(FILTER astra_sim_files EXCLUDE REGEX "/network_frontend/") foreach(file ${astra_sim_files}) string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path ${file}) - get_filename_component(output_dir ${NS3_SRC_DIR}/src/applications/${relative_path} DIRECTORY) - file(MAKE_DIRECTORY ${output_dir}) - configure_file(${file} ${NS3_SRC_DIR}/src/applications/${relative_path} COPYONLY) + ns3_export_file("${file}" "${NS3_SRC_DIR}/src/applications/${relative_path}") endforeach() - file(GLOB scratch_files - CONFIGURE_DEPENDS - ${ASTRA_SIM_DIR}/network_frontend/ns3/*) + file(GLOB scratch_files CONFIGURE_DEPENDS ${ASTRA_SIM_DIR}/network_frontend/ns3/*) foreach(file ${scratch_files}) get_filename_component(filename ${file} NAME) - configure_file(${file} ${NS3_SRC_DIR}/scratch/${filename} COPYONLY) + ns3_export_file("${file}" "${NS3_SRC_DIR}/scratch/${filename}") endforeach() - # NS3 + # Register original files as configure dependencies + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + ${astra_sim_files} + ${scratch_files} + ) + + # NS3 options string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) if (build_type STREQUAL "release") - set(NS3_ASSERT OFF CACHE BOOL "Override NS3_ASSERT" FORCE) + if (NOT DEFINED NS3_ASSERT) + set(NS3_ASSERT OFF CACHE BOOL "Override NS3_ASSERT" FORCE) + endif () set(NS3_LOG OFF CACHE BOOL "Override NS3_LOG" FORCE) endif () if (NOT DEFINED NS3_WARNINGS_AS_ERRORS) @@ -82,14 +139,26 @@ if(BUILD_SIM) if (NOT DEFINED NS3_MTP) set(NS3_MTP ON CACHE BOOL "Override NS3_MTP" FORCE) endif () - add_subdirectory(${NS3_SRC_DIR} ${NS3_SRC_DIR}/cmake-cache) + + # Remap original source files in the debug information of the target + get_filename_component(COPIED_PREFIX_1 ${NS3_SRC_DIR}/src/applications/astra-sim REALPATH) + get_filename_component(ORIGINAL_PREFIX_1 ${ASTRA_SIM_DIR} REALPATH) + get_filename_component(COPIED_PREFIX_2 ${NS3_SRC_DIR}/scratch REALPATH) + get_filename_component(ORIGINAL_PREFIX_2 ${ASTRA_SIM_DIR}/network_frontend/ns3 REALPATH) + add_compile_options( + -ffile-prefix-map=${COPIED_PREFIX_1}=${ORIGINAL_PREFIX_1} + -ffile-prefix-map=${COPIED_PREFIX_2}=${ORIGINAL_PREFIX_2} + ) + + # NS3 + add_subdirectory(${NS3_SRC_DIR} ${NS3_SRC_DIR}/${BUILD_DIR_NAME}) # Link binaries - add_custom_target(create_ns3_symlink + add_custom_target(create_ns3_symlink ALL COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin" COMMAND ${CMAKE_COMMAND} -E create_symlink - "$" - "${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator" + "$" + "${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator" DEPENDS scratch_AstraSimNetwork COMMENT "Creating simulator symlink..." ) diff --git a/ns-3-alibabacloud b/ns-3-alibabacloud index 29c45258d..377b4e062 160000 --- a/ns-3-alibabacloud +++ b/ns-3-alibabacloud @@ -1 +1 @@ -Subproject commit 29c45258d9ffcd9ebf4fe384450c2c0d97a34833 +Subproject commit 377b4e06203a899208dbf557c7e8ddd1bce0a1f1 From 7440e1238a81473625467c2b16710d826d93d879 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 17:06:22 +0200 Subject: [PATCH 07/11] exclude directories from GLOB when iterating simulation files --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 937b73b01..aefa0001e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,14 +106,14 @@ if(BUILD_SIM) # AstraSim add_subdirectory(astra-sim-alibabacloud/build/astra_ns3) - file(GLOB_RECURSE astra_sim_files CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/*") + file(GLOB_RECURSE astra_sim_files LIST_DIRECTORIES false CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/*") list(FILTER astra_sim_files EXCLUDE REGEX "/network_frontend/") foreach(file ${astra_sim_files}) string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path ${file}) ns3_export_file("${file}" "${NS3_SRC_DIR}/src/applications/${relative_path}") endforeach() - file(GLOB scratch_files CONFIGURE_DEPENDS ${ASTRA_SIM_DIR}/network_frontend/ns3/*) + file(GLOB scratch_files LIST_DIRECTORIES false CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/network_frontend/ns3/*") foreach(file ${scratch_files}) get_filename_component(filename ${file} NAME) ns3_export_file("${file}" "${NS3_SRC_DIR}/scratch/${filename}") From c348f45bcb974301f7d4cfde1331ba399b376625 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 17:15:32 +0200 Subject: [PATCH 08/11] make debug info conditional on the build type Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 937b73b01..d05991b48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,15 @@ cmake_minimum_required(VERSION 3.15) # C++ requirement set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) -add_definitions("-Wall -g") +add_compile_options(-Wall) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE) endif() +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + add_compile_options(-g) +endif() # Compiler requirement if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) From 10d4e97e28295d0b5d855382fc76585f69f23051 Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 17:17:11 +0200 Subject: [PATCH 09/11] do not remove BUILD_DIR in CLEAN_BUILD configuration step --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aefa0001e..66f980962 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,9 +78,6 @@ function(ns3_export_file src dst) endfunction() if(CLEAN_BUILD) - message(STATUS "Cleaning build directory: ${BUILD_DIR}") - file(REMOVE_RECURSE "${BUILD_DIR}") - file(MAKE_DIRECTORY ${BUILD_DIR}) message(STATUS "Cleaning output directory: ${NS3_SRC_DIR}/build") file(REMOVE "${NS3_SRC_DIR}/.lock-ns3_linux_build") file(REMOVE_RECURSE "${NS3_SRC_DIR}/build") From adf47c8784008008823629c1dae2488c0998d2ad Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Tue, 9 Jun 2026 17:29:02 +0200 Subject: [PATCH 10/11] update ns-3 module --- ns-3-alibabacloud | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ns-3-alibabacloud b/ns-3-alibabacloud index 377b4e062..1e9c87465 160000 --- a/ns-3-alibabacloud +++ b/ns-3-alibabacloud @@ -1 +1 @@ -Subproject commit 377b4e06203a899208dbf557c7e8ddd1bce0a1f1 +Subproject commit 1e9c87465bd3cea911ec58af4454e29a1c484171 From 1ad673053369623d395214ab7af5357e3a1ae5bf Mon Sep 17 00:00:00 2001 From: Gabriele Castellano Date: Thu, 11 Jun 2026 12:35:47 +0200 Subject: [PATCH 11/11] =?UTF-8?q?polish=20native=20CMake=20build=20workflo?= =?UTF-8?q?w=20-=20Move=20ns3=E2=80=91specific=20logic=20into=20cmake/ns3.?= =?UTF-8?q?cmake=20-=20Replace=20manual=20MPI=20compiler=20path=20hacks=20?= =?UTF-8?q?with=20modern=20`find=5Fpackage(MPI)`=20-=20Unify=20binary=20ou?= =?UTF-8?q?tput=20under=20top=E2=80=91level=20`bin/`=20via=20CMake=20custo?= =?UTF-8?q?m=20targets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 193 +++++------------- astra-sim-alibabacloud/CMakeLists.txt | 86 ++++---- .../analytical/CMakeLists.txt | 17 +- .../network_frontend/ns3/CMakeLists.txt | 85 ++++++++ .../network_frontend/phynet/CMakeLists.txt | 27 +-- .../build/astra_ns3/CMakeLists.txt | 20 +- .../build/astra_ns3/build.sh | 2 +- .../build/simai_analytical/CMakeLists.txt | 13 -- .../build/simai_analytical/build.sh | 2 +- .../build/simai_phy/CMakeLists.txt | 7 - .../build/simai_phy/build.sh | 2 +- 11 files changed, 202 insertions(+), 252 deletions(-) create mode 100755 astra-sim-alibabacloud/astra-sim/network_frontend/ns3/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 98bfdb862..b2e124423 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,100 +1,40 @@ -# CMake requirement cmake_minimum_required(VERSION 3.15) -# C++ requirement +project(SimAI LANGUAGES CXX) + set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) -add_compile_options(-Wall) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE) -endif() +add_compile_options(-Wall -g) -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - add_compile_options(-g) -endif() -# Compiler requirement -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) - message(FATAL_ERROR "g++ (GNU) version should be greater than 5.3, but found ${CMAKE_CXX_COMPILER_VERSION}") +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) + message(FATAL_ERROR + "g++ (GNU) version should be greater than 5.3, but found ${CMAKE_CXX_COMPILER_VERSION}") endif() endif() -project(SimAI) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE) +endif() set(NS3_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ns-3-alibabacloud/simulation") set(ASTRA_SIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/astra-sim") -set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") -set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/result") - -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -# Create required directories -file(MAKE_DIRECTORY ${BUILD_DIR}) -file(MAKE_DIRECTORY ${RESULT_DIR}) +set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/results") -# Option to clean build and result directories -option(CLEAN_BUILD "Clean build directory" OFF) -option(CLEAN_RESULT "Clean result directory" OFF) +file(MAKE_DIRECTORY "${RESULT_DIR}") -# Build types -option(BUILD_SIM "Build NS3 simulation" OFF) -option(BUILD_ANALYTICAL "Build analytical" OFF) -option(BUILD_PHY "Build physical" OFF) - -# Other options option(SYS_ASSERTS "Enable assert() in all profile with -UNDEBUG" OFF) -get_filename_component(BUILD_DIR_NAME ${BUILD_DIR} NAME) - -function(ns3_export_file src dst) - get_filename_component(_dst_abs "${dst}" ABSOLUTE) - get_filename_component(dst_dir "${dst}" DIRECTORY) - file(MAKE_DIRECTORY "${dst_dir}") - - if(NS3_USE_RELATIVE_PATHS_SYMLINKS) - # Compute a relative path from destination directory to source file. - file(RELATIVE_PATH src_path "${dst_dir}" "${src}") - # Ensure forward slashes for the preprocessor include - file(TO_CMAKE_PATH "${src_path}" src_path) - else() - set(src_path "${src}") - endif() - - if(NS3_EXPORT_HEADERS_AS_STUBS) - # Remove destination file if it is a symlink - if(IS_SYMLINK "${_dst_abs}") - file(REMOVE "${dst}") - endif() - if("${src_path}" MATCHES "\\.(h|hh)$") - file(GENERATE OUTPUT "${dst}" CONTENT "#include \"${src_path}\"\n") - else() - # Source files are just copied - configure_file(${src} ${dst} COPYONLY) - endif() - else() - if(NOT IS_SYMLINK "${_dst_abs}") - # Create/overwrite a symbolic link. - file(CREATE_LINK "${src_path}" "${dst}" SYMBOLIC) - endif() - endif() -endfunction() - -if(CLEAN_BUILD) - message(STATUS "Cleaning output directory: ${NS3_SRC_DIR}/build") - file(REMOVE "${NS3_SRC_DIR}/.lock-ns3_linux_build") - file(REMOVE_RECURSE "${NS3_SRC_DIR}/build") - message(STATUS "Cleaning build directory: ${NS3_SRC_DIR}/${BUILD_DIR_NAME}") - file(REMOVE_RECURSE "${NS3_SRC_DIR}/${BUILD_DIR_NAME}") - message(STATUS "Cleaning bin directory: ${CMAKE_CURRENT_SOURCE_DIR}/bin") - file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/bin") - file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin") -endif() +set(SIMAI_MODE "analytical" CACHE STRING "SimAI build mode") +set_property(CACHE SIMAI_MODE PROPERTY STRINGS analytical ns3 phy) -if(CLEAN_RESULT) - message(STATUS "Cleaning result directory: ${RESULT_DIR}") - file(REMOVE_RECURSE ${RESULT_DIR}) - file(MAKE_DIRECTORY ${RESULT_DIR}) +set(_valid_simai_modes analytical ns3 phy) +list(FIND _valid_simai_modes "${SIMAI_MODE}" _simai_mode_index) +if(_simai_mode_index EQUAL -1) + message(FATAL_ERROR + "Invalid SIMAI_MODE='${SIMAI_MODE}'. Expected one of: analytical, ns3, phy") endif() if(SYS_ASSERTS) @@ -102,72 +42,35 @@ if(SYS_ASSERTS) message(STATUS "Asserts enabled for all profiles.") endif() -if(BUILD_SIM) - # AstraSim - add_subdirectory(astra-sim-alibabacloud/build/astra_ns3) - - file(GLOB_RECURSE astra_sim_files LIST_DIRECTORIES false CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/*") - list(FILTER astra_sim_files EXCLUDE REGEX "/network_frontend/") - foreach(file ${astra_sim_files}) - string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path ${file}) - ns3_export_file("${file}" "${NS3_SRC_DIR}/src/applications/${relative_path}") - endforeach() - - file(GLOB scratch_files LIST_DIRECTORIES false CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/network_frontend/ns3/*") - foreach(file ${scratch_files}) - get_filename_component(filename ${file} NAME) - ns3_export_file("${file}" "${NS3_SRC_DIR}/scratch/${filename}") - endforeach() - - # Register original files as configure dependencies - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS - ${astra_sim_files} - ${scratch_files} +if(SIMAI_MODE STREQUAL "ns3") + add_subdirectory( + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/build/astra_ns3" ) - - # NS3 options - string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) - if (build_type STREQUAL "release") - if (NOT DEFINED NS3_ASSERT) - set(NS3_ASSERT OFF CACHE BOOL "Override NS3_ASSERT" FORCE) - endif () - set(NS3_LOG OFF CACHE BOOL "Override NS3_LOG" FORCE) - endif () - if (NOT DEFINED NS3_WARNINGS_AS_ERRORS) - set(NS3_WARNINGS_AS_ERRORS OFF CACHE BOOL "Override NS3_WARNINGS_AS_ERRORS" FORCE) - endif () - if (NOT DEFINED NS3_MTP) - set(NS3_MTP ON CACHE BOOL "Override NS3_MTP" FORCE) - endif () - - # Remap original source files in the debug information of the target - get_filename_component(COPIED_PREFIX_1 ${NS3_SRC_DIR}/src/applications/astra-sim REALPATH) - get_filename_component(ORIGINAL_PREFIX_1 ${ASTRA_SIM_DIR} REALPATH) - get_filename_component(COPIED_PREFIX_2 ${NS3_SRC_DIR}/scratch REALPATH) - get_filename_component(ORIGINAL_PREFIX_2 ${ASTRA_SIM_DIR}/network_frontend/ns3 REALPATH) - add_compile_options( - -ffile-prefix-map=${COPIED_PREFIX_1}=${ORIGINAL_PREFIX_1} - -ffile-prefix-map=${COPIED_PREFIX_2}=${ORIGINAL_PREFIX_2} + set(target_name "scratch_AstraSimNetwork") + set(symlink_name "SimAI_simulator") +elseif(SIMAI_MODE STREQUAL "analytical") + add_subdirectory( + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/build/simai_analytical" ) - - # NS3 - add_subdirectory(${NS3_SRC_DIR} ${NS3_SRC_DIR}/${BUILD_DIR_NAME}) - - # Link binaries - add_custom_target(create_ns3_symlink ALL - COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin" - COMMAND ${CMAKE_COMMAND} -E create_symlink - "$" - "${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator" - DEPENDS scratch_AstraSimNetwork - COMMENT "Creating simulator symlink..." + set(target_name "SimAI_analytical") + set(symlink_name "SimAI_analytical") +elseif(SIMAI_MODE STREQUAL "phy") + set(USE_RDMA TRUE) + add_subdirectory( + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/build/simai_phy" ) + set(target_name "SimAI_phynet") + set(symlink_name "SimAI_phynet") +else() + message(FATAL_ERROR "Unknown SIMAI_MODE=${SIMAI_MODE}") endif() -if(BUILD_ANALYTICAL) - add_subdirectory(astra-sim-alibabacloud/build/simai_analytical) -endif() - -if(BUILD_PHY) - add_subdirectory(astra-sim-alibabacloud/build/simai_phy) -endif() +# Link binaries +add_custom_target(create_symlink ALL + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_SOURCE_DIR}/bin" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "$" + "${CMAKE_SOURCE_DIR}/bin/${symlink_name}" + DEPENDS ${target} + COMMENT "Creating ${symlink_name} symlink..." +) diff --git a/astra-sim-alibabacloud/CMakeLists.txt b/astra-sim-alibabacloud/CMakeLists.txt index 1873afa99..ce0df3114 100755 --- a/astra-sim-alibabacloud/CMakeLists.txt +++ b/astra-sim-alibabacloud/CMakeLists.txt @@ -1,40 +1,52 @@ -set(use_rdma ${USE_RDMA}) -set(use_analytical ${USE_ANALYTICAL}) -file(GLOB astra_SRC - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/collective/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/fast-backend/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/memory/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/scheduling/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/topology/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/*.cc" - "${PROJECT_SOURCE_DIR}/../../astra-sim/workload/*.cc" - ) -file(GLOB HEADERS - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/collective/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/fast-backend/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/memory/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/scheduling/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/topology/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/system/*.hh" - "${PROJECT_SOURCE_DIR}/../../astra-sim/workload/*.hh" +cmake_minimum_required(VERSION 3.15) + +file(GLOB ASTRA_SIM_SOURCES CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/collective/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/fast-backend/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/memory/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/scheduling/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/topology/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/workload/*.cc" +) + +file(GLOB ASTRA_SIM_HEADERS CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/collective/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/collective/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/fast-backend/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/fast-backend/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/memory/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/memory/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/scheduling/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/scheduling/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/topology/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/topology/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/workload/*.hh" + "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/workload/*.h" ) -if(use_rdma) - add_definitions(-DPHY_RDMA) - include_directories("$ENV{MPI_INCLUDE_PATH}") - add_definitions(-DPHY_MTP) - set(CMAKE_BUILD_TYPE Debug) -elseif(use_analytical) - list(FILTER HEADERS EXCLUDE REGEX ".*SimAiFlowModelRdma.hh") - list(FILTER astra_SRC EXCLUDE REGEX ".*SimAiFlowModelRdma.cc") - list(FILTER HEADERS EXCLUDE REGEX "${PROJECT_SOURCE_DIR}/../../astra-sim/system/BootStrapnet.hh") - list(FILTER astra_SRC EXCLUDE REGEX "${PROJECT_SOURCE_DIR}/../../astra-sim/system/BootStrapnet.cc") - list(FILTER HEADERS EXCLUDE REGEX "${PROJECT_SOURCE_DIR}/../../astra-sim/system/PhyMultiThread.hh") - list(FILTER astra_SRC EXCLUDE REGEX "${PROJECT_SOURCE_DIR}/../../astra-sim/system/PhyMultiThread.cc") - add_definitions(-DANALYTI) + +if(SIMAI_MODE STREQUAL "analytical") + list(FILTER ASTRA_SIM_HEADERS EXCLUDE REGEX ".*SimAiFlowModelRdma\\.hh$") + list(FILTER ASTRA_SIM_SOURCES EXCLUDE REGEX ".*SimAiFlowModelRdma\\.cc$") + list(FILTER ASTRA_SIM_HEADERS EXCLUDE REGEX ".*BootStrapnet\\.hh$") + list(FILTER ASTRA_SIM_SOURCES EXCLUDE REGEX ".*BootStrapnet\\.cc$") + list(FILTER ASTRA_SIM_HEADERS EXCLUDE REGEX ".*PhyMultiThread\\.hh$") + list(FILTER ASTRA_SIM_SOURCES EXCLUDE REGEX ".*PhyMultiThread\\.cc$") endif() -include_directories("${PROJECT_SOURCE_DIR}/../../") -add_library(AstraSim ${astra_SRC}) -set_property(TARGET AstraSim PROPERTY CXX_STANDARD 11) +add_library(AstraSim ${ASTRA_SIM_SOURCES} ${ASTRA_SIM_HEADERS}) +target_compile_features(AstraSim PUBLIC cxx_std_17) +target_include_directories(AstraSim PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") + +if(USE_RDMA) + target_compile_definitions(AstraSim PRIVATE PHY_RDMA PHY_MTP) + + find_package(MPI REQUIRED) + target_link_libraries(AstraSim PUBLIC MPI::MPI_CXX) +endif() + +if(SIMAI_MODE STREQUAL "analytical") + target_compile_definitions(AstraSim PRIVATE ANALYTI) +endif() diff --git a/astra-sim-alibabacloud/astra-sim/network_frontend/analytical/CMakeLists.txt b/astra-sim-alibabacloud/astra-sim/network_frontend/analytical/CMakeLists.txt index 21cebc942..60f53b179 100644 --- a/astra-sim-alibabacloud/astra-sim/network_frontend/analytical/CMakeLists.txt +++ b/astra-sim-alibabacloud/astra-sim/network_frontend/analytical/CMakeLists.txt @@ -1,17 +1,8 @@ -# CMake requirement -cmake_minimum_required(VERSION 3.15) - -# 项目名称和设置 project(SimAI_analytical) -# 查找源文件 -file(GLOB SOURCES "*.cc") # 会查找当前目录下的所有 .cpp 文件 -file(GLOB HEADERS "*.h") # 会查找当前目录下的所有 .h 文件 -include_directories("${PROJECT_SOURCE_DIR}/../../../") - +file(GLOB SOURCES CONFIGURE_DEPENDS "*.cc") +file(GLOB HEADERS CONFIGURE_DEPENDS "*.hh" "*.h") -# 设置可执行文件 add_executable(SimAI_analytical ${SOURCES} ${HEADERS}) - -# 链接库 -target_link_libraries(SimAI_analytical AstraSim) # 替换为实际需要链接的库名 +target_include_directories(SimAI_analytical PRIVATE "${ASTRA_SIM_DIR}") +target_link_libraries(SimAI_analytical PRIVATE AstraSim) diff --git a/astra-sim-alibabacloud/astra-sim/network_frontend/ns3/CMakeLists.txt b/astra-sim-alibabacloud/astra-sim/network_frontend/ns3/CMakeLists.txt new file mode 100755 index 000000000..6074ee2c6 --- /dev/null +++ b/astra-sim-alibabacloud/astra-sim/network_frontend/ns3/CMakeLists.txt @@ -0,0 +1,85 @@ +function(ns3_export_file src dst) + get_filename_component(dst_dir "${dst}" DIRECTORY) + file(MAKE_DIRECTORY "${dst_dir}") + + get_filename_component(dst_abs "${dst}" ABSOLUTE) + + if(EXISTS "${dst}" OR IS_SYMLINK "${dst_abs}") + file(REMOVE "${dst}") + endif() + + if(NS3_USE_RELATIVE_PATHS_SYMLINKS) + file(RELATIVE_PATH src_path "${dst_dir}" "${src}") + file(TO_CMAKE_PATH "${src_path}" src_path) + else() + set(src_path "${src}") + endif() + + if(NS3_EXPORT_HEADERS_AS_STUBS) + if("${src_path}" MATCHES "\\.(h|hh)$") + file(GENERATE OUTPUT "${dst}" CONTENT "#include \"${src_path}\"\n") + else() + configure_file("${src}" "${dst}" COPYONLY) + endif() + else() + file(CREATE_LINK "${src_path}" "${dst}" SYMBOLIC) + endif() +endfunction() + +file(GLOB_RECURSE ASTRA_SIM_FILES CONFIGURE_DEPENDS + "${ASTRA_SIM_DIR}/*.cc" + "${ASTRA_SIM_DIR}/*.hh" + "${ASTRA_SIM_DIR}/*.h" +) +list(FILTER ASTRA_SIM_FILES EXCLUDE REGEX "/network_frontend/") +list(FILTER ASTRA_SIM_FILES EXCLUDE REGEX "/build/") + +foreach(src_file IN LISTS ASTRA_SIM_FILES) + string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path "${src_file}") + ns3_export_file("${src_file}" "${NS3_SRC_DIR}/src/applications/${relative_path}") +endforeach() + +file(GLOB NS3_FRONTEND_FILES CONFIGURE_DEPENDS + "${ASTRA_SIM_DIR}/network_frontend/ns3/*.cc" + "${ASTRA_SIM_DIR}/network_frontend/ns3/*.hh" + "${ASTRA_SIM_DIR}/network_frontend/ns3/*.h" +) + +foreach(src_file IN LISTS NS3_FRONTEND_FILES) + get_filename_component(filename "${src_file}" NAME) + ns3_export_file("${src_file}" "${NS3_SRC_DIR}/scratch/${filename}") +endforeach() + +string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type_lower) +if(_build_type_lower STREQUAL "release") + if(NOT DEFINED NS3_ASSERT) + set(NS3_ASSERT OFF CACHE BOOL "Override NS3_ASSERT" FORCE) + endif() + if(NOT DEFINED NS3_LOG) + set(NS3_LOG OFF CACHE BOOL "Override NS3_LOG" FORCE) + endif() +endif() + +if(NOT DEFINED NS3_WARNINGS_AS_ERRORS) + set(NS3_WARNINGS_AS_ERRORS OFF CACHE BOOL "Override NS3_WARNINGS_AS_ERRORS" FORCE) +endif() + +if(NOT DEFINED NS3_MTP) + set(NS3_MTP ON CACHE BOOL "Override NS3_MTP" FORCE) +endif() + +if(DEFINED NS3_NATIVE_OPTIMIZATIONS AND NS3_NATIVE_OPTIMIZATIONS) + add_compile_options(-march=native) +endif() + +get_filename_component(NS3_COPIED_PREFIX_1 "${NS3_SRC_DIR}/src/applications/astra-sim" REALPATH) +get_filename_component(NS3_ORIGINAL_PREFIX_1 "${ASTRA_SIM_DIR}" REALPATH) +get_filename_component(NS3_COPIED_PREFIX_2 "${NS3_SRC_DIR}/scratch" REALPATH) +get_filename_component(NS3_ORIGINAL_PREFIX_2 "${ASTRA_SIM_DIR}/network_frontend/ns3" REALPATH) + +add_compile_options( + -ffile-prefix-map=${NS3_COPIED_PREFIX_1}=${NS3_ORIGINAL_PREFIX_1} + -ffile-prefix-map=${NS3_COPIED_PREFIX_2}=${NS3_ORIGINAL_PREFIX_2} +) + +add_subdirectory("${NS3_SRC_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/ns3") diff --git a/astra-sim-alibabacloud/astra-sim/network_frontend/phynet/CMakeLists.txt b/astra-sim-alibabacloud/astra-sim/network_frontend/phynet/CMakeLists.txt index f581acdfc..5ce8ed84f 100644 --- a/astra-sim-alibabacloud/astra-sim/network_frontend/phynet/CMakeLists.txt +++ b/astra-sim-alibabacloud/astra-sim/network_frontend/phynet/CMakeLists.txt @@ -1,23 +1,16 @@ -# CMake requirement -cmake_minimum_required(VERSION 3.15) - - project(SimAI_phynet) -file(GLOB SOURCES "*.cc") -file(GLOB HEADERS "*.h") -include_directories("${PROJECT_SOURCE_DIR}/../../../") -include_directories("$ENV{MPI_INCLUDE_PATH}") -set(use_rdma ${USE_RDMA}) -if(use_rdma) - add_definitions(-DPHY_RDMA) - message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") -endif() -set(CMAKE_BUILD_TYPE Debug) -add_executable(SimAI_phynet ${SOURCES} ${HEADERS}) +file(GLOB SOURCES CONFIGURE_DEPENDS "*.cc") +file(GLOB HEADERS CONFIGURE_DEPENDS "*.hh" "*.h") +add_executable(SimAI_phynet ${SOURCES} ${HEADERS}) +target_include_directories(SimAI_phynet PRIVATE "${ASTRA_SIM_DIR}") target_link_options(SimAI_phynet PRIVATE "-static-libstdc++") +target_compile_definitions(SimAI_phynet PRIVATE PHY_MTP) -if(use_rdma) - target_link_libraries(SimAI_phynet AstraSim mpi ibverbs pthread) +if(USE_RDMA) + target_compile_definitions(SimAI_phynet PRIVATE PHY_RDMA) + target_link_libraries(SimAI_phynet PRIVATE AstraSim ibverbs pthread) +else() + target_link_libraries(SimAI_phynet PRIVATE AstraSim) endif() diff --git a/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt b/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt index 1c467487f..d0d4800b4 100644 --- a/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt +++ b/astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt @@ -1,21 +1,7 @@ -# CMake requirement cmake_minimum_required(VERSION 3.15) -# C++ requirement -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) -add_definitions("-Wall -g") -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE) -endif() - -# Compiler requirement -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) - message(FATAL_ERROR "g++ (GNU) version should be greater than 5.3, but found ${CMAKE_CXX_COMPILER_VERSION}") - endif() -endif() - - # Setup project project(AstraSimNetwork) + +# Compile AnalyticalBackend binary +add_subdirectory ("${PROJECT_SOURCE_DIR}/../../astra-sim/network_frontend/ns3" simai_ns3) diff --git a/astra-sim-alibabacloud/build/astra_ns3/build.sh b/astra-sim-alibabacloud/build/astra_ns3/build.sh index a80138123..5a6dd1c19 100755 --- a/astra-sim-alibabacloud/build/astra_ns3/build.sh +++ b/astra-sim-alibabacloud/build/astra_ns3/build.sh @@ -84,7 +84,7 @@ case "$1" in debug;; -c|--compile) setup - compile_astrasim + #compile_astrasim compile;; -r|--run) setup diff --git a/astra-sim-alibabacloud/build/simai_analytical/CMakeLists.txt b/astra-sim-alibabacloud/build/simai_analytical/CMakeLists.txt index 0e76ac090..f82929c44 100644 --- a/astra-sim-alibabacloud/build/simai_analytical/CMakeLists.txt +++ b/astra-sim-alibabacloud/build/simai_analytical/CMakeLists.txt @@ -1,18 +1,5 @@ -# CMake requirement cmake_minimum_required(VERSION 3.15) -# C++ requirement -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -# Compiler requirement -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) - message(FATAL_ERROR "g++ (GNU) version should be greater than 5.3, but found ${CMAKE_CXX_COMPILER_VERSION}") - endif() -endif() - - # Setup project project (AstraSim_Analytical) diff --git a/astra-sim-alibabacloud/build/simai_analytical/build.sh b/astra-sim-alibabacloud/build/simai_analytical/build.sh index cc2e30bf5..8829d3c5d 100755 --- a/astra-sim-alibabacloud/build/simai_analytical/build.sh +++ b/astra-sim-alibabacloud/build/simai_analytical/build.sh @@ -25,7 +25,7 @@ function setup { function compile { cd "${BUILD_DIR}" || exit - cmake -DUSE_ANALYTICAL=TRUE .. + cmake -DSIMAI_MODE="analytical" .. make } diff --git a/astra-sim-alibabacloud/build/simai_phy/CMakeLists.txt b/astra-sim-alibabacloud/build/simai_phy/CMakeLists.txt index bb64a2eb9..ebde4e24b 100644 --- a/astra-sim-alibabacloud/build/simai_phy/CMakeLists.txt +++ b/astra-sim-alibabacloud/build/simai_phy/CMakeLists.txt @@ -1,14 +1,7 @@ -# CMake requirement cmake_minimum_required(VERSION 3.15) -set(CMAKE_CXX_COMPILER "$ENV{MPI_BIN_PATH}") - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS} -std=c++11") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_LINK_FLAGS} -std=c++11") - project (SimAi_Phy) -add_definitions(-DPHY_MTP) add_subdirectory("${PROJECT_SOURCE_DIR}/../../" AstraSim) add_subdirectory ("${PROJECT_SOURCE_DIR}/../../astra-sim/network_frontend/phynet" simai_phynet) diff --git a/astra-sim-alibabacloud/build/simai_phy/build.sh b/astra-sim-alibabacloud/build/simai_phy/build.sh index a98187ff4..a8bb5a4e2 100755 --- a/astra-sim-alibabacloud/build/simai_phy/build.sh +++ b/astra-sim-alibabacloud/build/simai_phy/build.sh @@ -27,7 +27,7 @@ function compile { cd "${BUILD_DIR}" || exit case "$option" in "RDMA") - cmake -DUSE_RDMA=TRUE .. + cmake -DSIMAI_MODE="phy" -DUSE_RDMA=TRUE .. make;; esac }