Browse Source

GeTensor aligned addr & zero copy support

tags/v1.2.0
chenyemeng 3 years ago
parent
commit
3362eece4f
2 changed files with 5 additions and 7 deletions
  1. +3
    -4
      ge/graph/manager/host_mem_allocator.h
  2. +2
    -3
      ge/graph/manager/host_mem_manager.cc

+ 3
- 4
ge/graph/manager/host_mem_allocator.h View File

@@ -18,7 +18,7 @@
#define GE_GRAPH_MANAGER_HOST_MEM_ALLOCATOR_H_

#include <mutex>
#include <unordered_map>
#include <map>

#include "framework/common/ge_inner_error_codes.h"
#include "graph/aligned_ptr.h"
@@ -27,7 +27,7 @@
namespace ge {
class HostMemAllocator {
public:
explicit HostMemAllocator(rtMemType_t memory_type) : memory_type_(memory_type) {}
explicit HostMemAllocator(rtMemType_t) {}
~HostMemAllocator() = default;

HostMemAllocator(const HostMemAllocator &) = delete;
@@ -48,8 +48,7 @@ class HostMemAllocator {
private:
void Clear();

rtMemType_t memory_type_;
std::unordered_map<const void *, std::pair<size_t, std::shared_ptr<AlignedPtr>>> allocated_blocks_;
std::map<const void *, std::pair<size_t, std::shared_ptr<AlignedPtr>>> allocated_blocks_;
// lock around all operations
mutable std::mutex mutex_;
};


+ 2
- 3
ge/graph/manager/host_mem_manager.cc View File

@@ -44,13 +44,12 @@ Status SharedMemAllocator::Allocate(SharedMemInfo &mem_info) {
}
mem_info.fd = output_para.fd;
#ifndef ONLY_COMPILE_OPEN_SRC
mem_info.host_aligned_ptr = AlignedPtr::BuildFromAllocFunc(mem_info.mem_size,
[&output_para](std::unique_ptr<uint8_t[], deleter> &ptr) {
mem_info.host_aligned_ptr = AlignedPtr::BuildFromAllocFunc([&output_para](std::unique_ptr<uint8_t[], deleter> &ptr) {
ptr.reset(reinterpret_cast<uint8_t *>(output_para.ptr));
},
[](uint8_t *ptr) {
ptr = nullptr;
}, 0);
});
#else
mem_info.host_address = reinterpret_cast<uint8_t *>(output_para.ptr);
#endif


Loading…
Cancel
Save