Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aot] Enable validation layers for C-API tests #6893

Merged
merged 12 commits into from
Dec 27, 2022
4 changes: 2 additions & 2 deletions .github/workflows/scripts/win_build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ if ($llvmVer -eq "10") {
$env:TAICHI_CMAKE_ARGS += " -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang"

if ($installVulkan) {
$env:VULKAN_SDK = "C:\VulkanSDK\1.2.189.0"
$env:VULKAN_SDK = "C:\VulkanSDK\1.3.236.0"
jim19930609 marked this conversation as resolved.
Show resolved Hide resolved
if (-not (Test-Path $env:VULKAN_SDK)) {
Info("Download and install Vulkan")
Invoke-WebRequest `
-Uri 'https://sdk.lunarg.com/sdk/download/1.2.189.0/windows/VulkanSDK-1.2.189.0-Installer.exe' `
-Uri 'https://sdk.lunarg.com/sdk/download/1.3.236.0/windows/VulkanSDK-1.3.236.0-Installer.exe' `
-MaximumRetryCount 10 -RetryIntervalSec 5 `
-OutFile VulkanSDK.exe
$installer = Start-Process -FilePath VulkanSDK.exe -Wait -PassThru -ArgumentList @("/S")
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
docker exec --user dev check_clang_tidy /home/dev/taichi/.github/workflows/scripts/check_clang_tidy.sh "$CI_SETUP_CMAKE_ARGS"
env:
CR_PAT: ${{ secrets.GITHUB_TOKEN }}
CI_SETUP_CMAKE_ARGS: -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTI_WITH_OPENGL:BOOL=ON -DTI_WITH_CC:BOOL=ON -DTI_WITH_VULKAN:BOOL=ON -DTI_BUILD_TESTS:BOOL=ON -DTI_WITH_BACKTRACE:BOOL=ON
CI_SETUP_CMAKE_ARGS: -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTI_WITH_OPENGL:BOOL=ON -DTI_WITH_CC:BOOL=ON -DTI_WITH_VULKAN:BOOL=ON -DTI_BUILD_TESTS:BOOL=ON -DTI_BUILD_CI:BOOL=ON -DTI_WITH_BACKTRACE:BOOL=ON

build_and_test_cpu_mac:
name: Build and Test macos (CPU)
Expand Down Expand Up @@ -149,6 +149,7 @@ jobs:
-DTI_WITH_VULKAN:BOOL=ON
-DTI_WITH_C_API=ON
-DTI_WITH_BACKTRACE:BOOL=ON
-DTI_BUILD_CI:BOOL=ON
-DTI_BUILD_TESTS:BOOL=${{ matrix.with_cpp_tests }}

# [DEBUG] Copy this step around to enable debugging inside Github Action instances.
Expand Down Expand Up @@ -214,6 +215,7 @@ jobs:
-DTI_WITH_VULKAN:BOOL=ON
-DTI_WITH_BACKTRACE:BOOL=ON
-DTI_BUILD_TESTS:BOOL=ON
-DTI_BUILD_CI:BOOL=ON
-DTI_WITH_C_API=ON

- name: Check C-API Export Symbols
Expand Down Expand Up @@ -302,6 +304,7 @@ jobs:
-DTI_WITH_VULKAN:BOOL=OFF
-DTI_WITH_OPENGL:BOOL=OFF
-DTI_BUILD_TESTS:BOOL=ON
-DTI_BUILD_CI:BOOL=ON

- name: Test
id: test
Expand Down Expand Up @@ -370,6 +373,7 @@ jobs:
-DTI_WITH_DX12:BOOL=ON
-DTI_WITH_CC:BOOL=OFF
-DTI_BUILD_TESTS:BOOL=ON
-DTI_BUILD_CI:BOOL=ON
-DTI_WITH_BACKTRACE=ON
-DTI_WITH_C_API=ON

Expand Down Expand Up @@ -431,6 +435,7 @@ jobs:
-DTI_WITH_CC:BOOL=OFF
-DTI_WITH_VULKAN:BOOL=ON
-DTI_BUILD_TESTS:BOOL=ON
-DTI_BUILD_CI:BOOL=ON
-DTI_WITH_BACKTRACE:BOOL=ON
-DTI_WITH_C_API=ON

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(USE_LLD "Use lld (from llvm) linker" OFF)
option(USE_MOLD "Use mold (A Modern Linker)" OFF)
option(TI_BUILD_CI "(Internal Use) Enable certain validations and possible debuggers for Taichi CI system" OFF)
jim19930609 marked this conversation as resolved.
Show resolved Hide resolved
option(TI_WITH_BACKTRACE "Use backward-cpp to print out C++ stack trace upon failure" OFF)

if(LINUX OR APPLE)
Expand Down
10 changes: 9 additions & 1 deletion c_api/src/taichi_core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,15 @@ TiRuntime ti_create_runtime(TiArch arch) {
switch (arch) {
#ifdef TI_WITH_VULKAN
case TI_ARCH_VULKAN: {
out = (TiRuntime)(static_cast<Runtime *>(new VulkanRuntimeOwned));
#ifdef TI_BUILD_CI
auto param = make_vulkan_runtime_creator_params();
param.enable_validation_layer = true;
auto vulkan_runtime = new VulkanRuntimeOwned(std::move(param));
#else
auto vulkan_runtime = new VulkanRuntimeOwned;
#endif

out = (TiRuntime)(static_cast<Runtime *>(vulkan_runtime));
break;
}
#endif // TI_WITH_VULKAN
Expand Down
3 changes: 3 additions & 0 deletions c_api/src/taichi_vulkan_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ class VulkanRuntimeOwned : public VulkanRuntime {
virtual taichi::lang::gfx::GfxRuntime &get_gfx_runtime() override final;
};

taichi::lang::vulkan::VulkanDeviceCreator::Params
make_vulkan_runtime_creator_params();

#endif // TI_WITH_VULKAN
8 changes: 8 additions & 0 deletions c_api/tests/c_api_interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,18 @@ TEST_F(CapiTest, FailMapDeviceOnlyMemory) {
ti::Memory mem = runtime.allocate_memory(100);
mem.map();

#ifdef __APPLE__
// Vulkan Validation aren't supported on MacOS platform
EXPECT_TAICHI_ERROR(TI_ERROR_INVALID_STATE, "Assertion failure",
/*reset_error=*/false);
EXPECT_TAICHI_ERROR(TI_ERROR_INVALID_STATE, "RHI map memory failed",
/*reset_error=*/true);
#else
EXPECT_TAICHI_ERROR(
TI_ERROR_INVALID_STATE,
"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set",
/*reset_error=*/true);
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ if(TI_WITH_LLVM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_LLVM")
endif()

if(TI_BUILD_CI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_BUILD_CI")
endif()

## This version var is only used to locate slim_libdevice.10.bc
if(NOT CUDA_VERSION)
set(CUDA_VERSION 10.0)
Expand Down
36 changes: 30 additions & 6 deletions taichi/rhi/vulkan/vulkan_device_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ bool check_validation_layer_support() {
return true;
}

[[maybe_unused]] bool vk_ignore_validation_warning(
const std::string &msg_name) {
if (msg_name == "UNASSIGNED-DEBUG-PRINTF") {
// Ignore truncated Debug Printf message
return true;
}

if (msg_name == "VUID_Undefined") {
// FIXME: Remove this branch after upgrading Vulkan driver for built bots
return true;
}

return false;
}

VKAPI_ATTR VkBool32 VKAPI_CALL
vk_debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
VkDebugUtilsMessageTypeFlagsEXT message_type,
const VkDebugUtilsMessengerCallbackDataEXT *p_callback_data,
void *p_user_data) {
if (message_severity > VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
char msg_buf[512];
snprintf(msg_buf, sizeof(msg_buf), "Vulkan validation layer: %d, %s",
message_type, p_callback_data->pMessage);
RHI_LOG_ERROR(msg_buf);
}
if (message_type == VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT &&
message_severity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT &&
strstr(p_callback_data->pMessage, "DEBUG-PRINTF") != nullptr) {
Expand All @@ -57,6 +66,21 @@ vk_debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
auto const pos = msg.find_last_of("|");
std::cout << msg.substr(pos + 2);
}

if (message_severity > VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
char msg_buf[512];
snprintf(msg_buf, sizeof(msg_buf), "Vulkan validation layer: %d, %s",
message_type, p_callback_data->pMessage);

#ifdef TI_BUILD_CI
auto msg_name = std::string(p_callback_data->pMessageIdName);
if (!vk_ignore_validation_warning(msg_name))
TI_ERROR(msg_buf);
#else
RHI_LOG_ERROR(msg_buf);
#endif
}

return VK_FALSE;
}

Expand Down