Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Residency #101

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion .github/workflows/compile_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
lz4 \
pkgconf \
libzmq5 \
sqlite
sqlite \
libboost-all-dev
sudo pip install jsonschema cffi ply pyyaml
sudo chmod 777 /usr -R
- name: Install Spack
Expand Down Expand Up @@ -195,6 +196,11 @@ jobs:
externals:
- spec: "[email protected]"
prefix: /usr
boost:
buildable: False
externals:
- spec: "[email protected]"
prefix: /usr
gcc:
externals:
- spec: gcc@${GCC_VERSION} languages=c,c++
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,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
1 change: 1 addition & 0 deletions src/dyad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_subdirectory(core)
add_subdirectory(modules)
add_subdirectory(wrapper)
add_subdirectory(stream)
add_subdirectory(residency)

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()
205 changes: 205 additions & 0 deletions src/dyad/residency/fcache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#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
//=============================================================================

// -------------------------- LRU ------------------------
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);
if (!index_priority.empty ()) {
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);
}

// -------------------------- MRU ------------------------
void Set_MRU::evict (void)
{ // MRU
if (m_block_set.size () == 0) return;
priority_idx_t& index_priority = boost::multi_index::get<priority> (m_block_set);
if (!index_priority.empty ()) {
auto it = index_priority.end (); --it;
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);
}
}

bool Set_MRU::access (const std::string& fname)
{
return Set_LRU::access (fname);
}

std::ostream& operator<<(std::ostream& os, const Set_MRU & cc)
{
return cc.print (os);
}



// -------------------------- Prioritied ------------------------
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;
}

std::ostream& operator<<(std::ostream& os, const Set_Prioritized& cc)
{
return cc.print (os);
}

} // end of namespace dyad_residency
Loading
Loading