Skip to content

Commit

Permalink
oran: use Vcpkg to fetch the latest mlpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielcarvfer committed Aug 1, 2023
1 parent 9675d8f commit 2228f36
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 136 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ option(NS3_EIGEN "Build with Eigen support" ON)
option(NS3_STATIC "Build a static ns-3 library and link it against executables"
OFF
)
option(NS3_VCPKG "Enable the Vcpkg C++ library manager support" OFF)
option(NS3_VCPKG "Enable the Vcpkg C++ library manager support" ON)
option(NS3_VERBOSE "Print additional build system messages" OFF)
option(NS3_VISUALIZER "Build visualizer module" ON)
option(NS3_WARNINGS "Enable compiler warnings" ON)
Expand Down
36 changes: 20 additions & 16 deletions build-support/custom-modules/ns3-vcpkg-hunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

if(NOT ${NS3_VCPKG})
function(add_package package_name)
message(STATUS "Vcpkg support is not enabled. Skipping the installation of ${package_name}")
message(
STATUS
"Vcpkg support is not enabled. Skipping the installation of ${package_name}"
)
endfunction()
return()
endif()
Expand Down Expand Up @@ -59,9 +62,9 @@ function(setup_vcpkg)
endif()
get_filename_component(VCPKG_PARENT_DIR ${VCPKG_DIR} DIRECTORY)
execute_process(
COMMAND ${GIT_EXECUTABLE} clone --depth 1
https://github.com/microsoft/vcpkg.git
WORKING_DIRECTORY "${VCPKG_PARENT_DIR}/"
COMMAND ${GIT_EXECUTABLE} clone --depth 1
https://github.com/microsoft/vcpkg.git
WORKING_DIRECTORY "${VCPKG_PARENT_DIR}/"
)
endif()

Expand All @@ -70,15 +73,21 @@ function(setup_vcpkg)
else()
# Check if required packages are installed (unzip curl tar)
if(WIN32)
find_program(ZIP_PRESENT zip.exe)
find_program(UNZIP_PRESENT unzip.exe)
find_program(CURL_PRESENT curl.exe)
find_program(TAR_PRESENT tar.exe)
else()
find_program(ZIP_PRESENT zip)
find_program(UNZIP_PRESENT unzip)
find_program(CURL_PRESENT curl)
find_program(TAR_PRESENT tar)
endif()

if(${ZIP_PRESENT} STREQUAL ZIP_PRESENT-NOTFOUND)
message(FATAL_ERROR "Zip is required for VcPkg, but is not installed")
endif()

if(${UNZIP_PRESENT} STREQUAL UNZIP_PRESENT-NOTFOUND)
message(FATAL_ERROR "Unzip is required for VcPkg, but is not installed")
endif()
Expand Down Expand Up @@ -109,8 +118,8 @@ function(setup_vcpkg)
endif()

execute_process(
COMMAND ${COMPILER_ENFORCING} ${VCPKG_DIR}/${command}
WORKING_DIRECTORY ${VCPKG_DIR}
COMMAND ${COMPILER_ENFORCING} ${VCPKG_DIR}/${command}
WORKING_DIRECTORY ${VCPKG_DIR}
)
# message(STATUS "VCPKG bootstrapped") include_directories(${VCPKG_DIR})
set(ENV{VCPKG_ROOT} ${VCPKG_DIR})
Expand All @@ -120,15 +129,10 @@ function(setup_vcpkg)
execute_process(COMMAND chmod +x ${VCPKG_DIR}/${VCPKG_EXEC})
endif()

