Skip to content

Commit 5cab32c

Browse files
committed
[Fix] Rename config file as ucm_config_asu.yaml;
[Refactor] AsuStore makes key hash only by blockId now; [Refactor] Move PatchFakeBackendTransportConfig into asu_store.cpp:BuildTransportConfig where transProvider has type FAKE. Remove fake_backend.h/cpp; [Refactor] Make fake_trans_provider.cpp simplier when making FakeTransProviderConfig.
1 parent 38e1dbe commit 5cab32c

10 files changed

Lines changed: 65 additions & 157 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# UCM ASU fake backend example for vLLM / vLLM-Ascend software integration tests.
22
#
33
# Use with:
4-
# kv_connector_extra_config={"UCM_CONFIG_FILE": "/workspace/unified-cache-management/examples/ucm_config_asu_fake_backend.yaml"}
4+
# kv_connector_extra_config={"UCM_CONFIG_FILE": "/workspace/unified-cache-management/examples/ucm_config_asu.yaml"}
55

66
ucm_connectors:
77
- ucm_connector_name: "UcmPipelineStore"

ucm/store/asu/cc/asu_store.cc

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <utility>
3838
#include "asu_client/asu_client.h"
3939
#include "asu_transport/asu_transport.h"
40-
#include "asu_transport/fake_backend.h"
4140
#include "logger/logger.h"
4241
#include "ucmstore_v1.h"
4342

