Loading graph_framework/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ target_precompile_headers (rays $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/arithmetic.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/backend.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dispersion.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/absorption.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/math.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/node.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/solver.hpp>> Loading graph_framework/absorption.hpp +3 −2 Original line number Diff line number Diff line //------------------------------------------------------------------------------ /// @file absoprtion.hpp /// @brief Base class for a dispersion relation. /// @file absorption.hpp /// @brief Base class for an absorption model. /// /// Defines functions for computing power absorbtion. //------------------------------------------------------------------------------ Loading @@ -11,6 +11,7 @@ #include <thread> #include "newton.hpp" #include "output.hpp" namespace absorption { //****************************************************************************** Loading graph_framework/arithmetic.hpp +28 −28 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ #ifndef arithmetic_h #define arithmetic_h #include "trigonometry.hpp" #include "node.hpp" namespace graph { //------------------------------------------------------------------------------ Loading Loading @@ -741,12 +741,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1563,12 +1563,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1822,8 +1822,8 @@ namespace graph { } // Move trig to the right. auto cl = graph::cos_cast(this->left); auto sl = graph::sin_cast(this->left); auto cl = cos_cast(this->left); auto sl = sin_cast(this->left); if ((cl.get() && !this->right->is_power_like() && !this->right->is_all_variables() && !sin_cast(this->right).get()) || Loading Loading @@ -2455,12 +2455,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -3406,12 +3406,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -4837,12 +4837,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading graph_framework/math.hpp +25 −25 Original line number Diff line number Diff line Loading @@ -279,12 +279,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -546,12 +546,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -786,12 +786,12 @@ namespace graph { auto temp = std::make_shared<log_node<T, SAFE_MATH>> (x)->reduce(); // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1289,12 +1289,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1554,12 +1554,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading graph_framework/node.hpp +22 −12 Original line number Diff line number Diff line Loading @@ -311,12 +311,22 @@ namespace graph { << std::endl; } /// Cache for constructed nodes. inline thread_local static std::map<size_t, std::shared_ptr<leaf_node<T, SAFE_MATH>>> cache; /// Cache for the backend buffers. inline thread_local static std::map<size_t, backend::buffer<T>> backend_cache; // Create one struct that holds both caches: for constructed nodes and for the backend buffers //------------------------------------------------------------------------------ /// @brief Data structure to contain the two caches. /// /// This a avoids an issue on gnu compilers where it would try to redefine the /// __tls_guard twice depending on the include order. //------------------------------------------------------------------------------ struct caches_t { /// Cache of node. std::map<size_t, std::shared_ptr<leaf_node<T, SAFE_MATH>>> nodes; /// Cache of backend buffers. std::map<size_t, backend::buffer<T>> backends; }; /// A per thread instance of the cache structure. inline static thread_local caches_t caches; /// Type def to retrieve the backend type. typedef T base; Loading Loading @@ -593,12 +603,12 @@ namespace graph { auto temp = std::make_shared<constant_node<T, SAFE_MATH>> (d); // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1368,7 +1378,7 @@ namespace graph { using input_nodes = std::vector<shared_variable<T, SAFE_MATH>>; /// Convenience type alias for maping end codes back to inputs. template<jit::float_scalar T, bool SAFE_MATH=false> using map_nodes = std::vector<std::pair<graph::shared_leaf<T, SAFE_MATH>, using map_nodes = std::vector<std::pair<shared_leaf<T, SAFE_MATH>, shared_variable<T, SAFE_MATH>>>; //------------------------------------------------------------------------------ Loading Loading
graph_framework/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ target_precompile_headers (rays $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/arithmetic.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/backend.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dispersion.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/absorption.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/math.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/node.hpp>> $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/solver.hpp>> Loading
graph_framework/absorption.hpp +3 −2 Original line number Diff line number Diff line //------------------------------------------------------------------------------ /// @file absoprtion.hpp /// @brief Base class for a dispersion relation. /// @file absorption.hpp /// @brief Base class for an absorption model. /// /// Defines functions for computing power absorbtion. //------------------------------------------------------------------------------ Loading @@ -11,6 +11,7 @@ #include <thread> #include "newton.hpp" #include "output.hpp" namespace absorption { //****************************************************************************** Loading
graph_framework/arithmetic.hpp +28 −28 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ #ifndef arithmetic_h #define arithmetic_h #include "trigonometry.hpp" #include "node.hpp" namespace graph { //------------------------------------------------------------------------------ Loading Loading @@ -741,12 +741,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1563,12 +1563,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1822,8 +1822,8 @@ namespace graph { } // Move trig to the right. auto cl = graph::cos_cast(this->left); auto sl = graph::sin_cast(this->left); auto cl = cos_cast(this->left); auto sl = sin_cast(this->left); if ((cl.get() && !this->right->is_power_like() && !this->right->is_all_variables() && !sin_cast(this->right).get()) || Loading Loading @@ -2455,12 +2455,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -3406,12 +3406,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -4837,12 +4837,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading
graph_framework/math.hpp +25 −25 Original line number Diff line number Diff line Loading @@ -279,12 +279,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -546,12 +546,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -786,12 +786,12 @@ namespace graph { auto temp = std::make_shared<log_node<T, SAFE_MATH>> (x)->reduce(); // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1289,12 +1289,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1554,12 +1554,12 @@ namespace graph { // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading
graph_framework/node.hpp +22 −12 Original line number Diff line number Diff line Loading @@ -311,12 +311,22 @@ namespace graph { << std::endl; } /// Cache for constructed nodes. inline thread_local static std::map<size_t, std::shared_ptr<leaf_node<T, SAFE_MATH>>> cache; /// Cache for the backend buffers. inline thread_local static std::map<size_t, backend::buffer<T>> backend_cache; // Create one struct that holds both caches: for constructed nodes and for the backend buffers //------------------------------------------------------------------------------ /// @brief Data structure to contain the two caches. /// /// This a avoids an issue on gnu compilers where it would try to redefine the /// __tls_guard twice depending on the include order. //------------------------------------------------------------------------------ struct caches_t { /// Cache of node. std::map<size_t, std::shared_ptr<leaf_node<T, SAFE_MATH>>> nodes; /// Cache of backend buffers. std::map<size_t, backend::buffer<T>> backends; }; /// A per thread instance of the cache structure. inline static thread_local caches_t caches; /// Type def to retrieve the backend type. typedef T base; Loading Loading @@ -593,12 +603,12 @@ namespace graph { auto temp = std::make_shared<constant_node<T, SAFE_MATH>> (d); // Test for hash collisions. for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) { if (leaf_node<T, SAFE_MATH>::cache.find(i) == leaf_node<T, SAFE_MATH>::cache.end()) { leaf_node<T, SAFE_MATH>::cache[i] = temp; if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) == leaf_node<T, SAFE_MATH>::caches.nodes.end()) { leaf_node<T, SAFE_MATH>::caches.nodes[i] = temp; return temp; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::cache[i])) { return leaf_node<T, SAFE_MATH>::cache[i]; } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) { return leaf_node<T, SAFE_MATH>::caches.nodes[i]; } } #if defined(__clang__) || defined(__GNUC__) Loading Loading @@ -1368,7 +1378,7 @@ namespace graph { using input_nodes = std::vector<shared_variable<T, SAFE_MATH>>; /// Convenience type alias for maping end codes back to inputs. template<jit::float_scalar T, bool SAFE_MATH=false> using map_nodes = std::vector<std::pair<graph::shared_leaf<T, SAFE_MATH>, using map_nodes = std::vector<std::pair<shared_leaf<T, SAFE_MATH>, shared_variable<T, SAFE_MATH>>>; //------------------------------------------------------------------------------ Loading