Skip to content

Commit f2f7603

Browse files
[Opt] Replace acl with abstract runtime in kv client
Co-authored-by: zhaoxiaoyan-0826 <87650636+zhaoxiaoyan-0826@users.noreply.github.com>
1 parent 41abb90 commit f2f7603

27 files changed

Lines changed: 422 additions & 570 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ option(BUILD_UCM_STORE "build ucm store module." ON)
1111
option(BUILD_UCM_DRAMPOOL "build DramPool daemon." ON)
1212
option(BUILD_UCM_SPARSE "build ucm sparse module." OFF)
1313
option(BUILD_UCM_ASU "build ucm ASU transport module." OFF)
14+
option(BUILD_UCM_DELEGATOR "build ucm delegator module." OFF)
1415
option(BUILD_UCM_MINDIE "build ucm MindIE integration module." OFF)
1516
option(BUILD_UNIT_TESTS "build all unit test suits." OFF)
1617
option(BUILD_NUMA "build numactl library." OFF)

ucm/shared/trans/simu/simu_buffer.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ std::shared_ptr<void> SimuBuffer::MakeDeviceMappedHostBuffer(size_t size)
5656
return MakeHostBuffer(size);
5757
}
5858

59+
std::shared_ptr<void> SimuBuffer::MakeHostMappedDeviceBuffer(size_t size, void** pDevice)
60+
{
61+
auto host = MakeHostBuffer(size);
62+
if (pDevice) { *pDevice = host.get(); }
63+
return host;
64+
}
65+
5966
std::shared_ptr<void> SimuBuffer::MakeDeviceBuffer(size_t size)
6067
{
6168
constexpr int8_t deviceInitVal = 0xd;

ucm/shared/trans/simu/simu_buffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ class SimuBuffer : public ReservedBuffer {
3232
public:
3333
// Simu has no real device, so device-mapped-host memory is plain host memory.
3434
bool SupportsDeviceMappedHostBuffer() const override { return true; }
35+
bool SupportsHostMappedDeviceBuffer() const override { return true; }
3536
std::shared_ptr<void> MakeDeviceMappedHostBuffer(size_t size) override;
37+
std::shared_ptr<void> MakeHostMappedDeviceBuffer(size_t size,
38+
void** pDevice = nullptr) override;
3639
std::shared_ptr<void> MakeDeviceBuffer(size_t size) override;
3740
std::shared_ptr<void> MakeHostBuffer(size_t size) override;
3841
};

ucm/store/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if(RUNTIME_ENVIRONMENT STREQUAL "ascend" OR RUNTIME_ENVIRONMENT STREQUAL "simu")
1313
endif()
1414
if(BUILD_UCM_ASU)
1515
add_subdirectory(asu)
16+
endif()
17+
if(BUILD_UCM_DELEGATOR)
1618
add_subdirectory(delegator)
1719
endif()
1820
add_subdirectory(empty)

ucm/store/asu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ target_include_directories(asustore
44
PUBLIC
55
${CMAKE_CURRENT_SOURCE_DIR}/cc
66
)
7-
target_link_libraries(asustore PUBLIC storeintf asu_client infra_logger PRIVATE asu_ascend_deps trans)
7+
target_link_libraries(asustore PUBLIC storeintf asu_client infra_logger PRIVATE trans)
88
set_target_properties(asustore PROPERTIES
99
BUILD_WITH_INSTALL_RPATH TRUE
1010
BUILD_RPATH "$ORIGIN;$ORIGIN/../../transport/kv/asu"

ucm/store/asu/cc/asu_store.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class AsuStore final : public StoreV1 {
313313
for (std::size_t index = 0; index < count; ++index) {
314314
if (registrations[index].addr == 0 || registrations[index].size == 0) { continue; }
315315
UC::ASU::MemoryRegion region;
316-
region.memoryType = UC::ASU::MemoryType::ASCEND_DEVICE;
316+
region.memoryType = UC::ASU::MemoryType::DEVICE;
317317
region.addr = static_cast<std::uint64_t>(registrations[index].addr);
318318
region.size = static_cast<std::uint64_t>(registrations[index].size);
319319
region.deviceId = config_.deviceId;
@@ -727,7 +727,7 @@ class AsuStore final : public StoreV1 {
727727
for (std::size_t tensorIndex = 0; tensorIndex < shard.addrs.size(); ++tensorIndex) {
728728
UC::ASU::KVBuffer entry;
729729
entry.key = MakeAsuKey(shard.owner);
730-
entry.buffer.region.memoryType = UC::ASU::MemoryType::ASCEND_DEVICE;
730+
entry.buffer.region.memoryType = UC::ASU::MemoryType::DEVICE;
731731
entry.buffer.region.addr =
732732
reinterpret_cast<std::uint64_t>(shard.addrs[tensorIndex]);
733733
entry.buffer.region.size = config_.tensorSizes[tensorIndex];

ucm/store/test/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ if(BUILD_UNIT_TESTS)
33
file(GLOB_RECURSE UCMSTORE_TEST_SOURCE_FILES "./case/*.cc")
44
if(NOT BUILD_UCM_ASU)
55
list(FILTER UCMSTORE_TEST_SOURCE_FILES EXCLUDE REGEX ".*[/\\\\]asu[/\\\\].*")
6+
endif()
7+
if(NOT BUILD_UCM_DELEGATOR)
68
list(FILTER UCMSTORE_TEST_SOURCE_FILES EXCLUDE REGEX ".*[/\\\\]delegator[/\\\\].*")
79
endif()
810
if(RUNTIME_ENVIRONMENT STREQUAL "ascend" OR RUNTIME_ENVIRONMENT STREQUAL "simu")
@@ -48,12 +50,16 @@ if(BUILD_UNIT_TESTS)
4850
if(BUILD_UCM_ASU)
4951
target_link_libraries(ucmstore.test PRIVATE
5052
asu_client
51-
delegator
52-
delegator_store
5353
buffer_pool
54-
asu_ascend_deps
54+
trans
5555
)
5656
target_compile_definitions(ucmstore.test PRIVATE ASU_BUILD_TESTS)
5757
endif()
58+
if(BUILD_UCM_DELEGATOR)
59+
target_link_libraries(ucmstore.test PRIVATE
60+
delegator
61+
delegator_store
62+
)
63+
endif()
5864
gtest_discover_tests(ucmstore.test)
5965
endif()

ucm/transport/kv/asu/CMakeLists.txt

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
1-
if(NOT RUNTIME_ENVIRONMENT STREQUAL "ascend")
2-
message(FATAL_ERROR "BUILD_UCM_ASU requires RUNTIME_ENVIRONMENT=ascend. Current value: ${RUNTIME_ENVIRONMENT}")
1+
if(NOT (RUNTIME_ENVIRONMENT STREQUAL "ascend" OR RUNTIME_ENVIRONMENT STREQUAL "simu"))
2+
message(FATAL_ERROR
3+
"BUILD_UCM_ASU requires RUNTIME_ENVIRONMENT=ascend or simu. Current value: ${RUNTIME_ENVIRONMENT}")
34
endif()
45

5-
if(NOT DEFINED ASCEND_ROOT)
6-
if(DEFINED ENV{ASCEND_HOME_PATH})
7-
set(ASCEND_ROOT "$ENV{ASCEND_HOME_PATH}" CACHE PATH "Path to Ascend root directory")
8-
elseif(DEFINED ENV{ASCEND_TOOLKIT_HOME})
9-
set(ASCEND_ROOT "$ENV{ASCEND_TOOLKIT_HOME}" CACHE PATH "Path to Ascend root directory")
10-
else()
11-
set(ASCEND_ROOT "/usr/local/Ascend/ascend-toolkit/latest" CACHE PATH "Path to Ascend root directory")
12-
endif()
13-
endif()
14-
15-
find_path(ASU_ASCEND_INCLUDE_DIR
16-
NAMES acl/acl.h
17-
HINTS
18-
${ASCEND_ROOT}/include
19-
${ASCEND_ROOT}/aarch64-linux/include
20-
${ASCEND_ROOT}/arm64-linux/include
21-
NO_DEFAULT_PATH
22-
)
23-
if(NOT ASU_ASCEND_INCLUDE_DIR)
24-
message(FATAL_ERROR "Cannot find acl/acl.h under ASCEND_ROOT=${ASCEND_ROOT}")
25-
endif()
26-
27-
find_library(ASU_ASCENDCL_LIB
28-
NAMES ascendcl
29-
HINTS
30-
${ASCEND_ROOT}/lib64
31-
${ASCEND_ROOT}/aarch64-linux/lib64
32-
${ASCEND_ROOT}/aarch64-linux/devlib
33-
${ASCEND_ROOT}/arm64-linux/lib64
34-
${ASCEND_ROOT}/arm64-linux/devlib
35-
NO_DEFAULT_PATH
36-
)
37-
if(NOT ASU_ASCENDCL_LIB)
38-
message(FATAL_ERROR "Cannot find libascendcl under ASCEND_ROOT=${ASCEND_ROOT}")
39-
endif()
40-
41-
message(STATUS "ASU ASCEND include: ${ASU_ASCEND_INCLUDE_DIR}")
42-
message(STATUS "ASU ASCENDCL lib: ${ASU_ASCENDCL_LIB}")
43-
446
option(BUILD_UCM_ASU_PROVIDER_AICPU "Build ASU AICPU trans provider" OFF)
457
option(BUILD_UCM_ASU_PROVIDER_FAKE "Build ASU fake trans provider" ON)
468
option(BUILD_UCM_ASU_PROVIDER_AIV "Build ASU AIV trans provider (requires external libumc.a)" OFF)
479

48-
add_library(asu_ascend_deps INTERFACE)
49-
target_include_directories(asu_ascend_deps INTERFACE ${ASU_ASCEND_INCLUDE_DIR})
50-
target_link_libraries(asu_ascend_deps INTERFACE ${ASU_ASCENDCL_LIB})
51-
5210
file(GLOB ASU_COMMON_SOURCES CONFIGURE_DEPENDS common/*.cpp)
5311
file(GLOB ASU_TRANSPORT_SOURCES CONFIGURE_DEPENDS trans/src/*.cpp)
5412
file(GLOB LOGGER_SOURCES CONFIGURE_DEPENDS
@@ -57,7 +15,6 @@ file(GLOB LOGGER_SOURCES CONFIGURE_DEPENDS
5715
)
5816
list(APPEND ASU_TRANSPORT_SOURCES ${ASU_COMMON_SOURCES})
5917
list(APPEND ASU_TRANSPORT_SOURCES ${LOGGER_SOURCES})
60-
list(APPEND ASU_TRANSPORT_SOURCES ${UCM_ROOT_DIR}/ucm/shared/trans/ascend/ascend_buffer.cc)
6118
add_library(asu_transport SHARED ${ASU_TRANSPORT_SOURCES})
6219
target_include_directories(asu_transport
6320
PUBLIC
@@ -74,9 +31,7 @@ target_include_directories(asu_transport
7431
target_compile_definitions(asu_transport PRIVATE SPDLOG_FMT_EXTERNAL)
7532
target_link_libraries(asu_transport
7633
PUBLIC
77-
pthread fmt spdlog zlibstatic
78-
PRIVATE
79-
asu_ascend_deps
34+
pthread fmt spdlog zlibstatic trans
8035
)
8136

8237
if(BUILD_UCM_ASU_PROVIDER_AICPU)
@@ -150,7 +105,6 @@ if(BUILD_UNIT_TESTS)
150105
)
151106
target_link_libraries(asu.test PRIVATE
152107
asu_client
153-
asu_ascend_deps
154108
gtest_main gtest
155109
)
156110
gtest_discover_tests(asu.test)

ucm/transport/kv/asu/client/src/asu_client_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Status AsuClientImpl::RegisterRegionsOnce(const std::vector<MemoryRegion>& regio
250250
std::vector<TransProvider::RegisterMemoryDesc> registerDescs;
251251
registerDescs.reserve(regions.size());
252252
for (const auto& region : regions) {
253-
const auto memType = region.memoryType == MemoryType::ASCEND_DEVICE
253+
const auto memType = region.memoryType == MemoryType::DEVICE
254254
? TransProvider::MemType::MEM_DEVICE
255255
: TransProvider::MemType::MEM_HOST;
256256
registerDescs.push_back({memType, static_cast<std::uintptr_t>(region.addr),
@@ -624,7 +624,7 @@ Status AsuClientImpl::BindProviderRegions(const std::shared_ptr<TransProvider>&
624624
std::vector<TransProvider::BindMemoryDesc> bindDescs;
625625
bindDescs.reserve(registeredRegions.size());
626626
for (const auto& registeredRegion : registeredRegions) {
627-
const auto memType = registeredRegion.region.memoryType == MemoryType::ASCEND_DEVICE
627+
const auto memType = registeredRegion.region.memoryType == MemoryType::DEVICE
628628
? TransProvider::MemType::MEM_DEVICE
629629
: TransProvider::MemType::MEM_HOST;
630630
bindDescs.push_back({memType, static_cast<std::uintptr_t>(registeredRegion.region.addr),

ucm/transport/kv/asu/test/transport/asu_submit_flow_test.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
* */
24-
#include <acl/acl.h>
2524
#include <cstdint>
2625
#include <functional>
2726
#include <gtest/gtest.h>
@@ -33,6 +32,7 @@
3332
#include "asu_transport/trans_provider.h"
3433
#include "buffer_manager.h"
3534
#include "connection_internal.h"
35+
#include "trans/device.h"
3636

3737
namespace UC::ASU {
3838
namespace {
@@ -134,14 +134,18 @@ class AsuSubmitFlowBufferTest : public ::testing::Test {
134134
protected:
135135
static void SetUpTestSuite()
136136
{
137-
auto ret = aclInit(nullptr);
138-
if (ret != ACL_SUCCESS && ret != ACL_ERROR_REPEAT_INITIALIZE) {
139-
FAIL() << "aclInit failed: " << ret;
137+
const auto initStatus = device_.Init();
138+
if (initStatus.Failure() && initStatus != UC::Status::DuplicateKey()) {
139+
FAIL() << "Device::Init failed: " << initStatus.ToString();
140140
}
141-
ASSERT_EQ(aclrtSetDevice(0), ACL_SUCCESS);
141+
ASSERT_TRUE(device_.Setup(0).Success());
142142
}
143143

144-
static void TearDownTestSuite() { aclrtResetDevice(0); }
144+
static void TearDownTestSuite()
145+
{
146+
(void)device_.Reset(0);
147+
(void)device_.Finalize();
148+
}
145149

146150
void SetUp() override
147151
{
@@ -151,6 +155,7 @@ class AsuSubmitFlowBufferTest : public ::testing::Test {
151155
}
152156

153157
std::unique_ptr<AsuTransportImpl> transport_;
158+
static inline Trans::Device device_;
154159
};
155160

156161
} // namespace
@@ -161,18 +166,20 @@ class AsuTransportBufferRegistrationTest : public ::testing::Test {
161166
protected:
162167
static void SetUpTestSuite()
163168
{
164-
const auto ret = aclInit(nullptr);
165-
if (ret != ACL_SUCCESS && ret != ACL_ERROR_REPEAT_INITIALIZE) {
166-
FAIL() << "aclInit failed: " << ret;
169+
const auto initStatus = device_.Init();
170+
if (initStatus.Failure() && initStatus != UC::Status::DuplicateKey()) {
171+
FAIL() << "Device::Init failed: " << initStatus.ToString();
167172
}
168-
ASSERT_EQ(aclrtSetDevice(0), ACL_SUCCESS);
173+
ASSERT_TRUE(device_.Setup(0).Success());
169174
}
170175

171176
static void TearDownTestSuite()
172177
{
173-
EXPECT_EQ(aclrtResetDevice(0), ACL_SUCCESS);
174-
EXPECT_EQ(aclFinalize(), ACL_SUCCESS);
178+
(void)device_.Reset(0);
179+
(void)device_.Finalize();
175180
}
181+
182+
static inline Trans::Device device_;
176183
};
177184

178185
TEST_F(AsuTransportBufferRegistrationTest, InitRegistersAndShutdownUnregistersBothBuffers)

0 commit comments

Comments
 (0)