Skip to content

Commit

Permalink
Merge pull request #318 from leondavi/source_nif
Browse files Browse the repository at this point in the history
  • Loading branch information
leondavi authored May 8, 2024
2 parents ecf40ff + 0f35a7f commit a5a98b4
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 221 deletions.
1 change: 1 addition & 0 deletions NerlnetRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ case "$_arg_run_mode" in
(*) exit 1 ;;
esac

exit 0

#TODO TO BE REMOVED
# only for CI debug
Expand Down
1 change: 1 addition & 0 deletions src_cpp/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(NIFPP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../nifpp/")
set(SIMPLE_LOGGER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../simple-cpp-logger/include")

set(SRC_CODE
"nerltensor.h"
"common_definitions.h"
"nerlLayer.cpp"
"nerlLayer.h"
Expand Down
22 changes: 22 additions & 0 deletions src_cpp/common/nerltensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <string>
#include <unordered_map>
// enum defnitions
enum {NERL_TENSOR_DIMS = 3, CASE_1D = 1, CASE_2D =2, CASE_3D = 3};
enum NERLTENSOR_DATA_TYPES_NUM {ATOM_FLOAT, ATOM_DOUBLE, ATOM_INT32, ATOM_INT16, ATOM_UINT8};


static std::unordered_map<std::string, int> atom_str_to_enum_map = {
{"float", ATOM_FLOAT},
{"double", ATOM_DOUBLE},
{"int32", ATOM_INT32},
{"int16", ATOM_INT16},
{"uint8", ATOM_UINT8}
};

// functions
inline int atom_str_to_enum(std::string &in_str)
{
return atom_str_to_enum_map[in_str];
}
1 change: 0 additions & 1 deletion src_cpp/opennnBridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ set(SRC_CODE
"eigenTensorTypes.h"
"nifppEigenExtensions.h"
"nifppNerltensorEigen.h"
"definitionsNN.h"
"openNNnif.h"
"openNNnif.cpp"
"nerlWorkerOpenNN.h"
Expand Down
18 changes: 14 additions & 4 deletions src_cpp/opennnBridge/ae_red.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#include "ae_red.h"

using namespace nerlnet;

AeRed::AeRed(float k , float alpha)
namespace nerlnet
{

AeRed::AeRed(float k, float alpha)
{
_k = k;
_alpha = alpha;
_ema = 0;
_emad = 1;
_ema_event = 0;
_ema_normal = 0;
_prev_ema = 0;
_prev_emad = 0;
}

AeRed::~AeRed()
{

}

fTensor1DPtr AeRed::update_batch(fTensor1D loss_values)
Expand Down Expand Up @@ -38,4 +46,6 @@ float AeRed::update_sample(float loss_value){

if(loss_value > _threshold) return loss_value;
else return -loss_value;
}
}

} // namespace nerlnet
15 changes: 9 additions & 6 deletions src_cpp/opennnBridge/ae_red.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#define PARAM_K_DEFAULT 1.2f
#define ALPHA_DEFAULT 0.3f

#include "eigenTensorTypes.h"


Expand All @@ -11,6 +13,7 @@ class AeRed
{

public:

AeRed(float k = PARAM_K_DEFAULT , float alpha = ALPHA_DEFAULT);
~AeRed();

Expand All @@ -21,12 +24,12 @@ class AeRed
float _k;
float _alpha;
float _threshold;
float _ema = 0;
float _emad = 1;
float _ema_event = 0;
float _ema_normal = 0;
float _prev_ema = 0;
float _prev_emad = 0;
float _ema;
float _emad;
float _ema_event;
float _ema_normal;
float _prev_ema;
float _prev_emad;

};

Expand Down
30 changes: 0 additions & 30 deletions src_cpp/opennnBridge/definitionsNN.h

This file was deleted.

26 changes: 1 addition & 25 deletions src_cpp/opennnBridge/nifppNerltensorEigen.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#pragma once

#include "nerltensor.h"
#include "eigenTensorTypes.h"
#include "definitionsNN.h"
#include "nifppEigenExtensions.h"

namespace nifpp
{
enum {NERL_TENSOR_DIMS = 3, CASE_1D = 1, CASE_2D =2, CASE_3D = 3};

int atom_str_to_enum(str_atom in_str);
template<typename BasicType> int get_actual_dim(std::vector<BasicType> &dims);
template<typename BasicType, typename EigenTypePtr, typename EigenType> int get_tensor_1d(ErlNifEnv *env , ERL_NIF_TERM bin_term, EigenTypePtr &tensor_ptr);
template<typename BasicType, typename EigenTypePtr, typename EigenType> int get_tensor_2d(ErlNifEnv *env , ERL_NIF_TERM bin_term, EigenTypePtr &tensor_ptr);
Expand Down Expand Up @@ -263,25 +260,4 @@ namespace nifpp
vec = std::vector<Type>(bin.data, bin.data + bin.size / sizeof(Type));
return ret;
}

int atom_str_to_enum(str_atom in_str)
{
if (in_str == "float")
{
return ATOM_FLOAT;
}
else if (in_str == "double")
{
return ATOM_DOUBLE;
}
else if (in_str == "int32")
{
return ATOM_INT32;
}
else if (in_str == "int16")
{
return ATOM_INT16;
}
throw("Type is unsupported, update atom_str_to_enum and enum in nifppEigenExtensions.h");
}
}
143 changes: 0 additions & 143 deletions src_cpp/opennnBridge/openNNExtensionFunction.h

This file was deleted.

1 change: 0 additions & 1 deletion src_erl/NerlnetApp/src/nerl_tools.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ http_router_request(RouterHost, RouterPort, DestinationsList, ActionStr, Body) -


http_request(Host, Port, Path, {json, Body}) ->
io:format("Sending Json to ~p:~p~n",[Host,Port]),
JsonContentType = ?HTTP_CONTENT_TYPE_JSON,
Json = jsx:encode(Body),
http_request(Host, Port,Path, JsonContentType, Json);
Expand Down
25 changes: 14 additions & 11 deletions src_py/apiServer/experiment_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,20 @@ def print(self):
#LOG_INFO(f"CSV dataset: {self.csv_dataset.get_csv_file_path()}")
LOG_INFO(f"Number of features: {self.csv_dataset.get_num_of_features()}")
LOG_INFO(f"Number of labels: {self.csv_dataset.get_num_of_labels()}")
LOG_INFO("\nPhases:\n")
LOG_INFO("")
LOG_INFO("Phases:")
for phase in self.exp_phase_list:
LOG_INFO(f"Phase name: {phase.get_name()}")
LOG_INFO(f"Phase type: {phase.get_phase_type()}")
LOG_INFO(f"Sources: {phase.get_sources_str_list()}")
LOG_INFO("\nSource pieces:\n")
LOG_INFO(f" Phase name: {phase.get_name()}")
LOG_INFO(f" Phase type: {phase.get_phase_type()}")
LOG_INFO(f" Sources: {phase.get_sources_str_list()}")
LOG_INFO("")
LOG_INFO(" Source pieces:")
for source_piece in phase.get_sources_pieces():
LOG_INFO(f"Source name: {source_piece.get_source_name()}")
LOG_INFO(f"Batch size: {source_piece.get_batch_size()}")
LOG_INFO(f"Phase: {source_piece.get_phase()}")
LOG_INFO(f"Starting offset: {source_piece.get_starting_offset()}")
LOG_INFO(f"Number of batches: {source_piece.get_num_of_batches()}")
LOG_INFO(f"Workers target: {source_piece.get_target_workers()}")
LOG_INFO(f" Source name: {source_piece.get_source_name()}")
LOG_INFO(f" Batch size: {source_piece.get_batch_size()}")
LOG_INFO(f" Phase: {source_piece.get_phase()}")
LOG_INFO(f" Starting offset: {source_piece.get_starting_offset()}")
LOG_INFO(f" Number of batches: {source_piece.get_num_of_batches()}")
LOG_INFO(f" Workers target: {source_piece.get_target_workers()}")
LOG_INFO(" ----------------------")
LOG_INFO("")

0 comments on commit a5a98b4

Please sign in to comment.