Skip to content

Commit d409ed8

Browse files
catyans彦纾Yanshu
authored
[TENT] Add IntentType enum to Request for Transfer Intent API (#2810)
* [TENT] Add IntentType enum to Request for Transfer Intent API Define standard intent categories (FOREGROUND_GET, BACKGROUND_PREFETCH, MIGRATION, CHECKPOINT, WEIGHT_LOADING, STAGING_INTERNAL) so TENT can identify a request's business semantics before scheduling. Changes: - types.h: add IntentType enum class + Request::intent_type field (default INTENT_UNSPEC, behavior byte-identical to today) - pybind.cpp: export IntentType enum, add intent_type/policy_name/ deadline_ns to Request constructor and as readwrite attributes - intent_type_test.cpp: 6 gtest cases covering defaults, assignment, integer values, field independence, copy, and batch usage Relates to: TENT roadmap "Transfer Intent API" * ci: retrigger CI * fix: keep intent type binding scoped * test: wire intent type coverage into cmake --------- Co-authored-by: 彦纾 <wangyanshu.wys@alibaba-inc.com> Co-authored-by: Yanshu <237344440@qq.com>
1 parent 98ff4e4 commit d409ed8

4 files changed

Lines changed: 129 additions & 3 deletions

File tree

mooncake-transfer-engine/tent/include/tent/common/types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ inline TransportType c_to_transport_hint(int v) {
6666
return static_cast<TransportType>(v);
6767
}
6868

69+
enum class IntentType : int {
70+
INTENT_UNSPEC = 0,
71+
FOREGROUND_GET,
72+
BACKGROUND_PREFETCH,
73+
MIGRATION,
74+
CHECKPOINT,
75+
WEIGHT_LOADING,
76+
STAGING_INTERNAL,
77+
};
78+
6979
struct Request {
7080
enum OpCode { READ, WRITE };
7181
OpCode opcode;
@@ -86,6 +96,7 @@ struct Request {
8696
// (MLU = actual transfer time / available window) on completion; it does
8797
// not yet drive any admission or scheduling decision. See RFC #2519.
8898
uint64_t deadline_ns = 0;
99+
IntentType intent_type = IntentType::INTENT_UNSPEC;
89100
};
90101

91102
enum TransferStatusEnum {

mooncake-transfer-engine/tent/src/python/pybind.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ PYBIND11_MODULE(tent, m) {
302302
.value("SUNRISE_LINK", TransportType::SUNRISE_LINK)
303303
.export_values();
304304

305+
py::enum_<IntentType>(m, "IntentType")
306+
.value("INTENT_UNSPEC", IntentType::INTENT_UNSPEC)
307+
.value("FOREGROUND_GET", IntentType::FOREGROUND_GET)
308+
.value("BACKGROUND_PREFETCH", IntentType::BACKGROUND_PREFETCH)
309+
.value("MIGRATION", IntentType::MIGRATION)
310+
.value("CHECKPOINT", IntentType::CHECKPOINT)
311+
.value("WEIGHT_LOADING", IntentType::WEIGHT_LOADING)
312+
.value("STAGING_INTERNAL", IntentType::STAGING_INTERNAL)
313+
.export_values();
314+
305315
py::enum_<SegmentInfo::Type>(m, "SegmentInfoType")
306316
.value("Memory", SegmentInfo::Type::Memory)
307317
.value("File", SegmentInfo::Type::File)
@@ -324,7 +334,7 @@ PYBIND11_MODULE(tent, m) {
324334
size_t length, int priority,
325335
TransportType transport_hint,
326336
std::optional<std::string> policy_name,
327-
uint64_t deadline_ns) {
337+
uint64_t deadline_ns, IntentType intent_type) {
328338
Request r;
329339
r.opcode = opcode;
330340
r.source = U64ToPtr(source);
@@ -335,13 +345,15 @@ PYBIND11_MODULE(tent, m) {
335345
r.transport_hint = transport_hint;
336346
r.policy_name = std::move(policy_name);
337347
r.deadline_ns = deadline_ns;
348+
r.intent_type = intent_type;
338349
return r;
339350
}),
340351
py::arg("opcode"), py::arg("source"), py::arg("target_id"),
341352
py::arg("target_offset"), py::arg("length"),
342353
py::arg("priority") = PRIO_HIGH,
343354
py::arg("transport_hint") = TransportType::UNSPEC,
344-
py::arg("policy_name") = std::nullopt, py::arg("deadline_ns") = 0)
355+
py::arg("policy_name") = std::nullopt, py::arg("deadline_ns") = 0,
356+
py::arg("intent_type") = IntentType::INTENT_UNSPEC)
345357
.def_property(
346358
"opcode", [](const Request& r) { return r.opcode; },
347359
[](Request& r, Request::OpCode op) { r.opcode = op; })
@@ -354,7 +366,8 @@ PYBIND11_MODULE(tent, m) {
354366
.def_readwrite("priority", &Request::priority)
355367
.def_readwrite("transport_hint", &Request::transport_hint)
356368
.def_readwrite("policy_name", &Request::policy_name)
357-
.def_readwrite("deadline_ns", &Request::deadline_ns);
369+
.def_readwrite("deadline_ns", &Request::deadline_ns)
370+
.def_readwrite("intent_type", &Request::intent_type);
358371

359372
py::class_<TransferStatus>(m, "TransferStatus")
360373
.def(py::init<>())

mooncake-transfer-engine/tent/tests/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ target_include_directories(tent_transport_hint_test
189189
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
190190
add_test(NAME tent_transport_hint_test COMMAND tent_transport_hint_test)
191191

192+
add_executable(tent_intent_type_test intent_type_test.cpp)
193+
target_link_libraries(tent_intent_type_test PRIVATE gtest gtest_main
194+
tent_common)
195+
target_include_directories(tent_intent_type_test
196+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
197+
add_test(NAME tent_intent_type_test COMMAND tent_intent_type_test)
198+
192199
# ProgressWorker skeleton test: covers default-off behavior, event-driven
193200
# progress without poll-failover, and freeBatch races (issue #2116).
194201
add_executable(tent_progress_worker_test progress_worker_test.cpp)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2026 KVCache.AI
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// Unit tests for IntentType enum and its integration with Request.
16+
17+
#include <gtest/gtest.h>
18+
19+
#include <vector>
20+
21+
#include "tent/common/types.h"
22+
23+
namespace mooncake {
24+
namespace tent {
25+
namespace {
26+
27+
TEST(IntentTypeTest, DefaultIsUnspec) {
28+
Request r{};
29+
EXPECT_EQ(r.intent_type, IntentType::INTENT_UNSPEC);
30+
}
31+
32+
TEST(IntentTypeTest, AllValuesAssignable) {
33+
Request r{};
34+
r.intent_type = IntentType::FOREGROUND_GET;
35+
EXPECT_EQ(r.intent_type, IntentType::FOREGROUND_GET);
36+
r.intent_type = IntentType::BACKGROUND_PREFETCH;
37+
EXPECT_EQ(r.intent_type, IntentType::BACKGROUND_PREFETCH);
38+
r.intent_type = IntentType::MIGRATION;
39+
EXPECT_EQ(r.intent_type, IntentType::MIGRATION);
40+
r.intent_type = IntentType::CHECKPOINT;
41+
EXPECT_EQ(r.intent_type, IntentType::CHECKPOINT);
42+
r.intent_type = IntentType::WEIGHT_LOADING;
43+
EXPECT_EQ(r.intent_type, IntentType::WEIGHT_LOADING);
44+
r.intent_type = IntentType::STAGING_INTERNAL;
45+
EXPECT_EQ(r.intent_type, IntentType::STAGING_INTERNAL);
46+
}
47+
48+
TEST(IntentTypeTest, IntegerValues) {
49+
EXPECT_EQ(static_cast<int>(IntentType::INTENT_UNSPEC), 0);
50+
EXPECT_EQ(static_cast<int>(IntentType::FOREGROUND_GET), 1);
51+
EXPECT_EQ(static_cast<int>(IntentType::BACKGROUND_PREFETCH), 2);
52+
EXPECT_EQ(static_cast<int>(IntentType::MIGRATION), 3);
53+
EXPECT_EQ(static_cast<int>(IntentType::CHECKPOINT), 4);
54+
EXPECT_EQ(static_cast<int>(IntentType::WEIGHT_LOADING), 5);
55+
EXPECT_EQ(static_cast<int>(IntentType::STAGING_INTERNAL), 6);
56+
}
57+
58+
TEST(IntentTypeTest, DoesNotAffectOtherFields) {
59+
Request r{};
60+
r.opcode = Request::READ;
61+
r.priority = PRIO_LOW;
62+
r.deadline_ns = 12345;
63+
r.transport_hint = RDMA;
64+
r.intent_type = IntentType::CHECKPOINT;
65+
66+
EXPECT_EQ(r.opcode, Request::READ);
67+
EXPECT_EQ(r.priority, PRIO_LOW);
68+
EXPECT_EQ(r.deadline_ns, 12345u);
69+
EXPECT_EQ(r.transport_hint, RDMA);
70+
EXPECT_EQ(r.intent_type, IntentType::CHECKPOINT);
71+
}
72+
73+
TEST(IntentTypeTest, CopyPreservesIntentType) {
74+
Request r{};
75+
r.intent_type = IntentType::WEIGHT_LOADING;
76+
Request copy = r;
77+
EXPECT_EQ(copy.intent_type, IntentType::WEIGHT_LOADING);
78+
}
79+
80+
TEST(IntentTypeTest, VectorOfRequests) {
81+
std::vector<Request> batch(4);
82+
batch[0].intent_type = IntentType::FOREGROUND_GET;
83+
batch[1].intent_type = IntentType::BACKGROUND_PREFETCH;
84+
batch[2].intent_type = IntentType::MIGRATION;
85+
batch[3].intent_type = IntentType::INTENT_UNSPEC;
86+
87+
EXPECT_EQ(batch[0].intent_type, IntentType::FOREGROUND_GET);
88+
EXPECT_EQ(batch[1].intent_type, IntentType::BACKGROUND_PREFETCH);
89+
EXPECT_EQ(batch[2].intent_type, IntentType::MIGRATION);
90+
EXPECT_EQ(batch[3].intent_type, IntentType::INTENT_UNSPEC);
91+
}
92+
93+
} // namespace
94+
} // namespace tent
95+
} // namespace mooncake

0 commit comments

Comments
 (0)