Skip to content

Commit

Permalink
Provide CMake option to enable Vulkan API. (#46503)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #46503

Test Plan: Imported from OSS

Reviewed By: IvanKobzarev

Differential Revision: D24379144

Pulled By: AshkanAliabadi

fbshipit-source-id: 8d8c57f96bbac2a44615828a3474c912704f3a85
  • Loading branch information
Ashkan Aliabadi authored and facebook-github-bot committed Oct 21, 2020
1 parent 3e041b5 commit 6cd8b5e
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ cmake_dependent_option(
USE_VALGRIND "Use Valgrind. Only available on Linux." ON
"LINUX" OFF)
option(USE_VULKAN "Use Vulkan GPU backend" OFF)
option(USE_VULKAN_API "Use Vulkan GPU backend v2" OFF)
option(USE_VULKAN_WRAPPER "Use Vulkan wrapper" ON)
option(USE_VULKAN_SHADERC_RUNTIME "Use Vulkan Shader compilation runtime(Needs shaderc lib)" OFF)
option(USE_VULKAN_RELAXED_PRECISION "Use Vulkan relaxed precision(mediump)" OFF)
Expand Down Expand Up @@ -536,6 +537,10 @@ if(USE_VULKAN)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_VULKAN")
endif()

if(USE_VULKAN_API)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_VULKAN_API")
endif()

if(USE_VULKAN_WRAPPER)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_VULKAN_WRAPPER")
endif()
Expand Down
6 changes: 5 additions & 1 deletion aten/src/ATen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ file(GLOB native_cpp "native/*.cpp")
file(GLOB native_mkl_cpp "native/mkl/*.cpp")
file(GLOB native_mkldnn_cpp "native/mkldnn/*.cpp")
file(GLOB vulkan_cpp "vulkan/*.cpp")
file(GLOB native_vulkan_cpp "native/vulkan/api/*.cpp" "native/vulkan/*.cpp")
file(GLOB native_vulkan_cpp "native/vulkan/*.cpp")
file(GLOB native_vulkan_api_cpp "native/vulkan/api/*.cpp" "native/vulkan/ops/*.cpp")

# Metal
file(GLOB metal_h "metal/*.h")
Expand Down Expand Up @@ -124,6 +125,9 @@ if(AT_MKLDNN_ENABLED)
endif()
if(USE_VULKAN)
set(all_cpu_cpp ${all_cpu_cpp} ${vulkan_cpp} ${native_vulkan_cpp} ${vulkan_generated_cpp})
if(USE_VULKAN_API)
set(all_cpu_cpp ${all_cpu_cpp} ${native_vulkan_api_cpp})
endif()
else()
set(all_cpu_cpp ${all_cpu_cpp} ${vulkan_cpp})
endif()
Expand Down
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Adapter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Runtime.h>

Expand Down Expand Up @@ -34,3 +36,5 @@ struct Adapter final {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Allocator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>

#ifdef DEBUG
Expand All @@ -24,3 +26,5 @@
#ifdef __clang__
#pragma clang diagnostic pop
#endif /* __clang__ */

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Cache.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>

namespace at {
Expand Down Expand Up @@ -86,3 +88,5 @@ inline void Cache<Factory>::purge() {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Command.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Descriptor.h>
#include <ATen/native/vulkan/api/Pipeline.h>
Expand Down Expand Up @@ -93,3 +95,5 @@ inline Command::Buffer& Command::Buffer::operator=(Buffer&& buffer) {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/ATen.h>

#ifdef USE_VULKAN_SHADERC_RUNTIME
Expand Down Expand Up @@ -181,3 +183,5 @@ inline void Handle<Type, Deleter>::reset(Type payload) {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Adapter.h>
#include <ATen/native/vulkan/api/Command.h>
Expand Down Expand Up @@ -177,3 +179,5 @@ inline void Context::dispatch(
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Descriptor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Resource.h>
#include <ATen/native/vulkan/api/Shader.h>
Expand Down Expand Up @@ -154,3 +156,5 @@ inline Descriptor::Set& Descriptor::Set::operator=(Set&& set) {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Pipeline.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Cache.h>
#include <ATen/native/vulkan/api/Resource.h>
Expand Down Expand Up @@ -218,3 +220,5 @@ inline void Pipeline::Cache::purge() {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Resource.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Allocator.h>
#include <ATen/native/vulkan/api/Cache.h>
Expand Down Expand Up @@ -375,3 +377,5 @@ inline VkFence Resource::Fence::handle(const bool add_to_waitlist) const {
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
2 changes: 1 addition & 1 deletion aten/src/ATen/native/vulkan/api/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace api {
namespace {

struct Configuration final {
#ifndef DEBUG
#ifdef DEBUG
static constexpr Runtime::Type kRuntime = Runtime::Type::Debug;
#else
static constexpr Runtime::Type kRuntime = Runtime::Type::Release;
Expand Down
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Runtime.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>

namespace at {
Expand Down Expand Up @@ -61,3 +63,5 @@ Runtime* runtime();
} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/Shader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>
#include <ATen/native/vulkan/api/Cache.h>
#include <c10/util/hash.h>
Expand Down Expand Up @@ -293,3 +295,5 @@ inline bool operator==(
(_1.stageFlags == _2.stageFlags) &&
(_1.pImmutableSamplers == _2.pImmutableSamplers);
}

#endif /* USE_VULKAN_API */
4 changes: 4 additions & 0 deletions aten/src/ATen/native/vulkan/api/api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Common.h>

#include <ATen/native/vulkan/api/Adapter.h>
Expand All @@ -10,3 +12,5 @@
#include <ATen/native/vulkan/api/Resource.h>
#include <ATen/native/vulkan/api/Runtime.h>
#include <ATen/native/vulkan/api/Shader.h>

#endif /* USE_VULKAN_API */
2 changes: 0 additions & 2 deletions aten/src/ATen/test/vulkan_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/api.h>

namespace {

} // namespace
Expand Down

0 comments on commit 6cd8b5e

Please sign in to comment.