diff --git a/omnn/math/CMakeLists.txt b/omnn/math/CMakeLists.txt index e87d70db08..5776c5f2fb 100644 --- a/omnn/math/CMakeLists.txt +++ b/omnn/math/CMakeLists.txt @@ -1,3 +1,5 @@ +project(math) +cmake_minimum_required(VERSION 3.20) option(OPENMIND_MATH_USE_LEVELDB_CACHE "Use Google LevelDB library to cache solutions" TRUE) if(OPENMIND_MATH_USE_LEVELDB_CACHE) @@ -28,18 +30,18 @@ if(NOT WIN32) set(DEPENDENCIES ${DEPENDENCIES} boost_thread boost_serialization boost_system) endif() -lib(${DEPENDENCIES}) +link_libraries(${DEPENDENCIES}) -if (OPENMIND_USE_OPENCL) - target_include_directories(${this_target} PUBLIC - ${OpenCL_INCLUDE_DIR} - ) -endif() +if (OPENMIND_USE_OPENCL) + target_include_directories(${this_target} PUBLIC + ${OpenCL_INCLUDE_DIR} + ) +endif() -if (OPENMIND_BUILD_TESTS) +if (OPENMIND_BUILD_TESTS) add_subdirectory(test) endif () -if (OPENMIND_BUILD_3RD_PARTY_TESTS) +if (OPENMIND_BUILD_3RD_PARTY_TESTS) add_subdirectory(3rdPartyTests) endif () diff --git a/omnn/math/CacheFDBtry3.h b/omnn/math/CacheFDBtry3.h new file mode 100644 index 0000000000..c3479dedff --- /dev/null +++ b/omnn/math/CacheFDBtry3.h @@ -0,0 +1,146 @@ +#pragma once + + + +#ifdef OPENMIND_MATH_USE_FOUNDATIONDB_CACHE + +#include + +#include + +#else + +namespace fdb_cli{ + class FDB; +} +#endif + + +//#include +//#include +#include +#include + +#include +#include "Variable.h" + +namespace omnn::math { + +namespace bi = boost::intrusive; + +class EvictablePage + { + public: + using path_str_t = bi::path + using CheckCacheResult = std::pair; + + template < typename pageCache> + + class Reference : public EvictablePageCache ::future { + using base = std::future;//creo que lo de abajo es lo mismo + virtual bool evict() = 0; // evic=extracted + + + //EvictablePage(Reference pageCache) : pageCache(pageCache) {} + // virtual ~EvictablePage(); + } + + + protected: + pageCache& Get() { + evict()//Extract(); + return pageCache; + } + + + public: + using bi::bi; + + Reference (bi&& b) : bi(std::move(b)) + {} + + operator bool(){ + return (evict || + ( bi::valid() + && bi::wait_for(std::chrono::seconds(0)) == std::future_status::ready + )) && Get().first + ; + } + + bool NotInCache(){ + return (evict || + ( bi::valid() + && bi::wait_for(std::chrono::seconds(0)) == std::future_status::ready + )) && !Get().first; + } + }; + +class EvictablePageCache : public ReferenceCounted + { + using List = + bi::list, &EvictablePage::path>>; + + public: + using bi::bi; + using bi::operator bool; +// EvictablePageCache (bi&& b); + operator Valuable(); + }; + + using val_set_t = Valuable::solutions_t; + using CheckCachedSet = std::pair; + + + + + + + class CachedSet : public ReferenceCounted { + using base = ReferenceCounted ; + public: + using bi::bi; + using bi::operator bool; +// CachedSet(bi&& b); + operator val_set_t(); + }; + + private: + fdb_cli::FDB* fdb_c = nullptr; + path_str_t path; + + + + // Opens a file that uses the FDB in-memory page cache + static Future> open(std::string filename, int flags, int mode) { + //TraceEvent("AsyncFileCachedOpen").detail("Filename", filename); + auto itr = openFiles.find(filename); + if (itr == openFiles.end()) { + auto f = open_impl(filename, flags, mode); + if (f.isReady() && f.isError()) + return f; + + auto result = openFiles.try_emplace(filename, f); + + // This should be inserting a new entry + ASSERT(result.second); + itr = result.first; + + // We return here instead of falling through to the outer scope so that we don't delete all references to + // the underlying file before returning + return itr->second.get(); + } + return itr->second.get(); + } + + + void DbOpen(); + protected: + std::string Value(const std::string& key); + + public: + Cachefdb(const path_str_t& path); + ~Cachefdb(); + + public: + Cachefdb(const path_str_t& path); + ~Cachefdb(); diff --git a/omnn/math/CachefdbTRY2.h b/omnn/math/CachefdbTRY2.h new file mode 100644 index 0000000000..8fed4d1a43 --- /dev/null +++ b/omnn/math/CachefdbTRY2.h @@ -0,0 +1,110 @@ +#pragma once +//pragma says include the file once + + +#ifdef OPENMIND_MATH_USE_FOUNDATIONDB_CACHE +//check the following function is defined + + +#include + +#include +//copy and paste files into other files + +#else + +namespace fdb_cli{ +class FDB; +} +#endif + + + +//#include +#include +#include +#include + +#include +//definition and implementation are in the same file, .hpp calls a class + +#include "Variable.h" + +namespace omnn::math { + +namespace fs = boost::filesystem; + + class Cachefdb + { + public: + using path_str_t_fdb = fs::path; + + using CheckCache_fdb_Result = std::pair; + + template + + class Cached_fdb_ValueBase : public std::future { + using base_fdb = std::future; + ResultT_fdb result_fdb = {}; + bool extracted_fdb = {}; + void Extract_fdb() { + if(!extracted_fdb){ + extracted_fdb = true; + result_fdb = base::get(); //class base method get + } + } + protected: //once it's gotten the value becomes protected i.e. only member of class' functions can access to it + //but it cannot be accesed from other classes + ResultT_fdb& Get() { + Extract_fdb(); + return result_fdb; + } + public: + using base::base; + + Cached_fdb_ValueBase(base&& b) : base(std::move(b)) + {} + + operator bool(){ + return (extracted_fdb || + ( base::valid_fdb() + && base::wait_for(std::chrono::seconds(0)) == std::future_status::ready + )) && Get().first + ; + } + + bool NotInCache_fdb(){ + return (extracted_fdb || + ( base::valid_fdb() + && base::wait_for(std::chrono::seconds(0)) == std::future_status::ready + )) && !Get().first; + } + }; + + class Cached_fdb : public Cached_fdb_ValueBase { + using base = Cached_fdb_ValueBase; + public: + using base::base; + using base::operator bool; +// Cached_fdb(base&& b); + operator Valuable_fdb(); + }; + + using val_set_t_fdb = Valuable::solutions_t; + using CheckCached_fdb_Set = std::pair; + + class Cached_fdb_Set : public Cached_fdb_ValueBase { + using base = Cached_fdb_ValueBase; + public: + using base::base; + using base::operator bool; +// CachedSet_fdb(base&& b); + operator val_set_t(); + }; + + + + + + + \ No newline at end of file