@@ -30,6 +30,7 @@ const f::DDim kDims = {20, 20};
3030struct TestBroadcastOpHandle {
3131 std::vector<std::unique_ptr<p::DeviceContext>> ctxs_;
3232 std::vector<Scope*> local_scopes_;
33+ std::vector<Scope*> param_scopes_;
3334 Scope g_scope_;
3435 std::unique_ptr<OpHandleBase> op_handle_;
3536 std::vector<std::unique_ptr<VarHandleBase>> vars_;
@@ -72,11 +73,17 @@ struct TestBroadcastOpHandle {
7273 void InitBroadcastOp (size_t input_scope_idx) {
7374 for (size_t j = 0 ; j < gpu_list_.size (); ++j) {
7475 local_scopes_.push_back (&(g_scope_.NewScope ()));
75- local_scopes_[j]->Var (" out" );
76+ Scope& local_scope = local_scopes_.back ()->NewScope ();
77+ *local_scopes_.back ()
78+ ->Var (details::kLocalExecScopeName )
79+ ->GetMutable <Scope*>() = &local_scope;
80+ local_scope.Var (" out" );
81+ param_scopes_.emplace_back (&local_scope);
7682 }
77- local_scopes_ [input_scope_idx]->Var (" input" );
83+ param_scopes_ [input_scope_idx]->Var (" input" );
7884
7985 op_handle_.reset (new BroadcastOpHandle (local_scopes_, gpu_list_));
86+
8087 auto * in_var_handle =
8188 new VarHandle (1 , input_scope_idx, " input" , gpu_list_[input_scope_idx]);
8289 vars_.emplace_back (in_var_handle);
@@ -105,7 +112,8 @@ struct TestBroadcastOpHandle {
105112 }
106113
107114 void TestBroadcastLodTensor (size_t input_scope_idx) {
108- auto in_var = local_scopes_[input_scope_idx]->Var (" input" );
115+ auto in_var = param_scopes_[input_scope_idx]->FindVar (" input" );
116+ PADDLE_ENFORCE_NOT_NULL (in_var);
109117 auto in_lod_tensor = in_var->GetMutable <f::LoDTensor>();
110118 in_lod_tensor->mutable_data <float >(kDims , gpu_list_[input_scope_idx]);
111119
@@ -117,14 +125,16 @@ struct TestBroadcastOpHandle {
117125 paddle::framework::TensorFromVector<float >(
118126 send_vector, *(ctxs_[input_scope_idx]), in_lod_tensor);
119127 in_lod_tensor->set_lod (lod);
128+ in_lod_tensor->Resize (kDims );
120129
121130 op_handle_->Run (false );
122131
123132 WaitAll ();
124133
125134 p::CPUPlace cpu_place;
126135 for (size_t j = 0 ; j < gpu_list_.size (); ++j) {
127- auto out_var = local_scopes_[j]->Var (" out" );
136+ auto out_var = param_scopes_[j]->FindVar (" out" );
137+ PADDLE_ENFORCE_NOT_NULL (out_var);
128138 auto out_tensor = out_var->Get <f::LoDTensor>();
129139 PADDLE_ENFORCE_EQ (out_tensor.lod (), lod, " lod is not equal." );
130140
@@ -139,7 +149,8 @@ struct TestBroadcastOpHandle {
139149 }
140150
141151 void TestBroadcastSelectedRows (size_t input_scope_idx) {
142- auto in_var = local_scopes_[input_scope_idx]->Var (" input" );
152+ auto in_var = param_scopes_[input_scope_idx]->FindVar (" input" );
153+ PADDLE_ENFORCE_NOT_NULL (in_var);
143154 auto in_selected_rows = in_var->GetMutable <f::SelectedRows>();
144155 auto value = in_selected_rows->mutable_value ();
145156 value->mutable_data <float >(kDims , gpu_list_[input_scope_idx]);
@@ -162,7 +173,8 @@ struct TestBroadcastOpHandle {
162173
163174 p::CPUPlace cpu_place;
164175 for (size_t j = 0 ; j < gpu_list_.size (); ++j) {
165- auto out_var = local_scopes_[j]->Var (" out" );
176+ auto out_var = param_scopes_[j]->FindVar (" out" );
177+ PADDLE_ENFORCE_NOT_NULL (out_var);
166178 auto & out_select_rows = out_var->Get <f::SelectedRows>();
167179 auto rt = out_select_rows.value ();
168180
0 commit comments