MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/compiler/tf2tensorrt/convert/convert_graph_test.cc:76–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74};
75
76TEST(ConvertGraphTest, GetDeviceAndAllocator) {
77 ConversionParams params;
78 EngineInfo engine_info;
79 {
80 // params.cluster is not set, and no gpu device is available.
81 auto result = GetDeviceAndAllocator(params, engine_info);
82 EXPECT_EQ(-1, result.first);
83 EXPECT_EQ(nullptr, result.second);
84 }
85
86 // Create a session with two (virtual) gpu device.
87 SessionOptions options;
88 ConfigProto* config = &options.config;
89 GPUOptions* gpu_options = config->mutable_gpu_options();
90 auto virtual_devices =
91 gpu_options->mutable_experimental()->add_virtual_devices();
92 virtual_devices->add_memory_limit_mb(200);
93 virtual_devices->add_memory_limit_mb(200);
94 std::unique_ptr<Session> session(NewSession(options));
95
96 {
97 // params.cluster is not set, should find and return first gpu id and
98 // corresponding allocator.
99 auto result = GetDeviceAndAllocator(params, engine_info);
100 EXPECT_EQ(0, result.first);
101 EXPECT_NE(nullptr, result.second);
102 EXPECT_EQ("GPU_0_bfc", result.second->Name());
103 }
104
105 FakeCluster cluster;
106 params.cluster = &cluster;
107 {
108 // params.cluster->GetDeviceSet() returns null, should find and return first
109 // gpu id and corresponding allocator.
110 auto result = GetDeviceAndAllocator(params, engine_info);
111 EXPECT_EQ(0, result.first);
112 EXPECT_NE(nullptr, result.second);
113 EXPECT_EQ("GPU_0_bfc", result.second->Name());
114 }
115
116 // Build the DeviceSet.
117 DeviceSet device_set;
118 const DeviceMgr* device_mgr = nullptr;
119 TF_ASSERT_OK(session->LocalDeviceManager(&device_mgr));
120 for (auto d : device_mgr->ListDevices()) {
121 device_set.AddDevice(d);
122 }
123 cluster.SetDeviceSet(&device_set);
124 {
125 // engine_info.device is not set, should find and return first gpu id and
126 // corresponding allocator.
127 auto result = GetDeviceAndAllocator(params, engine_info);
128 EXPECT_EQ(0, result.first);
129 EXPECT_NE(nullptr, result.second);
130 EXPECT_EQ("GPU_0_bfc", result.second->Name());
131 }
132
133 engine_info.device = "/GPU:1";

Callers

nothing calls this directly

Calls 7

GetDeviceAndAllocatorFunction · 0.85
SetDeviceSetMethod · 0.80
NewSessionFunction · 0.50
NameMethod · 0.45
LocalDeviceManagerMethod · 0.45
ListDevicesMethod · 0.45
AddDeviceMethod · 0.45

Tested by

no test coverage detected