Skip to content

Commit

Permalink
[BE] Abstract out strings to top of file (pytorch#125640)
Browse files Browse the repository at this point in the history
Summary:
Move const strings to top of file. This is in preparation of tooling to
make use of shared constants (e.g. version string). A non-functional change.
Ideally we want these const strings to be available from both C++ and Python - but I haven't figured out how to correctly share things in PyTorch. I'll do this in a subsequent change.

Test Plan:
python test/distributed/test_c10d_nccl.py NCCLTraceTest

Pull Request resolved: pytorch#125640
Approved by: https://github.com/wconstab
  • Loading branch information
c-p-i-o authored and ZelboK committed May 19, 2024
1 parent b3f0fce commit aa17484
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions torch/csrc/distributed/c10d/TraceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@
#include <vector>
namespace c10d {

static c10::IValue entries_key = "entries";
static c10::IValue nccl_comm_key = "nccl_comm_state";
static c10::IValue version_key = "version";
// Update whenever changing contents or formatting of the dump
// (minor when adding fields, major when changing existing fields)
static c10::IValue version_val = "1.5";
static c10::IValue pg_config_key = "pg_config";
static c10::IValue record_id_key = "record_id";
static c10::IValue pg_id_key = "pg_id";
static c10::IValue pg_name_key = "process_group";
static c10::IValue seq_id_key = "seq_id";
static c10::IValue op_id_key = "op_id";
static c10::IValue profiling_name_key = "profiling_name";
static c10::IValue input_sizes_key = "input_sizes";
static c10::IValue output_sizes_key = "output_sizes";
static c10::IValue time_created_key = "time_created_ns";
static c10::IValue duration_key = "duration_ms";

static c10::IValue frames_key = "frames";
static c10::IValue state_key = "state";
static c10::IValue line_key = "line";
static c10::IValue name_key = "name";
static c10::IValue filename_key = "filename";
static c10::IValue retired_key = "retired";
static c10::IValue time_discovered_started_key = "time_discovered_started_ns";
static c10::IValue time_discovered_completed_key =
"time_discovered_completed_ns";

/* Trace Utils Related to TORCH_NCCL_DESYNC_DEBUG */

inline std::string getTraceStartKey(const std::string& pgName, int rank) {
Expand Down Expand Up @@ -606,32 +634,6 @@ struct NCCLTraceBuffer {
std::unordered_map<std::string, std::string>>>& ncclDumpMap) {
auto result = dump_entries();
auto entries = new_list();
c10::IValue entries_key = "entries";
c10::IValue nccl_comm_key = "nccl_comm_state";
c10::IValue version_key = "version";
// Update whenever changing contents or formatting of the dump
// (minor when adding fields, major when changing existing fields)
c10::IValue version_val = "1.5";
c10::IValue pg_config_key = "pg_config";
c10::IValue record_id_key = "record_id";
c10::IValue pg_id_key = "pg_id";
c10::IValue pg_name_key = "process_group";
c10::IValue seq_id_key = "seq_id";
c10::IValue op_id_key = "op_id";
c10::IValue profiling_name_key = "profiling_name";
c10::IValue input_sizes_key = "input_sizes";
c10::IValue output_sizes_key = "output_sizes";
c10::IValue time_created_key = "time_created_ns";
c10::IValue duration_key = "duration_ms";

c10::IValue frames_key = "frames";
c10::IValue state_key = "state";
c10::IValue line_key = "line";
c10::IValue name_key = "name";
c10::IValue filename_key = "filename";
c10::IValue retired_key = "retired";
c10::IValue time_discovered_started_key = "time_discovered_started_ns";
c10::IValue time_discovered_completed_key = "time_discovered_completed_ns";

std::vector<torch::CapturedTraceback*> tracebacks;
for (auto& e : result) {
Expand Down

0 comments on commit aa17484

Please sign in to comment.