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

Method Compile

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

Source from the content-addressed store, hash-verified

421 int num_dims() const { return num_spatial_dims_ + 2; }
422
423 void Compile(XlaOpKernelContext* ctx) override {
424 TensorShape gradients_shape;
425 OP_REQUIRES_OK(ctx, ctx->ConstantInputAsShape(0, &gradients_shape));
426
427 const TensorShape out_backprop_shape = ctx->InputShape(1);
428
429 // For avgpooling, tensor_in_shape should have num_dims() dimensions.
430 OP_REQUIRES(ctx, gradients_shape.dims() == num_dims(),
431 errors::InvalidArgument("orig_input_shape must be ", num_dims(),
432 "-dimensional"));
433
434 // For avgpooling, out_backprop should have num_dims() dimensions.
435 OP_REQUIRES(ctx, out_backprop_shape.dims() == num_dims(),
436 errors::InvalidArgument("out_backprop must be ", num_dims(),
437 "-dimensional"));
438
439 auto out_backprop = ctx->Input(1);
440 std::vector<int64> stride_int64s(stride_.begin(), stride_.end());
441 xla::Padding xla_padding =
442 (padding_ == VALID) ? xla::Padding::kValid : xla::Padding::kSame;
443 xla::PrimitiveType xla_reduction_type;
444 auto reduction_type = XlaHelpers::SumAccumulationType(ctx->input_type(1));
445 OP_REQUIRES_OK(
446 ctx, DataTypeToPrimitiveType(reduction_type, &xla_reduction_type));
447 auto converted_out_backprop =
448 xla::ConvertElementType(out_backprop, xla_reduction_type);
449 auto xla_data_format =
450 XlaTensorFormat(data_format_, gradients_shape.dims() - 2);
451 auto padding_values =
452 MakeSpatialPadding(gradients_shape.dim_sizes(), ksize_, stride_int64s,
453 xla_padding, xla_data_format);
454 auto in_backprop =
455 xla::AvgPoolGrad(converted_out_backprop, gradients_shape.dim_sizes(),
456 ksize_, stride_int64s, padding_values, xla_data_format,
457 /*counts_include_padding=*/padding_ == VALID);
458 // Convert the pooling result back to the input type before returning it.
459 xla::PrimitiveType xla_out_backprop_type;
460 OP_REQUIRES_OK(ctx, DataTypeToPrimitiveType(ctx->input_type(1),
461 &xla_out_backprop_type));
462 ctx->SetOutput(0,
463 xla::ConvertElementType(in_backprop, xla_out_backprop_type));
464 }
465
466 protected:
467 const int num_spatial_dims_;

Callers

nothing calls this directly

Calls 15

InvalidArgumentFunction · 0.85
DataTypeToPrimitiveTypeFunction · 0.85
XlaTensorFormatFunction · 0.85
MakeSpatialPaddingFunction · 0.85
ConstantInputAsShapeMethod · 0.80
InputShapeMethod · 0.80
ConvertElementTypeFunction · 0.50
AvgPoolGradFunction · 0.50
dimsMethod · 0.45
InputMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected