Skip to content

Commit

Permalink
Add the initial version of residency management logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeseungYeom committed Feb 7, 2024
1 parent 22d1680 commit b6df248
Show file tree
Hide file tree
Showing 6 changed files with 664 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ include_directories(${CMAKE_SOURCE_DIR}/include) # public header
add_subdirectory(src/dyad)
#cmake_policy(SET CMP0079 NEW) # In case that we need more control over the target building order

if (DEFINED BOOST_ROOT)
message(STATUS "BOOST_ROOT: " ${BOOST_ROOT})
set(Boost_NO_SYSTEM_PATHS ON)
else ()
if (DEFINED ENV{BOOST_ROOT})
message(STATUS "ENV BOOST_ROOT: " $ENV{BOOST_ROOT})
set(Boost_NO_SYSTEM_PATHS ON)
endif ()
endif ()

# boost::multi_index is needed and is header-only
find_package(Boost
# HINTS ${BOOST_ROOT} $ENV{BOOST_ROOT}
REQUIRED COMPONENTS)
# regex filesystem system program_options)

message(STATUS "Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS})
message(STATUS "Boost_LIBRARY_DIRS: " ${Boost_LIBRARY_DIRS})


#-----------------------------------------------------------------------------
# Configure the config.cmake file for the build directory
Expand Down
52 changes: 52 additions & 0 deletions src/dyad/residency/CMakeLists.txt
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()
173 changes: 173 additions & 0 deletions src/dyad/residency/fcache.cpp
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
Loading

0 comments on commit b6df248

Please sign in to comment.