message: share some code between CPU and DPCPP
diff: @@ -67,6 +67,16 @@ class NewLinearOp : public torch::autograd::Function<NewLinearOp> {
  TORCH_WARN(e.what());
  #endif
  }
  + if (input.dim() == 1) {
  + grad_output = grad_output.unsqueeze(0);
  + input = input.unsqueeze(0);
  + }
  + else if (input.dim() > 2){
  + std::vector<int64_t> mm_output_size;
  + mm_output_size.push_back(-1);
  + mm_output_size.push_back(weight.sizes()[0]);
  + grad_output = grad_output.reshape(mm_output_size);
  + }
  if (input.device().type() == c10::DeviceType::DPCPP) {
  TORCH_INTERNAL_ASSERT_DEBUG_ONLY(input.layout() == c10::kStrided);
  TORCH_INTERNAL_ASSERT_DEBUG_ONLY(weight.layout() == c10::kStrided);
  @@ -75,19 +85,11 @@ class NewLinearOp : public torch::autograd::Function<NewLinearOp> {
  auto&& _ipex_weight = torch_ipex::bridge::shallowFallbackToCPUTensor(weight);
  auto&& _ipex_grad_output = torch_ipex::bridge::shallowFallbackToCPUTensor(grad_output);
  if (input.dim() <= 2){
  - if (input.dim() == 1) {
  - _ipex_grad_output = _ipex_grad_output.unsqueeze(0);
  - _ipex_input = _ipex_input.unsqueeze(0);
  - }
  grad_input = _ipex_grad_output.mm(_ipex_weight);
  if (input.dim() == 1) grad_input = grad_input.squeeze_(0);
  grad_weight = _ipex_grad_output.t().mm(_ipex_input);
  }
  else{ //input.dim() > 2
  - std::vector<int64_t> mm_output_size;
  - mm_output_size.push_back(-1);
  - mm_output_size.push_back(weight.sizes()[0]);
  - _ipex_grad_output = _ipex_grad_output.reshape(mm_output_size);
  grad_input = _ipex_grad_output.mm(_ipex_weight).reshape(input.sizes());
  grad_weight = _ipex_grad_output.t().mm(_ipex_input.view({-1, input.sizes()[input.dim() - 1]}));
  }
  @@ -100,19 +102,11 @@ class NewLinearOp : public torch::autograd::Function<NewLinearOp> {
  return {torch_ipex::bridge::shallowUpgradeToDPCPPTensor(grad_input), torch_ipex::bridge::shallowUpgradeToDPCPPTensor(grad_weight), torch_ipex::bridge::shallowUpgradeToDPCPPTensor(grad_bias)};
  } else {
  if (input.dim() <= 2){
  - if (input.dim() == 1) {
  - grad_output = grad_output.unsqueeze(0);
  - input = input.unsqueeze(0);
  - }
  grad_input = grad_output.mm(weight);
  if (input.dim() == 1) grad_input = grad_input.squeeze_(0);
  grad_weight = grad_output.t().mm(input);
  }
  else if (input.dim() > 2){
  - std::vector<int64_t> mm_output_size;
  - mm_output_size.push_back(-1);
  - mm_output_size.push_back(weight.sizes()[0]);
  - grad_output = grad_output.reshape(mm_output_size);
  grad_input = grad_output.mm(weight).reshape(input.sizes());
  grad_weight = grad_output.t().mm(input.view({-1, input.sizes()[input.dim() - 1]}));
  }
  