Question about data layout transform
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.
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?
Thanks @pzelazko-intel, this question is from Liu, Brian in Intel.