Skip to content

Commit f189551

Browse files
Dark Knightfacebook-github-bot
authored andcommitted
Revert D72722867: Multisect successfully blamed "D72475332: [torchcodec][diff_train] Make device interface generic (#606)" for one test failure
Summary: This diff reverts D72722867 D72475332: [torchcodec][diff_train] Make device interface generic (#606) by generatedunixname499836121 causes the following test failure: Tests affected: - [cogwheel:cogwheel_fblearner_inferno_hello_world#main](https://www.internalfb.com/intern/test/844425115815788/) Here's the Multisect link: https://www.internalfb.com/multisect/25810176 Here are the tasks that are relevant to this breakage: T191383700: 100+ tests, 10+ build rules, some CI signals unhealthy for offline_inference The backout may land if someone accepts it. If this diff has been generated in error, you can Commandeer and Abandon it. Reviewed By: scotts Differential Revision: D72775487
1 parent 619f1ce commit f189551

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/torchcodec/_core/DeviceInterface.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
namespace facebook::torchcodec {
1212

1313
namespace {
14-
using DeviceInterfaceMap = std::map<torch::DeviceType, CreateDeviceInterfaceFn>;
1514
std::mutex g_interface_mutex;
16-
std::unique_ptr<DeviceInterfaceMap> g_interface_map;
15+
std::map<torch::DeviceType, CreateDeviceInterfaceFn> g_interface_map;
1716

1817
std::string getDeviceType(const std::string& device) {
1918
size_t pos = device.find(':');
@@ -29,18 +28,11 @@ bool registerDeviceInterface(
2928
torch::DeviceType deviceType,
3029
CreateDeviceInterfaceFn createInterface) {
3130
std::scoped_lock lock(g_interface_mutex);
32-
if (!g_interface_map) {
33-
// We delay this initialization until runtime to avoid the Static
34-
// Initialization Order Fiasco:
35-
//
36-
// https://en.cppreference.com/w/cpp/language/siof
37-
g_interface_map = std::make_unique<DeviceInterfaceMap>();
38-
}
3931
TORCH_CHECK(
40-
g_interface_map->find(deviceType) == g_interface_map->end(),
32+
g_interface_map.find(deviceType) == g_interface_map.end(),
4133
"Device interface already registered for ",
4234
deviceType);
43-
g_interface_map->insert({deviceType, createInterface});
35+
g_interface_map.insert({deviceType, createInterface});
4436
return true;
4537
}
4638

@@ -53,16 +45,14 @@ torch::Device createTorchDevice(const std::string device) {
5345
std::scoped_lock lock(g_interface_mutex);
5446
std::string deviceType = getDeviceType(device);
5547
auto deviceInterface = std::find_if(
56-
g_interface_map->begin(),
57-
g_interface_map->end(),
48+
g_interface_map.begin(),
49+
g_interface_map.end(),
5850
[&](const std::pair<torch::DeviceType, CreateDeviceInterfaceFn>& arg) {
5951
return device.rfind(
6052
torch::DeviceTypeName(arg.first, /*lcase*/ true), 0) == 0;
6153
});
6254
TORCH_CHECK(
63-
deviceInterface != g_interface_map->end(),
64-
"Unsupported device: ",
65-
device);
55+
deviceInterface != g_interface_map.end(), "Unsupported device: ", device);
6656

6757
return torch::Device(device);
6858
}
@@ -77,12 +67,11 @@ std::unique_ptr<DeviceInterface> createDeviceInterface(
7767

7868
std::scoped_lock lock(g_interface_mutex);
7969
TORCH_CHECK(
80-
g_interface_map->find(deviceType) != g_interface_map->end(),
70+
g_interface_map.find(deviceType) != g_interface_map.end(),
8171
"Unsupported device: ",
8272
device);
8373

84-
return std::unique_ptr<DeviceInterface>(
85-
(*g_interface_map)[deviceType](device));
74+
return std::unique_ptr<DeviceInterface>(g_interface_map[deviceType](device));
8675
}
8776

8877
} // namespace facebook::torchcodec

0 commit comments

Comments
 (0)