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

feat: Add support for multi-device safe mode in C++ #2824

Merged
merged 1 commit into from
May 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ void multi_gpu_device_check() {
}
}

bool get_multi_device_safe_mode() {
return MULTI_DEVICE_SAFE_MODE;
}

void set_multi_device_safe_mode(bool multi_device_safe_mode) {
MULTI_DEVICE_SAFE_MODE = multi_device_safe_mode;
}

namespace {
static DeviceList cuda_device_list;
}
Expand Down
4 changes: 4 additions & 0 deletions core/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ std::vector<at::Tensor> execute_engine(std::vector<at::Tensor> inputs, c10::intr

void multi_gpu_device_check();

bool get_multi_device_safe_mode();

void set_multi_device_safe_mode(bool multi_device_safe_mode);

class DeviceList {
using DeviceMap = std::unordered_map<int, RTDevice>;
DeviceMap device_list;
Expand Down
13 changes: 13 additions & 0 deletions tests/core/runtime/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//tests/core/runtime:runtime_test.bzl", "runtime_test")

package(default_visibility = ["//visibility:public"])

config_setting(
Expand All @@ -6,3 +8,14 @@ config_setting(
"define": "abi=pre_cxx11_abi",
},
)

runtime_test(
name = "test_multi_device_safe_mode",
)

test_suite(
name = "runtime_tests",
tests = [
":test_multi_device_safe_mode",
],
)
25 changes: 25 additions & 0 deletions tests/core/runtime/runtime_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
runtime test macros
"""

load("@rules_cc//cc:defs.bzl", "cc_test")

def runtime_test(name, visibility = None):
"""Macro to define a runtime test

Args:
name: Name of test file
visibility: Visibility of the test target
"""
cc_test(
name = name,
srcs = [name + ".cpp"],
visibility = visibility,
deps = [
"//tests/util",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
"//conditions:default": ["@libtorch//:libtorch"],
}),
)
8 changes: 8 additions & 0 deletions tests/core/runtime/test_multi_device_safe_mode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "core/runtime/runtime.h"
#include "gtest/gtest.h"

TEST(Runtime, MultiDeviceSafeMode) {
ASSERT_TRUE(!torch_tensorrt::core::runtime::get_multi_device_safe_mode());
torch_tensorrt::core::runtime::set_multi_device_safe_mode(true);
ASSERT_TRUE(torch_tensorrt::core::runtime::get_multi_device_safe_mode());
}