diff --git a/CMakeLists.txt b/CMakeLists.txt index 24775d6b1..c237234d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,11 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -latomic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -latomic") set(CMAKE_CXX_FLAGS_RELEASE "-O3") -#add_compile_definitions(EIGEN_MAX_ALIGN_BYTES=8) #Open this line for RASPI - +# Options +option(NERLWOLF "Use Wolfram Engine workers extension" OFF) option(USE_OpenMP "Use-OpenMP" ON) + +#add_compile_definitions(EIGEN_MAX_ALIGN_BYTES=8) #Open this line for RASPI if(USE_OpenMP) find_package(OpenMP) if(OPENMP_FOUND) @@ -30,5 +32,10 @@ endif() ########################### add_subdirectory(src_cpp) # actually adding opennnBridge -add_library(${PROJECT_NAME} SHARED $) -target_link_libraries(${PROJECT_NAME} PUBLIC opennnBridge) +add_library(nerlnet_onn SHARED $) +target_link_libraries(nerlnet_onn PUBLIC opennnBridge) + +if (NERLWOLF) + add_library(nerlnet_wolf SHARED $) + target_link_libraries(nerlnet_wolf PUBLIC wolframBridge) +endif() diff --git a/NerlnetBuild.sh b/NerlnetBuild.sh index 36b7e9b3a..c18374531 100755 --- a/NerlnetBuild.sh +++ b/NerlnetBuild.sh @@ -2,20 +2,20 @@ NERLNET_PREFIX="[NERLNET_SCRIPT]" INPUT_DATA_DIR="inputDataDir" -SHORT_OPTIONS_LIST=p:,j:,c:,h -LONG_OPTIONS_LIST=pull:,jobs:,clean:,help # arguments parsing # Thanks to https://github.com/matejak/argbash Branch="master" JobsNum=4 +NerlWolf=OFF help() { echo "-------------------------------------" && echo "Nerlnet Build" && echo "-------------------------------------" echo "Usage:" echo "--p or --pull Warning! this uses checkout -f! and branch name checkout to branch $Branch and pull the latest" - echo "--j or --jobs number of jobs to cmake build" + echo "--w or --wolf wolfram engine workers extension (nerlwolf)" + echo "--j or --jobs number of jobs to cmake build" echo "--c or --clean remove build directory" exit 2 } @@ -63,6 +63,8 @@ print_help() printf 'Usage: %s [-h|--help] [-c|--clean] [-j|--jobs ] [-p|--pull ]\n' "$0" printf '\t%s\n' "-j, --jobs: number of jobs (default: '4')" printf '\t%s\n' "-p, --pull: pull from branch (default: '4')" + printf '\t%s\n' "-w, --wolf: wolfram engine extension build (default: 'off')" + } @@ -88,6 +90,17 @@ parse_commandline() clean_build_directory exit 0 ;; + -w|--wolf) + test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 + NerlWolf="$2" + shift + ;; + --wolf=*) + NerlWolf="${_key##--jobs=}" + ;; + -w*) + NerlWolf="${_key##-j}" + ;; -j|--jobs) test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 JobsNum="$2" @@ -140,7 +153,7 @@ fi echo "$NERLNET_BUILD_PREFIX Building Nerlnet Library" echo "$NERLNET_BUILD_PREFIX Cmake command of Nerlnet NIFPP" set -e -cmake -S . -B build/release -DCMAKE_BUILD_TYPE=RELEASE +cmake -S . -B build/release -DNERLWOLF=$NerlWolf -DCMAKE_BUILD_TYPE=RELEASE cd build/release echo "$NERLNET_BUILD_PREFIX Script CWD: $PWD" echo "$NERLNET_BUILD_PREFIX Build Nerlnet" diff --git a/src_cpp/CMakeLists.txt b/src_cpp/CMakeLists.txt index 48c2f8c39..2b8abf5ce 100644 --- a/src_cpp/CMakeLists.txt +++ b/src_cpp/CMakeLists.txt @@ -8,4 +8,8 @@ project(src_cpp) add_subdirectory(opennnBridge) -add_library(${PROJECT_NAME} SHARED $) + +if(NERLWOLF) + message("[NERLNET] Wolfram Engine nif extension is enabled") + add_subdirectory(wolframBridge) +endif() \ No newline at end of file diff --git a/src_cpp/wolframBridge/CMakeLists.txt b/src_cpp/wolframBridge/CMakeLists.txt new file mode 100644 index 000000000..d34cc8aa8 --- /dev/null +++ b/src_cpp/wolframBridge/CMakeLists.txt @@ -0,0 +1,33 @@ +#**************************************************** +# Authors: David Leon +# 16/9/2023 +# +# @copyright Copyright (c) 2023 Nerlnet +# *****************************************************/ + +project(wolframBridge) + +set(SIMPLE_LOGGER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../simple-cpp-logger/include") +set(NIFPP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../nifpp/") +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_CXX_FLAGS "-fpic") +set(ERL_NIF_DEFAULT_LOCATION "/usr/local/lib/erlang/usr/include") + +# cpp Simple logger options +add_definitions( -D LOGGER_MAX_LOG_LEVEL_PRINTED=6 ) +add_definitions( -D LOGGER_PREFIX_LEVEL=2 ) +add_definitions( -D LOGGER_ENABLE_COLORS=1 ) +add_definitions( -D LOGGER_ENABLE_COLORS_ON_USER_HEADER=0 ) + + +set(SRC_CODE + "start.cpp") + +add_library(${PROJECT_NAME} SHARED ${SRC_CODE}) +#target_link_libraries(${PROJECT_NAME} PUBLIC) + +# Include NIF, OpenNN and Simple Cpp Logger +target_include_directories(${PROJECT_NAME} PUBLIC + ${NIFPP_PATH} + ${SIMPLE_LOGGER_PATH} + ${ERL_NIF_DEFAULT_LOCATION}) \ No newline at end of file diff --git a/src_cpp/wolframBridge/start.cpp b/src_cpp/wolframBridge/start.cpp new file mode 100644 index 000000000..573e76d87 --- /dev/null +++ b/src_cpp/wolframBridge/start.cpp @@ -0,0 +1,8 @@ + +#include "nifpp.h" +// Starting point for wolframBridge + +int start() +{ + return 0; +} diff --git a/src_erl/NerlnetApp/src/Bridge/nerlTensor.hrl b/src_erl/NerlnetApp/src/Bridge/nerlTensor.hrl index 5b6f2c2d1..c7297b2c4 100644 --- a/src_erl/NerlnetApp/src/Bridge/nerlTensor.hrl +++ b/src_erl/NerlnetApp/src/Bridge/nerlTensor.hrl @@ -8,7 +8,7 @@ -define(TRAIN_TIMEOUT,20000). % 20 seconds limit for prediction results %% nerlNIF defines --define(NERLNET_LIB,"libnerlnet"). +-define(NERLNET_LIB,"libnerlnet_onn"). -define(NERLNET_PATH,"/usr/local/lib/nerlnet-lib/NErlNet"). -define(BUILD_TYPE_DEBUG,"debug"). -define(BUILD_TYPE_RELEASE,"/build/release"). diff --git a/src_erl/NerlnetApp/src/Bridge/workers/workerDefinitions.hrl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerDefinitions.hrl similarity index 100% rename from src_erl/NerlnetApp/src/Bridge/workers/workerDefinitions.hrl rename to src_erl/NerlnetApp/src/Bridge/onnWorkers/workerDefinitions.hrl diff --git a/src_erl/NerlnetApp/src/Bridge/workers/workerFederatedClient.erl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerFederatedClient.erl similarity index 100% rename from src_erl/NerlnetApp/src/Bridge/workers/workerFederatedClient.erl rename to src_erl/NerlnetApp/src/Bridge/onnWorkers/workerFederatedClient.erl diff --git a/src_erl/NerlnetApp/src/Bridge/workers/workerFederatedServer.erl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerFederatedServer.erl similarity index 100% rename from src_erl/NerlnetApp/src/Bridge/workers/workerFederatedServer.erl rename to src_erl/NerlnetApp/src/Bridge/onnWorkers/workerFederatedServer.erl diff --git a/src_erl/NerlnetApp/src/Bridge/workers/workerGeneric.erl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerGeneric.erl similarity index 100% rename from src_erl/NerlnetApp/src/Bridge/workers/workerGeneric.erl rename to src_erl/NerlnetApp/src/Bridge/onnWorkers/workerGeneric.erl diff --git a/src_erl/NerlnetApp/src/Bridge/workers/workerNN.erl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerNN.erl similarity index 100% rename from src_erl/NerlnetApp/src/Bridge/workers/workerNN.erl rename to src_erl/NerlnetApp/src/Bridge/onnWorkers/workerNN.erl diff --git a/src_erl/NerlnetApp/src/Bridge/wolfWorkers/wolfworkerDefinitions.hrl b/src_erl/NerlnetApp/src/Bridge/wolfWorkers/wolfworkerDefinitions.hrl new file mode 100644 index 000000000..e69de29bb diff --git a/src_erl/NerlnetApp/src/Bridge/wolfWorkers/wolfworkerGeneric.erl b/src_erl/NerlnetApp/src/Bridge/wolfWorkers/wolfworkerGeneric.erl new file mode 100644 index 000000000..306c518d1 --- /dev/null +++ b/src_erl/NerlnetApp/src/Bridge/wolfWorkers/wolfworkerGeneric.erl @@ -0,0 +1,3 @@ +-module(wolfworkerGeneric). + +-include("wolfworkerDefinitions.hrl"). \ No newline at end of file