<commit_before>
// Copyright 2010-2012 University of Washington. All Rights Reserved.
// LICENSE_PLACEHOLDER
// This software was created with Government support under DE
// AC05-76RL01830 awarded by the United States Department of
// Energy. The Government has certain rights in the software.


#ifndef __RDMAAGGREGATOR_HPP__
#define __RDMAAGGREGATOR_HPP__

#include <gflags/gflags.h>
#include <glog/logging.h>

#include "Communicator.hpp"
#include "Worker.hpp"
#include "tasks/TaskingScheduler.hpp"
#include "Tasking.hpp"
#include "Addressing.hpp"
//#include "PerformanceTools.hpp"

#include "LocaleSharedMemory.hpp"

#include "MessageBase.hpp"
#include "RDMABuffer.hpp"

#include "ConditionVariableLocal.hpp"
#include "CountingSemaphoreLocal.hpp"
#include "FullEmpty.hpp"

#include "ReusePool.hpp"
#include "ReuseList.hpp"

#include "Statistics.hpp"

// #include <boost/interprocess/containers/vector.hpp>

DECLARE_int64( target_size );
DECLARE_int64( aggregator_autoflush_ticks );

/// stats for application messages
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, app_messages_enqueue );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, app_messages_enqueue_cas );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, app_messages_immediate );

/// stats for RDMA Aggregator events
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_capacity_flushes );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_requested_flushes );

GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_send );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_receive );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_send_success );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_receive_success );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_yields );

GRAPPA_DECLARE_STAT( SummarizingStatistic<double>, rdma_local_delivery_time );

extern double tick_rate;


namespace Grappa {

  typedef Node Core;

  /// Internal messaging functions
  namespace impl {

    /// @addtogroup Communication
    /// @{

    class MessageBase;

    /// global aggregator instance
    class RDMAAggregator;
    extern Grappa::impl::RDMAAggregator global_rdma_aggregator;


    struct MessageList {
      union {
        struct {
          unsigned count_ : 16;
          intptr_t pointer_ : 48;
        };
        intptr_t raw_; // unnecessary; just to ensure alignment
      };
    };
    
    struct PrefetchEntry {
      union {
        struct {
          unsigned size_ : 16;
          intptr_t pointer_ : 48;
        };
        intptr_t raw_; // unnecessary; just to ensure alignment
      };
    };

    /// used to start deaggregation of remote message
    struct SendBufferInfo {
      int8_t offset;
      int32_t actual_size;
    };

    /// refers to a buffer on the remote machine
    struct ReceiveBufferInfo {
      char * buffer;
      FullEmpty< SendBufferInfo > * info_ptr;
    };



    /// accesor for pointer in message lists
    template< typename MessageListOrPrefetchEntry >
    static inline Grappa::impl::MessageBase * get_pointer( MessageListOrPrefetchEntry * ml ) { 
      return reinterpret_cast< Grappa::impl::MessageBase * >( ml->pointer_ );
    }

    /// accesor for wait list in synchronization object
    template< typename MessageListOrPrefetchEntry >
    static inline void set_pointer( MessageListOrPrefetchEntry * ml, Grappa::impl::MessageBase * m ) { 
      ml->pointer_ = reinterpret_cast< intptr_t >( m ); 
    }

    static const int prefetch_dist = 4;
    static const int prefetch_type = 3; // 0 (non-temporal) or 3 (L1) are probably the best choice
    static const int remote_buffer_pool_size = 6;

    struct CoreData {
      // things that must be included per core:
      //
      // pointer to message list
      // size of message list
      // index into prefetch queue
      //
      // prefetch queue
      //<commit_msg>update prefetch distance and type for better performance<commit_after>
// Copyright 2010-2012 University of Washington. All Rights Reserved.
// LICENSE_PLACEHOLDER
// This software was created with Government support under DE
// AC05-76RL01830 awarded by the United States Department of
// Energy. The Government has certain rights in the software.


#ifndef __RDMAAGGREGATOR_HPP__
#define __RDMAAGGREGATOR_HPP__

#include <gflags/gflags.h>
#include <glog/logging.h>

#include "Communicator.hpp"
#include "Worker.hpp"
#include "tasks/TaskingScheduler.hpp"
#include "Tasking.hpp"
#include "Addressing.hpp"
//#include "PerformanceTools.hpp"

#include "LocaleSharedMemory.hpp"

#include "MessageBase.hpp"
#include "RDMABuffer.hpp"

#include "ConditionVariableLocal.hpp"
#include "CountingSemaphoreLocal.hpp"
#include "FullEmpty.hpp"

#include "ReusePool.hpp"
#include "ReuseList.hpp"

#include "Statistics.hpp"

// #include <boost/interprocess/containers/vector.hpp>

DECLARE_int64( target_size );
DECLARE_int64( aggregator_autoflush_ticks );

/// stats for application messages
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, app_messages_enqueue );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, app_messages_enqueue_cas );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, app_messages_immediate );

/// stats for RDMA Aggregator events
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_capacity_flushes );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_requested_flushes );

GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_send );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_receive );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_send_success );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_receive_success );
GRAPPA_DECLARE_STAT( SimpleStatistic<int64_t>, rdma_poll_yields );

GRAPPA_DECLARE_STAT( SummarizingStatistic<double>, rdma_local_delivery_time );

extern double tick_rate;


namespace Grappa {

  typedef Node Core;

  /// Internal messaging functions
  namespace impl {

    /// @addtogroup Communication
    /// @{

    class MessageBase;

    /// global aggregator instance
    class RDMAAggregator;
    extern Grappa::impl::RDMAAggregator global_rdma_aggregator;


    struct MessageList {
      union {
        struct {
          unsigned count_ : 16;
          intptr_t pointer_ : 48;
        };
        intptr_t raw_; // unnecessary; just to ensure alignment
      };
    };
    
    struct PrefetchEntry {
      union {
        struct {
          unsigned size_ : 16;
          intptr_t pointer_ : 48;
        };
        intptr_t raw_; // unnecessary; just to ensure alignment
      };
    };

    /// used to start deaggregation of remote message
    struct SendBufferInfo {
      int8_t offset;
      int32_t actual_size;
    };

    /// refers to a buffer on the remote machine
    struct ReceiveBufferInfo {
      char * buffer;
      FullEmpty< SendBufferInfo > * info_ptr;
    };



    /// accesor for pointer in message lists
    template< typename MessageListOrPrefetchEntry >
    static inline Grappa::impl::MessageBase * get_pointer( MessageListOrPrefetchEntry * ml ) { 
      return reinterpret_cast< Grappa::impl::MessageBase * >( ml->pointer_ );
    }

    /// accesor for wait list in synchronization object
    template< typename MessageListOrPrefetchEntry >
    static inline void set_pointer( MessageListOrPrefetchEntry * ml, Grappa::impl::MessageBase * m ) { 
      ml->pointer_ = reinterpret_cast< intptr_t >( m ); 
    }

    static const int prefetch_dist = 6;
    static const int prefetch_type = 0; // 0 (non-temporal) or 3 (L1) are probably the best choice
    static const int remote_buffer_pool_size = 6;

    struct CoreData {
      // things that must be included per core:
      //
      // pointer to message list
      // size of message list
      // index into prefetch queue
      //
      // prefetch queue
      //
{'fraction_non_alphanumeric': 0.08816470885436403, 'fraction_numerical': 0.015157256536566882, 'mean_word_length': 3.6741440377804016, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4119466', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2412, 'n_words': 609}