1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "tensorflow/core/platform/test.h" 17 18 #if GOOGLE_CUDA 19 20 #include "tensorflow/core/common_runtime/gpu/gpu_device.h" 21 22 #include <algorithm> 23 #include <iostream> 24 #include <vector> 25 26 #include "tensorflow/core/common_runtime/device.h" 27 #include "tensorflow/core/lib/core/stringpiece.h" 28 #include "tensorflow/core/platform/platform.h" 29 #include "tensorflow/core/public/session_options.h" 30 31 namespace tensorflow { 32 namespace { 33 34 TEST(GPUDeviceOnNonGPUMachineTest, CreateGPUDevicesOnNonGPUMachine) { 35 SessionOptions opts; 36 std::vector<tensorflow::Device*> devices; 37 TF_CHECK_OK(DeviceFactory::GetFactory("GPU")->CreateDevices( 38 opts, "/job:localhost/replica:0/task:0", &devices)); 39 EXPECT_TRUE(devices.empty()); 40 } 41 42 } // namespace 43 } // namespace tensorflow 44 45 #endif // GOOGLE_CUDA 46 47 int main(int argc, char** argv) { 48 #if GOOGLE_CUDA 49 // Sets CUDA_VISIBLE_DEVICES to empty string to simulate non-gpu environment. 50 setenv("CUDA_VISIBLE_DEVICES", "", 1); 51 #endif // GOOGLE_CUDA 52 testing::InitGoogleTest(&argc, argv); 53 return RUN_ALL_TESTS(); 54 } 55