Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

Question about data layout transform

Open luotao1 opened this issue 8 years ago • 2 comments

We are adding MKLDNN data layout support and the design/implementation is on the way.

I have one question as below: Q: How to define/use GetKernelTypeForVar() in each OP? Currently it seems that no any OP overload it. Now it's used in framework (i.e. OperatorWithKernel::RunImpl) to detect whether data transorm is needed as below:

 expected_kernel_key = this->GetExpectedKernelType()
 for each input var:
    kernel_type_for_this_var = this ->GetKernelTypeForVar(var)
    if (TranFromNeeded(kernel_type_for_var, expected_kernel_key) {
        do transform....
    }

This question is from Liu, Brian in Intel.

luotao1 avatar Apr 18 '18 06:04 luotao1

hello @luotao1, I'm working on MKLDNN data layout support. In my current implementation I've modified GetKernelTypeForVar so that it returns OpKernelType with layout taken from tensor:

OpKernelType OperatorWithKernel::GetKernelTypeForVar(
    const std::string& var_name, const Tensor& tensor,
    const OpKernelType& expected_kernel_type) const {
  return OpKernelType(expected_kernel_type.data_type_, tensor.place(), tensor.layout());
}

After this change I can assess if I need to transform tensor from mkldnn tensor to nchw/nhwc when expected kernel is non-mkldnn one. Did I answer your question?

pzelazko-intel avatar Apr 18 '18 11:04 pzelazko-intel

Thanks @pzelazko-intel, this question is from Liu, Brian in Intel.

luotao1 avatar Apr 18 '18 11:04 luotao1