interpreter_util.h 3.3 KB
Newer Older
H
hong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// 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.

#pragma once

#include <chrono>
#include <iostream>
#include <map>
#include <memory>
21
#include <string>
H
hong 已提交
22 23 24 25 26
#include <unordered_map>
#include <vector>

#include "paddle/fluid/framework/executor_gc_helper.h"
#include "paddle/fluid/framework/garbage_collector.h"
27
#include "paddle/fluid/framework/new_executor/interpreter/execution_config.h"
W
wanghuancoder 已提交
28
#include "paddle/fluid/framework/new_executor/new_executor_defs.h"
L
liutiexing 已提交
29 30
#include "paddle/fluid/framework/new_executor/workqueue/workqueue.h"
#include "paddle/fluid/framework/new_executor/workqueue/workqueue_utils.h"
H
hong 已提交
31 32 33 34 35 36 37 38 39 40 41
#include "paddle/fluid/framework/op_info.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/variable.h"
#include "paddle/fluid/framework/variable_helper.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/init.h"

42 43
using AtomicVectorSizeT = std::vector<std::atomic<size_t>>;

H
hong 已提交
44 45
namespace paddle {
namespace framework {
46
namespace interpreter {
47 48
class AsyncWorkQueue {
 public:
49 50 51 52
  AsyncWorkQueue(size_t host_num_threads,
                 size_t deivce_num_threads,
                 EventsWaiter* waiter);

L
liutiexing 已提交
53
  // void WaitEmpty() { queue_group_->WaitQueueGroupEmpty(); }
54

55
  void AddTask(const OpFuncType& op_func_type, std::function<void()> fn);
56

57 58
  void Cancel() { queue_group_->Cancel(); }

59 60 61 62
  size_t QueueNumThreads(size_t idx) {
    return queue_group_->QueueNumThreads(idx);
  }

63 64 65 66 67
 private:
  size_t host_num_thread_;
  std::unique_ptr<WorkQueueGroup> queue_group_;
};

68 69
bool IsCommunicationOp(const std::string& op_name);

70
bool IsCommunicationOp(const Instruction& instr);
71

72 73 74 75 76 77 78 79 80 81 82 83
bool IsCpuOp(const Instruction& instr);

bool IsMemcpyD2H(const Instruction& instr);

bool IsMemcpyH2D(const Instruction& instr);

bool IsMemcpyOp(const Instruction& instr);

bool IsSupportedHeterPlace(const phi::Place& place);

void AddFetch(const std::vector<std::string>& fetch_names,
              framework::BlockDesc* block);
L
Leo Chen 已提交
84 85 86 87 88 89

void BuildOpFuncList(const platform::Place& place,
                     const framework::BlockDesc& block,
                     const std::set<std::string>& skip_gc_vars,
                     std::vector<OpFuncNode>* vec_func_list,
                     VariableScope* scope,
90 91
                     const ExecutionConfig& execution_config,
                     bool use_local_scope = true);
L
Leo Chen 已提交
92

93 94 95
void BuildVariableScope(const framework::BlockDesc& block,
                        VariableScope* var_scope,
                        bool use_local_scope = true);
W
wanghuancoder 已提交
96

97
void LogDeviceMemoryStats(const platform::Place& place);
98

99
}  // namespace interpreter
H
hong 已提交
100 101
}  // namespace framework
}  // namespace paddle