MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / enable

Method enable

imperative/src/impl/tensor_sanity_check.cpp:62–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void TensorSanityCheck::enable() {
63 CompNode::sync_all();
64 OpTrait::for_each_trait([this](OpTrait& trait) {
65 auto backup = std::make_unique<ApplyOnPhysicalTensor>(
66 std::move(trait.apply_on_physical_tensor));
67 trait.apply_on_physical_tensor = ApplyOnPhysicalTensor(
68 [this, backup = backup.get()](
69 const OpDef& def, const SmallVector<TensorPtr>& inputs,
70 SmallVector<LogicalTensorDesc>& output_descs,
71 const bool& validated) {
72 for (auto&& i : inputs) {
73 if (!m_checker->check(i)) {
74 mgb_throw(
75 TensorChecksumCalc::Error,
76 "tensor modified before exec %s",
77 print_op(def).c_str());
78 }
79 }
80 auto output = (*backup)(def, inputs, output_descs, validated);
81 for (auto&& i : output) {
82 mgb_assert(m_checker->check(i));
83 }
84 for (auto&& i : inputs) {
85 if (!m_checker->check(i)) {
86 mgb_throw(
87 TensorChecksumCalc::Error,
88 "tensor modified after exec %s",
89 print_op(def).c_str());
90 }
91 }
92 return output;
93 });
94 m_checker->hook_list.push_back({&trait, std::move(backup)});
95 });
96}
97
98void TensorSanityCheck::disable() {
99 for (auto&& hook : m_checker->hook_list) {

Callers

nothing calls this directly

Calls 3

getMethod · 0.45
checkMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected