Remove OptionsGuard from ATen (#13738)

Summary:
Deletes the `OptionsGuard` from ATen. This works towards the goal of reworking `DefaultTensorOptions`. `OptionsGuard` is troublesome because it relies on mutating thread local state. This PR fixes those code locations and then deletes the `OptionsGuard`.

ezyang gchanan
Pull Request resolved: https://github.com/pytorch/pytorch/pull/13738

Differential Revision: D13000962

Pulled By: goldsborough

fbshipit-source-id: c8143ee75070c2280f5fd1d9af86f8ce14279b72
This commit is contained in:
Peter Goldsborough
2018-11-15 17:28:20 -08:00
committed by Facebook Github Bot
parent 8f4dc192b6
commit 37cb357d8d
13 changed files with 16 additions and 212 deletions

View File

@ -3,7 +3,6 @@
#include <ATen/Context.h>
#include <ATen/DeviceGuard.h>
#include <ATen/Functions.h>
#include <ATen/OptionsGuard.h>
#include <ATen/core/ScalarType.h>
#include <ATen/core/TensorOptions.h>
@ -79,49 +78,3 @@ TEST(TensorOptionsTest, ConstructsWellFromCUDATensors_MultiCUDA) {
REQUIRE_OPTIONS(kCUDA, 1, kFloat, kSparse);
}
}
TEST(OptionsGuardTest, TestFunctionality_MultiCUDA) {
Tensor tensor;
{
OptionsGuard guard(device(kCUDA));
tensor = at::empty({10});
}
REQUIRE_TENSOR_OPTIONS(kCUDA, 0, kFloat, kStrided);
{
OptionsGuard guard(device({kCUDA, 1}));
tensor = at::empty({10});
}
REQUIRE_TENSOR_OPTIONS(kCUDA, 1, kFloat, kStrided);
{
OptionsGuard guard(device(kCUDA).dtype(kInt));
tensor = at::empty({10});
}
REQUIRE_TENSOR_OPTIONS(kCUDA, 0, kInt, kStrided);
}
TEST(OptionsGuardTest, DeviceGuardOptionsGuardInteraction_MultiCUDA) {
Tensor tensor;
{
// Check that OptionsGuard respects any active device before construction.
DeviceGuard guard(CUDADevice(1));
{
OptionsGuard guard(device(kCUDA));
tensor = at::empty({10});
REQUIRE_TENSOR_OPTIONS(kCUDA, 1, kFloat, kStrided);
{
// Check that OptionsGuard respects any active device after
// construction.
DeviceGuard guard(CUDADevice(0));
tensor = at::empty({10});
REQUIRE_TENSOR_OPTIONS(kCUDA, 0, kFloat, kStrided);
{
OptionsGuard guard(device({kCUDA, 1}));
tensor = at::empty({10});
REQUIRE_TENSOR_OPTIONS(kCUDA, 1, kFloat, kStrided);
}
}
}
}
}