| 275 | }; |
| 276 | |
| 277 | void set_constant(const DeviceContext& dev_ctx, |
| 278 | DenseTensor* tensor, |
| 279 | float value) { |
| 280 | TensorSetConstantWithPlace func(dev_ctx, tensor, value); |
| 281 | #ifdef PADDLE_WITH_CUSTOM_DEVICE |
| 282 | if (dev_ctx.GetPlace().GetType() == AllocationType::CUSTOM) { |
| 283 | func(CustomPlace()); |
| 284 | return; |
| 285 | } |
| 286 | #endif |
| 287 | #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) |
| 288 | // tensor->place().apply_visitor(func); |
| 289 | phi::VisitPlace(tensor->place(), func); |
| 290 | #elif defined(PADDLE_WITH_XPU) |
| 291 | if (dev_ctx.GetPlace().GetType() == AllocationType::XPU) { |
| 292 | func(phi::XPUPlace()); |
| 293 | return; |
| 294 | } else { |
| 295 | func(CPUPlace()); |
| 296 | } |
| 297 | #else |
| 298 | func(CPUPlace()); |
| 299 | #endif |
| 300 | } |
| 301 | |
| 302 | template struct ColwiseSum<CPUContext, float>; |
| 303 | template struct ColwiseSum<CPUContext, double>; |