set(vcpkg_toolchain ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake)
if(NOT CMAKE_TOOLCHAIN_FILE OR NOT ("${CMAKE_TOOLCHAIN_FILE}" STREQUAL
"${vcpkg_toolchain}")
set(CMAKE_PREFIX_PATH
"${VCPKG_DIR}/installed/${VCPKG_TRIPLET}/;${CMAKE_PREFIX_PATH}"
PARENT_SCOPE
)
message(
FATAL_ERROR
"To use Vcpkg, reconfigure with -DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake"
)
endif()
endfunction()

function(add_package package_name)
Expand All @@ -140,8 +144,8 @@ function(add_package package_name)
endif()
message(STATUS "${package_name} will be installed")
execute_process(
COMMAND ${VCPKG_DIR}/${VCPKG_EXEC} install ${package_name} --triplet
${VCPKG_TRIPLET} OUTPUT_QUIET # comment for easier debugging
COMMAND ${VCPKG_DIR}/${VCPKG_EXEC} install ${package_name} --triplet
${VCPKG_TRIPLET} # comment for easier debugging
)
message(STATUS "${package_name} was installed")
endfunction()
Expand Down
36 changes: 27 additions & 9 deletions src/oran/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
find_library(ARMADILLO armadillo)
find_library(MLPACK mlpack)
set(mlpack_libraries)
if(NOT(${ARMADILLO} STREQUAL ARMADILLO-NOTFOUND) AND NOT(${MLPACK} STREQUAL MLPACK-NOTFOUND))
set(mlpack_libraries ${ARMADILLO} ${MLPACK})
add_package(Armadillo)
add_package(Mlpack)
find_library(
ARMADILLO
armadillo
)
find_path(
MLPACK_INCLUDE_DIRS
"mlpack/mlpack.hpp"
)

if((${ARMADILLO}
STREQUAL
ARMADILLO-NOTFOUND
)
OR (${MLPACK_INCLUDE_DIRS}
STREQUAL
MLPACK_INCLUDE_DIRS-NOTFOUND
)
)
message(FATAL_ERROR "Missing Armadillo or Mlpack")
endif()

include_directories(${MLPACK_INCLUDE_DIRS})

build_lib(
LIBNAME oran
SOURCE_FILES
model/PubSubInfra.cc
model/E2AP.cc
#model/E2SM-KPM.cc -- these are part of E2AP. separated only for readability.
#model/E2SM-RC.cc /
# model/E2SM-KPM.cc -- these are part of E2AP. separated only for
# readability. model/E2SM-RC.cc /
model/E2SM-KPM-measurements.cc
model/ORAN-message-types.cc
model/xAppHandover.cc
Expand All @@ -24,7 +42,7 @@ build_lib(
model/xApp.h
model/E2SM-KPM-measurements.h
model/E2SM-RC-control-types.h
model/E2SM-RC-indication-types.h
model/E2SM-RC-indication-types.h
model/ORAN-message-types.h
model/xAppHandover.h
model/xAppHandoverMlpackKmeans.h
Expand All @@ -33,5 +51,5 @@ build_lib(
${libcore}
${libnetwork}
${libinternet}
${mlpack_libraries}
${ARMADILLO}
)
197 changes: 94 additions & 103 deletions src/oran/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
build_lib_example(
NAME TestE2SmRcIndicationMessages
SOURCE_FILES TestE2SmRcMessages.cc
LIBRARIES_TO_LINK
${libcore}
${liboran}
${liblte}
NAME TestE2SmRcIndicationMessages
SOURCE_FILES TestE2SmRcMessages.cc
LIBRARIES_TO_LINK
${libcore}
${liboran}
${liblte}
)

build_lib_example(
Expand All @@ -19,110 +19,101 @@ build_lib_example(
)

build_lib_example(
NAME TestE2AP
SOURCE_FILES TestE2AP.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
NAME TestE2AP
SOURCE_FILES TestE2AP.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
)

build_lib_example(
NAME TestHandover
SOURCE_FILES TestHandover.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
NAME TestHandover
SOURCE_FILES TestHandover.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
)

build_lib_example(
NAME TestHandoverXapp
SOURCE_FILES TestHandoverXapp.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
NAME TestHandoverXapp
SOURCE_FILES TestHandoverXapp.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
)

if(NOT(${ARMADILLO} STREQUAL ARMADILLO-NOTFOUND) AND NOT(${MLPACK} STREQUAL MLPACK-NOTFOUND))
build_lib_example(
NAME TestHandoverXappMLPACK
SOURCE_FILES TestHandoverXappMLPACK.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
IGNORE_PCH TRUE
)
build_lib_example(
NAME TestHandoverXappMLPACKReinforcedLearning
SOURCE_FILES TestHandoverXappMLPACKReinforcedLearning.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
IGNORE_PCH TRUE
)
build_lib_example(
NAME HandoverXappsScenario
SOURCE_FILES HandoverXappsScenario.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
${libnetanim}
IGNORE_PCH TRUE
)
target_compile_options(TestHandoverXappMLPACK PUBLIC -fopenmp)
target_compile_options(TestHandoverXappMLPACKReinforcedLearning PUBLIC -fopenmp)
target_compile_options(HandoverXappsScenario PUBLIC -fopenmp)
target_link_options(TestHandoverXappMLPACK PUBLIC -fopenmp)
target_link_options(TestHandoverXappMLPACKReinforcedLearning PUBLIC -fopenmp)
target_link_options(HandoverXappsScenario PUBLIC -fopenmp)

if(NOT
(${ARMADILLO}
STREQUAL
ARMADILLO-NOTFOUND)
AND NOT
(${MLPACK_INCLUDE_DIRS}
STREQUAL
MLPACK_INCLUDE_DIRS-NOTFOUND)
)
build_lib_example(
NAME TestHandoverXappMLPACK
SOURCE_FILES TestHandoverXappMLPACK.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
IGNORE_PCH
TRUE
)
build_lib_example(
NAME TestHandoverXappMLPACKReinforcedLearning
SOURCE_FILES TestHandoverXappMLPACKReinforcedLearning.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
IGNORE_PCH
TRUE
)
build_lib_example(
NAME HandoverXappsScenario
SOURCE_FILES HandoverXappsScenario.cc
LIBRARIES_TO_LINK
${libcore}
${libmobility}
${libpoint-to-point}
${liblte}
${liboran}
${libapplications}
${libnetanim}
IGNORE_PCH
TRUE
)
endif()

#find_package(Torch)
#if(${Torch_FOUND})
# # Download libtorch from https://pytorch.org/cppdocs/installing.html
# # Then unzip to ~/.local
# find_library(TORCH torch HINTS ~/.local/lib)
# find_library(TORCH_LIBRARY torch_library HINTS ~/.local/lib)
# list(REMOVE_ITEM TORCH_LIBRARIES "torch")
# list(REMOVE_ITEM TORCH_LIBRARIES "torch_library")
# list(INSERT TORCH_LIBRARIES 0 ${TORCH_LIBRARY})
# list(INSERT TORCH_LIBRARIES 0 ${TORCH})
# include_directories(${TORCH_INCLUDE_DIRS})
# build_lib_example(
# NAME TestHandoverXappMLTorch
# SOURCE_FILES TestHandoverXappMLTorch.cc
# LIBRARIES_TO_LINK
# ${libcore}
# ${libmobility}
# ${libpoint-to-point}
# ${liblte}
# ${liboran}
# ${libapplications}
# ${TORCH_LIBRARIES}
# )
# target_compile_options(TestHandoverXappMLTorch PUBLIC ${TORCH_CXX_FLAGS})
#endif()
# find_package(Torch) if(${Torch_FOUND}) # Download libtorch from
# https://pytorch.org/cppdocs/installing.html # Then unzip to ~/.local
# find_library(TORCH torch HINTS ~/.local/lib) find_library(TORCH_LIBRARY
# torch_library HINTS ~/.local/lib) list(REMOVE_ITEM TORCH_LIBRARIES "torch")
# list(REMOVE_ITEM TORCH_LIBRARIES "torch_library") list(INSERT TORCH_LIBRARIES
# 0 ${TORCH_LIBRARY}) list(INSERT TORCH_LIBRARIES 0 ${TORCH})
# include_directories(${TORCH_INCLUDE_DIRS}) build_lib_example( NAME
# TestHandoverXappMLTorch SOURCE_FILES TestHandoverXappMLTorch.cc
# LIBRARIES_TO_LINK ${libcore} ${libmobility} ${libpoint-to-point} ${liblte}
# ${liboran} ${libapplications} ${TORCH_LIBRARIES} )
# target_compile_options(TestHandoverXappMLTorch PUBLIC ${TORCH_CXX_FLAGS})
# endif()
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class xAppHandoverML : public xAppHandover
}
// Prepare to run K-means
arma::Row<size_t> assignments;
mlpack::kmeans::KMeans<> k;
mlpack::KMeans<> k;
arma::mat centroids;
k.Cluster(dataset, cells.size(), assignments, centroids);

Expand Down
1 change: 1 addition & 0 deletions src/oran/model/E2AP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "E2AP.h"
#include "ns3/pointer.h"

using namespace ns3;
using namespace oran;
Expand Down
Loading

0 comments on commit 2228f36

Please sign in to comment.