Skip to content
Snippets Groups Projects
Commit 76c06f01 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Allow for possible operator slots to change with rung/needed storage

No longer just 3
parent 86dbe75a
No related branches found
No related tags found
No related merge requests found
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
#include <iostream> #include <iostream>
int node_value_arrs::N_SELECTED = 0; int node_value_arrs::N_SELECTED = 0;
int node_value_arrs::N_SAMPLES = 0; int node_value_arrs::N_SAMPLES = 0;
unsigned long int node_value_arrs::N_STORE_FEATURES = 0; int node_value_arrs::N_STORE_FEATURES = 0;
int node_value_arrs::N_RUNGS_STORED = 0; int node_value_arrs::N_RUNGS_STORED = 0;
int node_value_arrs::N_SAMPLES_TEST = 0; int node_value_arrs::N_SAMPLES_TEST = 0;
int node_value_arrs::MAX_N_THREADS = omp_get_max_threads(); int node_value_arrs::MAX_N_THREADS = omp_get_max_threads();
unsigned long int node_value_arrs::NEXT_IND = 0; int node_value_arrs::N_OP_SLOTS = 0;
int node_value_arrs::MAX_RUNG = 0;
std::vector<int> node_value_arrs::TEMP_STORAGE_REG; std::vector<int> node_value_arrs::TEMP_STORAGE_REG;
std::vector<int> node_value_arrs::TEMP_STORAGE_TEST_REG; std::vector<int> node_value_arrs::TEMP_STORAGE_TEST_REG;
...@@ -20,7 +21,7 @@ std::vector<double> node_value_arrs::TEST_VALUES_ARR; ...@@ -20,7 +21,7 @@ std::vector<double> node_value_arrs::TEST_VALUES_ARR;
std::vector<double> node_value_arrs::TEMP_STORAGE_ARR; std::vector<double> node_value_arrs::TEMP_STORAGE_ARR;
std::vector<double> node_value_arrs::TEMP_STORAGE_TEST_ARR; std::vector<double> node_value_arrs::TEMP_STORAGE_TEST_ARR;
void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat, bool set_task_sz) void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat, int max_rung, bool set_task_sz)
{ {
if(set_task_sz) if(set_task_sz)
TASK_SZ_TRAIN = {n_samples}; TASK_SZ_TRAIN = {n_samples};
...@@ -32,18 +33,20 @@ void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, i ...@@ -32,18 +33,20 @@ void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, i
N_SAMPLES_TEST = n_samples_test; N_SAMPLES_TEST = n_samples_test;
N_RUNGS_STORED = 0; N_RUNGS_STORED = 0;
N_STORE_FEATURES = n_primary_feat; N_STORE_FEATURES = n_primary_feat;
MAX_RUNG = max_rung;
N_OP_SLOTS = static_cast<int>(std::pow(2, max_rung)) - 1;
VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES); VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES);
TEST_VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES_TEST); TEST_VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES_TEST);
TEMP_STORAGE_ARR = std::vector<double>(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1) * N_SAMPLES); TEMP_STORAGE_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES);
TEMP_STORAGE_REG = std::vector<int>(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1), -1); TEMP_STORAGE_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), -1);
TEMP_STORAGE_TEST_ARR = std::vector<double>(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1) * N_SAMPLES_TEST); TEMP_STORAGE_TEST_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_REG = std::vector<int>(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1), -1); TEMP_STORAGE_TEST_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), -1);
} }
void node_value_arrs::initialize_values_arr(std::vector<int> task_sz_train, std::vector<int> task_sz_test, int n_primary_feat) void node_value_arrs::initialize_values_arr(std::vector<int> task_sz_train, std::vector<int> task_sz_test, int n_primary_feat, int max_rung)
{ {
TASK_SZ_TRAIN = task_sz_train; TASK_SZ_TRAIN = task_sz_train;
TASK_SZ_TEST = task_sz_test; TASK_SZ_TEST = task_sz_test;
...@@ -52,6 +55,7 @@ void node_value_arrs::initialize_values_arr(std::vector<int> task_sz_train, std: ...@@ -52,6 +55,7 @@ void node_value_arrs::initialize_values_arr(std::vector<int> task_sz_train, std:
std::accumulate(task_sz_train.begin(), task_sz_train.end(), 0), std::accumulate(task_sz_train.begin(), task_sz_train.end(), 0),
std::accumulate(task_sz_test.begin(), task_sz_test.end(), 0), std::accumulate(task_sz_test.begin(), task_sz_test.end(), 0),
n_primary_feat, n_primary_feat,
max_rung,
false false
); );
} }
...@@ -85,20 +89,23 @@ void node_value_arrs::resize_values_arr(int n_dims, unsigned long int n_feat, bo ...@@ -85,20 +89,23 @@ void node_value_arrs::resize_values_arr(int n_dims, unsigned long int n_feat, bo
if(use_temp) if(use_temp)
{ {
TEMP_STORAGE_ARR.resize(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1) * N_SAMPLES); N_OP_SLOTS = static_cast<int>(std::pow(2, MAX_RUNG - N_RUNGS_STORED)) - 1;
TEMP_STORAGE_ARR.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES);
TEMP_STORAGE_ARR.shrink_to_fit(); TEMP_STORAGE_ARR.shrink_to_fit();
TEMP_STORAGE_REG.resize(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1), - 1); TEMP_STORAGE_REG.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), - 1);
TEMP_STORAGE_REG.shrink_to_fit(); TEMP_STORAGE_REG.shrink_to_fit();
TEMP_STORAGE_TEST_ARR.resize(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1) * N_SAMPLES_TEST); TEMP_STORAGE_TEST_ARR.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_ARR.shrink_to_fit(); TEMP_STORAGE_TEST_ARR.shrink_to_fit();
TEMP_STORAGE_TEST_REG.resize(MAX_N_THREADS * (3 * N_STORE_FEATURES + 1), - 1); TEMP_STORAGE_TEST_REG.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), - 1);
TEMP_STORAGE_TEST_REG.shrink_to_fit(); TEMP_STORAGE_TEST_REG.shrink_to_fit();
} }
else else
{ {
N_OP_SLOTS = 0;
TEMP_STORAGE_ARR = {}; TEMP_STORAGE_ARR = {};
TEMP_STORAGE_REG = {}; TEMP_STORAGE_REG = {};
TEMP_STORAGE_TEST_ARR = {}; TEMP_STORAGE_TEST_ARR = {};
...@@ -112,7 +119,7 @@ double* node_value_arrs::get_value_ptr(unsigned long int arr_ind, unsigned long ...@@ -112,7 +119,7 @@ double* node_value_arrs::get_value_ptr(unsigned long int arr_ind, unsigned long
return access_value_arr(arr_ind); return access_value_arr(arr_ind);
temp_storage_reg(arr_ind, offset) = feat_ind; temp_storage_reg(arr_ind, offset) = feat_ind;
return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * 3 + 1)); return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1));
} }
double* node_value_arrs::get_test_value_ptr(unsigned long int arr_ind, unsigned long int feat_ind, int offset) double* node_value_arrs::get_test_value_ptr(unsigned long int arr_ind, unsigned long int feat_ind, int offset)
...@@ -121,7 +128,7 @@ double* node_value_arrs::get_test_value_ptr(unsigned long int arr_ind, unsigned ...@@ -121,7 +128,7 @@ double* node_value_arrs::get_test_value_ptr(unsigned long int arr_ind, unsigned
return access_test_value_arr(arr_ind); return access_test_value_arr(arr_ind);
temp_storage_test_reg(arr_ind, offset) = feat_ind; temp_storage_test_reg(arr_ind, offset) = feat_ind;
return access_temp_storage_test((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * 3 + 1)); return access_temp_storage_test((arr_ind % N_STORE_FEATURES) + (offset % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1));
} }
void node_value_arrs::initialize_d_matrix_arr() void node_value_arrs::initialize_d_matrix_arr()
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define NODE_VALUE_ARR #define NODE_VALUE_ARR
#include <algorithm> #include <algorithm>
#include <cmath>
#include <memory> #include <memory>
#include <numeric> #include <numeric>
#include <vector> #include <vector>
...@@ -35,10 +36,11 @@ namespace node_value_arrs ...@@ -35,10 +36,11 @@ namespace node_value_arrs
extern int N_SELECTED; //!< Number of features selected extern int N_SELECTED; //!< Number of features selected
extern int N_SAMPLES; //!< Number of training samples for each feature extern int N_SAMPLES; //!< Number of training samples for each feature
extern int N_SAMPLES_TEST; //!< Number of test samples for each feature extern int N_SAMPLES_TEST; //!< Number of test samples for each feature
extern unsigned long int N_STORE_FEATURES; //!< Number of features with stored values extern int N_STORE_FEATURES; //!< Number of features with stored values
extern int N_RUNGS_STORED; //!< Number of rungs with values stored extern int N_RUNGS_STORED; //!< Number of rungs with values stored
extern int MAX_N_THREADS; //!< Get the maximum number of threads possible extern int MAX_N_THREADS; //!< Get the maximum number of threads possible
extern unsigned long int NEXT_IND; //!< The next array index to use extern int N_OP_SLOTS; //!< The number of possible operator slots
extern int MAX_RUNG; //!< The maximum rung for all features
/** /**
* @brief Initialize the node value arrays * @brief Initialize the node value arrays
...@@ -47,9 +49,10 @@ namespace node_value_arrs ...@@ -47,9 +49,10 @@ namespace node_value_arrs
* @param n_samples Number of training samples for each feature * @param n_samples Number of training samples for each feature
* @param n_samples_test Number of test samples for each feature * @param n_samples_test Number of test samples for each feature
* @param n_primary_feat Number of primary features * @param n_primary_feat Number of primary features
* @param max_rung Largest rung of a feature
* @param set_test_task_sz If True reset the task_sz vectors * @param set_test_task_sz If True reset the task_sz vectors
*/ */
void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat, bool et_task_sz); void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat, int max_rung, bool et_task_sz);
/** /**
* @brief Initialize the node value arrays * @brief Initialize the node value arrays
...@@ -61,7 +64,21 @@ namespace node_value_arrs ...@@ -61,7 +64,21 @@ namespace node_value_arrs
*/ */
inline void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat) inline void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat)
{ {
initialize_values_arr(n_samples, n_samples_test, n_primary_feat, true); initialize_values_arr(n_samples, n_samples_test, n_primary_feat, 0, true);
}
/**
* @brief Initialize the node value arrays
* @details Using the size of the initial feature space constructor the storage arrays
*
* @param n_samples Number of training samples for each feature
* @param n_samples_test Number of test samples for each feature
* @param n_primary_feat Number of primary features
* @param max_rung Largest rung of a feature
*/
inline void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat, int max_rung)
{
initialize_values_arr(n_samples, n_samples_test, n_primary_feat, max_rung, true);
} }
/** /**
...@@ -71,8 +88,9 @@ namespace node_value_arrs ...@@ -71,8 +88,9 @@ namespace node_value_arrs
* @param task_sz_train Number of training samples per task * @param task_sz_train Number of training samples per task
* @param task_sz_test Number of test sample per task * @param task_sz_test Number of test sample per task
* @param n_primary_feat Number of primary features * @param n_primary_feat Number of primary features
* @param max_rung Largest rung of a feature
*/ */
void initialize_values_arr(std::vector<int> task_sz_train, std::vector<int> task_sz_test, int n_primary_feat); void initialize_values_arr(std::vector<int> task_sz_train, std::vector<int> task_sz_test, int n_primary_feat, int max_rung=0);
/** /**
* @brief Resize the node value arrays * @brief Resize the node value arrays
...@@ -121,7 +139,7 @@ namespace node_value_arrs ...@@ -121,7 +139,7 @@ namespace node_value_arrs
* *
* @return The register element for a given feature index and offset * @return The register element for a given feature index and offset
*/ */
inline int& temp_storage_reg(unsigned long int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * 3 + 1)];} inline int& temp_storage_reg(unsigned long int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_STORE_FEATURES) + (offset % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1)];}
/** /**
* @brief Get a reference slot/feature register of the test data * @brief Get a reference slot/feature register of the test data
...@@ -131,7 +149,7 @@ namespace node_value_arrs ...@@ -131,7 +149,7 @@ namespace node_value_arrs
* *
* @return The register element for a given feature index and offset * @return The register element for a given feature index and offset
*/ */
inline int& temp_storage_test_reg(unsigned long int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * 3 + 1)];} inline int& temp_storage_test_reg(unsigned long int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_STORE_FEATURES) + (offset % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1)];}
/** /**
* @brief Access element of the permanent training data storage array * @brief Access element of the permanent training data storage array
......
...@@ -270,7 +270,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm, st ...@@ -270,7 +270,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm, st
units.erase(units.begin() + taskind); units.erase(units.begin() + taskind);
} }
node_value_arrs::initialize_values_arr(_prop_train.size(), _prop_test.size(), headers.size()); node_value_arrs::initialize_values_arr(_prop_train.size(), _prop_test.size(), headers.size(), _max_rung);
std::vector<node_ptr> phi_0; std::vector<node_ptr> phi_0;
for(int ff = 0; ff < headers.size(); ++ff) for(int ff = 0; ff < headers.size(); ++ff)
phi_0.push_back(std::make_shared<FeatureNode>(ff, headers[ff], data[ff], test_data[ff], units[ff])); phi_0.push_back(std::make_shared<FeatureNode>(ff, headers[ff], data[ff], test_data[ff], units[ff]));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment