-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the initial version of residency management logic
- Loading branch information
1 parent
22d1680
commit b6df248
Showing
6 changed files
with
664 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
set(DYAD_FCACHE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/fcache.cpp) | ||
set(DYAD_FCACHE_PRIVATE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../utils/murmur3.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_logging.h) | ||
set(DYAD_FCACHE_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/fcache.hpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/fcache_impl.hpp) | ||
|
||
|
||
add_library(${PROJECT_NAME}_fcache SHARED ${DYAD_FCACHE_SRC} | ||
${DYAD_FCACHE_PRIVATE_HEADERS} ${DYAD_FCACHE_PUBLIC_HEADERS}) | ||
set_target_properties(${PROJECT_NAME}_fcache PROPERTIES CMAKE_INSTALL_RPATH | ||
"${CMAKE_INSTALL_PREFIX}/${DYAD_LIBDIR}") | ||
|
||
if(DYAD_LOGGER STREQUAL "CPP_LOGGER") | ||
target_link_libraries(${PROJECT_NAME}_fcache PRIVATE ${CPP_LOGGER_LIBRARIES}) | ||
endif() | ||
if(DYAD_PROFILER STREQUAL "DLIO_PROFILER") | ||
target_link_libraries(${PROJECT_NAME}_fcache PRIVATE ${DLIO_PROFILER_LIBRARIES}) | ||
endif() | ||
|
||
target_compile_definitions(${PROJECT_NAME}_fcache PUBLIC DYAD_HAS_CONFIG) | ||
target_include_directories(${PROJECT_NAME}_fcache PUBLIC | ||
${Boost_INCLUDE_DIRS} | ||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src> | ||
$<INSTALL_INTERFACE:${DYAD_INSTALL_INCLUDE_DIR}>) | ||
|
||
add_executable(test_fcache test_fcache.cpp) | ||
target_compile_definitions(test_fcache PUBLIC DYAD_HAS_CONFIG) | ||
target_link_libraries(test_fcache PUBLIC ${PROJECT_NAME}_fcache) | ||
target_link_libraries(test_fcache PRIVATE ${PROJECT_NAME}_murmur3) | ||
|
||
if(DYAD_LOGGER STREQUAL "CPP_LOGGER") | ||
target_link_libraries(test_fcache PRIVATE ${CPP_LOGGER_LIBRARIES}) | ||
endif() | ||
if(DYAD_PROFILER STREQUAL "DLIO_PROFILER") | ||
target_link_libraries(test_cmp_fcache PRIVATE ${DLIO_PROFILER_LIBRARIES}) | ||
endif() | ||
|
||
|
||
if (TARGET DYAD_CXX_FLAGS_werror) | ||
target_link_libraries(${PROJECT_NAME}_fcache PRIVATE DYAD_CXX_FLAGS_werror) | ||
endif () | ||
|
||
install( | ||
TARGETS ${PROJECT_NAME}_fcache | ||
EXPORT ${DYAD_EXPORTED_TARGETS} | ||
LIBRARY DESTINATION ${DYAD_INSTALL_LIB_DIR} | ||
ARCHIVE DESTINATION ${DYAD_INSTALL_LIB_DIR} | ||
RUNTIME DESTINATION ${DYAD_INSTALL_BIN_DIR} | ||
) | ||
if(NOT "${DYAD_FCACHE_PUBLIC_HEADERS}" STREQUAL "") | ||
dyad_install_headers("${DYAD_FCACHE_PUBLIC_HEADERS}" ${CMAKE_CURRENT_SOURCE_DIR}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
#include <dyad/residency/fcache.hpp> | ||
#include <dyad/utils/murmur3.h> | ||
|
||
#define DYAD_UTIL_LOGGER | ||
#include <dyad/common/dyad_logging.h> | ||
|
||
|
||
namespace dyad_residency { | ||
|
||
//============================================================================= | ||
// Associative Cache Set | ||
//============================================================================= | ||
|
||
bool Set_LRU::lookup (const std::string& fname, id_iterator_t &it) | ||
{ | ||
id_idx_t& index_id = boost::multi_index::get<id> (m_block_set); | ||
it = index_id.find (fname); | ||
return (it != index_id.end ()); | ||
} | ||
|
||
void Set_LRU::evict (void) | ||
{ // LRU | ||
if (m_block_set.size () == 0) return; | ||
priority_idx_t& index_priority = boost::multi_index::get<priority> (m_block_set); | ||
priority_iterator_t it = index_priority.begin (); | ||
DYAD_LOG_INFO (NULL, " %s evicts %s from set %u\n", \ | ||
m_level.c_str (), it->m_id.c_str (), m_id); | ||
index_priority.erase (it); | ||
} | ||
|
||
void Set_LRU::load_and_access (const std::string& fname) | ||
{ | ||
m_num_miss++; | ||
|
||
DYAD_LOG_INFO (NULL, " %s adds %s to set %u\n", \ | ||
m_level.c_str (), fname.c_str (), m_id); | ||
if (m_size == m_block_set.size ()) { | ||
evict (); | ||
} | ||
|
||
m_block_set.insert (Simple_Block (fname)); | ||
m_seqno++; | ||
} | ||
|
||
void Set_LRU::access (id_iterator_t &it) | ||
{ | ||
Simple_Block blk = *it; | ||
m_block_set.erase (it); | ||
m_block_set.insert (blk); | ||
m_seqno++; | ||
} | ||
|
||
bool Set_LRU::access (const std::string& fname) | ||
{ | ||
id_iterator_t it; | ||
if (lookup (fname, it)) { // hit | ||
DYAD_LOG_INFO (NULL, " %s reuses %s from set %u\n", \ | ||
m_level.c_str (), fname.c_str (), m_id); | ||
access (it); | ||
return true; | ||
} else { // miss | ||
load_and_access (fname); | ||
return false; | ||
} | ||
} | ||
|
||
unsigned int Set_LRU::get_priority () | ||
{ | ||
return m_seqno; | ||
} | ||
|
||
std::ostream& Set_LRU::print (std::ostream &os) const | ||
{ | ||
os << "size : " << m_size << std::endl; | ||
os << "num accesses : " << m_seqno<< std::endl; | ||
os << "num misses : " << m_num_miss << std::endl; | ||
os << "blkId : " << std::endl; | ||
|
||
const priority_idx_t& index_priority = boost::multi_index::get<priority> (m_block_set); | ||
priority_citerator_t it = index_priority.begin (); | ||
priority_citerator_t itend = index_priority.end (); | ||
|
||
for (; it != itend; it++) { | ||
os << it->m_id << std::endl; | ||
} | ||
return os; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const Set_LRU & cc) | ||
{ | ||
return cc.print (os); | ||
} | ||
|
||
|
||
|
||
bool Set_Prioritized::lookup (const std::string& fname, id_iterator_t &it) | ||
{ | ||
id_idx_t& index_id = boost::multi_index::get<id> (m_block_set); | ||
it = index_id.find (fname); | ||
return (it != index_id.end ()); | ||
} | ||
|
||
void Set_Prioritized::evict (void) | ||
{ | ||
if (m_block_set.size () == 0) return; | ||
priority_idx_t& index_priority = boost::multi_index::get<priority> (m_block_set); | ||
priority_iterator_t it = index_priority.begin (); | ||
DYAD_LOG_INFO (NULL, " %s evicts %s from set %u\n", \ | ||
m_level.c_str (), it->m_id.c_str (), m_id); | ||
index_priority.erase (it); | ||
} | ||
|
||
void Set_Prioritized::load_and_access (const std::string& fname) | ||
{ | ||
m_num_miss++; | ||
|
||
DYAD_LOG_INFO (NULL, " %s adds %s to set %u\n", \ | ||
m_level.c_str (), fname.c_str (), m_id); | ||
if (m_size == m_block_set.size ()) { | ||
evict (); | ||
} | ||
|
||
m_block_set.insert (Ranked_Block (fname, get_priority ())); | ||
m_seqno++; | ||
} | ||
|
||
void Set_Prioritized::access (id_iterator_t &it) | ||
{ | ||
Ranked_Block blk = *it; | ||
// reassigning the priority | ||
blk.m_priority = get_priority (); | ||
m_block_set.erase (it); | ||
m_block_set.insert (blk); | ||
m_seqno++; | ||
} | ||
|
||
bool Set_Prioritized::access (const std::string& fname) | ||
{ | ||
id_iterator_t it; | ||
if (lookup (fname, it)) { // hit | ||
DYAD_LOG_INFO (NULL, " %s reuses %s from set %u\n", \ | ||
m_level.c_str (), fname.c_str (), m_id); | ||
access (it); | ||
return true; | ||
} else { // miss | ||
load_and_access (fname); | ||
return false; | ||
} | ||
} | ||
|
||
unsigned int Set_Prioritized::get_priority () | ||
{ | ||
return m_seqno; | ||
} | ||
|
||
std::ostream& Set_Prioritized::print (std::ostream &os) const | ||
{ | ||
os << "size : " << m_size << std::endl; | ||
os << "num accesses : " << m_seqno<< std::endl; | ||
os << "num misses : " << m_num_miss << std::endl; | ||
os << "priority blkId:" << std::endl; | ||
|
||
const priority_idx_t& index_priority = boost::multi_index::get<priority> (m_block_set); | ||
priority_citerator_t it = index_priority.begin (); | ||
priority_citerator_t itend = index_priority.end (); | ||
|
||
for (; it != itend; it++) { | ||
os << it->m_priority << ", " << it->m_id << std::endl; | ||
} | ||
return os; | ||
} | ||
|
||
} // end of namespace dyad_residency |
Oops, something went wrong.