-
Notifications
You must be signed in to change notification settings - Fork 606
[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
Conversation
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]
🔗 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 SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 8df50ae with merge base 398ce66 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. 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-source-id: 231368379 Pull Request resolved: #4044
This pull request has been merged in 6b3de99. |
Stack from ghstack (oldest at bottom):
Separate change because this one is real messy.
Before
After
Differential Revision: D58954595