| 219 | } |
| 220 | |
| 221 | void Compile(XlaOpKernelContext* ctx) override { |
| 222 | auto ksize_or_error = GetKernelSize(ctx); |
| 223 | OP_REQUIRES_OK(ctx, ksize_or_error.status()); |
| 224 | std::vector<int64> ksize = ksize_or_error.ValueOrDie(); |
| 225 | |
| 226 | auto stride_or_error = GetStride(ctx); |
| 227 | OP_REQUIRES_OK(ctx, stride_or_error.status()); |
| 228 | std::vector<int64> stride = stride_or_error.ValueOrDie(); |
| 229 | |
| 230 | const TensorShape input_shape = ctx->InputShape(0); |
| 231 | OP_REQUIRES(ctx, input_shape.dims() == num_dims(), |
| 232 | errors::InvalidArgument("Input to ", type_string(), |
| 233 | " operator must have ", num_dims(), |
| 234 | " dimensions")); |
| 235 | |
| 236 | auto xla_data_format = |
| 237 | XlaTensorFormat(data_format_, input_shape.dims() - 2); |
| 238 | auto spatial_padding = MakeSpatialPadding( |
| 239 | input_shape.dim_sizes(), ksize, stride, padding_, xla_data_format); |
| 240 | |
| 241 | // Convert the input to the reduction type. |
| 242 | auto converted_input = |
| 243 | ConvertElementType(ctx->Input(0), xla_reduction_type_); |
| 244 | auto pooling = |
| 245 | xla::AvgPool(converted_input, ksize, stride, spatial_padding, |
| 246 | xla_data_format, padding_ == xla::Padding::kValid); |
| 247 | // Convert the pooling result back to the input type before returning it. |
| 248 | ctx->SetOutput(0, ConvertElementType(pooling, ctx->input_xla_type(0))); |
| 249 | } |
| 250 | }; |
| 251 | |
| 252 | class AvgPool2DOp : public AvgPoolOp { |
nothing calls this directly
no test coverage detected