Esempio n. 1
0
// returns the program cache for the context
inline boost::shared_ptr<program_cache> get_program_cache(const context &context)
{
    typedef lru_cache<cl_context, boost::shared_ptr<program_cache> > cache_map;

    static cache_map caches(8);

    boost::shared_ptr<program_cache> cache = caches.get(context.get());
    if(!cache){
        cache = boost::make_shared<program_cache>(64);

        caches.insert(context.get(), cache);
    }

    return cache;
}
Esempio n. 2
0
/** @returns true on a cache hit, false of a cache miss.  Reference
    value result only valid on a cache hit. */
bool CachingSolver::cacheLookup(const Query& query,
                                IncompleteSolver::PartialValidity &result) {
  bool negationUsed;
  ref<Expr> canonicalQuery = canonicalizeQuery(query.expr, negationUsed);

  CacheEntry ce(query.constraints, canonicalQuery);
  cache_map::iterator it = cache.find(ce);
  
  if (it != cache.end()) {
    result = (negationUsed ?
              IncompleteSolver::negatePartialValidity(it->second) :
              it->second);
    return true;
  }
  
  return false;
}
Esempio n. 3
0
			void insert(const cache_key_type &key, const cache_value_type &val)
			{
				// Record k as most-recently-used key 
				list_iterator it = list_.insert(list_.end(), key); 

				// Create the key-value entry, linked to the usage record. 
				map_.insert(std::make_pair(key, std::make_pair(val, it))); 
			}
Esempio n. 4
0
 Result Cache<Result(Args...)>::operator()(Args... args) {
     argument_tuple tup{args...};
     auto map_iter = map.find(tup);
     bool insert = map_iter == map.end();
     log.push_back(nullptr);
     ScopeFailure guard([&] { log.pop_back(); });
     if (insert)
         map_iter = map.insert({tup, {tuple_invoke(fun, tup), {}}}).first;
     log.back() = &map_iter->first;
     if (! insert)
         log.erase(map_iter->second.log_iter);
     map_iter->second.log_iter = std::prev(log.end());
     if (insert && map.size() > cap) {
         map.erase(*log.front());
         log.pop_front();
     }
     return map_iter->second.result;
 }
Esempio n. 5
0
/// Inserts the given query, result pair into the cache.
void CachingSolver::cacheInsert(const Query& query,
                                IncompleteSolver::PartialValidity result) {
  bool negationUsed;
  ref<Expr> canonicalQuery = canonicalizeQuery(query.expr, negationUsed);

  CacheEntry ce(query.constraints, canonicalQuery);
  IncompleteSolver::PartialValidity cachedResult = 
    (negationUsed ? IncompleteSolver::negatePartialValidity(result) : result);
  
  cache.insert(std::make_pair(ce, cachedResult));
}
Esempio n. 6
0
			// Purge the least-recently-used element in the cache 
			void evict() 
			{ 
				// Assert method is never called when cache is empty 
				assert(!list_.empty());
				if( list_.empty() )
					return;

				// Identify least recently used key 
				map_const_iterator it = map_.find(list_.front()); 
				assert(it != map_.end());
				if( it == map_.end() )
					return;

				if( it->second.first.second != 0 )
					it->second.first.second(list_.front(), it->second.first.first);

				// Erase both elements to completely purge record 
				map_.erase(it); 
				list_.pop_front();
			}
Esempio n. 7
0
 ~CachingSolver() { cache.clear(); delete solver; }
Esempio n. 8
0
 ~CachingSolver() { cache.clear(); unsat_core_store.clear(); delete solver; }
Esempio n. 9
0
			// 清空所有数据
			void clear()
			{
				list_.clear();
				map_.clear();
			}
Esempio n. 10
0
			std::pair<bool, map_iterator> exsit(const cache_key_type& k)
			{
				// Attempt to find existing record 
				map_iterator iter = map_.find(k);
				return std::make_pair(iter != map_.end(), iter); 
			}
Esempio n. 11
0
			map_const_iterator end() const
			{
				return map_.end();
			}
Esempio n. 12
0
			map_iterator end()
			{
				return map_.end();
			}
Esempio n. 13
0
			map_const_iterator begin() const
			{
				return map_.begin();
			}
Esempio n. 14
0
			map_iterator begin()
			{
				return map_.begin();
			}
Esempio n. 15
0
 /** Swap the content of two cache_map instances.
  *
  *  @param m1 a cache_map
  *  @param m2 another cache_map
  */
 friend inline void swap(
     cache_map<Key,T,HashFunction,KeyEqual,DiscardFunction,Allocator>& m1,
     cache_map<Key,T,HashFunction,KeyEqual,DiscardFunction,Allocator>& m2 )
 {
     m1.swap( m2 );
 }