Skip to content

Commit 9376ba8

Browse files
author
彦纾
committed
[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"
1 parent 866ed32 commit 9376ba8

3 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: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ PYBIND11_MODULE(tent, m) {
301301
.value("SUNRISE_LINK", TransportType::SUNRISE_LINK)
302302
.export_values();
303303

304+
py::enum_<IntentType>(m, "IntentType")
305+
.value("INTENT_UNSPEC", IntentType::INTENT_UNSPEC)
306+
.value("FOREGROUND_GET", IntentType::FOREGROUND_GET)
307+
.value("BACKGROUND_PREFETCH", IntentType::BACKGROUND_PREFETCH)
308+
.value("MIGRATION", IntentType::MIGRATION)
309+
.value("CHECKPOINT", IntentType::CHECKPOINT)
310+
.value("WEIGHT_LOADING", IntentType::WEIGHT_LOADING)
311+
.value("STAGING_INTERNAL", IntentType::STAGING_INTERNAL)
312+
.export_values();
313+
304314
py::enum_<SegmentInfo::Type>(m, "SegmentInfoType")
305315
.value("Memory", SegmentInfo::Type::Memory)
306316
.value("File", SegmentInfo::Type::File)
@@ -321,7 +331,9 @@ PYBIND11_MODULE(tent, m) {
321331
.def(py::init([](Request::OpCode opcode, uint64_t source,
322332
uint64_t target_id, uint64_t target_offset,
323333
size_t length, int priority,
324-
TransportType transport_hint) {
334+
TransportType transport_hint,
335+
std::optional<std::string> policy_name,
336+
uint64_t deadline_ns, IntentType intent_type) {
325337
Request r;
326338
r.opcode = opcode;
327339
r.source = U64ToPtr(source);
@@ -330,12 +342,17 @@ PYBIND11_MODULE(tent, m) {
330342
r.length = length;
331343
r.priority = priority;
332344
r.transport_hint = transport_hint;
345+
r.policy_name = std::move(policy_name);
346+
r.deadline_ns = deadline_ns;
347+
r.intent_type = intent_type;
333348
return r;
334349
}),
335350
py::arg("opcode"), py::arg("source"), py::arg("target_id"),
336351
py::arg("target_offset"), py::arg("length"),
337352
py::arg("priority") = PRIO_HIGH,
338-
py::arg("transport_hint") = TransportType::UNSPEC)
353+
py::arg("transport_hint") = TransportType::UNSPEC,
354+
py::arg("policy_name") = std::nullopt, py::arg("deadline_ns") = 0,
355+
py::arg("intent_type") = IntentType::INTENT_UNSPEC)
339356
.def_property(
340357
"opcode", [](const Request& r) { return r.opcode; },
341358
[](Request& r, Request::OpCode op) { r.opcode = op; })
@@ -346,7 +363,10 @@ PYBIND11_MODULE(tent, m) {
346363
.def_readwrite("target_offset", &Request::target_offset)
347364
.def_readwrite("length", &Request::length)
348365
.def_readwrite("priority", &Request::priority)
349-
.def_readwrite("transport_hint", &Request::transport_hint);
366+
.def_readwrite("transport_hint", &Request::transport_hint)
367+
.def_readwrite("policy_name", &Request::policy_name)
368+
.def_readwrite("deadline_ns", &Request::deadline_ns)
369+
.def_readwrite("intent_type", &Request::intent_type);
350370

351371
py::class_<TransferStatus>(m, "TransferStatus")
352372
.def(py::init<>())
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)