diff --git a/backends/vulkan/runtime/graph/ComputeGraph.cpp b/backends/vulkan/runtime/graph/ComputeGraph.cpp index 6aa9171d9f..6583d4a5a3 100644 --- a/backends/vulkan/runtime/graph/ComputeGraph.cpp +++ b/backends/vulkan/runtime/graph/ComputeGraph.cpp @@ -6,12 +6,15 @@ * LICENSE file in the root directory of this source tree. */ -#include +// @lint-ignore-every CLANGTIDY +// facebook-security-vulnerable-integer-sign-conversion -#include +#include #include +#include + namespace at { namespace native { namespace vulkan { diff --git a/backends/vulkan/runtime/graph/ComputeGraph.h b/backends/vulkan/runtime/graph/ComputeGraph.h index 7917304f0c..776f5e12ee 100644 --- a/backends/vulkan/runtime/graph/ComputeGraph.h +++ b/backends/vulkan/runtime/graph/ComputeGraph.h @@ -12,9 +12,7 @@ #ifdef USE_VULKAN_API -#include -#include -#include +#include #include diff --git a/backends/vulkan/runtime/graph/GraphConfig.h b/backends/vulkan/runtime/graph/GraphConfig.h index e2c8d6bed0..ce0f0839a9 100644 --- a/backends/vulkan/runtime/graph/GraphConfig.h +++ b/backends/vulkan/runtime/graph/GraphConfig.h @@ -10,7 +10,7 @@ #ifdef USE_VULKAN_API -#include +#include namespace at { namespace native { diff --git a/backends/vulkan/runtime/graph/ops/ExecuteNode.cpp b/backends/vulkan/runtime/graph/ops/ExecuteNode.cpp index c9c338bc17..f6649fb19c 100644 --- a/backends/vulkan/runtime/graph/ops/ExecuteNode.cpp +++ b/backends/vulkan/runtime/graph/ops/ExecuteNode.cpp @@ -10,7 +10,7 @@ #include -#include +#include namespace at { namespace native { diff --git a/backends/vulkan/runtime/graph/ops/ExecuteNode.h b/backends/vulkan/runtime/graph/ops/ExecuteNode.h index f3c2bba9c0..5bcad8fb80 100644 --- a/backends/vulkan/runtime/graph/ops/ExecuteNode.h +++ b/backends/vulkan/runtime/graph/ops/ExecuteNode.h @@ -10,9 +10,7 @@ #ifdef USE_VULKAN_API -#include -#include -#include +#include #include diff --git a/backends/vulkan/runtime/graph/ops/OperatorRegistry.cpp b/backends/vulkan/runtime/graph/ops/OperatorRegistry.cpp index ba559d870c..9f489e1c3f 100644 --- a/backends/vulkan/runtime/graph/ops/OperatorRegistry.cpp +++ b/backends/vulkan/runtime/graph/ops/OperatorRegistry.cpp @@ -8,8 +8,6 @@ #include -#include - namespace at { namespace native { namespace vulkan { diff --git a/backends/vulkan/runtime/graph/ops/PrepackNode.cpp b/backends/vulkan/runtime/graph/ops/PrepackNode.cpp index 69e6ffabd6..43ad64c942 100644 --- a/backends/vulkan/runtime/graph/ops/PrepackNode.cpp +++ b/backends/vulkan/runtime/graph/ops/PrepackNode.cpp @@ -10,8 +10,8 @@ #include -#include -#include +#include +#include namespace at { namespace native { diff --git a/backends/vulkan/runtime/graph/ops/PrepackNode.h b/backends/vulkan/runtime/graph/ops/PrepackNode.h index 59071e9371..80465703da 100644 --- a/backends/vulkan/runtime/graph/ops/PrepackNode.h +++ b/backends/vulkan/runtime/graph/ops/PrepackNode.h @@ -10,9 +10,7 @@ #ifdef USE_VULKAN_API -#include -#include -#include +#include #include diff --git a/backends/vulkan/runtime/graph/ops/impl/Arithmetic.cpp b/backends/vulkan/runtime/graph/ops/impl/Arithmetic.cpp index ff9b4ff2b2..52cd04c492 100644 --- a/backends/vulkan/runtime/graph/ops/impl/Arithmetic.cpp +++ b/backends/vulkan/runtime/graph/ops/impl/Arithmetic.cpp @@ -8,11 +8,13 @@ #include -#include #include #include +#include +#include + namespace at { namespace native { namespace vulkan { diff --git a/backends/vulkan/runtime/graph/ops/impl/Arithmetic.h b/backends/vulkan/runtime/graph/ops/impl/Arithmetic.h index 8e5c345a92..b81ee21e64 100644 --- a/backends/vulkan/runtime/graph/ops/impl/Arithmetic.h +++ b/backends/vulkan/runtime/graph/ops/impl/Arithmetic.h @@ -12,8 +12,6 @@ #include -#include - namespace at { namespace native { namespace vulkan { diff --git a/backends/vulkan/runtime/graph/ops/impl/Staging.cpp b/backends/vulkan/runtime/graph/ops/impl/Staging.cpp index 953a06426a..349e000086 100644 --- a/backends/vulkan/runtime/graph/ops/impl/Staging.cpp +++ b/backends/vulkan/runtime/graph/ops/impl/Staging.cpp @@ -8,9 +8,10 @@ #include -#include -#include -#include +#include + +#include +#include namespace at { namespace native { diff --git a/backends/vulkan/runtime/graph/ops/OpUtils.h b/backends/vulkan/runtime/graph/ops/impl/utils/DimUtils.h similarity index 75% rename from backends/vulkan/runtime/graph/ops/OpUtils.h rename to backends/vulkan/runtime/graph/ops/impl/utils/DimUtils.h index b5acb3945a..299c3bb99f 100644 --- a/backends/vulkan/runtime/graph/ops/OpUtils.h +++ b/backends/vulkan/runtime/graph/ops/impl/utils/DimUtils.h @@ -12,8 +12,6 @@ #include -#include - namespace at { namespace native { namespace vulkan { @@ -75,27 +73,6 @@ uint32_t dim_at(const vTensor& v_in) { return dim_at(v_in.sizes()); } -/* - * For most global work group sizes, returns {4, 4, 4}, but adjusts the size for - * 2D global work group sizes. Always maintains a total of 64 invocations - */ -api::utils::uvec3 adaptive_work_group_size( - const api::utils::uvec3& global_work_group); - -template -T extract_scalar(const Value& value) { - if (value.isInt()) { - return static_cast(value.toInt()); - } - if (value.isDouble()) { - return static_cast(value.toDouble()); - } - if (value.isBool()) { - return static_cast(value.toBool()); - } - VK_THROW("Cannot extract scalar from Value with type ", value.type()); -} - } // namespace vulkan } // namespace native } // namespace at diff --git a/backends/vulkan/runtime/graph/ops/impl/utils/ScalarUtils.h b/backends/vulkan/runtime/graph/ops/impl/utils/ScalarUtils.h new file mode 100644 index 0000000000..38cb8eed3b --- /dev/null +++ b/backends/vulkan/runtime/graph/ops/impl/utils/ScalarUtils.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#ifdef USE_VULKAN_API + +#include + +#include + +namespace at { +namespace native { +namespace vulkan { + +template +T extract_scalar(const Value& value) { + if (value.isInt()) { + return static_cast(value.toInt()); + } + if (value.isDouble()) { + return static_cast(value.toDouble()); + } + if (value.isBool()) { + return static_cast(value.toBool()); + } + VK_THROW("Cannot extract scalar from Value with type ", value.type()); +} + +} // namespace vulkan +} // namespace native +} // namespace at + +#endif /* USE_VULKAN_API */ diff --git a/backends/vulkan/runtime/graph/ops/OpUtils.cpp b/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.cpp similarity index 68% rename from backends/vulkan/runtime/graph/ops/OpUtils.cpp rename to backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.cpp index ce82aef092..72e1bc5a0d 100644 --- a/backends/vulkan/runtime/graph/ops/OpUtils.cpp +++ b/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.cpp @@ -6,7 +6,9 @@ * LICENSE file in the root directory of this source tree. */ -#include +#include + +#include namespace at { namespace native { @@ -29,6 +31,14 @@ api::utils::uvec3 adaptive_work_group_size( return local_group_size; } +api::utils::ivec4 get_size_as_ivec4(const vTensor& t) { + return api::utils::make_ivec4( + {dim_at(t), + dim_at(t), + dim_at(t), + dim_at(t)}); +} + } // namespace vulkan } // namespace native } // namespace at diff --git a/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.h b/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.h new file mode 100644 index 0000000000..a01e8c0a4d --- /dev/null +++ b/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#ifdef USE_VULKAN_API + +#include + +namespace at { +namespace native { +namespace vulkan { + +api::utils::uvec3 adaptive_work_group_size( + const api::utils::uvec3& global_work_group); + +api::utils::ivec4 get_size_as_ivec4(const vTensor& t); + +} // namespace vulkan +} // namespace native +} // namespace at + +#endif /* USE_VULKAN_API */ diff --git a/backends/vulkan/runtime/graph/ops/Utils.cpp b/backends/vulkan/runtime/graph/ops/utils/BindingUtils.cpp similarity index 83% rename from backends/vulkan/runtime/graph/ops/Utils.cpp rename to backends/vulkan/runtime/graph/ops/utils/BindingUtils.cpp index dda813c669..6e471167ec 100644 --- a/backends/vulkan/runtime/graph/ops/Utils.cpp +++ b/backends/vulkan/runtime/graph/ops/utils/BindingUtils.cpp @@ -6,22 +6,12 @@ * LICENSE file in the root directory of this source tree. */ -#include - -#include +#include namespace at { namespace native { namespace vulkan { -api::utils::ivec4 get_size_as_ivec4(const vTensor& t) { - return api::utils::make_ivec4( - {dim_at(t), - dim_at(t), - dim_at(t), - dim_at(t)}); -} - void bind_tensor_to_descriptor_set( vTensor& tensor, api::PipelineBarrier& pipeline_barrier, diff --git a/backends/vulkan/runtime/graph/ops/Utils.h b/backends/vulkan/runtime/graph/ops/utils/BindingUtils.h similarity index 94% rename from backends/vulkan/runtime/graph/ops/Utils.h rename to backends/vulkan/runtime/graph/ops/utils/BindingUtils.h index b79c95eb93..28649a1194 100644 --- a/backends/vulkan/runtime/graph/ops/Utils.h +++ b/backends/vulkan/runtime/graph/ops/utils/BindingUtils.h @@ -16,8 +16,6 @@ namespace at { namespace native { namespace vulkan { -api::utils::ivec4 get_size_as_ivec4(const vTensor& t); - void bind_tensor_to_descriptor_set( vTensor& tensor, api::PipelineBarrier& pipeline_barrier, diff --git a/backends/vulkan/runtime/graph/ops/StagingUtils.cpp b/backends/vulkan/runtime/graph/ops/utils/StagingUtils.cpp similarity index 87% rename from backends/vulkan/runtime/graph/ops/StagingUtils.cpp rename to backends/vulkan/runtime/graph/ops/utils/StagingUtils.cpp index 1637cfb2e1..50f812df84 100644 --- a/backends/vulkan/runtime/graph/ops/StagingUtils.cpp +++ b/backends/vulkan/runtime/graph/ops/utils/StagingUtils.cpp @@ -6,15 +6,36 @@ * LICENSE file in the root directory of this source tree. */ -#include +// @lint-ignore-every CLANGTIDY facebook-security-vulnerable-memcpy -#include -#include +#include + +#include + +#include namespace at { namespace native { namespace vulkan { +template +void memcpy_to_mapping_impl( + const void* src, + api::MemoryMap& dst_mapping, + const size_t nbytes) { + T* data_ptr = dst_mapping.template data(); + memcpy(data_ptr, reinterpret_cast(src), nbytes); +} + +template +void memcpy_from_mapping_impl( + api::MemoryMap& src_mapping, + void* dst, + const size_t nbytes) { + T* data_ptr = src_mapping.template data(); + memcpy(reinterpret_cast(dst), data_ptr, nbytes); +} + void memcpy_to_mapping( const void* src, api::MemoryMap& dst_mapping, diff --git a/backends/vulkan/runtime/graph/ops/StagingUtils.h b/backends/vulkan/runtime/graph/ops/utils/StagingUtils.h similarity index 51% rename from backends/vulkan/runtime/graph/ops/StagingUtils.h rename to backends/vulkan/runtime/graph/ops/utils/StagingUtils.h index c101581a77..2e5de6efb0 100644 --- a/backends/vulkan/runtime/graph/ops/StagingUtils.h +++ b/backends/vulkan/runtime/graph/ops/utils/StagingUtils.h @@ -12,49 +12,10 @@ #include -#include - namespace at { namespace native { namespace vulkan { -// -// Functions to memcpy data into staging buffer -// - -void memcpy_to_mapping( - const void* src, - api::MemoryMap& dst_mapping, - const size_t nbytes, - const api::ScalarType dtype); -void memcpy_from_mapping( - const api::MemoryMap& src_mapping, - void* dst, - const size_t nbytes, - const api::ScalarType dtype); - -// -// Utility functions for memcpy -// - -template -void memcpy_to_mapping_impl( - const void* src, - api::MemoryMap& dst_mapping, - const size_t nbytes) { - T* data_ptr = dst_mapping.template data(); - memcpy(data_ptr, reinterpret_cast(src), nbytes); -} - -template -void memcpy_from_mapping_impl( - api::MemoryMap& src_mapping, - void* dst, - const size_t nbytes) { - T* data_ptr = src_mapping.template data(); - memcpy(reinterpret_cast(dst), data_ptr, nbytes); -} - // // Functions to copy data into and out of a staging buffer // diff --git a/backends/vulkan/test/vulkan_compute_api_test.cpp b/backends/vulkan/test/vulkan_compute_api_test.cpp index 334a293710..6b041ab826 100644 --- a/backends/vulkan/test/vulkan_compute_api_test.cpp +++ b/backends/vulkan/test/vulkan_compute_api_test.cpp @@ -10,14 +10,15 @@ #include -#include - #include -#include #include #include +#include + +#include + using namespace at::native::vulkan; #define CREATE_FLOAT_TEXTURE(sizes, allocate_memory) \