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

Function TemporalShiftKernel

paddle/phi/kernels/xpu/temporal_shift_kernel.cc:25–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24template <typename T, typename Context>
25void TemporalShiftKernel(const Context& dev_ctx,
26 const DenseTensor& x,
27 int seg_num,
28 float shift_ratio,
29 const std::string& data_format_str,
30 DenseTensor* out) {
31 if (out && out->numel() == 0) {
32 dev_ctx.template Alloc<T>(out);
33 return;
34 }
35 auto* input = &x;
36 auto* output = out;
37 int64_t t = seg_num;
38 const DataLayout data_layout = StringToDataLayout(data_format_str);
39
40 const int64_t nt = input->dims()[0];
41 const int64_t n = nt / t;
42 const int64_t c =
43 (data_layout == DataLayout::NCHW ? input->dims()[1] : input->dims()[3]);
44 const int64_t h =
45 (data_layout == DataLayout::NCHW ? input->dims()[2] : input->dims()[1]);
46 const int64_t w =
47 (data_layout == DataLayout::NCHW ? input->dims()[3] : input->dims()[2]);
48
49 DDim out_dims = (data_layout == DataLayout::NCHW ? make_ddim({nt, c, h, w})
50 : make_ddim({nt, h, w, c}));
51 const T* input_data = input->data<T>();
52 output->Resize(out_dims);
53 T* output_data = dev_ctx.template Alloc<T>(output);
54
55 if (data_layout == DataLayout::NCHW) {
56 int r = xpu::temporal_shift(dev_ctx.x_context(),
57 input_data,
58 output_data,
59 n,
60 c,
61 h,
62 w,
63 t,
64 shift_ratio,
65 false);
66 PADDLE_ENFORCE_XDNN_SUCCESS(r, "temporal_shift");
67 } else {
68 int r = xpu::temporal_shift(dev_ctx.x_context(),
69 input_data,
70 output_data,
71 n,
72 c,
73 h,
74 w,
75 t,
76 shift_ratio,
77 true);
78 PADDLE_ENFORCE_XDNN_SUCCESS(r, "temporal_shift");
79 }
80}
81
82} // namespace phi

Callers

nothing calls this directly

Calls 7

StringToDataLayoutFunction · 0.85
make_ddimFunction · 0.85
x_contextMethod · 0.80
temporal_shiftFunction · 0.50
numelMethod · 0.45
dimsMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected