diff --git a/tensorflow/lite/delegates/gpu/common/memory_management.h b/tensorflow/lite/delegates/gpu/common/memory_management.h index 147826134fa..4b8023b8d54 100644 --- a/tensorflow/lite/delegates/gpu/common/memory_management.h +++ b/tensorflow/lite/delegates/gpu/common/memory_management.h @@ -40,6 +40,11 @@ struct TensorUsageRecord { TensorUsageRecord(uint32_t size, TaskId first, TaskId last) : tensor_size(size), first_task(first), last_task(last) {} + + // Default order of tensor usage records is increasing order of first_task. + bool operator<(const TensorUsageRecord& other) const { + return first_task < other.first_task; + } }; // Information about assignment of tensors to shared objects diff --git a/tensorflow/lite/delegates/gpu/common/memory_management_test.cc b/tensorflow/lite/delegates/gpu/common/memory_management_test.cc index 6fd8b217b67..a1484cd0e55 100644 --- a/tensorflow/lite/delegates/gpu/common/memory_management_test.cc +++ b/tensorflow/lite/delegates/gpu/common/memory_management_test.cc @@ -28,17 +28,17 @@ TEST(Model, EmptyRecords) { ObjectsAssignment assignment; ASSERT_TRUE( AssignObjectsToTensors({}, MemoryStrategy::NAIVE, &assignment).ok()); - ASSERT_TRUE(assignment.object_ids.empty()); - ASSERT_TRUE(assignment.object_sizes.empty()); + EXPECT_TRUE(assignment.object_ids.empty()); + EXPECT_TRUE(assignment.object_sizes.empty()); ASSERT_TRUE( AssignObjectsToTensors({}, MemoryStrategy::GREEDY, &assignment).ok()); - ASSERT_TRUE(assignment.object_ids.empty()); - ASSERT_TRUE(assignment.object_sizes.empty()); + EXPECT_TRUE(assignment.object_ids.empty()); + EXPECT_TRUE(assignment.object_sizes.empty()); ASSERT_TRUE( AssignObjectsToTensors({}, MemoryStrategy::MINCOSTFLOW, &assignment) .ok()); - ASSERT_TRUE(assignment.object_ids.empty()); - ASSERT_TRUE(assignment.object_sizes.empty()); + EXPECT_TRUE(assignment.object_ids.empty()); + EXPECT_TRUE(assignment.object_sizes.empty()); } TEST(Model, OneRecord) {