Skip to content

Commit

Permalink
#0: remove reserve to avoid bad alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
yugaoTT committed Jun 3, 2024
1 parent 16eae04 commit 156c9bd
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ void get_dram_reader_core_coords_wormhole_b0(
// get dram banks and coords
uint32_t num_banks = device->num_dram_channels();
uint32_t max_bank_id = num_banks - 1;
std::vector<CoreCoord> dram_coord_phy; dram_coord_phy.reserve(num_banks);
std::vector<CoreCoord> dram_coord_phy;
for (int i = 0; i < num_banks; ++i) {
dram_coord_phy.push_back(device->dram_core_from_dram_channel(i));
}

// get worker logical coords
std::vector<CoreCoord> all_worker_cores_logical; all_worker_cores_logical.reserve(num_cores_x * num_cores_y);
std::vector<CoreCoord> all_worker_cores_logical;
for (int i = 0; i < num_cores_x; ++i) {
for (int j = 0; j < num_cores_y; ++j) {
all_worker_cores_logical.push_back(CoreCoord(i, j));
}
}

// get y coords of the workers
std::vector<uint32_t> all_worker_cores_y_physical; all_worker_cores_y_physical.reserve(num_cores_y);
std::vector<uint32_t> all_worker_cores_y_physical;
uint32_t max_worker_y_physical = 0;
uint32_t min_worker_y_physical = 10000;
for (int i = 0; i < num_cores_y; ++i) {
Expand All @@ -170,7 +170,7 @@ void get_dram_reader_core_coords_wormhole_b0(
}

// get the ajacent cores of DRAM banks
std::vector<CoreCoord> adj_core_physical; adj_core_physical.reserve(num_banks);
std::vector<CoreCoord> adj_core_physical;
for (int i = 0; i < num_banks; ++i) {
auto dram_core = dram_coord_phy[i];
uint32_t adj_core_x = dram_core.x + 1;
Expand All @@ -179,10 +179,10 @@ void get_dram_reader_core_coords_wormhole_b0(
}

// split the adjacent coords into two groups, because DRAM banks has two cols
std::vector<CoreCoord> adj_core_physical_g1; adj_core_physical_g1.reserve(num_banks);
std::vector<size_t> adj_core_physical_y_g1; adj_core_physical_y_g1.reserve(num_banks);
std::vector<CoreCoord> adj_core_physical_g2; adj_core_physical_g2.reserve(num_banks);
std::vector<size_t> adj_core_physical_y_g2; adj_core_physical_y_g2.reserve(num_banks);
std::vector<CoreCoord> adj_core_physical_g1;
std::vector<size_t> adj_core_physical_y_g1;
std::vector<CoreCoord> adj_core_physical_g2;
std::vector<size_t> adj_core_physical_y_g2;
for (auto core : adj_core_physical) {
if (core.x == adj_core_physical.front().x) {
adj_core_physical_g1.push_back(core);
Expand Down Expand Up @@ -260,7 +260,7 @@ void get_dram_reader_core_coords_wormhole_b0(
process_group(adj_core_physical_g2, adj_core_physical_y_g2, x_step);

// merge two group into one
std::vector<CoreCoord> adj_core_physical_realloc; adj_core_physical_realloc.reserve(num_banks);
std::vector<CoreCoord> adj_core_physical_realloc;
for (int i = 0; i < indices_g1_realloc.size(); ++i) {
adj_core_physical_realloc.push_back(adj_core_physical_g1[indices_g1_realloc[i]]);
}
Expand All @@ -269,7 +269,7 @@ void get_dram_reader_core_coords_wormhole_b0(
}

// find the logical coord from physical coord
std::vector<CoreCoord> adj_core_logical_realloc; adj_core_logical_realloc.reserve(num_banks);
std::vector<CoreCoord> adj_core_logical_realloc;
for (int i = 0; i < adj_core_physical_realloc.size(); ++i) {
for (int j = 0; j < all_worker_cores_logical.size(); ++j) {
auto core = device->worker_core_from_logical_core(all_worker_cores_logical[j]);
Expand Down Expand Up @@ -453,15 +453,13 @@ operation::ProgramWithCallbacks create_program_dram_sharded(
move_common_entries(all_storage_cores_vec, all_worker_cores_vec, storage_worker_common);

std::vector<CoreRange> all_storage_cores_range;
all_storage_cores_range.reserve(all_storage_cores_vec.size());
std::transform(
all_storage_cores_vec.begin(),
all_storage_cores_vec.end(),
std::back_inserter(all_storage_cores_range),
[](const CoreCoord& coord) { return CoreRange(coord); });

std::vector<CoreRange> all_worker_cores_range;
all_worker_cores_range.reserve(all_worker_cores_vec.size());
std::transform(
all_worker_cores_vec.begin(),
all_worker_cores_vec.end(),
Expand Down

0 comments on commit 156c9bd

Please sign in to comment.