<commit_before>#include "config.h"

#include "network_model.h"
#include "network_model_analytical_params.h"
#include "network_types.h"
#include "packet_type.h"
#include "simulator.h"

#include <sstream>
#include "log.h"

#define DEBUG

UInt32 Config::m_knob_total_cores;
UInt32 Config::m_knob_num_process;
bool Config::m_knob_simarch_has_shared_mem;
std::string Config::m_knob_output_file;
bool Config::m_knob_enable_performance_modeling;
bool Config::m_knob_enable_dcache_modeling;
bool Config::m_knob_enable_icache_modeling;

UInt32 Config::m_knob_dir_max_sharers;
UInt32 Config::m_knob_cache_line_size;
UInt32 Config::m_knob_ahl_param;

using namespace std;

Config *Config::m_singleton;

Config *Config::getSingleton()
{
   assert(m_singleton != NULL);
   return m_singleton;
}

Config::Config()
      :
        m_current_process_num((UInt32)-1)
{

   try
   {
   m_knob_total_cores = Sim()->getCfg()->getInt("general/total_cores");
   m_knob_num_process = Sim()->getCfg()->getInt("general/num_processes");
   m_knob_simarch_has_shared_mem = Sim()->getCfg()->getBool("general/enable_shared_mem");
   m_knob_output_file = Sim()->getCfg()->getString("general/output_file");
   m_knob_enable_performance_modeling = Sim()->getCfg()->getBool("general/enable_performance_modeling");
   m_knob_enable_dcache_modeling = Sim()->getCfg()->getBool("general/enable_dcache_modeling");
   m_knob_enable_icache_modeling = Sim()->getCfg()->getBool("general/enable_icache_modeling");

   m_knob_dir_max_sharers = Sim()->getCfg()->getInt("dram/max_sharers");
   m_knob_cache_line_size = Sim()->getCfg()->getInt("ocache/line_size");
   m_knob_ahl_param = Sim()->getCfg()->getInt("dram/ahl_param");
   }
   catch(...)
   {
      LOG_PRINT_ERROR("Config obtained a bad value from config.");
   }

   m_num_processes = m_knob_num_process;
   m_total_cores = m_knob_total_cores;

   m_singleton = this;

   assert(m_num_processes > 0);
   assert(m_total_cores > 0);

   // Add one for the MCP
   m_total_cores += 1;

   GenerateCoreMap();

   // Create network parameters
   m_analytic_network_parms = new NetworkModelAnalyticalParameters();
   m_analytic_network_parms->Tw2 = 1; // single cycle between nodes in 2d mesh
   m_analytic_network_parms->s = 1; // single cycle switching time
   m_analytic_network_parms->n = 1; // 2-d mesh network
   m_analytic_network_parms->W = 32; // 32-bit wide channels
   m_analytic_network_parms->update_interval = 100000;
   m_analytic_network_parms->proc_cost = 100;

}

Config::~Config()
{
   // Clean up the dynamic memory we allocated
   delete m_analytic_network_parms;
   delete [] m_proc_to_core_list_map;
}

void Config::GenerateCoreMap()
{
   m_proc_to_core_list_map = new CoreList[m_num_processes];
   m_core_to_proc_map.resize(m_total_cores);

   // Stripe the cores across the processes
   UInt32 current_proc = 0;
   for (UInt32 i=0; i < m_total_cores - 1; i++)
   {
      m_core_to_proc_map[i] = current_proc;
      m_proc_to_core_list_map[current_proc].push_back(i);
      current_proc++;
      current_proc %= m_num_processes;
   }

   // Add one for the MCP
   m_proc_to_core_list_map[0].push_back(m_total_cores - 1);
   m_core_to_proc_map[m_total_cores - 1] = 0;
}

void Config::logCoreMap()
{
   // Log the map we just created
   LOG_PRINT("Process num: %d\n", m_num_processes);
   for (UInt32 i=0; i < m_num_processes; i++)
   {
      stringstream ss;
      ss << "Process " << i << ": (" << m_proc_to_core_list_map[i].size() << ") ";
      for (CLCI m = m_proc_to_core_list_map[i].begin(); m != m_proc_to_core_list_map[i].end(); m++)
         ss << "[" << *m << "]";
      LOG_PRINT(ss.str().c_str());
   }
}

// Parse XML config file and use it to fill in config state.  Only modifies
// fields specified in the config file.  Therefore, this method can be used
// to override only the specific options given in the file.
void Config::loadFromFile(char* filename)
{
   return;
}

// Fill in config state from command-line arguments.  Only modifies fields
// specified on the command line.  Therefore, this method can be used to
// override only the specific options given.
void Config::loadFromCmdLine()
{
   return;
}

bool Config::isSimulatingSharedMemory() const
{
   return (bool)m_knob_simarch_has_shared_mem;
}

