stdlib: Add Vector2d to PyStats
Change-Id: Icb2f691abf88ef4bac8d277e421329edb000209b
This commit is contained in:
@@ -31,5 +31,6 @@ if env['CONF']['USE_TEST_OBJECTS']:
|
||||
'StatTester',
|
||||
'ScalarStatTester',
|
||||
'VectorStatTester',
|
||||
'Vector2dStatTester',
|
||||
])
|
||||
Source('stat_tester.cc')
|
||||
|
||||
@@ -62,3 +62,28 @@ class VectorStatTester(StatTester):
|
||||
"The vector stat's subdescriptions. If empty, the subdescriptions "
|
||||
"are not used.",
|
||||
)
|
||||
|
||||
|
||||
class Vector2dStatTester(StatTester):
|
||||
type = "Vector2dStatTester"
|
||||
cxx_header = "test_objects/stat_tester.hh"
|
||||
cxx_class = "gem5::Vector2dStatTester"
|
||||
|
||||
x_size = Param.Int("The number of elements in the x dimension.")
|
||||
y_size = Param.Int("The number of elements in the y dimension.")
|
||||
|
||||
values = VectorParam.Float("The vector stat's values, flattened.")
|
||||
subnames = VectorParam.String(
|
||||
[],
|
||||
"The vector stat's subnames. If position is empty, index int is "
|
||||
"used instead.",
|
||||
)
|
||||
subdescs = VectorParam.String(
|
||||
[],
|
||||
"The vector stat's subdescriptions. If empty, the subdescriptions "
|
||||
"are not used.",
|
||||
)
|
||||
ysubnames = VectorParam.String(
|
||||
[],
|
||||
"The vector stat's y subdescriptions. If empty, the subdescriptions ",
|
||||
)
|
||||
|
||||
@@ -84,4 +84,53 @@ VectorStatTester::VectorStatTesterStats::VectorStatTesterStats(
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Vector2dStatTester::setStats()
|
||||
{
|
||||
for (int i = 0; i < params.x_size; i++)
|
||||
{
|
||||
for (int j = 0; j < params.y_size; j++)
|
||||
{
|
||||
stats.vector2d[i][j] = (params.values[j + i * params.y_size]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector2dStatTester::Vector2dStatTesterStats::Vector2dStatTesterStats(
|
||||
statistics::Group *parent,
|
||||
const Vector2dStatTesterParams ¶ms
|
||||
) : statistics::Group(parent),
|
||||
vector2d(this,
|
||||
params.name.c_str(),
|
||||
statistics::units::Count::get(),
|
||||
params.description.c_str()
|
||||
)
|
||||
{
|
||||
vector2d.init(params.x_size, params.y_size);
|
||||
|
||||
assert(params.x_size * params.y_size == params.values.size());
|
||||
|
||||
for (int i = 0; i < params.x_size; i++)
|
||||
{
|
||||
if (params.subnames.size() > i) {
|
||||
vector2d.subname(i, params.subnames[i]);
|
||||
} else {
|
||||
vector2d.subname(i, std::to_string(i));
|
||||
}
|
||||
if (params.subdescs.size() > i) {
|
||||
vector2d.subdesc(i, params.subdescs[i]);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < params.y_size; j++)
|
||||
{
|
||||
if (params.ysubnames.size() > j) {
|
||||
vector2d.ysubname(j, params.ysubnames[j]);
|
||||
} else {
|
||||
vector2d.ysubname(j, std::to_string(j));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace gem5
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "base/statistics.hh"
|
||||
#include "params/ScalarStatTester.hh"
|
||||
#include "params/StatTester.hh"
|
||||
#include "params/Vector2dStatTester.hh"
|
||||
#include "params/VectorStatTester.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
@@ -136,6 +137,28 @@ class VectorStatTester : public StatTester
|
||||
} stats;
|
||||
};
|
||||
|
||||
class Vector2dStatTester : public StatTester
|
||||
{
|
||||
private:
|
||||
Vector2dStatTesterParams params;
|
||||
|
||||
public:
|
||||
Vector2dStatTester(const Vector2dStatTesterParams &p) :
|
||||
StatTester(p), params(p), stats(this, p) {}
|
||||
|
||||
protected:
|
||||
void setStats() override;
|
||||
struct Vector2dStatTesterStats : public statistics::Group
|
||||
{
|
||||
Vector2dStatTesterStats(
|
||||
statistics::Group *parent,
|
||||
const Vector2dStatTesterParams ¶ms
|
||||
);
|
||||
statistics::Vector2d vector2d;
|
||||
} stats;
|
||||
};
|
||||
|
||||
|
||||
} // namespace gem5
|
||||
|
||||
#endif // __STAT_TESTER_HH__
|
||||
|
||||
Reference in New Issue
Block a user