Skip to content

Conversation

@dj-jayu
Copy link
Member

@dj-jayu dj-jayu commented Nov 18, 2025

Replaces hardcoded / compile-time tuning options with runtime-configurable parameters managed by a Config singleton and exposed via CLI options. Users can now adjust behavior without recompiling gs_patterns.

Key changes

  • Add Config system (config.h/.cpp) to:

    • Parse CLI options.

    • Provide getters for all most parameters (buffer sizes, thresholds, limits, etc.).

  • Extract error classes into errors.h to avoid circular includes and clean up gs_patterns.h.

  • Update CMakeLists.txt to include config.* and errors.h.

  • Rework gs_patterns_main.cpp to use Config::parseArgs() and Config getters instead of manual argument parsing.

  • Replace compile-time constants in core logic (gs_patterns_core., gspin_patterns., gsnv_patterns.*) with:

    • Runtime parameters like per_sample, trace_buffer_size, max_gather_scatter, top_patterns, thresholds, and max_line_length.
  • Dynamic heap allocations (std::unique_ptr / std::vector) instead of fixed-size stack allocated arrays, by necessity.

  • Add parameterized constructors for MemPatternsForPin and MemPatternsForNV that take configuration values from Config, enabling per-run tuning.

  • Add TUNING_PARAMETERS.md documenting all new CLI flags, defaults, ranges, and usage examples for Pin/DynamoRIO and NVBit.

  • Backwards compatibility

    • Config defaults match the old hardcoded constants, so behavior is unchanged if no new flags are provided.

    • Existing CLI forms still work; this PR only adds optional parameters.

dj-jayu and others added 13 commits November 17, 2025 23:56
…ular dependency with #includes in gs_patterns.h and config.h
…agement

Replace hardcoded constants with configurable parameters and modernize
memory management using RAII principles.

changes:
- Move compile-time constants (IWINDOW, NGS, NTOP, etc.) to Config system
- Replace raw pointers with std::unique_ptr and std::vector for automatic
  memory management
- Extract exception classes (GSError, GSFileError, etc.) to errors.h
- Add Config::get_instance() integration for runtime configuration
- Convert multi-dimensional raw arrays to flattened smart pointer layouts
  in Metrics, InstrInfo, and InstrWindow classes
- Add [[nodiscard]] attributes to InstrAddrAdapter const methods
- Implement SrcLine2D proxy class for safer 2D array access in Metrics
- Update Metrics::patterns from raw pointer array to vector<vector<int64_t>>
- Add get_window_size() accessor to InstrWindow
- Initialize InstrWindow state members with default values
- Change virtual destructors to = default (RAII handles cleanup)

Added explict #include <cstdint> to gs_patterns.h to avoid failed compilation (uintptr_t, uint64_t were not being recognized in some compilation environments)
Replace manual command-line argument parsing with centralized Config
class to improve code maintainability and consistency.

- Remove inline argument parsing loop in favor of Config::parseArgs()
- Access configuration values through Config getters (use_gs_nv,
  verbose, one_warp, positional_args)
- Improve argument validation with mode-specific error messages
- Comment out local usage() function (now handled by Config::printHelp())
- Use positional_args vector instead of direct argv indexing
…ime parameters:

- Add config.h include for configuration management
- Replace PERSAMPLE, IWINDOW, and NGS with function parameters
  (per_sample, max_gather_scatter, window_size)
- Add configurable thresholds to create_metrics_file():
  unique_distances_threshold, out_threshold, min_accesses_threshold,
  histogram_bounds, histogram_bounds_alloc
- Add max_line_length parameter to translate_iaddr()
- Add per_sample parameter to handle_2nd_pass_trace_entry()
- Add top_patterns and max_gather_scatter parameters to get_top_target()
…gurable parameters

  * Add threshold parameters to create_metrics_file (unique_distances_threshold,
    out_threshold, min_accesses_threshold, histogram_bounds)
  * Add size parameters to get_top_target (top_patterns, max_gather_scatter)
  * Add per_sample parameter to handle_2nd_pass_trace_entry

  * Replace fixed-size stack arrays with std::make_unique<char[]> in translate_iaddr
  * Replace fixed-size n_stride array with dynamic allocation
  * Add max_line_length parameter to translate_iaddr
  * Use snprintf instead of sprintf to prevent buffer overflows

  * Make filtering logic explicit with named boolean variables
    (has_too_few_instances, is_not_complex, is_not_out_of_bounds)
  * Use print_bounds variable for flexible histogram output formatting
  * Update Metrics API calls to use .get() accessor and .data() methods

- include config.h
Make pattern analysis configurable with dynamic sizing

Replace hardcoded constants with configurable member variables:
- Replace NBUFS/NGS/NTOP with _trace_buffer_size/_max_gather_scatter/_top_patterns
- Replace MAX_LINE_LENGTH with _max_line_length member variable
- Add configurable thresholds for spatter file generation

Improve memory management:
- Convert fixed-size arrays to std::unique_ptr for dynamic allocation
- Replace trace_buff[NBUFS] with dynamically allocated buffer
- Replace gather_base[NTOP]/scatter_base[NTOP] with unique_ptr arrays

Add parameterization to core functions:
- Pass _max_gather_scatter and _per_sample to handle_trace_entry()
- Pass threshold parameters to create_spatter_file()
- Pass _top_patterns to get_top_target()
- Add trace_buffer_size parameter to tline_read()
- Add _per_sample parameter to handle_2nd_pass_trace_entry()

Update array access patterns:
- Change srcline access from direct indexing to .get(k) method
- Add explicit null termination for safety on srcline strings
…orNV constructor

- Add explicit constructor with configuration parameters from Config singleton
- Initialize member variables: _per_sample, _histogram_bounds,
  _histogram_bounds_alloc, _unique_distances_threshold, _out_threshold,
  _min_accesses_threshold, _trace_buffer_size, _top_patterns,
  _max_line_length, and _max_gather_scatter
- Add config.h include for Config class support
- Move configuration values from hardcoded/default to constructor parameters
Make buffer sizes and thresholds configurable via parameters

Replace hardcoded constants with configurable member variables to improve
flexibility:

- Replace NBUFS with _trace_buffer_size parameter in drline_read()
- Replace NGS with _max_gather_scatter for gather/scatter limits
- Replace NTOP with _top_patterns for top pattern tracking
- Add configurable thresholds: _unique_distances_threshold, _out_threshold,
  _min_accesses_threshold, _histogram_bounds, _histogram_bounds_alloc
- Add _per_sample and _max_line_length configuration parameters

Convert fixed-size stack arrays to dynamically allocated unique_ptr arrays:
- drtrace buffer in process_traces() and process_second_pass()
- gather_base and scatter_base arrays in process_second_pass()

Pass new parameters through to handle_trace_entry(), get_top_target(),
create_spatter_file(), and handle_2nd_pass_trace_entry() functions.
…ForPin constructor

Replace default constructor with parameterized version that accepts
configuration values for pattern analysis thresholds and limits.
Parameters include max_line_length, per_sample, histogram_bounds,
unique_distances_threshold, and others, all defaulting to values
from Config singleton.

Store configuration parameters as private member variables to allow
runtime customization of pattern detection behavior.
documentation file describing the user runtime parameters and basic usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants