MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compile

Method Compile

tensorflow/compiler/tf2xla/kernels/pooling_ops.cc:221–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
252class AvgPool2DOp : public AvgPoolOp {

Callers

nothing calls this directly

Calls 13

GetKernelSizeFunction · 0.85
InvalidArgumentFunction · 0.85
XlaTensorFormatFunction · 0.85
MakeSpatialPaddingFunction · 0.85
InputShapeMethod · 0.80
input_xla_typeMethod · 0.80
ConvertElementTypeFunction · 0.50
AvgPoolFunction · 0.50
statusMethod · 0.45
dimsMethod · 0.45
dim_sizesMethod · 0.45
InputMethod · 0.45

Tested by

no test coverage detected