Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions omnn/math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -28,18 +30,18 @@ if(NOT WIN32)
set(DEPENDENCIES ${DEPENDENCIES} boost_thread boost_serialization boost_system)
endif()

lib(${DEPENDENCIES})

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this lib function declares new library project with dependencies enumerated in params (${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 ()
146 changes: 146 additions & 0 deletions omnn/math/CacheFDBtry3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#pragma once



#ifdef OPENMIND_MATH_USE_FOUNDATIONDB_CACHE

#include <foundationdb/fdb_c.h>

#include <free_fdb/ffdb.h>

#else

namespace fdb_cli{
class FDB;
}
#endif


//#include <filesystem>
//#include <future>
#include <memory>
#include <string>

#include <boost/filesystem.hpp>
#include "Variable.h"

namespace omnn::math {

namespace bi = boost::intrusive;

class EvictablePage
{
public:
using path_str_t = bi::path
using CheckCacheResult = std::pair<bool,Valuable>;

template < typename pageCache>

class Reference : public EvictablePageCache ::future<pageCache> {
using base = std::future<pageCache>;//creo que lo de abajo es lo mismo

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public:

virtual bool evict() = 0; // evic=extracted


//EvictablePage(Reference<EvictablePageCache> 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<EvictablePageCache>
{
using List =
bi::list<EvictablePage, bi::path<EvictablePage, bi::future<>, &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<bool,val_set_t>;






class CachedSet : public ReferenceCounted <CheckCachedSet> {
using base = ReferenceCounted <CheckCachedSet>;
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<Reference<IAsyncFile>> 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&amp; path);
~Cachefdb();
110 changes: 110 additions & 0 deletions omnn/math/CachefdbTRY2.h
Original file line number Diff line number Diff line change
@@ -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 <foundationdb/fdb_c.h>

#include <free_fdb/ffdb.hh>
//copy and paste files into other files

#else

namespace fdb_cli{
class FDB;
}
#endif



//#include <filesystem>
#include <future>
#include <memory>
#include <string>

#include <boost/filesystem.hpp>
//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<bool,Valuable>;

template <typename ResultT_fdb>

class Cached_fdb_ValueBase : public std::future<ResultT_fdb> {
using base_fdb = std::future<ResultT_fdb>;
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<CheckCache_fdb_Result> {
using base = Cached_fdb_ValueBase<CheckCache_fdb_Result>;
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<bool,val_set_t>;

class Cached_fdb_Set : public Cached_fdb_ValueBase<CheckCached_fdb_Set> {
using base = Cached_fdb_ValueBase<CheckCached_fdb_Set>;
public:
using base::base;
using base::operator bool;
// CachedSet_fdb(base&& b);
operator val_set_t();
};