Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion htsim/sim/datacenter/dragonfly_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

bool DragonflySwitch::_trim_disable = false;
uint16_t DragonflySwitch::_trim_size = 0;
int64_t DragonflySwitch::_rng_seed = -1;
DragonflySwitch::RoutingStrategy DragonflySwitch::_routing_strategy = DragonflySwitch::MINIMAL;

string ntoa(double n);
Expand All @@ -30,7 +31,12 @@ DragonflySwitch::DragonflySwitch(EventList& event_list,

_pipe = new CallbackPipe(delay, event_list, this);

_generator = std::mt19937(33);
if (_rng_seed < 0) {
_generator = std::mt19937(33);
} else {
std::seed_seq seq{(uint32_t)_rng_seed, (uint32_t)_id};
_generator = std::mt19937(seq);
}
_dist_a = std::uniform_int_distribution<>(0, _a - 1);
_dist_h = std::uniform_int_distribution<>(0, _h - 1);

Expand Down
3 changes: 3 additions & 0 deletions htsim/sim/datacenter/dragonfly_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DragonflySwitch : public Switch {
}
static uint16_t get_trim_disable() { return _trim_disable; }
static uint16_t get_trim_size() { return _trim_size; }
// -1 keeps the legacy behaviour (every switch seeded with 33).
static void set_rng_seed(int64_t seed) { _rng_seed = seed; }

private:
SwitchType _type;
Expand Down Expand Up @@ -70,6 +72,7 @@ class DragonflySwitch : public Switch {
static bool _trim_disable;
static uint16_t _trim_size;
static RoutingStrategy _routing_strategy;
static int64_t _rng_seed;
};

#endif
11 changes: 11 additions & 0 deletions htsim/sim/datacenter/main_uec_df.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main(int argc, char** argv) {
Clock c(timeFromSec(5 / 100.), eventlist);

int seed = 13;
bool seed_set = false;
srand(seed);
srandom(seed);

Expand Down Expand Up @@ -163,6 +164,10 @@ int main(int argc, char** argv) {
else
throw std::logic_error("LB not recognized");
i++;
} else if (!strcmp(argv[i], "-seed")) {
seed = std::stoi(argv[i + 1]);
seed_set = true;
i++;
} else if (!strcmp(argv[i], "-paths")) {
path_entropy_size = std::stoi(argv[i + 1]);
i++;
Expand Down Expand Up @@ -280,6 +285,12 @@ int main(int argc, char** argv) {
}

// Topology
if (seed_set) {
srand(seed);
srandom(seed);
DragonflySwitch::set_rng_seed(seed);
std::cout << "Random seed " << seed << std::endl;
}
DragonflySwitch::set_config(routing_strategy, trim_disable, trim_size);
DragonflyTopology* topo = new DragonflyTopology(qt, queuesize, qlf, &eventlist);
topo->load_topology(topo_base_path);
Expand Down
11 changes: 11 additions & 0 deletions htsim/sim/datacenter/main_uec_sf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main(int argc, char** argv) {
Clock c(timeFromSec(5 / 100.), eventlist);

int seed = 13;
bool seed_set = false;
srand(seed);
srandom(seed);

Expand Down Expand Up @@ -165,6 +166,10 @@ int main(int argc, char** argv) {
else
throw std::logic_error("LB not recognized");
i++;
} else if (!strcmp(argv[i], "-seed")) {
seed = std::stoi(argv[i + 1]);
seed_set = true;
i++;
} else if (!strcmp(argv[i], "-paths")) {
path_entropy_size = std::stoi(argv[i + 1]);
i++;
Expand Down Expand Up @@ -282,6 +287,12 @@ int main(int argc, char** argv) {
}

// Topology
if (seed_set) {
srand(seed);
srandom(seed);
SlimFlySwitch::set_rng_seed(seed);
std::cout << "Random seed " << seed << std::endl;
}
SlimFlySwitch::set_config(routing_strategy, trim_disable, trim_size);
SlimFlyTopology* topo = new SlimFlyTopology(topo_base_path, qt, queuesize, qlf, &eventlist);
topo->load_topology(topo_base_path);
Expand Down
8 changes: 7 additions & 1 deletion htsim/sim/datacenter/slimfly_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern void tokenize(std::string const& str, const char delim, std::vector<std::

bool SlimFlySwitch::_trim_disable = false;
uint16_t SlimFlySwitch::_trim_size = 0;
int64_t SlimFlySwitch::_rng_seed = -1;
SlimFlySwitch::RoutingStrategy SlimFlySwitch::_routing_strategy = SlimFlySwitch::MINIMAL;

string ntoa(double n);
Expand Down Expand Up @@ -37,7 +38,12 @@ SlimFlySwitch::SlimFlySwitch(std::string path_fib,

void SlimFlySwitch::init_neighbours() {
_neighbours = _topo->get_neighbours(_id);
_generator = mt19937(33);
if (_rng_seed < 0) {
_generator = std::mt19937(33);
} else {
std::seed_seq seq{(uint32_t)_rng_seed, (uint32_t)_id};
_generator = std::mt19937(seq);
}
_dist_neighbour = uniform_int_distribution<>(0, _neighbours->size() - 1);
}

Expand Down
3 changes: 3 additions & 0 deletions htsim/sim/datacenter/slimfly_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SlimFlySwitch : public Switch {
}
static uint16_t get_trim_disable() { return _trim_disable; }
static uint16_t get_trim_size() { return _trim_size; }
// -1 keeps the legacy behaviour (every switch seeded with 33).
static void set_rng_seed(int64_t seed) { _rng_seed = seed; }

private:
std::string _path_fib;
Expand Down Expand Up @@ -71,6 +73,7 @@ class SlimFlySwitch : public Switch {
static bool _trim_disable;
static uint16_t _trim_size;
static RoutingStrategy _routing_strategy;
static int64_t _rng_seed;
};

#endif
Loading