Skip to content

Commit f66979b

Browse files
authored
Merge branch 'master' into merge-substitution-builder
2 parents f9d0d79 + 3ee5e48 commit f66979b

File tree

7 files changed

+44
-24
lines changed

7 files changed

+44
-24
lines changed

lib/compiler/include/compiler/cost_estimator/op_cost_metrics.struct.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ features = [
77
]
88

99
includes = [
10+
"utils/nonnegative_int/nonnegative_int.h"
1011
]
1112

1213
[[fields]]
@@ -15,4 +16,4 @@ type = "float"
1516

1617
[[fields]]
1718
name = "memory"
18-
type = "size_t"
19+
type = "::FlexFlow::nonnegative_int"

lib/compiler/test/src/compiler/machine_mapping/get_optimal_machine_mapping.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ TEST_SUITE(FF_TEST_SUITE) {
146146

147147
auto map1 = std::unordered_map<OpCostEstimateKey, OpCostMetrics>{{
148148
{map_unmapped_op_cost_estimate_key(k1, mv1),
149-
OpCostMetrics{/*runtime=*/1.0, /*memory=*/0}},
149+
OpCostMetrics{/*runtime=*/1.0, /*memory=*/nonnegative_int{0}}},
150150
{map_unmapped_op_cost_estimate_key(k2, mv1),
151-
OpCostMetrics{/*runtime=*/2.0, /*memory=*/0}},
151+
OpCostMetrics{/*runtime=*/2.0, /*memory=*/nonnegative_int{0}}},
152152
{map_unmapped_op_cost_estimate_key(k1, mv2),
153-
OpCostMetrics{/*runtime=*/1.5, /*memory=*/0}},
153+
OpCostMetrics{/*runtime=*/1.5, /*memory=*/nonnegative_int{0}}},
154154
{map_unmapped_op_cost_estimate_key(k2, mv2),
155-
OpCostMetrics{/*runtime=*/2.5, /*memory=*/0}},
155+
OpCostMetrics{/*runtime=*/2.5, /*memory=*/nonnegative_int{0}}},
156156
}};
157157

