Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "orttraining/core/framework/torch/python_common.h"
 
#include <iostream>
#include "core/common/logging/logging.h"
#include "orttraining/core/framework/torch/refcount_tracker.h"
#include "core/platform/env.h"
 
namespace onnxruntime {
namespace language_interop_ops {
namespace torch {
 
void RefCountTracker::TrackPyObject(RefCountTracker::ObjCategory category, PyObject* py_obj, const std::string& log_tag) {
#ifdef NDEBUG
  ORT_UNUSED_PARAMETER(category);
  ORT_UNUSED_PARAMETER(py_obj);
  ORT_UNUSED_PARAMETER(log_tag);
#else
  AddressInfos& addrs = addr_info_map_[category];
  assert(py_obj != NULL);
  void* addr = static_cast<void*>(py_obj);
  auto it = addrs.find(addr);
  if (it == addrs.end()) {
    addrs.insert({addr, {log_tag}});
  } else {
    addrs[addr].push_back(log_tag);
  }
  LOGS_DEFAULT(VERBOSE) << "Track" << ObjCategoryToString(category) << "\tAddress: [" << addr << "]\tRefCnt: "
                        << Py_REFCNT(addr) << "\tLogTag: " << log_tag;
#endif
}
 
void RefCountTracker::DumpDetails(const std::string& phase_name) const {
#ifdef NDEBUG
  ORT_UNUSED_PARAMETER(phase_name);
#else
  std::ostringstream oss;
  oss << "======================" << phase_name << "=================" << std::endl;
  for (auto addr_info_it = addr_info_map_.begin(); addr_info_it != addr_info_map_.end(); ++addr_info_it) {
    oss << "Category: " << ObjCategoryToString(addr_info_it->first) << std::endl;
    for (auto it = addr_info_it->second.begin(); it != addr_info_it->second.end(); ++it) {
      oss << "\tAddress: [" << it->first << "] \tRefCnt: " << Py_REFCNT(it->first) << " \tLogTag: (";
      for (auto vit = it->second.begin(); vit != it->second.end(); ++vit) {
        oss << *vit << ",";
      }
      oss << ")\n";
    }
  }
  oss << "==========================================================" << std::endl;
  LOGS_DEFAULT(VERBOSE) << oss.str();
#endif
}
 
void RefCountTracker::Reset() {
#ifndef NDEBUG
  for (auto addr_info_it = addr_info_map_.begin(); addr_info_it != addr_info_map_.end(); ++addr_info_it) {
    addr_info_it->second.clear();
  }
#endif
}
 
}  // namespace torch
}  // namespace language_interop_ops
}  // namespace onnxruntime