Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backends/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ file(GLOB_RECURSE vulkan_runtime_utils_cpp ${RUNTIME_PATH}/utils/*.cpp)

# vulkan_backend

# Try to find boost to log stack traces when throwing exceptions
find_package(Boost 1.89 COMPONENTS stacktrace_basic stacktrace_addr2line)

file(GLOB vulkan_backend_cpp ${RUNTIME_PATH}/*.cpp)
list(APPEND vulkan_backend_cpp ${vulkan_graph_cpp})
list(APPEND vulkan_backend_cpp ${vulkan_standard_shaders_cpp})
Expand All @@ -121,6 +124,14 @@ target_include_directories(
vulkan_backend PRIVATE ${SCHEMA_INCLUDE_DIR} ${COMMON_INCLUDES}
)
target_link_libraries(vulkan_backend PRIVATE vulkan_schema executorch_core)
# Optionally link boost for stacktraces if boost is available
if(DEFINED Boost_STACKTRACE_BASIC_LIBRARY)
target_link_libraries(
vulkan_backend PRIVATE ${Boost_STACKTRACE_LIBRARY}
${Boost_STACKTRACE_ADDR2LINE_LIBRARY}
)
list(APPEND VULKAN_CXX_FLAGS "-DETVK_BOOST_STACKTRACE_AVAILABLE")
endif()
target_compile_options(vulkan_backend PRIVATE ${VULKAN_CXX_FLAGS})
# Link this library with --whole-archive due to dynamic backend registration
executorch_target_link_options_shared_lib(vulkan_backend)
Expand Down
17 changes: 17 additions & 0 deletions backends/vulkan/runtime/vk_api/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

#include <sstream>

#ifdef ETVK_BOOST_STACKTRACE_AVAILABLE
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif // _GNU_SOURCE
#include <boost/stacktrace.hpp>
#endif // ETVK_BOOST_STACKTRACE_AVAILABLE

namespace vkcompute {
namespace vkapi {

Expand Down Expand Up @@ -65,6 +72,11 @@ Error::Error(SourceLocation source_location, std::string msg)
std::ostringstream oss;
oss << "Exception raised from " << source_location_ << ": ";
oss << msg_;
#ifdef ETVK_BOOST_STACKTRACE_AVAILABLE
oss << "\n";
oss << "Stack trace:\n";
oss << boost::stacktrace::stacktrace();
#endif // ETVK_BOOST_STACKTRACE_AVAILABLE
what_ = oss.str();
}

Expand All @@ -74,6 +86,11 @@ Error::Error(SourceLocation source_location, const char* cond, std::string msg)
oss << "Exception raised from " << source_location_ << ": ";
oss << "(" << cond << ") is false! ";
oss << msg_;
#ifdef ETVK_BOOST_STACKTRACE_AVAILABLE
oss << "\n";
oss << "Stack trace:\n";
oss << boost::stacktrace::stacktrace();
#endif // ETVK_BOOST_STACKTRACE_AVAILABLE
what_ = oss.str();
}

Expand Down
13 changes: 12 additions & 1 deletion backends/vulkan/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def get_vulkan_preprocessor_flags(no_volk, is_fbcode):
default_flags = []
android_flags = []

debug_mode = read_config("etvk", "debug", "0") == "1"

if not no_volk:
for flags in [default_flags, android_flags]:
flags.append("-DUSE_VULKAN_WRAPPER")
Expand All @@ -32,6 +34,10 @@ def get_vulkan_preprocessor_flags(no_volk, is_fbcode):
if link_moltenvk:
mac_flags = []

if debug_mode:
mac_flags.append("-DETVK_BOOST_STACKTRACE_AVAILABLE")
default_flags.append("-DETVK_BOOST_STACKTRACE_AVAILABLE")

VK_API_PREPROCESSOR_FLAGS += select({
"DEFAULT": default_flags,
"ovr_config//os:android": android_flags,
Expand Down Expand Up @@ -59,7 +65,6 @@ def get_vulkan_preprocessor_flags(no_volk, is_fbcode):
if etvk_default_cache_path != "":
VK_API_PREPROCESSOR_FLAGS += ["-DETVK_DEFAULT_CACHE_PATH={}".format(etvk_default_cache_path)]

debug_mode = read_config("etvk", "debug", "0") == "1"
if debug_mode:
VK_API_PREPROCESSOR_FLAGS += ["-DVULKAN_DEBUG"]

Expand Down Expand Up @@ -136,6 +141,8 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False, no_volk = Fal
)

def define_common_targets(is_fbcode = False):
debug_mode = read_config("etvk", "debug", "0") == "1"

runtime.python_library(
name = "gen_vulkan_spv_lib",
srcs = [
Expand Down Expand Up @@ -200,6 +207,10 @@ def define_common_targets(is_fbcode = False):
"//third-party/khronos:moltenVK_static"
]

if debug_mode:
mac_deps.append("fbsource//third-party/boost:boost")
default_deps.append("fbsource//third-party/boost:boost")

VK_API_DEPS += select({
"DEFAULT": default_deps,
"ovr_config//os:android": android_deps,
Expand Down
Loading