diff --git a/paddle/operators/math/math_function.cc b/paddle/operators/math/math_function.cc index 175df2030d50ecbc5775b574342cf9feb959b73f..09c3f0b1e6f787547b9253d3aeadf70674708ba0 100644 --- a/paddle/operators/math/math_function.cc +++ b/paddle/operators/math/math_function.cc @@ -272,11 +272,10 @@ struct TensorSetConstantWithPlace : public boost::static_visitor { void set_constant(const platform::DeviceContext& context, framework::Tensor* tensor, float value) { + TensorSetConstantWithPlace func(context, tensor, value); #ifdef PADDLE_WITH_CUDA - boost::apply_visitor(TensorSetConstantWithPlace(context, tensor, value), - tensor->place()); + tensor->place().apply_visitor(func); #else - TensorSetConstantWithPlace func(context, tensor, value); func(platform::CPUPlace()); #endif }