@@ -47,31 +46,16 @@ namespace {
4746
using AsuStatus = UC::ASU::Status;
4847
using AsuStatusCode = UC::ASU::StatusCode;
4948

50-
std::uint64_t HashAsuKey(const Detail::BlockId& block, std::size_t shardIndex,
51-
std::size_t tensorIndex)
49+
std::uint64_t HashAsuKey(const Detail::BlockId& block)
5250
{
53-
std::uint64_t hash = 1469598103934665603ULL;
54-
const auto mixByte = [&hash](std::uint8_t value) {
55-
hash ^= value;
56-
hash *= 1099511628211ULL;
57-
};
58-
59-
for (auto b : block) { mixByte(std::to_integer<std::uint8_t>(b)); }
60-
for (std::size_t shift = 0; shift < sizeof(shardIndex) * 8; shift += 8) {
61-
mixByte(static_cast<std::uint8_t>((shardIndex >> shift) & 0xFF));
62-
}
63-
for (std::size_t shift = 0; shift < sizeof(tensorIndex) * 8; shift += 8) {
64-
mixByte(static_cast<std::uint8_t>((tensorIndex >> shift) & 0xFF));
65-
}
66-
return hash;
51+
static Detail::BlockIdHasher hasher;
52+
return static_cast<std::uint64_t>(hasher(block));
6753
}
6854

69-
std::string MakeAsuKey(const Detail::BlockId& block, std::size_t shardIndex,
70-
std::size_t tensorIndex)
55+
std::string MakeAsuKey(const Detail::BlockId& block)
7156
{
7257
std::ostringstream os;
73-
os << std::hex << std::setfill('0') << std::setw(16)
74-
<< HashAsuKey(block, shardIndex, tensorIndex);
58+
os << std::hex << std::setfill('0') << std::setw(16) << HashAsuKey(block);
7559
return os.str();
7660
}
7761

@@ -193,11 +177,26 @@ UC::ASU::TransportConfig BuildTransportConfig(const Config& config, std::size_t
193177
transportConfig.endpoints.emplace_back(std::move(endpoint));
194178
}
195179
if (config.transProviderType == UC::ASU::TransProviderType::FAKE) {
196-
UC::ASU::FakeBackendConfig fakeConfig;
197-
fakeConfig.storePath = config.fakeBackendPath;
198-
fakeConfig.latencyMs = config.fakeBackendLatencyMs;
199-
fakeConfig.deviceId = config.deviceId >= 0 ? config.deviceId : 0;
200-
UC::ASU::PatchFakeBackendTransportConfig(transportConfig, fakeConfig);
180+
const auto fakeDeviceId = config.deviceId >= 0 ? config.deviceId : 0;
181+
transportConfig.attrs.try_emplace("kernel_count", "1");
182+
transportConfig.attrs.try_emplace("quiet_count", "1");
183+
transportConfig.attrs["kv_ns_id"] = std::to_string(transportConfig.asuId);
184+
transportConfig.attrs.try_emplace("dtype", "0");
185+
transportConfig.attrs.try_emplace("dspec", "0");
186+
transportConfig.attrs.try_emplace("lr", "false");
187+
transportConfig.attrs["sc"] = "true";
188+
transportConfig.attrs["fake_backend.path"] = config.fakeBackendPath;
189+
transportConfig.attrs["fake_backend.latency_ms"] =
190+
std::to_string(config.fakeBackendLatencyMs);
191+
transportConfig.attrs["fake_backend.device_id"] = std::to_string(fakeDeviceId);
192+
if (transportConfig.endpoints.empty()) {
193+
UC::ASU::AsuEndpoint endpoint;
194+
endpoint.ip = "fake_backend";
195+
endpoint.port = 19001;
196+
endpoint.protocol = UC::ASU::Protocol::TCP;
197+
endpoint.deviceId = fakeDeviceId;
198+
transportConfig.endpoints.emplace_back(std::move(endpoint));
199+
}
201200
}
202201
return transportConfig;
203202
}
@@ -586,7 +585,7 @@ class AsuStore final : public StoreV1 {
586585
std::vector<UC::ASU::CacheKey> keys;
587586
keys.reserve(num);
588587
for (std::size_t blockIndex = 0; blockIndex < num; ++blockIndex) {
589-
keys.emplace_back(MakeAsuKey(blocks[blockIndex], 0, 0));
588+
keys.emplace_back(MakeAsuKey(blocks[blockIndex]));
590589
}
591590
return keys;
592591
}
@@ -623,7 +622,7 @@ class AsuStore final : public StoreV1 {
623622
}
624623
for (std::size_t tensorIndex = 0; tensorIndex < shard.addrs.size(); ++tensorIndex) {
625624
UC::ASU::KVBuffer entry;
626-
entry.key = MakeAsuKey(shard.owner, shard.index, tensorIndex);
625+
entry.key = MakeAsuKey(shard.owner);
627626
entry.buffer.region.memoryType = memoryType;
628627
entry.buffer.region.addr =
629628
reinterpret_cast<std::uint64_t>(shard.addrs[tensorIndex]);

ucm/transport/kv/asu/trans/include/asu_transport/fake_backend.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

ucm/transport/kv/asu/trans/src/asu_transport_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Status AsuTransportImpl::Init(const TransportConfig& config)
6565
break;
6666
case TransProviderType::FAKE:
6767
transProvider_ =
68-
std::make_unique<FakeTransProvider>(MakeFakeBackendConfig(config_));
68+
std::make_unique<FakeTransProvider>(MakeFakeTransProviderConfig(config_));
6969
break;
7070
case TransProviderType::AIV:
7171
return Status::Error(StatusCode::UNSUPPORTED,

ucm/transport/kv/asu/trans/src/fake_backend.cpp

Lines changed: 0 additions & 53 deletions
This file was deleted.

ucm/transport/kv/asu/trans/src/fake_trans_provider.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ constexpr std::uint8_t kDeleteEntryFailed = 0x1;
4848
constexpr std::uint8_t kExistEntryNotExist = 0x0;
4949
constexpr std::uint8_t kExistEntryExist = 0x1;
5050

51-
std::filesystem::path StoreRoot(const FakeBackendConfig& config)
52-
{
53-
if (!config.storePath.empty()) { return config.storePath; }
54-
return "./asu-fake-backend-store";
55-
}
56-
5751
std::uint64_t ReadU64(std::uint32_t low, std::uint32_t high)
5852
{
5953
return static_cast<std::uint64_t>(low) | (static_cast<std::uint64_t>(high) << 32);
@@ -89,17 +83,18 @@ std::string KeyFileName(const std::string& key)
8983
return stream.str();
9084
}
9185

92-
std::filesystem::path AsuRoot(const FakeBackendConfig& config, AsuId asuId)
86+
std::filesystem::path AsuRoot(const FakeTransProviderConfig& config, AsuId asuId)
9387
{
94-
return StoreRoot(config) / ("asu-" + std::to_string(asuId));
88+
return std::filesystem::path(config.storePath) / ("asu-" + std::to_string(asuId));
9589
}
9690

97-
std::filesystem::path KeyPath(const FakeBackendConfig& config, AsuId asuId, const std::string& key)
91+
std::filesystem::path KeyPath(const FakeTransProviderConfig& config, AsuId asuId,
92+
const std::string& key)
9893
{
9994
return AsuRoot(config, asuId) / KeyFileName(key);
10095
}
10196

102-
bool StoreBytes(const FakeBackendConfig& config, AsuId asuId, const std::string& key,
97+
bool StoreBytes(const FakeTransProviderConfig& config, AsuId asuId, const std::string& key,
10398
std::uint64_t addr, std::uint32_t length)
10499
{
105100
std::vector<char> buffer(length);
@@ -124,7 +119,7 @@ bool StoreBytes(const FakeBackendConfig& config, AsuId asuId, const std::string&
124119
return output.good();
125120
}
126121

127-
bool LoadBytes(const FakeBackendConfig& config, AsuId asuId, const std::string& key,
122+
bool LoadBytes(const FakeTransProviderConfig& config, AsuId asuId, const std::string& key,
128123
std::uint64_t addr, std::uint32_t length)
129124
{
130125
std::ifstream input(KeyPath(config, asuId, key), std::ios::binary);
@@ -151,14 +146,14 @@ bool LoadBytes(const FakeBackendConfig& config, AsuId asuId, const std::string&
151146
return true;
152147
}
153148

154-
bool DeleteKey(const FakeBackendConfig& config, AsuId asuId, const std::string& key)
149+
bool DeleteKey(const FakeTransProviderConfig& config, AsuId asuId, const std::string& key)
155150
{
156151
std::error_code errorCode;
157152
std::filesystem::remove(KeyPath(config, asuId, key), errorCode);
158153
return !errorCode;
159154
}
160155

161-
bool ExistsKey(const FakeBackendConfig& config, AsuId asuId, const std::string& key)
156+
bool ExistsKey(const FakeTransProviderConfig& config, AsuId asuId, const std::string& key)
162157
{
163158
std::error_code errorCode;
164159
return std::filesystem::exists(KeyPath(config, asuId, key), errorCode);
@@ -223,7 +218,7 @@ std::vector<std::string> ReadKeyEntries(const std::uint32_t* request, std::uint1
223218
return keys;
224219
}
225220

226-
Status CompleteBatchStore(const FakeBackendConfig& config, AsuId asuId,
221+
Status CompleteBatchStore(const FakeTransProviderConfig& config, AsuId asuId,
227222
const std::uint32_t* request)
228223
{
229224
const auto cid = static_cast<std::uint16_t>(RequestCid(request));
@@ -248,7 +243,7 @@ Status CompleteBatchStore(const FakeBackendConfig& config, AsuId asuId,
248243
return Status::OK();
249244
}
250245

251-
Status CompleteBatchRetrieve(const FakeBackendConfig& config, AsuId asuId,
246+
Status CompleteBatchRetrieve(const FakeTransProviderConfig& config, AsuId asuId,
252247
const std::uint32_t* request)
253248
{
254249
const auto cid = static_cast<std::uint16_t>(RequestCid(request));
@@ -273,7 +268,8 @@ Status CompleteBatchRetrieve(const FakeBackendConfig& config, AsuId asuId,
273268
return Status::OK();
274269
}
275270

276-
Status CompleteDelete(const FakeBackendConfig& config, AsuId asuId, const std::uint32_t* request)
271+
Status CompleteDelete(const FakeTransProviderConfig& config, AsuId asuId,
272+
const std::uint32_t* request)
277273
{
278274
const auto cid = static_cast<std::uint16_t>(RequestCid(request));
279275
const auto responseBufferAddr = ReadU64(request[3], request[4]);
@@ -294,7 +290,8 @@ Status CompleteDelete(const FakeBackendConfig& config, AsuId asuId, const std::u
294290
return Status::OK();
295291
}
296292

297-
Status CompleteExist(const FakeBackendConfig& config, AsuId asuId, const std::uint32_t* request)
293+
Status CompleteExist(const FakeTransProviderConfig& config, AsuId asuId,
294+
const std::uint32_t* request)
298295
{
299296
const auto cid = static_cast<std::uint16_t>(RequestCid(request));
300297
const auto responseBufferAddr = ReadU64(request[3], request[4]);
@@ -319,7 +316,7 @@ Status CompleteExist(const FakeBackendConfig& config, AsuId asuId, const std::ui
319316
return Status::OK();
320317
}
321318

322-
Status CompleteFakeBackendRequest(FakeBackendConfig config, const void* sendBuffer,
319+
Status CompleteFakeBackendRequest(const FakeTransProviderConfig& config, const void* sendBuffer,
323320
std::uint64_t len)
324321
{
325322
if (config.latencyMs > 0) {
@@ -350,12 +347,14 @@ Status CompleteFakeBackendRequest(FakeBackendConfig config, const void* sendBuff
350347

351348
} // namespace
352349

353-
FakeBackendConfig MakeFakeBackendConfig(const TransportConfig& config)
350+
FakeTransProviderConfig MakeFakeTransProviderConfig(const TransportConfig& config)
354351
{
355-
FakeBackendConfig fakeConfig;
352+
FakeTransProviderConfig fakeConfig;
356353
fakeConfig.deviceId = config.endpoints.empty() ? 0 : config.endpoints.front().deviceId;
357354
auto pathIter = config.attrs.find("fake_backend.path");
358-
if (pathIter != config.attrs.end()) { fakeConfig.storePath = pathIter->second; }
355+
if (pathIter != config.attrs.end() && !pathIter->second.empty()) {
356+
fakeConfig.storePath = pathIter->second;
357+
}
359358
auto latencyIter = config.attrs.find("fake_backend.latency_ms");
360359
if (latencyIter != config.attrs.end()) {
361360
fakeConfig.latencyMs = static_cast<std::uint64_t>(std::stoull(latencyIter->second));
@@ -364,14 +363,10 @@ FakeBackendConfig MakeFakeBackendConfig(const TransportConfig& config)
364363
if (deviceIter != config.attrs.end()) {
365364
fakeConfig.deviceId = static_cast<std::int32_t>(std::stol(deviceIter->second));
366365
}
367-
if (fakeConfig.storePath.empty()) { fakeConfig.storePath = "./asu-fake-backend-store"; }
368366
return fakeConfig;
369367
}
370368

371-
FakeTransProvider::FakeTransProvider(FakeBackendConfig config) : config_(std::move(config))
372-
{
373-
if (config_.storePath.empty()) { config_.storePath = "./asu-fake-backend-store"; }
374-
}
369+
FakeTransProvider::FakeTransProvider(FakeTransProviderConfig config) : config_(std::move(config)) {}
375370

376371
Status FakeTransProvider::SetUpAclRuntime()
377372
{

ucm/transport/kv/asu/trans/src/fake_trans_provider.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@
2323
* */
2424
#pragma once
2525

26-
#include "asu_transport/fake_backend.h"
26+
#include "asu_transport/asu_transport.h"
2727
#include "trans_provider.h"
2828

2929
namespace UC::ASU {
3030

31+
struct FakeTransProviderConfig {
32+
std::string storePath{"./asu-fake-backend-store"};
33+
std::uint64_t latencyMs{1};
34+
std::int32_t deviceId{0};
35+
};
36+
3137
class FakeTransProvider : public TransProvider {
3238
public:
33-
explicit FakeTransProvider(FakeBackendConfig config);
39+
explicit FakeTransProvider(FakeTransProviderConfig config);
3440

3541
Status CreateConnection(const std::string&, const std::string&, uint32_t, uint32_t qpNum,
3642
uint32_t, std::vector<ConnectionHandle>& handles) override;
@@ -54,10 +60,10 @@ class FakeTransProvider : public TransProvider {
5460
private:
5561
Status SetUpAclRuntime();
5662

57-
FakeBackendConfig config_;
63+
FakeTransProviderConfig config_;
5864
bool aclReady_{false};
5965
};
6066

61-
FakeBackendConfig MakeFakeBackendConfig(const TransportConfig& config);
67+
FakeTransProviderConfig MakeFakeTransProviderConfig(const TransportConfig& config);
6268

6369
} // namespace UC::ASU

0 commit comments

Comments
 (0)