Browse Source

assign graph memory max size and variable memory max size adaptively

tags/v1.5.1
lichun 3 years ago
parent
commit
fec3176277
2 changed files with 64 additions and 0 deletions
  1. +1
    -0
      tests/ut/ge/CMakeLists.txt
  2. +63
    -0
      tests/ut/ge/graph/manager/graph_var_manager_unittest.cc

+ 1
- 0
tests/ut/ge/CMakeLists.txt View File

@@ -690,6 +690,7 @@ set(MULTI_PARTS_TEST_FILES
"graph/manager/run_graph_unittest.cc" "graph/manager/run_graph_unittest.cc"
"graph/partition/dynamic_shape_partition_unittest.cc" "graph/partition/dynamic_shape_partition_unittest.cc"
"graph/manager/graph_manager_unittest.cc" "graph/manager/graph_manager_unittest.cc"
"graph/manager/graph_var_manager_unittest.cc"
"graph/optimize/mem_rw_conflict_optimize_unittest.cc" "graph/optimize/mem_rw_conflict_optimize_unittest.cc"
"graph/optimize/graph_optimize_unittest.cc" "graph/optimize/graph_optimize_unittest.cc"
"session/omg_omg_unittest.cc" "session/omg_omg_unittest.cc"


+ 63
- 0
tests/ut/ge/graph/manager/graph_var_manager_unittest.cc View File

@@ -0,0 +1,63 @@
/**
* 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/ge_context.h"
#undef protected
#undef private

namespace ge {
class UtestGraphVarManagerTest : public testing::Test {
protected:
void SetUp() {}
void TearDown() {}
};

TEST_F(UtestGraphVarManagerTest, test_get_total_memory_size) {
size_t total_mem_size = 0;
Status ret = VarManager::Instance(0)->GetTotalMemorySize(total_mem_size);
EXPECT_EQ(total_mem_size, 1024UL * 1024UL * 1024UL);
EXPECT_EQ(ret, SUCCESS);
}

TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_no_related_option) {
const map<string, string> options{};
Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options);
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(ret, SUCCESS);
}

TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_graph_mem_max_size) {
const map<string, string> options{{"ge.graphMemoryMaxSize", 1024UL * 1024UL * 1024UL / 2}};
Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options);
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", 1024UL * 1024UL * 1024UL / 2}};
Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options);
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);
}
} // namespace ge

Loading…
Cancel
Save