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

Method BuildPhiKernelContext

paddle/fluid/framework/operator.cc:3171–3710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3169}
3170
3171void OperatorWithKernel::BuildPhiKernelContext(
3172 const RuntimeContext& ctx,
3173 phi::DeviceContext* dev_ctx,
3174 phi::KernelContext* phi_kernel_context) const {
3175 phi_kernel_context->SetDeviceContext(dev_ctx);
3176
3177 auto& input_names = kernel_signature_->input_names;
3178 auto& attr_names = kernel_signature_->attr_names;
3179 auto& output_names = kernel_signature_->output_names;
3180
3181 auto input_defs = phi_kernel_->args_def().input_defs();
3182 auto attr_defs = phi_kernel_->args_def().attribute_defs();
3183 auto output_defs = phi_kernel_->args_def().output_defs();
3184
3185#if defined(PADDLE_WITH_DNNL)
3186 if (phi::OneDNNContext::classof(dev_ctx)) {
3187 // Onednn holds this op's variable's name and init them here.
3188 phi::OneDNNContext* one_dnn_ctx = static_cast<phi::OneDNNContext*>(dev_ctx);
3189 one_dnn_ctx->SetInputsName(Inputs());
3190 one_dnn_ctx->SetOutputsName(Outputs());
3191 }
3192#endif
3193
3194 PADDLE_ENFORCE_EQ(input_names.size(),
3195 input_defs.size(),
3196 common::errors::InvalidArgument(
3197 "The size of inputs_args names (%d) must be equal to "
3198 "the size of kernel input_defs (%d).",
3199 input_names.size(),
3200 input_defs.size()));
3201
3202 PADDLE_ENFORCE_EQ(output_names.size(),
3203 output_defs.size(),
3204 common::errors::InvalidArgument(
3205 "The size of outputs_args names (%d) must be equal to "
3206 "the size of kernel output_defs (%d).",
3207 output_names.size(),
3208 output_defs.size()));
3209
3210 PADDLE_ENFORCE_EQ(attr_names.size(),
3211 attr_defs.size(),
3212 common::errors::InvalidArgument(
3213 "The size of attribute_args names (%d) must be equal "
3214 "to the size of kernel attribute_defs (%d).",
3215 attr_names.size(),
3216 attr_defs.size()));
3217 for (size_t i = 0; i < input_names.size(); ++i) {
3218 auto it = ctx.inputs.find(input_names[i]);
3219
3220 // calculate the start and end index of the input tensors
3221 size_t start_idx =
3222 (i == 0 ? 0 : phi_kernel_context->InputRangeAt(i - 1).second);
3223 // deal with optional here
3224 if ((it == ctx.inputs.end() || it->second.empty()) &&
3225 (input_defs[i].type_index ==
3226 std::type_index(typeid(paddle::optional<DenseTensor>)) ||
3227 input_defs[i].type_index ==
3228 std::type_index(typeid(paddle::optional<phi::SelectedRows>)) ||

Callers 3

RunOperatorMethod · 0.80
BuildOpFuncListFunction · 0.80

Calls 15

OutputsClass · 0.85
type_indexClass · 0.85
ToTypeNameFunction · 0.85
AttrTypeIDFunction · 0.85
ScalarClass · 0.85
PADDLE_GET_CONSTFunction · 0.85
MakePhiScalarFromVarFunction · 0.85
IntArrayClass · 0.85
MakePhiIntArrayFromVarFunction · 0.85
GetExtraAttrPropertiesFunction · 0.85

Tested by

no test coverage detected