Skip to content

Commit 6827824

Browse files
committed
[vpr][base] moove calculate_device_util to stats
1 parent df0d366 commit 6827824

File tree

4 files changed

+62
-61
lines changed

4 files changed

+62
-61
lines changed

vpr/src/base/SetupGrid.cpp

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "vtr_assert.h"
1616
#include "vtr_math.h"
1717
#include "vtr_log.h"
18+
#include "stats.h"
1819

1920
#include "vpr_types.h"
2021
#include "vpr_error.h"
@@ -755,59 +756,6 @@ static void CheckGrid(const DeviceGrid& grid) {
755756
}
756757
}
757758

758-
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts) {
759-
//Record the resources of the grid
760-
std::map<t_physical_tile_type_ptr, size_t> grid_resources;
761-
for (int layer_num = 0; layer_num < grid.get_num_layers(); ++layer_num) {
762-
for (int x = 0; x < (int)grid.width(); ++x) {
763-
for (int y = 0; y < (int)grid.height(); ++y) {
764-
int width_offset = grid.get_width_offset({x, y, layer_num});
765-
int height_offset = grid.get_height_offset({x, y, layer_num});
766-
if (width_offset == 0 && height_offset == 0) {
767-
const auto& type = grid.get_physical_type({x, y, layer_num});
768-
++grid_resources[type];
769-
}
770-
}
771-
}
772-
}
773-
774-
//Determine the area of grid in tile units
775-
float grid_area = 0.;
776-
for (auto& kv : grid_resources) {
777-
t_physical_tile_type_ptr type = kv.first;
778-
size_t count = kv.second;
779-
780-
float type_area = type->width * type->height;
781-
782-
grid_area += type_area * count;
783-
}
784-
785-
//Determine the area of instances in tile units
786-
float instance_area = 0.;
787-
for (auto& kv : instance_counts) {
788-
if (is_empty_type(kv.first)) {
789-
continue;
790-
}
791-
792-
t_physical_tile_type_ptr type = pick_physical_type(kv.first);
793-
794-
size_t count = kv.second;
795-
796-
float type_area = type->width * type->height;
797-
798-
//Instances of multi-capaicty blocks take up less space
799-
if (type->capacity != 0) {
800-
type_area /= type->capacity;
801-
}
802-
803-
instance_area += type_area * count;
804-
}
805-
806-
float utilization = instance_area / grid_area;
807-
808-
return utilization;
809-
}
810-
811759
size_t count_grid_tiles(const DeviceGrid& grid) {
812760
return grid.get_num_layers() * grid.width() * grid.height();
813761
}

vpr/src/base/SetupGrid.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ DeviceGrid create_device_grid(const std::string& layout_name,
2727
size_t min_width,
2828
size_t min_height);
2929

30-
/**
31-
* @brief Calculate the device utilization
32-
*
33-
* Calculate the device utilization (i.e. fraction of used grid tiles)
34-
* foor the specified grid and resource requirements
35-
*/
36-
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts);
37-
3830
/**
3931
* @brief Returns the effective size of the device
4032
* (size of the bounding box of non-empty grid tiles)

vpr/src/base/stats.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,59 @@ int count_netlist_clocks() {
449449
return static_cast<int>(clock_names.size());
450450
}
451451

452+
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts) {
453+
//Record the resources of the grid
454+
std::map<t_physical_tile_type_ptr, size_t> grid_resources;
455+
for (int layer_num = 0; layer_num < grid.get_num_layers(); ++layer_num) {
456+
for (int x = 0; x < (int)grid.width(); ++x) {
457+
for (int y = 0; y < (int)grid.height(); ++y) {
458+
int width_offset = grid.get_width_offset({x, y, layer_num});
459+
int height_offset = grid.get_height_offset({x, y, layer_num});
460+
if (width_offset == 0 && height_offset == 0) {
461+
const auto& type = grid.get_physical_type({x, y, layer_num});
462+
++grid_resources[type];
463+
}
464+
}
465+
}
466+
}
467+
468+
//Determine the area of grid in tile units
469+
float grid_area = 0.;
470+
for (auto& kv : grid_resources) {
471+
t_physical_tile_type_ptr type = kv.first;
472+
size_t count = kv.second;
473+
474+
float type_area = type->width * type->height;
475+
476+
grid_area += type_area * count;
477+
}
478+
479+
//Determine the area of instances in tile units
480+
float instance_area = 0.;
481+
for (auto& kv : instance_counts) {
482+
if (is_empty_type(kv.first)) {
483+
continue;
484+
}
485+
486+
t_physical_tile_type_ptr type = pick_physical_type(kv.first);
487+
488+
size_t count = kv.second;
489+
490+
float type_area = type->width * type->height;
491+
492+
//Instances of multi-capaicty blocks take up less space
493+
if (type->capacity != 0) {
494+
type_area /= type->capacity;
495+
}
496+
497+
instance_area += type_area * count;
498+
}
499+
500+
float utilization = instance_area / grid_area;
501+
502+
return utilization;
503+
}
504+
452505
void print_resource_usage(const std::map<t_logical_block_type_ptr, size_t>& num_type_instances) {
453506
auto& device_ctx = g_vpr_ctx.device();
454507

vpr/src/base/stats.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ void get_num_bends_and_length(ParentNetId inet, int* bends, int* length, int* se
2323

2424
int count_netlist_clocks();
2525

26+
/**
27+
* @brief Calculate the device utilization
28+
*
29+
* Calculate the device utilization (i.e. fraction of used grid tiles)
30+
* foor the specified grid and resource requirements
31+
*/
32+
float calculate_device_utilization(const DeviceGrid& grid, const std::map<t_logical_block_type_ptr, size_t>& instance_counts);
33+
2634
/**
2735
* @brief Prints the number of resources in the netlist and the number of available resources in the architecture.
2836
* @param num_type_instances The number of instances of each logical block type

0 commit comments

Comments
 (0)