Skip to content

Commit 6cc94b2

Browse files
wlei-llvmmeta-codesync[bot]
authored andcommitted
Add IPOINT configuration via environment variables (#183)
Summary: Pull Request resolved: #183 Add support for configuring instrumentation point (IPOINT_BEFORE vs IPOINT_AFTER) through two new environment variables: - CUTRACER_INSTRUMENT_IPOINT_UNIFORM=a|b - Applies the same IPOINT uniformly to all enabled instruments - CUTRACER_INSTRUMENT_IPOINT=a,b,... - Per-instrument IPOINT list (count must match final enabled instruments) Design: - Retired `enabled_instrument_types` (unordered_set) in favor of a single `enabled_instrument_types_ordered` vector + `instrument_type_to_index` map as the source of truth - `add_enabled_instrument_type()` handles deduplication (returns false if already present) - Init order: `init_instrumentation` (user-specified) runs first, then `init_analysis` (may add more instruments). Both use the same `add_enabled_instrument_type()`. - CUTRACER_INSTRUMENT_IPOINT count must match the final `enabled_instrument_types_ordered.size()` (including analysis-added instruments) - Includes validation for mutual exclusivity and count matching, plus warnings when mem_value_trace uses IPOINT_BEFORE Reviewed By: FindHao Differential Revision: D94141021 fbshipit-source-id: 80a51e327689b6138936be9ef071ffacc54875af
1 parent c942fec commit 6cc94b2

3 files changed

Lines changed: 352 additions & 37 deletions

File tree

include/env_config.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@
1010
#include <stdint.h>
1111

1212
#include <string>
13+
#include <unordered_map>
1314
#include <unordered_set>
1415
#include <vector>
16+
1517
// Forward declaration to avoid circular dependency
1618
enum class InstrumentType;
1719
enum class InstrCategory;
1820

21+
/**
22+
* @brief Instrumentation point type for NVBit
23+
*
24+
* Controls whether instrumentation is inserted before or after the instruction.
25+
*/
26+
enum class IPointType {
27+
DEFAULT = -1, // Not set - use the default_ipoint passed to get_ipoint_from_config
28+
BEFORE = 0, // IPOINT_BEFORE - instrument before instruction execution
29+
AFTER = 1, // IPOINT_AFTER - instrument after instruction execution
30+
};
31+
1932
/**
2033
* @brief Defines the type of analysis to be performed on the collected trace
2134
* data.
@@ -52,8 +65,13 @@ extern bool dump_cubin;
5265

5366
// Kernel name filters
5467
extern std::vector<std::string> kernel_filters;
68+
5569
// Instrumentation configuration
56-
extern std::unordered_set<InstrumentType> enabled_instrument_types;
70+
// Uses instrument_type_to_index map for O(1) lookup (replaces the old unordered_set)
71+
// Ordered list of enabled instrument types (preserves insertion order for IPOINT mapping)
72+
extern std::vector<InstrumentType> enabled_instrument_types_ordered;
73+
// Map from InstrumentType to its index in enabled_instrument_types_ordered (O(1) lookup)
74+
extern std::unordered_map<InstrumentType, int> instrument_type_to_index;
5775

5876
// Analysis configuration
5977
extern std::unordered_set<AnalysisType> enabled_analysis_types;
@@ -126,3 +144,32 @@ bool should_instrument_category(InstrCategory category);
126144

127145
// Check if category-based filtering is enabled
128146
bool has_category_filter_enabled();
147+
148+
// IPOINT configuration for instrumentation
149+
//
150+
// Two environment variables control IPOINT behavior:
151+
//
152+
// 1. CUTRACER_INSTRUMENT_IPOINT_UNIFORM=a|b
153+
// Applies the same IPOINT to ALL enabled instruments.
154+
// Example: CUTRACER_INSTRUMENT_IPOINT_UNIFORM=b (all use IPOINT_BEFORE)
155+
//
156+
// 2. CUTRACER_INSTRUMENT_IPOINT=a,b,a,...
157+
// Per-instrument IPOINT list. Count MUST match the final enabled instruments
158+
// (including analysis-added ones). Order follows enabled_instrument_types_ordered.
159+
// Example: CUTRACER_INSTRUMENT=reg_trace,mem_value_trace
160+
// CUTRACER_INSTRUMENT_IPOINT=b,a (reg_trace=BEFORE, mem_value_trace=AFTER)
161+
//
162+
// Error if both are set simultaneously.
163+
// Warning if mem_value_trace uses IPOINT_BEFORE (may not capture loaded values).
164+
//
165+
// Values: 'a'/'after' = IPOINT_AFTER, 'b'/'before' = IPOINT_BEFORE
166+
167+
// Uniform IPOINT for all instrumentation (set via CUTRACER_INSTRUMENT_IPOINT_UNIFORM)
168+
extern IPointType uniform_ipoint;
169+
170+
// Per-instrument IPOINT overrides (set via CUTRACER_INSTRUMENT_IPOINT)
171+
// Indexed by position in enabled_instrument_types_ordered
172+
extern std::vector<IPointType> ipoint_overrides;
173+
174+
// Initialize IPOINT configuration from environment variables
175+
void init_instrument_ipoint();

0 commit comments

Comments
 (0)