remove stream id from membuf add kernel dependence to determine whether is usablepull/1271/head
parent
932e0ccffd
commit
cbf5390b34
File diff suppressed because it is too large
Load Diff
@ -1,102 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 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 "pre_activate/mem_reuse/stream_reuse.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace memreuse {
|
||||
void StreamReuse::SetStreamReuseResource() {
|
||||
#ifdef ENABLE_D
|
||||
auto logic_physic_map = device::ascend::AscendStreamAssign::GetInstance().logic_to_physic_map();
|
||||
auto logic_independent_map = device::ascend::AscendStreamAssign::GetInstance().logic_to_independent_map();
|
||||
MS_LOG(INFO) << "stream mem reuse for Davici";
|
||||
if (!logic_independent_map.empty() && !logic_physic_map.empty()) {
|
||||
set_logic_physic_map(logic_physic_map);
|
||||
set_logic_independent_map(logic_independent_map);
|
||||
InitReusableStreamMap();
|
||||
} else {
|
||||
MS_LOG(INFO) << "Non task sink or No Parallel stream exists";
|
||||
}
|
||||
#endif
|
||||
MS_LOG(INFO) << "no need to set stream mem reuse resource";
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint32_t, uint32_t>> StreamReuse::SortLogicPhysicMapToList() {
|
||||
std::vector<std::pair<uint32_t, uint32_t>> logic_physic_list;
|
||||
(void)std::transform(logic_physic_map_.begin(), logic_physic_map_.end(), std::back_inserter(logic_physic_list),
|
||||
[](std::pair<uint32_t, uint32_t> log_phy) { return log_phy; });
|
||||
std::sort(
|
||||
logic_physic_list.begin(), logic_physic_list.end(),
|
||||
[](const std::pair<uint32_t, uint32_t> &logic_phyic_pair1, const std::pair<uint32_t, uint32_t> &logic_phyic_pair2) {
|
||||
return logic_phyic_pair1.second < logic_phyic_pair2.second;
|
||||
});
|
||||
return logic_physic_list;
|
||||
}
|
||||
|
||||
std::unordered_map<int, std::set<uint32_t>> StreamReuse::GetLogicPhysicsStreamMap() {
|
||||
auto logic_physic_list = SortLogicPhysicMapToList();
|
||||
std::unordered_map<int, std::set<uint32_t>> logic_phyics_map;
|
||||
for (size_t i = 0; i < logic_physic_list.size() - IntToSize(1); ++i) {
|
||||
auto curr_logic_physic = logic_physic_list.at(i);
|
||||
auto next_logic_physic = logic_physic_list.at(i + 1);
|
||||
for (auto j = curr_logic_physic.second; j < next_logic_physic.second; ++j) {
|
||||
(void)logic_phyics_map[curr_logic_physic.first].insert(j);
|
||||
}
|
||||
}
|
||||
// sort the logic independ map by value
|
||||
std::map<uint32_t, uint32_t> temp_map;
|
||||
for (const auto &logic_independ : logic_independent_map_) {
|
||||
(void)temp_map.insert(std::make_pair(logic_independ.second, logic_independ.first));
|
||||
}
|
||||
auto first_independent_stream_id = (*temp_map.begin()).first;
|
||||
auto last_physic_logic_stream_id = (*logic_physic_list.rbegin()).second;
|
||||
for (auto i = last_physic_logic_stream_id; i < first_independent_stream_id; ++i) {
|
||||
(void)logic_phyics_map[(*logic_physic_list.rbegin()).first].insert(i);
|
||||
}
|
||||
return logic_phyics_map;
|
||||
}
|
||||
|
||||
void StreamReuse::InitReusableStreamMap() {
|
||||
// logic_phyics_map, key, logic_stream_id; value, physic_strema_ids included in that logic stream
|
||||
auto logic_phyics_map = GetLogicPhysicsStreamMap();
|
||||
// parallel_streams_map: key, current_stream_id; value, streams parallel to current stream
|
||||
for (const auto &logic_to_phyics : logic_phyics_map) {
|
||||
auto logic_stream_id = logic_to_phyics.first;
|
||||
auto iter_inde = logic_independent_map_.find(logic_stream_id);
|
||||
if (iter_inde != logic_independent_map_.end()) {
|
||||
// exist independent steam parallel to these logic streams
|
||||
auto independent_stream_id = iter_inde->second;
|
||||
auto physics_stream_id = logic_to_phyics.second;
|
||||
for (const auto &physic : physics_stream_id) {
|
||||
(void)parallel_streams_map_[physic].insert(independent_stream_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &logic_to_independent : logic_independent_map_) {
|
||||
auto logic_stream_id = logic_to_independent.first;
|
||||
auto independent_stream_id = logic_to_independent.second;
|
||||
auto iter_physics = logic_phyics_map.find(logic_stream_id);
|
||||
if (iter_physics != logic_phyics_map.end()) {
|
||||
// exist logic steam parallel to these independent streams, default
|
||||
auto physics_set = iter_physics->second;
|
||||
for (const auto &physic : physics_set) {
|
||||
(void)parallel_streams_map_[independent_stream_id].insert(physic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace memreuse
|
||||
} // namespace mindspore
|
@ -1,63 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_STREAM_REUSE_H_
|
||||
#define MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_STREAM_REUSE_H_
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <fstream>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include "session/anf_runtime_algorithm.h"
|
||||
#include "pre_activate/mem_reuse/kernel_refcount.h"
|
||||
|
||||
#ifdef ENABLE_D
|
||||
#include "device/ascend/ascend_stream_assign.h"
|
||||
#endif
|
||||
|
||||
namespace mindspore {
|
||||
namespace memreuse {
|
||||
class StreamReuse {
|
||||
public:
|
||||
StreamReuse() = default;
|
||||
~StreamReuse() = default;
|
||||
void SetStreamReuseResource();
|
||||
void InitReusableStreamMap();
|
||||
std::vector<std::pair<uint32_t, uint32_t>> SortLogicPhysicMapToList();
|
||||
std::unordered_map<int, std::set<uint32_t>> GetLogicPhysicsStreamMap();
|
||||
void set_logic_physic_map(const std::unordered_map<uint32_t, uint32_t> &logic_physic_map) {
|
||||
logic_physic_map_ = logic_physic_map;
|
||||
}
|
||||
void set_logic_independent_map(const std::unordered_map<uint32_t, uint32_t> &logic_independent_map) {
|
||||
logic_independent_map_ = logic_independent_map;
|
||||
}
|
||||
std::unordered_map<uint32_t, std::unordered_set<uint32_t>> parallel_streams_map() { return parallel_streams_map_; }
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32_t, std::unordered_set<uint32_t>> parallel_streams_map_;
|
||||
std::unordered_map<uint32_t, uint32_t> logic_physic_map_;
|
||||
std::unordered_map<uint32_t, uint32_t> logic_independent_map_;
|
||||
};
|
||||
} // namespace memreuse
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_STREAM_REUSE_H_
|
@ -1,63 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 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 <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "operator/ops.h"
|
||||
#include "pre_activate/mem_reuse/stream_reuse.h"
|
||||
#include "common/common_test.h"
|
||||
#include "common/py_func_graph_fetcher.h"
|
||||
|
||||
using mindspore::memreuse::StreamReuse;
|
||||
|
||||
namespace mindspore {
|
||||
class TestStreamMemReuse : public UT::Common {
|
||||
public:
|
||||
TestStreamMemReuse() : getPyFun_("gtest_input.mem_reuse.TestMemReuseAllocator", true) {}
|
||||
void SetUp() {}
|
||||
|
||||
public:
|
||||
UT::PyFuncGraphFetcher getPyFun_;
|
||||
};
|
||||
|
||||
TEST_F(TestStreamMemReuse, init_reusable_stream_map_test) {
|
||||
std::unordered_map<uint32_t, uint32_t> logic_physic_map{{1, 0}, {2, 8}, {3, 3}};
|
||||
std::unordered_map<uint32_t, uint32_t> logic_independent_map{{3, 10}, {2, 11}};
|
||||
auto stream_reuse = std::make_shared<StreamReuse>();
|
||||
stream_reuse->set_logic_physic_map(logic_physic_map);
|
||||
stream_reuse->set_logic_independent_map(logic_independent_map);
|
||||
|
||||
auto logic_phyics_map = stream_reuse->GetLogicPhysicsStreamMap();
|
||||
for (const auto &logic_physics : logic_phyics_map) {
|
||||
MS_LOG(INFO) << "[logic_id: " << logic_physics.first << "]";
|
||||
for (const auto &physic : logic_physics.second) {
|
||||
MS_LOG(INFO) << "physic: " << physic;
|
||||
}
|
||||
}
|
||||
MS_LOG(INFO) << "===========UT logic_physic_map size: " << logic_physic_map.size() << "========";
|
||||
ASSERT_EQ(logic_physic_map.size(), 3);
|
||||
stream_reuse->InitReusableStreamMap();
|
||||
auto parallel_streams_map = stream_reuse->parallel_streams_map();
|
||||
for (const auto ¶llel_streams : parallel_streams_map) {
|
||||
MS_LOG(INFO) << "[stream id: " << parallel_streams.first << "]";
|
||||
for (const auto &stream : parallel_streams.second) {
|
||||
MS_LOG(INFO) << "parallel stream id: " << stream;
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(parallel_streams_map[7].size(), 1);
|
||||
}
|
||||
} // namespace mindspore
|
Loading…
Reference in new issue