SIGN IN SIGN UP

Stylize check_fn in codegen (#4044)

Summary:
Pull Request resolved: https://github.com/pytorch/executorch/pull/4044

Separate change because this one is real messy.

## Before
```
    void check_add_Tensor(const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha=1) {
        if (test_dtype == at::kHalf) {
        if (!graph->context()->adapter_ptr()->has_full_float16_buffers_support()) {
          GTEST_SKIP();}
        }
        at::Tensor out = at::add(self, other, alpha);
        IOValueRef self_ref = graph->add_input_tensor(self.sizes().vec(), from_at_scalartype(self.scalar_type()));
        IOValueRef other_ref = graph->add_input_tensor(other.sizes().vec(), from_at_scalartype(other.scalar_type()));
        ValueRef alpha_ref = graph->add_scalar<double>(alpha.toDouble());
        ValueRef out_ref = graph->add_tensor(out.sizes().vec(), from_at_scalartype(out.scalar_type()));
        VK_GET_OP_FN("aten.add.Tensor")(*graph, {self_ref.value, other_ref.value, alpha_ref, out_ref});
        ValueRef out_ref_staging = graph->set_output_tensor(out_ref);
        graph->prepare();
        graph->encode_prepack();
        graph->prepack();
        graph->encode_execute();
        {
        graph->get_tensor(self_ref.value)->virtual_resize(self.sizes().vec());
        graph->copy_into_staging(self_ref.staging, self.const_data_ptr(), self.numel());
        graph->get_tensor(other_ref.value)->virtual_resize(other.sizes().vec());
        graph->copy_into_staging(other_ref.staging, other.const_data_ptr(), other.numel());
        graph->propagate_resize();
        graph->execute();
        at::Tensor vk_out_ref = at::empty_like(out).contiguous();
        graph->copy_from_staging(out_ref_staging, vk_out_ref.mutable_data_ptr(), vk_out_ref.numel());
        EXPECT_TRUE(check_close(out, vk_out_ref, rtol, atol));
        }

    }
```
## After
```
  void check_add_Tensor(const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha=1) {
    if (test_dtype == at::kHalf) {
      if (!graph->context()->adapter_ptr()->has_full_float16_buffers_support()) {
        GTEST_SKIP();
      }
    }

    at::Tensor out = at::add(self, other, alpha);
    IOValueRef self_ref = graph->add_input_tensor(self.sizes().vec(), from_at_scalartype(self.scalar_type()));
    IOValueRef other_ref = graph->add_input_tensor(other.sizes().vec(), from_at_scalartype(other.scalar_type()));
    ValueRef alpha_ref = graph->add_scalar<double>(alpha.toDouble());
    ValueRef out_ref = graph->add_tensor(out.sizes().vec(), from_at_scalartype(out.scalar_type()));
    VK_GET_OP_FN("aten.add.Tensor")(*graph, {self_ref.value, other_ref.value, alpha_ref, out_ref});
    ValueRef out_ref_staging = graph->set_output_tensor(out_ref);
    graph->prepare();
    graph->encode_prepack();
    graph->prepack();
    graph->encode_execute();

    {
      graph->get_tensor(self_ref.value)->virtual_resize(self.sizes().vec());
      graph->copy_into_staging(self_ref.staging, self.const_data_ptr(), self.numel());
      graph->get_tensor(other_ref.value)->virtual_resize(other.sizes().vec());
      graph->copy_into_staging(other_ref.staging, other.const_data_ptr(), other.numel());
      graph->propagate_resize();
      graph->execute();
      at::Tensor vk_out_ref = at::empty_like(out).contiguous();
      graph->copy_from_staging(out_ref_staging, vk_out_ref.mutable_data_ptr(), vk_out_ref.numel());
      EXPECT_TRUE(check_close(out, vk_out_ref, rtol, atol));
    }
  }
```

bypass-github-export-checks
bypass-github-pytorch-ci-checks
bypass-github-executorch-ci-checks

Reviewed By: copyrightly

Differential Revision: D58954595

fbshipit-source-id: 4112697eb25bdb65b77cbaa0b5d48142d782444d
J
Jorge Pineda committed
6b3de999bfa24c591f2d233cb81f175022e18692
Parent: 6f06316
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 6/24/2024, 7:35:45 PM