Skip to content

Commit

Permalink
复用runtime_op中的一部分内存
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhellofss committed Mar 17, 2024
1 parent ab9d5a6 commit 0642c77
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demos/yolo/yolo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void YoloDemo(const std::vector<std::string>& image_paths, const std::string& pa

std::vector<std::shared_ptr<Tensor<float>>> outputs;
graph.set_inputs("pnnx_input_0", inputs);
for (int i = 0; i < 1; ++i) {
for (int i = 0; i < 10000; ++i) {
graph.Forward(true);
}
outputs = graph.get_outputs("pnnx_output_0");
Expand Down
2 changes: 2 additions & 0 deletions include/runtime/runtime_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct RuntimeOperatorBase {

int32_t end_forward_index = -1;

int32_t occur_forward_index = -1;

/// Whether this operator has run in current execution
bool has_forward = false;

Expand Down
1 change: 1 addition & 0 deletions source/runtime/runtime_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ void RuntimeGraph::ReverseTopoSort() {
} else {
op->end_forward_index = last_forward_index;
}
op->occur_forward_index = -1;
}
}

Expand Down
9 changes: 7 additions & 2 deletions source/runtime/runtime_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ void RuntimeOperatorUtils<float>::InitOperatorOutput(
}

const auto& prev_runtime_op = operators.at(j);
if (!prev_runtime_op->output_operands || prev_runtime_op->end_forward_index == -1) {
if (!prev_runtime_op->output_operands || prev_runtime_op->occur_forward_index != -1) {
continue;
}

if (runtime_op->forward_index > prev_runtime_op->occur_forward_index) {
prev_runtime_op->occur_forward_index = -1;
}

if (runtime_op->forward_index > prev_runtime_op->end_forward_index) {
if (prev_runtime_op->output_operands->size() == operand_size) {
has_found = true;
Expand All @@ -160,7 +165,7 @@ void RuntimeOperatorUtils<float>::InitOperatorOutput(
std::make_shared<ftensor>(output_tensor->raw_ptr(), output_tensor->shapes());
CheckAndReshapeTensor(output_tensors->datas[b], operand_shapes);
}
prev_runtime_op->end_forward_index = -1;
prev_runtime_op->occur_forward_index = runtime_op->end_forward_index;
}
}
}
Expand Down

0 comments on commit 0642c77

Please sign in to comment.