bool Config::getEnablePerformanceModeling() const
{<commit_msg>[config] Check that each process is assigned a core during initialization.<commit_after>#include "config.h"

#include "network_model.h"
#include "network_model_analytical_params.h"
#include "network_types.h"
#include "packet_type.h"
#include "simulator.h"

#include <sstream>
#include "log.h"

#define DEBUG

UInt32 Config::m_knob_total_cores;
UInt32 Config::m_knob_num_process;
bool Config::m_knob_simarch_has_shared_mem;
std::string Config::m_knob_output_file;
bool Config::m_knob_enable_performance_modeling;
bool Config::m_knob_enable_dcache_modeling;
bool Config::m_knob_enable_icache_modeling;

UInt32 Config::m_knob_dir_max_sharers;
UInt32 Config::m_knob_cache_line_size;
UInt32 Config::m_knob_ahl_param;

using namespace std;

Config *Config::m_singleton;

Config *Config::getSingleton()
{
   assert(m_singleton != NULL);
   return m_singleton;
}

Config::Config()
      :
        m_current_process_num((UInt32)-1)
{

   try
   {
   m_knob_total_cores = Sim()->getCfg()->getInt("general/total_cores");
   m_knob_num_process = Sim()->getCfg()->getInt("general/num_processes");
   m_knob_simarch_has_shared_mem = Sim()->getCfg()->getBool("general/enable_shared_mem");
   m_knob_output_file = Sim()->getCfg()->getString("general/output_file");
   m_knob_enable_performance_modeling = Sim()->getCfg()->getBool("general/enable_performance_modeling");
   m_knob_enable_dcache_modeling = Sim()->getCfg()->getBool("general/enable_dcache_modeling");
   m_knob_enable_icache_modeling = Sim()->getCfg()->getBool("general/enable_icache_modeling");

   m_knob_dir_max_sharers = Sim()->getCfg()->getInt("dram/max_sharers");
   m_knob_cache_line_size = Sim()->getCfg()->getInt("ocache/line_size");
   m_knob_ahl_param = Sim()->getCfg()->getInt("dram/ahl_param");
   }
   catch(...)
   {
      LOG_PRINT_ERROR("Config obtained a bad value from config.");
   }

   m_num_processes = m_knob_num_process;
   m_total_cores = m_knob_total_cores;

   m_singleton = this;

   assert(m_num_processes > 0);
   assert(m_total_cores > 0);

   // Add one for the MCP
   m_total_cores += 1;

   GenerateCoreMap();

   // Create network parameters
   m_analytic_network_parms = new NetworkModelAnalyticalParameters();
   m_analytic_network_parms->Tw2 = 1; // single cycle between nodes in 2d mesh
   m_analytic_network_parms->s = 1; // single cycle switching time
   m_analytic_network_parms->n = 1; // 2-d mesh network
   m_analytic_network_parms->W = 32; // 32-bit wide channels
   m_analytic_network_parms->update_interval = 100000;
   m_analytic_network_parms->proc_cost = 100;

}

Config::~Config()
{
   // Clean up the dynamic memory we allocated
   delete m_analytic_network_parms;
   delete [] m_proc_to_core_list_map;
}

void Config::GenerateCoreMap()
{
   m_proc_to_core_list_map = new CoreList[m_num_processes];
   m_core_to_proc_map.resize(m_total_cores);

   // Stripe the cores across the processes
   UInt32 current_proc = 0;
   for (UInt32 i=0; i < m_total_cores - 1; i++)
   {
      m_core_to_proc_map[i] = current_proc;
      m_proc_to_core_list_map[current_proc].push_back(i);
      current_proc++;
      current_proc %= m_num_processes;
   }

   // Add one for the MCP
   m_proc_to_core_list_map[0].push_back(m_total_cores - 1);
   m_core_to_proc_map[m_total_cores - 1] = 0;
}

void Config::logCoreMap()
{
   // Log the map we just created
   LOG_PRINT("Process num: %d\n", m_num_processes);
   for (UInt32 i=0; i < m_num_processes; i++)
   {
      LOG_ASSERT_ERROR(!m_proc_to_core_list_map[i].empty(),
                       "Process %u assigned zero cores.", i);

      stringstream ss;
      ss << "Process " << i << ": (" << m_proc_to_core_list_map[i].size() << ") ";
      for (CLCI m = m_proc_to_core_list_map[i].begin(); m != m_proc_to_core_list_map[i].end(); m++)
         ss << "[" << *m << "]";
      LOG_PRINT(ss.str().c_str());
   }
}

// Parse XML config file and use it to fill in config state.  Only modifies
// fields specified in the config file.  Therefore, this method can be used
// to override only the specific options given in the file.
void Config::loadFromFile(char* filename)
{
   return;
}

// Fill in config state from command-line arguments.  Only modifies fields
// specified on the command line.  Therefore, this method can be used to
// override only the specific options given.
void Config::loadFromCmdLine()
{
   return;
}

bool Config::isSimulatingSharedMemory() const
{
   return (bool)m_knob_simarch_has_shared_mem;
}

bool Config::getEnablePerformanceModeling() const
{
{'fraction_non_alphanumeric': 0.12463176977113075, 'fraction_numerical': 0.011103557670518922, 'mean_word_length': 4.597336715282181, 'pattern_counts': {'":': 2, '<': 41, '<?xml version=': 0, '>': 61, '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': '5963867', 'n_tokens_mistral': 3270, 'n_tokens_neox': 3105, 'n_words': 609}