From 2538ce6ee9a51a38ba4ce01b458d9475a9f053d5 Mon Sep 17 00:00:00 2001 From: Dave Bort Date: Fri, 4 Oct 2024 11:54:48 -0700 Subject: [PATCH] Migrate backends/vulkan to the new namespace (#5876) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/5876 Move the vulkan backend out of the `torch::` namespace, and update to avoid using the `torch::` or `exec_aten::` namespaces. Reviewed By: jorgep31415 Differential Revision: D63903939 fbshipit-source-id: 42ff0ba2b560eb3e2bee02c014e39f44d7b0ec94 (cherry picked from commit b9e9479e91b92d850660165924802a5b72a86ad7) --- backends/vulkan/runtime/VulkanBackend.cpp | 29 ++++++++++++++----- .../vulkan/runtime/VulkanDelegateHeader.cpp | 11 ++++--- .../vulkan/runtime/VulkanDelegateHeader.h | 11 +++---- backends/vulkan/test/utils/test_utils.cpp | 2 +- .../vulkan/test/vulkan_compute_api_test.cpp | 6 ++-- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/backends/vulkan/runtime/VulkanBackend.cpp b/backends/vulkan/runtime/VulkanBackend.cpp index 7ed9469f77f..8c0c0f511f2 100644 --- a/backends/vulkan/runtime/VulkanBackend.cpp +++ b/backends/vulkan/runtime/VulkanBackend.cpp @@ -30,11 +30,23 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace backends { namespace vulkan { namespace { +using executorch::runtime::ArrayRef; +using executorch::runtime::Backend; +using executorch::runtime::BackendExecutionContext; +using executorch::runtime::BackendInitContext; +using executorch::runtime::CompileSpec; +using executorch::runtime::DelegateHandle; +using executorch::runtime::Error; +using executorch::runtime::EValue; +using executorch::runtime::FreeableBuffer; +using executorch::runtime::kTensorDimensionLimit; +using executorch::runtime::Result; + using namespace vkcompute; // Flatbuffer types @@ -357,7 +369,7 @@ class GraphBuilder { bool maybe_resize_input( ComputeGraph* graph, const size_t input_i, - exec_aten::Tensor& et_tensor) { + executorch::aten::Tensor& et_tensor) { ValueRef in_tensor_ref = graph->inputs()[input_i].value; vTensorPtr in_tensor = graph->get_tensor(in_tensor_ref); @@ -392,17 +404,18 @@ bool maybe_resize_input( void maybe_resize_output( ComputeGraph* graph, const size_t output_i, - exec_aten::Tensor& et_tensor) { + executorch::aten::Tensor& et_tensor) { ValueRef out_tensor_ref = graph->outputs()[output_i].value; vTensorPtr out_tensor = graph->get_tensor(out_tensor_ref); - exec_aten::SizesType new_output_size[kTensorDimensionLimit]; + executorch::aten::SizesType new_output_size[kTensorDimensionLimit]; size_t ndim = out_tensor->sizes().size(); for (int i = 0; i < ndim; ++i) { new_output_size[i] = out_tensor->sizes()[i]; } - exec_aten::ArrayRef output_size{new_output_size, ndim}; + executorch::aten::ArrayRef output_size{ + new_output_size, ndim}; Error err = resize_tensor(et_tensor, output_size); ET_CHECK_MSG(err == Error::Ok, "Failed to resize output tensor."); @@ -555,5 +568,5 @@ static auto success_with_compiler = register_backend(backend); } // namespace } // namespace vulkan -} // namespace executor -} // namespace torch +} // namespace backends +} // namespace executorch diff --git a/backends/vulkan/runtime/VulkanDelegateHeader.cpp b/backends/vulkan/runtime/VulkanDelegateHeader.cpp index a9a9fa849a7..81fd0bbc953 100644 --- a/backends/vulkan/runtime/VulkanDelegateHeader.cpp +++ b/backends/vulkan/runtime/VulkanDelegateHeader.cpp @@ -15,10 +15,13 @@ #pragma clang diagnostic ignored "-Wdeprecated" -namespace torch { -namespace executor { +namespace executorch { +namespace backends { namespace vulkan { +using executorch::runtime::Error; +using executorch::runtime::Result; + namespace { struct ByteSlice { @@ -101,5 +104,5 @@ Result VulkanDelegateHeader::parse(const void* data) { } } // namespace vulkan -} // namespace executor -} // namespace torch +} // namespace backends +} // namespace executorch diff --git a/backends/vulkan/runtime/VulkanDelegateHeader.h b/backends/vulkan/runtime/VulkanDelegateHeader.h index c5e8859743a..0fc163bbe3c 100644 --- a/backends/vulkan/runtime/VulkanDelegateHeader.h +++ b/backends/vulkan/runtime/VulkanDelegateHeader.h @@ -10,8 +10,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace backends { namespace vulkan { // Byte decoding utilities @@ -22,7 +22,8 @@ uint32_t getUInt16LE(const uint8_t* data); struct VulkanDelegateHeader { bool is_valid() const; - static Result parse(const void* data); + static executorch::runtime::Result parse( + const void* data); uint32_t header_size; uint32_t flatbuffer_offset; @@ -32,5 +33,5 @@ struct VulkanDelegateHeader { }; } // namespace vulkan -} // namespace executor -} // namespace torch +} // namespace backends +} // namespace executorch diff --git a/backends/vulkan/test/utils/test_utils.cpp b/backends/vulkan/test/utils/test_utils.cpp index d3bb884e9f1..223c1906120 100644 --- a/backends/vulkan/test/utils/test_utils.cpp +++ b/backends/vulkan/test/utils/test_utils.cpp @@ -322,7 +322,7 @@ void record_reference_matmul( _(uint8_t, Byte) \ _(int8_t, Char) \ _(int32_t, Int) \ - _(exec_aten::Half, Half) \ + _(executorch::aten::Half, Half) \ _(float, Float) \ _(int8_t, QInt8) diff --git a/backends/vulkan/test/vulkan_compute_api_test.cpp b/backends/vulkan/test/vulkan_compute_api_test.cpp index 59b3ee42dc8..236c59169d3 100644 --- a/backends/vulkan/test/vulkan_compute_api_test.cpp +++ b/backends/vulkan/test/vulkan_compute_api_test.cpp @@ -485,7 +485,7 @@ TEST_F(VulkanComputeAPITest, test_buffer_float16) { if (!context()->adapter_ptr()->has_full_float16_buffers_support()) { GTEST_SKIP(); } - test_storage_buffer_type(16); + test_storage_buffer_type(16); } TEST_F(VulkanComputeAPITest, test_buffer_int8) { @@ -567,7 +567,7 @@ TEST_F(VulkanComputeAPITest, buffer_tensor_sanity_check) { run_buffer_tensor_sanity_check(a); break; case vkapi::kHalf: - run_buffer_tensor_sanity_check(a); + run_buffer_tensor_sanity_check(a); break; case vkapi::kChar: run_buffer_tensor_sanity_check(a); @@ -2399,7 +2399,7 @@ TEST(VulkanToFromGPUShaderTest, round_trip_tests) { for (auto& sizes : to_test) { RUN_TESTS(float, vkapi::kFloat) - RUN_TESTS(exec_aten::Half, vkapi::kHalf) + RUN_TESTS(executorch::aten::Half, vkapi::kHalf) } for (auto& sizes : to_test_int8) {