158158
CostEstimator cost_estimator = make_fake_cost_estimator(

lib/compiler/test/src/compiler/machine_mapping/memory_optimization/get_optimal_machine_mapping_with_memory.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ TEST_SUITE(FF_TEST_SUITE) {
146146

147147
CostEstimator cost_estimator = make_fake_cost_estimator(
148148
std::unordered_map<OpCostEstimateKey, OpCostMetrics>{{
149-
{map_unmapped_op_cost_estimate_key(k1, mv1), OpCostMetrics{1.0, 2}},
150-
{map_unmapped_op_cost_estimate_key(k2, mv1), OpCostMetrics{2.0, 3}},
151-
{map_unmapped_op_cost_estimate_key(k1, mv2), OpCostMetrics{1.5, 1}},
152-
{map_unmapped_op_cost_estimate_key(k2, mv2), OpCostMetrics{2.5, 2}},
149+
{map_unmapped_op_cost_estimate_key(k1, mv1),
150+
OpCostMetrics{1.0, nonnegative_int{2}}},
151+
{map_unmapped_op_cost_estimate_key(k2, mv1),
152+
OpCostMetrics{2.0, nonnegative_int{3}}},
153+
{map_unmapped_op_cost_estimate_key(k1, mv2),
154+
OpCostMetrics{1.5, nonnegative_int{1}}},
155+
{map_unmapped_op_cost_estimate_key(k2, mv2),
156+
OpCostMetrics{2.5, nonnegative_int{2}}},
153157
}},
154158
std::unordered_map<TensorSetMovement, float>{{
155159
{TensorSetMovement{{}}, 0.0},
@@ -183,13 +187,13 @@ TEST_SUITE(FF_TEST_SUITE) {
183187
cache, context, problem_tree, full_machine_spec, constraints);
184188
MachineMappingWithMemoryResult correct = MachineMappingWithMemoryResult{{
185189
MachineMappingForSingleLayer{
186-
OpCostMetrics{1.0, 2},
190+
OpCostMetrics{1.0, nonnegative_int{2}},
187191
ParallelLayerGuidObliviousMachineMapping{{
188192
{binary_tree_root_path(), mv1},
189193
}},
190194
},
191195
MachineMappingForSingleLayer{
192-
OpCostMetrics{1.5, 1},
196+
OpCostMetrics{1.5, nonnegative_int{1}},
193197
ParallelLayerGuidObliviousMachineMapping{{
194198
{binary_tree_root_path(), mv2},
195199
}},
@@ -214,7 +218,7 @@ TEST_SUITE(FF_TEST_SUITE) {
214218
MachineMappingForSingleLayer{
215219
OpCostMetrics{
216220
/*runtime=*/1.0 + 2.0 + 0.1,
217-
/*memory=*/2 + 3,
221+
/*memory=*/nonnegative_int{2 + 3},
218222
},
219223
ParallelLayerGuidObliviousMachineMapping{{
220224
{
@@ -232,7 +236,7 @@ TEST_SUITE(FF_TEST_SUITE) {
232236
}},
233237
},
234238
MachineMappingForSingleLayer{
235-
OpCostMetrics{1.5 + 2.5 + 0.1, 1 + 2},
239+
OpCostMetrics{1.5 + 2.5 + 0.1, nonnegative_int{1 + 2}},
236240
ParallelLayerGuidObliviousMachineMapping{{
237241
{
238242
BinaryTreePath{{
@@ -266,7 +270,7 @@ TEST_SUITE(FF_TEST_SUITE) {
266270
cache, context, problem_tree, full_machine_spec, constraints);
267271
MachineMappingWithMemoryResult correct =
268272
MachineMappingWithMemoryResult{{MachineMappingForSingleLayer{
269-
OpCostMetrics{2.5, 2},
273+
OpCostMetrics{2.5, nonnegative_int{2}},
270274
ParallelLayerGuidObliviousMachineMapping{{
271275
{
272276
BinaryTreePath{{

lib/compiler/test/src/compiler/machine_mapping/memory_optimization/machine_mapping_result_with_memory.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ TEST_SUITE(FF_TEST_SUITE) {
5353

5454
OpCostMetrics cost1 = OpCostMetrics{
5555
/*runtime=*/2.0,
56-
/*memory=*/2,
56+
/*memory=*/nonnegative_int{2},
5757
};
5858
OpCostMetrics cost2 = OpCostMetrics{
5959
/*runtime=*/4.0,
60-
/*memory=*/1,
60+
/*memory=*/nonnegative_int{1},
6161
};
6262
OpCostMetrics cost3 = OpCostMetrics{
6363
/*runtime=*/2.0,
64-
/*memory=*/3,
64+
/*memory=*/nonnegative_int{3},
6565
};
6666

6767
MachineMappingForSingleLayer mm1 = MachineMappingForSingleLayer{
@@ -183,7 +183,7 @@ TEST_SUITE(FF_TEST_SUITE) {
183183

184184
OpCostMetrics pre_cost = OpCostMetrics{
185185
/*runtime=*/2.0,
186-
/*memory=*/2,
186+
/*memory=*/nonnegative_int{2},
187187
};
188188
MachineMappingWithMemoryResult pre = MachineMappingWithMemoryResult{{
189189
MachineMappingForSingleLayer{
@@ -209,7 +209,7 @@ TEST_SUITE(FF_TEST_SUITE) {
209209

210210
OpCostMetrics post_cost = OpCostMetrics{
211211
/*runtime=*/4.0,
212-
/*memory=*/1,
212+
/*memory=*/nonnegative_int{1},
213213
};
214214

215215
MachineMappingWithMemoryResult post = MachineMappingWithMemoryResult{{
@@ -378,7 +378,7 @@ TEST_SUITE(FF_TEST_SUITE) {
378378

379379
OpCostMetrics lhs_cost = OpCostMetrics{
380380
/*runtime=*/2.0,
381-
/*memory=*/2,
381+
/*memory=*/nonnegative_int{2},
382382
};
383383
MachineMappingWithMemoryResult lhs = MachineMappingWithMemoryResult{{
384384
MachineMappingForSingleLayer{
@@ -404,7 +404,7 @@ TEST_SUITE(FF_TEST_SUITE) {
404404

405405
OpCostMetrics rhs_cost = OpCostMetrics{
406406
/*runtime=*/4.0,
407-
/*memory=*/1,
407+
/*memory=*/nonnegative_int{1},
408408
};
409409
MachineMappingWithMemoryResult rhs = MachineMappingWithMemoryResult{{
410410
MachineMappingForSingleLayer{
@@ -519,15 +519,15 @@ TEST_SUITE(FF_TEST_SUITE) {
519519

520520
OpCostMetrics cost1 = OpCostMetrics{
521521
/*runtime=*/2.0,
522-
/*memory=*/2,
522+
/*memory=*/nonnegative_int{2},
523523
};
524524
OpCostMetrics cost2 = OpCostMetrics{
525525
/*runtime=*/4.0,
526-
/*memory=*/1,
526+
/*memory=*/nonnegative_int{1},
527527
};
528528
OpCostMetrics cost3 = OpCostMetrics{
529529
/*runtime=*/2.0,
530-
/*memory=*/3,
530+
/*memory=*/nonnegative_int{3},
531531
};
532532

533533
MachineMappingForSingleLayer mm1 = MachineMappingForSingleLayer{

lib/utils/include/utils/nonnegative_int/nonnegative_int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class nonnegative_int {
3838
friend bool operator!=(int const &lhs, nonnegative_int const &rhs);
3939
friend bool operator>=(int const &lhs, nonnegative_int const &rhs);
4040

41+
nonnegative_int operator+(nonnegative_int const &other) const;
42+
4143
friend std::ostream &operator<<(std::ostream &os, nonnegative_int const &n);
4244

4345
friend int format_as(nonnegative_int const &);

lib/utils/src/utils/nonnegative_int/nonnegative_int.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ bool operator>=(int const &lhs, nonnegative_int const &rhs) {
7171
return lhs >= rhs.value_;
7272
}
7373

74+
nonnegative_int nonnegative_int::operator+(nonnegative_int const &other) const {
75+
return nonnegative_int{this->value_ + other.value_};
76+
}
77+
7478
std::ostream &operator<<(std::ostream &os, nonnegative_int const &n) {
7579
os << n.value_;
7680
return os;

lib/utils/test/src/utils/nonnegative_int/nonnegative_int.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ TEST_SUITE(FF_TEST_SUITE) {
198198
}
199199
}
200200

201+
TEST_CASE("nonnegative_int + operation") {
202+
nonnegative_int nn_int_1a = nonnegative_int{1};
203+
nonnegative_int nn_int_1b = nonnegative_int{1};
204+
nonnegative_int nn_int_2 = nonnegative_int{2};
205+
SUBCASE("LHS: nonnegative_int, RHS: nonnegative_int") {
206+
CHECK(nn_int_1a + nn_int_1b == nn_int_2);
207+
}
208+
}
209+
201210
TEST_CASE("adl_serializer<nonnegative_int>") {
202211
SUBCASE("to_json") {
203212
nonnegative_int input = nonnegative_int{5};

0 commit comments

Comments
 (0)