From 8d575556f13b6a74c738946960023d3f2c35db51 Mon Sep 17 00:00:00 2001 From: Jorge Pineda Date: Tue, 2 Jul 2024 09:34:25 -0700 Subject: [PATCH] [ET-VK] Organize `StringUtil.h` and `Utils.h` into `utils/` and `VkUtils.h` Everything in `utils/` will take the `namespace vkcompute:::utils`; everything in `VkUtils.h` deals with the Vulkan API directly. Differential Revision: [D59281548](https://our.internmc.facebook.com/intern/diff/D59281548/) [ghstack-poisoned] --- backends/vulkan/runtime/api/Adapter.h | 2 +- backends/vulkan/runtime/api/Command.h | 2 +- backends/vulkan/runtime/api/Context.cpp | 1 + backends/vulkan/runtime/api/Context.h | 2 ++ backends/vulkan/runtime/api/Descriptor.cpp | 3 ++- backends/vulkan/runtime/api/Exception.h | 22 +++++++++---------- backends/vulkan/runtime/api/QueryPool.cpp | 2 +- backends/vulkan/runtime/api/Shader.h | 3 ++- backends/vulkan/runtime/api/Tensor.cpp | 2 +- backends/vulkan/runtime/api/VkUtils.h | 21 ++++++++++++++++++ backends/vulkan/runtime/api/api.h | 3 ++- .../vulkan/runtime/api/memory/Allocator.h | 4 ++-- backends/vulkan/runtime/api/memory/Buffer.h | 2 +- backends/vulkan/runtime/api/memory/Image.h | 2 +- .../vulkan/runtime/api/utils/MacroUtils.h | 16 ++++++++++++++ .../api/{StringUtil.h => utils/StringUtils.h} | 6 ++--- .../runtime/api/{Utils.h => utils/VecUtils.h} | 17 -------------- backends/vulkan/runtime/graph/Logging.h | 2 +- .../vulkan/runtime/graph/ops/impl/Arange.cpp | 2 +- 19 files changed, 69 insertions(+), 45 deletions(-) create mode 100644 backends/vulkan/runtime/api/VkUtils.h create mode 100644 backends/vulkan/runtime/api/utils/MacroUtils.h rename backends/vulkan/runtime/api/{StringUtil.h => utils/StringUtils.h} (96%) rename backends/vulkan/runtime/api/{Utils.h => utils/VecUtils.h} (96%) diff --git a/backends/vulkan/runtime/api/Adapter.h b/backends/vulkan/runtime/api/Adapter.h index 7ab64201af6..7d64cb7bcfd 100644 --- a/backends/vulkan/runtime/api/Adapter.h +++ b/backends/vulkan/runtime/api/Adapter.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include diff --git a/backends/vulkan/runtime/api/Command.h b/backends/vulkan/runtime/api/Command.h index c04339ceddd..1d60afcfa5f 100644 --- a/backends/vulkan/runtime/api/Command.h +++ b/backends/vulkan/runtime/api/Command.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/backends/vulkan/runtime/api/Context.cpp b/backends/vulkan/runtime/api/Context.cpp index ec10354c67d..18415857495 100644 --- a/backends/vulkan/runtime/api/Context.cpp +++ b/backends/vulkan/runtime/api/Context.cpp @@ -7,6 +7,7 @@ */ #include +#include #ifndef VULKAN_DESCRIPTOR_POOL_SIZE #define VULKAN_DESCRIPTOR_POOL_SIZE 1024u diff --git a/backends/vulkan/runtime/api/Context.h b/backends/vulkan/runtime/api/Context.h index a175a4a2677..cf411c86012 100644 --- a/backends/vulkan/runtime/api/Context.h +++ b/backends/vulkan/runtime/api/Context.h @@ -17,6 +17,8 @@ #include #include +#include + namespace vkcompute { namespace api { diff --git a/backends/vulkan/runtime/api/Descriptor.cpp b/backends/vulkan/runtime/api/Descriptor.cpp index ef7188ff279..82204b5f329 100644 --- a/backends/vulkan/runtime/api/Descriptor.cpp +++ b/backends/vulkan/runtime/api/Descriptor.cpp @@ -7,7 +7,8 @@ */ #include -#include + +#include #include #include diff --git a/backends/vulkan/runtime/api/Exception.h b/backends/vulkan/runtime/api/Exception.h index 05dc10ee953..eb3f6c46994 100644 --- a/backends/vulkan/runtime/api/Exception.h +++ b/backends/vulkan/runtime/api/Exception.h @@ -11,21 +11,21 @@ #include -#include +#include #include #include #include #include -#define VK_CHECK(function) \ - do { \ - const VkResult result = (function); \ - if (VK_SUCCESS != result) { \ - throw ::vkcompute::api::Error( \ - {__func__, __FILE__, static_cast(__LINE__)}, \ - ::vkcompute::api::concat_str(#function, " returned ", result)); \ - } \ +#define VK_CHECK(function) \ + do { \ + const VkResult result = (function); \ + if (VK_SUCCESS != result) { \ + throw ::vkcompute::api::Error( \ + {__func__, __FILE__, static_cast(__LINE__)}, \ + ::vkcompute::utils::concat_str(#function, " returned ", result)); \ + } \ } while (false) #define VK_CHECK_COND(cond, ...) \ @@ -34,7 +34,7 @@ throw ::vkcompute::api::Error( \ {__func__, __FILE__, static_cast(__LINE__)}, \ #cond, \ - ::vkcompute::api::concat_str(__VA_ARGS__)); \ + ::vkcompute::utils::concat_str(__VA_ARGS__)); \ } \ } while (false) @@ -42,7 +42,7 @@ do { \ throw ::vkcompute::api::Error( \ {__func__, __FILE__, static_cast(__LINE__)}, \ - ::vkcompute::api::concat_str(__VA_ARGS__)); \ + ::vkcompute::utils::concat_str(__VA_ARGS__)); \ } while (false) namespace vkcompute { diff --git a/backends/vulkan/runtime/api/QueryPool.cpp b/backends/vulkan/runtime/api/QueryPool.cpp index 03d4115c495..3a931f1bb57 100644 --- a/backends/vulkan/runtime/api/QueryPool.cpp +++ b/backends/vulkan/runtime/api/QueryPool.cpp @@ -9,7 +9,7 @@ // @lint-ignore-every CLANGTIDY facebook-hte-BadImplicitCast #include -#include +#include #include #include diff --git a/backends/vulkan/runtime/api/Shader.h b/backends/vulkan/runtime/api/Shader.h index 9a04b52b80a..eb727d6428b 100644 --- a/backends/vulkan/runtime/api/Shader.h +++ b/backends/vulkan/runtime/api/Shader.h @@ -13,7 +13,8 @@ #include #include -#include + +#include #include #include diff --git a/backends/vulkan/runtime/api/Tensor.cpp b/backends/vulkan/runtime/api/Tensor.cpp index 819eb7fc0af..bbf46a6e9ab 100644 --- a/backends/vulkan/runtime/api/Tensor.cpp +++ b/backends/vulkan/runtime/api/Tensor.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include namespace vkcompute { diff --git a/backends/vulkan/runtime/api/VkUtils.h b/backends/vulkan/runtime/api/VkUtils.h new file mode 100644 index 00000000000..b0e6a820423 --- /dev/null +++ b/backends/vulkan/runtime/api/VkUtils.h @@ -0,0 +1,21 @@ +/* + * 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 + +#include + +namespace vkcompute { +namespace api { + +inline VkExtent3D create_extent3d(const utils::uvec3& extents) { + return VkExtent3D{extents.data[0u], extents.data[1u], extents.data[2u]}; +} + +} // namespace api +} // namespace vkcompute diff --git a/backends/vulkan/runtime/api/api.h b/backends/vulkan/runtime/api/api.h index 8d78374e4eb..f5d4771976b 100644 --- a/backends/vulkan/runtime/api/api.h +++ b/backends/vulkan/runtime/api/api.h @@ -20,7 +20,8 @@ #include #include #include -#include + +#include #include #include diff --git a/backends/vulkan/runtime/api/memory/Allocator.h b/backends/vulkan/runtime/api/memory/Allocator.h index f1d3a449f56..5567047d7ee 100644 --- a/backends/vulkan/runtime/api/memory/Allocator.h +++ b/backends/vulkan/runtime/api/memory/Allocator.h @@ -12,14 +12,14 @@ #include -#include - #include #include #include #include +#include + namespace vkcompute { namespace api { diff --git a/backends/vulkan/runtime/api/memory/Buffer.h b/backends/vulkan/runtime/api/memory/Buffer.h index c0eea5bea6e..e80b2395c22 100644 --- a/backends/vulkan/runtime/api/memory/Buffer.h +++ b/backends/vulkan/runtime/api/memory/Buffer.h @@ -12,7 +12,7 @@ #include -#include +#include #include diff --git a/backends/vulkan/runtime/api/memory/Image.h b/backends/vulkan/runtime/api/memory/Image.h index e3f4d7437df..8a7cf6081ac 100644 --- a/backends/vulkan/runtime/api/memory/Image.h +++ b/backends/vulkan/runtime/api/memory/Image.h @@ -12,7 +12,7 @@ #include -#include +#include #include diff --git a/backends/vulkan/runtime/api/utils/MacroUtils.h b/backends/vulkan/runtime/api/utils/MacroUtils.h new file mode 100644 index 00000000000..a7ca353ac30 --- /dev/null +++ b/backends/vulkan/runtime/api/utils/MacroUtils.h @@ -0,0 +1,16 @@ +/* + * 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 + +// Suppress an unused variable. Copied from C10_UNUSED +#if defined(_MSC_VER) && !defined(__clang__) +#define VK_UNUSED __pragma(warning(suppress : 4100 4101)) +#else +#define VK_UNUSED __attribute__((__unused__)) +#endif //_MSC_VER diff --git a/backends/vulkan/runtime/api/StringUtil.h b/backends/vulkan/runtime/api/utils/StringUtils.h similarity index 96% rename from backends/vulkan/runtime/api/StringUtil.h rename to backends/vulkan/runtime/api/utils/StringUtils.h index 982ef7fe93e..986b58c3303 100644 --- a/backends/vulkan/runtime/api/StringUtil.h +++ b/backends/vulkan/runtime/api/utils/StringUtils.h @@ -9,14 +9,12 @@ #pragma once // @lint-ignore-every CLANGTIDY facebook-hte-LocalUncheckedArrayBounds -#include #include #include #include -#include namespace vkcompute { -namespace api { +namespace utils { namespace detail { @@ -86,5 +84,5 @@ inline std::string concat_str(const Args&... args) { typename detail::CanonicalizeStrTypes::type...>::call(args...); } -} // namespace api +} // namespace utils } // namespace vkcompute diff --git a/backends/vulkan/runtime/api/Utils.h b/backends/vulkan/runtime/api/utils/VecUtils.h similarity index 96% rename from backends/vulkan/runtime/api/Utils.h rename to backends/vulkan/runtime/api/utils/VecUtils.h index 4bf4dc271ae..0d5598490bf 100644 --- a/backends/vulkan/runtime/api/Utils.h +++ b/backends/vulkan/runtime/api/utils/VecUtils.h @@ -17,15 +17,6 @@ #include -// Compiler Macros - -// Suppress an unused variable. Copied from C10_UNUSED -#if defined(_MSC_VER) && !defined(__clang__) -#define VK_UNUSED __pragma(warning(suppress : 4100 4101)) -#else -#define VK_UNUSED __attribute__((__unused__)) -#endif //_MSC_VER - namespace vkcompute { namespace utils { @@ -459,12 +450,4 @@ inline int64_t multiply_integers(Iter begin, Iter end) { } } // namespace utils - -namespace api { - -inline VkExtent3D create_extent3d(const utils::uvec3& extents) { - return VkExtent3D{extents.data[0u], extents.data[1u], extents.data[2u]}; -} - -} // namespace api } // namespace vkcompute diff --git a/backends/vulkan/runtime/graph/Logging.h b/backends/vulkan/runtime/graph/Logging.h index 76aaf885f66..fb2f66e2d6f 100644 --- a/backends/vulkan/runtime/graph/Logging.h +++ b/backends/vulkan/runtime/graph/Logging.h @@ -8,7 +8,7 @@ #pragma once -#include +#include #include #include diff --git a/backends/vulkan/runtime/graph/ops/impl/Arange.cpp b/backends/vulkan/runtime/graph/ops/impl/Arange.cpp index 84ed0adb3ac..696898816a0 100644 --- a/backends/vulkan/runtime/graph/ops/impl/Arange.cpp +++ b/backends/vulkan/runtime/graph/ops/impl/Arange.cpp @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. */ -#include +#include #include