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

Residency2 #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
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()
260 changes: 260 additions & 0 deletions src/dyad/residency/fcache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
#include <dyad/residency/fcache.hpp>
#include <dyad/utils/murmur3.h>
#include <typeinfo>
#include <iostream>

#define DYAD_UTIL_LOGGER
#include <dyad/common/dyad_logging.h>


namespace dyad_residency {

std::string id_str (const std::string& id)
{
return id;
}

template <typename T>
std::string id_str (const T& id)
{
using namespace std;
return to_string (id);
}


//=============================================================================
// Associative Cache Set
//=============================================================================

template <typename IDT>
bool Set_LRU<IDT>::lookup (const IDT& 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 ());
}

template <typename IDT>
void Set_LRU<IDT>::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 (), id_str (it->m_id).c_str (), m_id);
index_priority.erase (it);
}

template <typename IDT>
void Set_LRU<IDT>::load_and_access (const IDT& fname)
{
m_num_miss++;

DYAD_LOG_INFO (NULL, " %s adds %s to set %u\n", \
m_level.c_str (), id_str (fname).c_str (), m_id);
if (m_size == m_block_set.size ()) {
evict ();
}

m_block_set.insert (Simple_Block<IDT> (fname));
m_seqno++;
}

template <typename IDT>
void Set_LRU<IDT>::access (id_iterator_t &it)
{
Simple_Block<IDT> blk = *it;
m_block_set.erase (it);
m_block_set.insert (blk);
m_seqno++;
}

template <typename IDT>
bool Set_LRU<IDT>::access (const IDT& 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 (), id_str (fname).c_str (), m_id);
access (it);
return true;
} else { // miss
load_and_access (fname);
return false;
}
}

template <typename IDT>
unsigned int Set_LRU<IDT>::get_priority (unsigned int)
{
return m_seqno;
}

template <typename IDT>
std::ostream& Set_LRU<IDT>::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;
}

template <typename IDT>
std::ostream& operator<<(std::ostream& os, const Set_LRU<IDT>& cc)
{
return cc.print (os);
}



template <typename IDT, typename PRT>
bool Set_Prioritized<IDT, PRT>::lookup (const IDT& 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 ());
}

template <typename IDT, typename PRT>
void Set_Prioritized<IDT, PRT>::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 (), id_str (it->m_id).c_str (), m_id);
index_priority.erase (it);
}

template <typename IDT, typename PRT>
void Set_Prioritized<IDT, PRT>::load_and_access (const IDT& fname)
{
m_num_miss++;

DYAD_LOG_INFO (NULL, " %s adds %s to set %u\n", \
m_level.c_str (), id_str (fname).c_str (), m_id);
if (m_size == m_block_set.size ()) {
evict ();
}

m_block_set.insert (Ranked_Block<IDT, PRT> (fname, get_priority (PRT ())));
m_seqno++;
}

template <typename IDT, typename PRT>
void Set_Prioritized<IDT, PRT>::access (id_iterator_t &it)
{
Ranked_Block<IDT, PRT> blk = *it;
// reassigning the priority
blk.m_priority = get_priority (PRT ());
m_block_set.erase (it);
m_block_set.insert (blk);
m_seqno++;
}

template <typename IDT, typename PRT>
bool Set_Prioritized<IDT, PRT>::access (const IDT& 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 (), id_str (fname).c_str (), m_id);
access (it);
return true;
} else { // miss
load_and_access (fname);
return false;
}
}

template <typename IDT, typename PRT>
PRT Set_Prioritized<IDT, PRT>::get_priority (PRT)
{
return m_seqno;
}

template <typename IDT, typename PRT>
std::ostream& Set_Prioritized<IDT, PRT>::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;
}

template <typename IDT, typename PRT>
std::ostream& operator<<(std::ostream& os, const Set_Prioritized<IDT, PRT>& cc)
{
return cc.print (os);
}


namespace {
template <typename T>
void __attribute__ ((unused)) instantiate_LRU ()
{
Set_LRU<T> set_lru (1u, 1u, 0u);
T id;
set_lru.size ();
set_lru.get_num_access ();
set_lru.get_num_miss ();
set_lru.reset_cnts ();
set_lru.get_level ();
set_lru.set_level ("na");
set_lru.access (id);
set_lru.print (std::cout);
std::cout << set_lru;
}

template <typename T, typename P>
void __attribute__ ((unused)) instantiate_Prioritized ()
{
Set_Prioritized<T, P> set_prt (1u, 1u, 0u);
T id;
set_prt.size ();
set_prt.get_num_access ();
set_prt.get_num_miss ();
set_prt.reset_cnts ();
set_prt.get_level ();
set_prt.set_level ("na");
set_prt.access (id);
set_prt.print (std::cout);
std::cout << set_prt;
}

void __attribute__ ((unused)) instantiate_all ()
{
instantiate_LRU<unsigned int> ();
instantiate_LRU<int> ();
instantiate_LRU<std::string> ();

instantiate_Prioritized<unsigned int, unsigned> ();
instantiate_Prioritized<int, unsigned> ();
instantiate_Prioritized<std::string, unsigned> ();

instantiate_Prioritized<unsigned int, float> ();
instantiate_Prioritized<int, float> ();
instantiate_Prioritized<std::string, float> ();
}

} // end of namespace

} // end of namespace dyad_residency
Loading
Loading