Skip to content

[ET-VK] Stylize check_fn in codegen #4044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jorgep31415
Copy link
Contributor

@jorgep31415 jorgep31415 commented Jun 24, 2024

Stack from ghstack (oldest at bottom):

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));
    }
  }

Differential Revision: D58954595

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));
    }
  }
```

Differential Revision: [D58954595](https://our.internmc.facebook.com/intern/diff/D58954595/)

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Jun 24, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/4044

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 8df50ae with merge base 398ce66 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 24, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D58954595

jorgep31415 added a commit that referenced this pull request Jun 24, 2024
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));
    }
  }
```

Differential Revision: [D58954595](https://our.internmc.facebook.com/intern/diff/D58954595/)

ghstack-source-id: 231368379
Pull Request resolved: #4044
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 6b3de99.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants