Skip to content

Commit

Permalink
Merge branch 'profrtconfig' into 'master'
Browse files Browse the repository at this point in the history
Profiling Runtime Configuration

See merge request StanfordLegion/legion!1177
  • Loading branch information
elliottslaughter committed Mar 20, 2024
2 parents 6af4314 + d0595ac commit 7d57a58
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 5 deletions.
27 changes: 26 additions & 1 deletion runtime/legion/legion_profiling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,32 @@ namespace Legion {
LegionProfDesc::MaxDimDesc max_dim_desc;
max_dim_desc.max_dim = LEGION_MAX_DIM;
serializer->serialize(max_dim_desc);

// Log the runtime configuration
const LegionProfDesc::RuntimeConfig config = {
#ifdef DEBUG_LEGION
true,
#else
false,
#endif
runtime->legion_spy_enabled,
#ifdef LEGION_GC
true,
#else
false,
#endif
runtime->program_order_execution,
!runtime->unsafe_mapper,
runtime->check_privileges,
runtime->safe_control_replication > 0,
runtime->verify_partitions,
#ifdef LEGION_BOUNDS_CHECKS
true,
#else
false,
#endif
runtime->resilient_mode,
};
serializer->serialize(config);
#ifdef DEBUG_LEGION
for (unsigned idx = 0; idx < LEGION_PROF_LAST; idx++)
total_outstanding_requests[idx] = 0;
Expand Down
12 changes: 12 additions & 0 deletions runtime/legion/legion_profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ namespace Legion {
struct MaxDimDesc {
unsigned max_dim;
};
struct RuntimeConfig {
bool debug;
bool spy;
bool gc;
bool inorder;
bool safe_mapper;
bool safe_runtime;
bool safe_ctrlrepl;
bool part_checks;
bool bounds_checks;
bool resilient;
};
struct MachineDesc {
unsigned node_id;
unsigned num_nodes;
Expand Down
46 changes: 46 additions & 0 deletions runtime/legion/legion_profiling_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ namespace Legion {
<< "max_dim:maxdim:" << sizeof(unsigned)
<< "}" << std::endl;

ss << "RuntimeConfig {"
<< "id:" << RUNTIME_CONFIG_ID << delim
<< "debug:bool:" << sizeof(bool) << delim
<< "spy:bool:" << sizeof(bool) << delim
<< "gc:bool:" << sizeof(bool) << delim
<< "inorder:bool:" << sizeof(bool) << delim
<< "safe_mapper:bool:" << sizeof(bool) << delim
<< "safe_runtime:bool:" << sizeof(bool) << delim
<< "safe_ctrlrepl:bool:" << sizeof(bool) << delim
<< "part_checks:bool:" << sizeof(bool) << delim
<< "bounds_checks:bool:" << sizeof(bool) << delim
<< "resilient:bool:" << sizeof(bool)
<< "}" << std::endl;

ss << "MachineDesc {"
<< "id:" << MACHINE_DESC_ID << delim
<< "node_id:unsigned:" << sizeof(unsigned) << delim
Expand Down Expand Up @@ -499,6 +513,25 @@ namespace Legion {

}

//--------------------------------------------------------------------------
void LegionProfBinarySerializer::serialize(
const LegionProfDesc::RuntimeConfig &config)
//--------------------------------------------------------------------------
{
int ID = RUNTIME_CONFIG_ID;
lp_fwrite(f, (char*)&ID, sizeof(ID));
lp_fwrite(f, (char*)&config.debug, sizeof(config.debug));
lp_fwrite(f, (char*)&config.spy, sizeof(config.spy));
lp_fwrite(f, (char*)&config.gc, sizeof(config.gc));
lp_fwrite(f, (char*)&config.inorder, sizeof(config.inorder));
lp_fwrite(f, (char*)&config.safe_mapper, sizeof(config.safe_mapper));
lp_fwrite(f, (char*)&config.safe_runtime, sizeof(config.safe_runtime));
lp_fwrite(f, (char*)&config.safe_ctrlrepl, sizeof(config.safe_ctrlrepl));
lp_fwrite(f, (char*)&config.part_checks, sizeof(config.part_checks));
lp_fwrite(f, (char*)&config.bounds_checks, sizeof(config.bounds_checks));
lp_fwrite(f, (char*)&config.resilient, sizeof(config.resilient));
}

//--------------------------------------------------------------------------
void LegionProfBinarySerializer::serialize(
const LegionProfDesc::MachineDesc
Expand Down Expand Up @@ -1629,6 +1662,19 @@ namespace Legion {
max_dim_desc.max_dim);
}

//--------------------------------------------------------------------------
void LegionProfASCIISerializer::serialize(
const LegionProfDesc::RuntimeConfig &config)
//--------------------------------------------------------------------------
{
log_prof.print("Runtime Config %d %d %d %d %d %d %d %d %d %d",
config.debug ? 1 : 0, config.spy ? 1 : 0, config.gc ? 1 : 0,
config.inorder ? 1 : 0, config.safe_mapper ? 1 : 0,
config.safe_runtime ? 1 : 0, config.safe_ctrlrepl ? 1 : 0,
config.part_checks ? 1 : 0, config.bounds_checks ? 1 : 0,
config.resilient ? 1 : 0);
}

//--------------------------------------------------------------------------
void LegionProfASCIISerializer::serialize(
const LegionProfDesc::MachineDesc
Expand Down
4 changes: 4 additions & 0 deletions runtime/legion/legion_profiling_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Legion {
virtual void serialize(const LegionProfDesc::MetaDesc&) = 0;
virtual void serialize(const LegionProfDesc::OpDesc&) = 0;
virtual void serialize(const LegionProfDesc::MaxDimDesc&) = 0;
virtual void serialize(const LegionProfDesc::RuntimeConfig&) = 0;
virtual void serialize(const LegionProfDesc::MachineDesc&) = 0;
virtual void serialize(const LegionProfDesc::ZeroTime&) = 0;
virtual void serialize(const LegionProfDesc::CalibrationErr&) = 0;
Expand Down Expand Up @@ -118,6 +119,7 @@ namespace Legion {
void serialize(const LegionProfDesc::MetaDesc&);
void serialize(const LegionProfDesc::OpDesc&);
void serialize(const LegionProfDesc::MaxDimDesc&);
void serialize(const LegionProfDesc::RuntimeConfig&);
void serialize(const LegionProfDesc::MachineDesc&);
void serialize(const LegionProfDesc::ZeroTime&);
void serialize(const LegionProfDesc::CalibrationErr&);
Expand Down Expand Up @@ -181,6 +183,7 @@ namespace Legion {
PROC_DESC_ID,
MEM_DESC_ID,
MAX_DIM_DESC_ID,
RUNTIME_CONFIG_ID,
MACHINE_DESC_ID,
TASK_KIND_ID,
TASK_VARIANT_ID,
Expand Down Expand Up @@ -239,6 +242,7 @@ namespace Legion {
void serialize(const LegionProfDesc::MetaDesc&);
void serialize(const LegionProfDesc::OpDesc&);
void serialize(const LegionProfDesc::MaxDimDesc&);
void serialize(const LegionProfDesc::RuntimeConfig&);
void serialize(const LegionProfDesc::MachineDesc&);
void serialize(const LegionProfDesc::ZeroTime&);
void serialize(const LegionProfDesc::CalibrationErr&);
Expand Down
2 changes: 1 addition & 1 deletion runtime/legion/legion_profiling_version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1001
1002
9 changes: 9 additions & 0 deletions tools/legion_prof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,7 @@ def __init__(self, call_threshold: int) -> None:
"MetaDesc": self.log_meta_desc,
"OpDesc": self.log_op_desc,
"MaxDimDesc": self.log_max_dim,
"RuntimeConfig": self.log_runtime_config,
"MachineDesc": self.log_machine_desc,
"ZeroTime": self.log_zero_time,
"ProcDesc": self.log_proc_desc,
Expand Down Expand Up @@ -3572,6 +3573,14 @@ def __init__(self, call_threshold: int) -> None:
def log_max_dim(self, max_dim: int) -> None:
self.max_dim = max_dim

@typecheck
def log_runtime_config(self, debug: bool, spy: bool,
gc: bool, inorder: bool,
safe_mapper: bool, safe_runtime: bool,
safe_ctrlrepl: bool, part_checks: bool,
bounds_checks: bool, resilient: bool) -> None:
pass

# MachineDesc
@typecheck
def log_machine_desc(self, node_id: int, num_nodes: int,
Expand Down
4 changes: 2 additions & 2 deletions tools/legion_prof_rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/legion_prof_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ num_enum = "0.7"
rayon = "1.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
legion_prof_viewer = { version = "0.1.0", optional = true }
legion_prof_viewer = { version = "0.2.1", optional = true }
url = { version = "2", optional = true }
slice-group-by = "0.3" # because &[]::group_by is unstable
log = "0.4"
Expand Down
11 changes: 11 additions & 0 deletions tools/legion_prof_rs/src/backend/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,16 @@ impl StateDataSource {
let last_time = last_time + Timestamp::from_ns(last_time.to_ns() / 200);
ts::Interval::new(ts::Timestamp(0), last_time.into())
}

fn generate_warning_message(&self) -> Option<String> {
if !self.state.runtime_config.any() {
return None;
}
Some(format!(
"This profile was generated with {}. Extreme performance degradation may occur.",
self.state.runtime_config
))
}
}

impl DataSource for StateDataSource {
Expand All @@ -1445,6 +1455,7 @@ impl DataSource for StateDataSource {
interval: self.interval(),
tile_set: TileSet::default(),
field_schema: self.field_schema.clone(),
warning_message: self.generate_warning_message(),
}
}

Expand Down
29 changes: 29 additions & 0 deletions tools/legion_prof_rs/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub enum Record {
MetaDesc { kind: VariantID, message: bool, ordered_vc: bool, name: String },
OpDesc { kind: u32, name: String },
MaxDimDesc { max_dim: MaxDim },
RuntimeConfig { debug: bool, spy: bool, gc: bool, inorder: bool, safe_mapper: bool, safe_runtime: bool, safe_ctrlrepl: bool, part_checks: bool, bounds_checks: bool, resilient: bool },
MachineDesc { node_id: NodeID, num_nodes: u32, version: u32, hostname: String, host_id: u64, process_id: u32 },
ZeroTime { zero_time: i64 },
ProcDesc { proc_id: ProcID, kind: ProcKind, cuda_device_uuid: Uuid },
Expand Down Expand Up @@ -382,6 +383,33 @@ fn parse_max_dim_desc(input: &[u8], _max_dim: i32) -> IResult<&[u8], Record> {
let (input, max_dim) = le_i32(input)?;
Ok((input, Record::MaxDimDesc { max_dim }))
}
fn parse_runtime_config(input: &[u8], _max_dim: i32) -> IResult<&[u8], Record> {
let (input, debug) = parse_bool(input)?;
let (input, spy) = parse_bool(input)?;
let (input, gc) = parse_bool(input)?;
let (input, inorder) = parse_bool(input)?;
let (input, safe_mapper) = parse_bool(input)?;
let (input, safe_runtime) = parse_bool(input)?;
let (input, safe_ctrlrepl) = parse_bool(input)?;
let (input, part_checks) = parse_bool(input)?;
let (input, bounds_checks) = parse_bool(input)?;
let (input, resilient) = parse_bool(input)?;
Ok((
input,
Record::RuntimeConfig {
debug,
spy,
gc,
inorder,
safe_mapper,
safe_runtime,
safe_ctrlrepl,
part_checks,
bounds_checks,
resilient,
},
))
}
fn parse_machine_desc(input: &[u8], _max_dim: i32) -> IResult<&[u8], Record> {
let (input, nodeid) = le_u32(input)?;
let (input, num_nodes) = le_u32(input)?;
Expand Down Expand Up @@ -1072,6 +1100,7 @@ fn parse<'a>(
parsers.insert(ids["MetaDesc"], parse_meta_desc);
parsers.insert(ids["OpDesc"], parse_op_desc);
parsers.insert(ids["MaxDimDesc"], parse_max_dim_desc);
parsers.insert(ids["RuntimeConfig"], parse_runtime_config);
parsers.insert(ids["MachineDesc"], parse_machine_desc);
parsers.insert(ids["ZeroTime"], parse_zero_time);
parsers.insert(ids["ProcDesc"], parse_proc_desc);
Expand Down
82 changes: 82 additions & 0 deletions tools/legion_prof_rs/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2737,11 +2737,68 @@ impl ProfUIDAllocator {
}
}

#[derive(Debug, Default)]
pub struct RuntimeConfig {
pub debug: bool,
pub spy: bool,
pub gc: bool,
pub inorder: bool,
pub safe_mapper: bool,
pub safe_runtime: bool,
pub safe_ctrlrepl: bool,
pub part_checks: bool,
pub bounds_checks: bool,
pub resilient: bool,
}

impl RuntimeConfig {
pub fn any(&self) -> bool {
self.debug
|| self.spy
|| self.gc
|| self.inorder
|| self.safe_mapper
|| self.safe_runtime
|| self.safe_ctrlrepl
|| self.part_checks
|| self.bounds_checks
|| self.resilient
}
}

impl fmt::Display for RuntimeConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut first = true;
let mut conf = |cond, name| {
if cond {
if !first {
write!(f, ", ")?;
}
write!(f, "{}", name)?;
first = false;
}
Ok(())
};

conf(self.debug, "Debug Mode")?;
conf(self.spy, "Legion Spy")?;
conf(self.gc, "Legion GC")?;
conf(self.inorder, "-lg:inorder")?;
conf(self.safe_mapper && !self.debug, "-lg:safe_mapper")?;
conf(self.safe_runtime && !self.debug, "Safe Runtime")?;
conf(self.safe_ctrlrepl, "-lg:safe_ctrlrepl")?;
conf(self.part_checks, "-lg:partcheck")?;
conf(self.bounds_checks, "Bounds Checks")?;
conf(self.resilient, "Resilience")
}
}

#[derive(Debug, Default)]
pub struct State {
prof_uid_allocator: ProfUIDAllocator,
max_dim: i32,
pub num_nodes: u32,
pub runtime_config: RuntimeConfig,
pub zero_time: TimestampDelta,
pub _calibration_err: i64,
pub procs: BTreeMap<ProcID, Proc>,
Expand Down Expand Up @@ -3792,6 +3849,31 @@ fn process_record(
Record::MaxDimDesc { max_dim } => {
state.max_dim = *max_dim;
}
Record::RuntimeConfig {
debug,
spy,
gc,
inorder,
safe_mapper,
safe_runtime,
safe_ctrlrepl,
part_checks,
bounds_checks,
resilient,
} => {
state.runtime_config = RuntimeConfig {
debug: *debug,
spy: *spy,
gc: *gc,
inorder: *inorder,
safe_mapper: *safe_mapper,
safe_runtime: *safe_runtime,
safe_ctrlrepl: *safe_ctrlrepl,
part_checks: *part_checks,
bounds_checks: *bounds_checks,
resilient: *resilient,
};
}
Record::MachineDesc { num_nodes, .. } => {
state.num_nodes = *num_nodes;
}
Expand Down
11 changes: 11 additions & 0 deletions tools/legion_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class LegionProfASCIIDeserializer(LegionDeserializer):
"MetaDesc": re.compile(prefix + r'Prof Meta Desc (?P<kind>[0-9]+) (?P<message>[0-1]) (?P<ordered_vc>[0-1]) (?P<name>[a-zA-Z0-9_ ]+)'),
"OpDesc": re.compile(prefix + r'Prof Op Desc (?P<kind>[0-9]+) (?P<name>[a-zA-Z0-9_ ]+)'),
"MaxDimDesc": re.compile(prefix + r'Max Dim Desc (?P<max_dim>[0-9]+)'),
"RuntimeConfig": re.compile(prefix +r'Runtime Config (?P<debug>[0-1]) (?P<spy>[0-1]) (?P<gc>[0-1]) (?P<inorder>[0-1]) (?P<safe_mapper>[0-1]) (?P<safe_runtime>[0-1]) (?P<safe_ctrlrepl>[0-1]) (?P<part_checks>[0-1]) (?P<bounds_checks>[0-1]) (?P<resilient>[0-1])'),
"MachineDesc": re.compile(prefix + r'Machine Desc (?P<node_id>[0-9]+) (?P<num_nodes>[0-9]+) (?P<version>[0-9]+)'),
"MachineDesc": re.compile(prefix + r'Machine Desc (?P<node_id>[0-9]+) (?P<num_nodes>[0-9]+) (?P<version>[0-9]+) (?P<hostname>[a-zA-Z0-9_ ]+) (?P<host_id>[0-9]+) (?P<process_id>[0-9]+)'),
"ZeroTime": re.compile(prefix + r'Zero Time (?P<zero_time>[0-9]+)'),
Expand Down Expand Up @@ -276,6 +277,16 @@ class LegionProfASCIIDeserializer(LegionDeserializer):
"host_id": int,
"process_id": int,
"calibration_err": int,
"debug": bool,
"gc": bool,
"spy": bool,
"inorder": bool,
"safe_mapper": bool,
"safe_runtime": bool,
"safe_ctrlrepl": bool,
"part_checks": bool,
"bounds_checks": bool,
"resilient": bool,
}

def __init__(self, state: State, callbacks: Dict[str, Callable]) -> None:
Expand Down

0 comments on commit 7d57a58

Please sign in to comment.