|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /**
- * Copyright 2021 Huawei Technologies Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include <gtest/gtest.h>
- #include <memory>
-
- #define protected public
- #define private public
- #include "graph/manager/graph_var_manager.h"
- #include "graph/manager/graph_mem_manager.h"
- #include "graph/ge_context.h"
-
- namespace ge {
- class UtestGraphVarManagerTest : public testing::Test {
- protected:
- void SetUp() {
- VarManagerPool::Instance().Destory();
- }
- void TearDown() {
- VarManagerPool::Instance().Destory();
- }
- };
-
- TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_no_related_option) {
- const map<string, string> options{};
- EXPECT_EQ(VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL), SUCCESS);
- EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (26.0f / 32.0f)));
- EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (5.0f / 32.0f)));
- EXPECT_EQ(VarManager::Instance(0)->Init(0, 0, 0, 0), SUCCESS);
- }
-
- TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_graph_mem_max_size) {
- const map<string, string> options{{"ge.graphMemoryMaxSize", "536870912"}};
- Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL);
- EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL / 2));
- EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (5.0f / 32.0f)));
- EXPECT_EQ(ret, SUCCESS);
- }
-
- TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_var_mem_max_size) {
- const map<string, string> options{{"ge.variableMemoryMaxSize", "536870912"}};
- Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL);
- EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (26.0f / 32.0f)));
- EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL / 2));
- EXPECT_EQ(ret, SUCCESS);
- }
-
- TEST_F(UtestGraphVarManagerTest, test_mem_manager_not_set) {
- EXPECT_EQ(VarManager::Instance(0)->Init(0, 0, 0, 0), SUCCESS);
-
- EXPECT_EQ(VarManager::Instance(0)->MallocVarMemory(1024), FAILED);
- EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryBase(RT_MEMORY_RDMA_HBM), nullptr);
- EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryAddr(nullptr, RT_MEMORY_RDMA_HBM), nullptr);
-
- GeTensorDesc tensor_desc;
- EXPECT_EQ(VarManager::Instance(0)->AssignVarMem("global_step", tensor_desc, RT_MEMORY_RDMA_HBM), INTERNAL_ERROR);
- }
-
- TEST_F(UtestGraphVarManagerTest, test_with_mem_manager) {
- const std::vector<rtMemType_t> memory_types({RT_MEMORY_HBM, RT_MEMORY_P2P_DDR});
- EXPECT_EQ(MemManager::Instance().Initialize(memory_types), SUCCESS);
- VarManager::Instance(0)->SetMemManager(&MemManager::Instance());
- EXPECT_EQ(VarManager::Instance(0)->Init(0, 0, 0, 0), SUCCESS);
-
- EXPECT_EQ(VarManager::Instance(0)->MallocVarMemory(1024), SUCCESS);
- EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryBase(RT_MEMORY_RDMA_HBM), nullptr);
-
- uint8_t logic_addr = 0;
- EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryAddr(&logic_addr, RT_MEMORY_RDMA_HBM), &logic_addr);
- EXPECT_NE(VarManager::Instance(0)->GetVarMemoryAddr(&logic_addr, RT_MEMORY_HBM), nullptr);
-
- // RdmaPoolAllocator block_bin_ not found.
- GeTensorDesc tensor_desc;
- EXPECT_EQ(VarManager::Instance(0)->AssignVarMem("global_step", tensor_desc, RT_MEMORY_RDMA_HBM), INTERNAL_ERROR);
- }
- } // namespace ge
|