1 #include <gtest/gtest.h>     3 #include <ATen/Context.h>     4 #include <ATen/DeviceGuard.h>     5 #include <ATen/Functions.h>     6 #include <c10/core/ScalarType.h>     7 #include <c10/core/TensorOptions.h>     9 #include <torch/cuda.h>    25 #define REQUIRE_OPTIONS(device_, index_, type_, layout_)                      \    26   ASSERT_EQ(options.device().type(), Device((device_), (index_)).type()); \    28       options.device().index() == Device((device_), (index_)).index());       \    29   ASSERT_EQ(typeMetaToScalarType(options.dtype()), (type_));                  \    30   ASSERT_TRUE(options.layout() == (layout_))    32 #define REQUIRE_TENSOR_OPTIONS(device_, index_, type_, layout_)                \    33   ASSERT_EQ(tensor.device().type(), Device((device_), (index_)).type());   \    34   ASSERT_EQ(tensor.device().index(), Device((device_), (index_)).index()); \    35   ASSERT_EQ(tensor.scalar_type(), (type_));                                \    36   ASSERT_TRUE(tensor.type().layout() == (layout_))    38 TEST(TensorOptionsTest, ConstructsWellFromCUDATypes_CUDA) {
    39   auto options = CUDA(kFloat).options();
    40   REQUIRE_OPTIONS(kCUDA, -1, kFloat, kStrided);
    42   options = CUDA(kInt).options();
    43   REQUIRE_OPTIONS(kCUDA, -1, kInt, kStrided);
    45   options = getNonVariableType(Backend::SparseCUDA, kFloat).options();
    46   REQUIRE_OPTIONS(kCUDA, -1, kFloat, kSparse);
    48   options = getNonVariableType(Backend::SparseCUDA, kByte).options();
    49   REQUIRE_OPTIONS(kCUDA, -1, kByte, kSparse);
    51   options = CUDA(kFloat).options(5);
    52   REQUIRE_OPTIONS(kCUDA, 5, kFloat, kStrided);
    55       getNonVariableType(Backend::SparseCUDA, kFloat).options(5);
    56   REQUIRE_OPTIONS(kCUDA, 5, kFloat, kSparse);
    59 TEST(TensorOptionsTest, ConstructsWellFromCUDATensors_MultiCUDA) {
    60   auto options = empty(5, device(kCUDA).dtype(kDouble)).
options();
    61   REQUIRE_OPTIONS(kCUDA, 0, kDouble, kStrided);
    63   options = empty(5, getNonVariableType(Backend::SparseCUDA, kByte)).
options();
    64   REQUIRE_OPTIONS(kCUDA, 0, kByte, kSparse);
    66   if (torch::cuda::device_count() > 1) {
    70       tensor = empty(5, device(kCUDA));
    73     REQUIRE_OPTIONS(kCUDA, 1, kFloat, kStrided);
    77       tensor = empty(5, device(kCUDA).layout(kSparse));
    80     REQUIRE_OPTIONS(kCUDA, 1, kFloat, kSparse);
 
TensorOptions options() const 
Returns the TensorOptions corresponding to this Tensor. 
 
Represents a a compute device on which a tensor is located. 
 
int16_t DeviceIndex
An index representing a specific device; e.g., the 1 in GPU 1. 
 
RAII guard that sets a certain default device in its constructor, and changes it back to the device t...
 
Flush-To-Zero and Denormals-Are-Zero mode.