MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CreateThreadScope

Method CreateThreadScope

paddle/fluid/framework/hogwild_worker.cc:915–1089  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

913 return false;
914}
915void HogwildWorker::CreateThreadScope(const ProgramDesc &program) {
916 auto &block = program.Block(0);
917
918 PADDLE_ENFORCE_NOT_NULL(
919 root_scope_,
920 common::errors::NotFound(
921 "Root scope should be set before creating thread scope."));
922
923 thread_scope_ = &root_scope_->NewScope();
924
925 int persist_total = 0;
926 int persist_param = 0;
927 int persist_share = 0;
928 int persist_reset = 0;
929 int pinned_param = 0;
930 int resize_var_cnt = 0;
931 int fp16_param = 0;
932 std::vector<std::string> del_var_names;
933 for (auto &var : block.AllVars()) {
934 auto name = var->Name();
935 if (remove_vars_.find(name) != remove_vars_.end()) {
936 if (free_param_vars_.find(name) != free_param_vars_.end()) {
937 del_var_names.push_back(name);
938 VLOG(1) << "remove need delete var name=" << name;
939 }
940 continue;
941 }
942 all_param_.push_back(name);
943 if (var->Persistable()) {
944 ++persist_total;
945 if (stat_var_name_map_.find(name) != stat_var_name_map_.end()) {
946 Variable *root_var = root_scope_->FindVar(name);
947 PADDLE_ENFORCE_NOT_NULL(
948 root_var,
949 common::errors::NotFound("Root scope should contain variable."));
950
951 auto root_tensor = root_var->Get<phi::DenseTensor>();
952 if (root_tensor.place() == place_) {
953 continue;
954 }
955 auto *ptr1 = thread_scope_->Var(name);
956 InitializeVariable(ptr1, var->GetType());
957 phi::DenseTensor *thread_tensor = ptr1->GetMutable<phi::DenseTensor>();
958#define MemsetCallback(cpp_type, proto_type) \
959 do { \
960 if (framework::TransToProtoVarType(root_tensor.dtype()) == proto_type) { \
961 SetZero<cpp_type>(thread_tensor, root_tensor); \
962 } \
963 } while (0)
964 _ForEachDataType_(MemsetCallback);
965 }
966#if defined(PADDLE_WITH_HETERPS) && defined(PADDLE_WITH_PSCORE)
967 else if (unpersist_vars_.find(name) == unpersist_vars_.end()) { // NOLINT
968 if (use_gpu_graph_ && use_ps_gpu_) {
969 Variable *root_var = root_scope_->FindVar(name);
970 if (!root_var) {
971 VLOG(0) << "not found var name=" << name;
972 continue;

Callers

nothing calls this directly

Calls 15

Tensor2PinnedFunction · 0.85
is_gpu_placeFunction · 0.85
TensorCopyFunction · 0.85
make_ddimFunction · 0.85
AllVarsMethod · 0.80
ResetHolderWithTypeMethod · 0.80
IsParameterMethod · 0.80
EraseVarsMethod · 0.80
InitializeVariableFunction · 0.70
TransDataTypeFunction · 0.70
ifFunction · 0.70
TransToPhiDataTypeFunction · 0.50

Tested by

no test coverage detected