Home | History | Annotate | Download | only in gpu
      1 /* Copyright 2015 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/common_runtime/gpu/gpu_id_manager.h"
     17 
     18 #include "tensorflow/core/common_runtime/gpu/gpu_id.h"
     19 #include "tensorflow/core/platform/test.h"
     20 
     21 namespace tensorflow {
     22 namespace test {
     23 
     24 TEST(GpuIdManagerTest, Basics) {
     25   TfGpuId key_0(0);
     26   CudaGpuId value_0(0);
     27   GpuIdManager::InsertTfCudaGpuIdPair(key_0, value_0);
     28   EXPECT_EQ(value_0, GpuIdManager::TfToCudaGpuId(key_0));
     29 
     30   // Multiple calls to map the same value is ok.
     31   GpuIdManager::InsertTfCudaGpuIdPair(key_0, value_0);
     32   EXPECT_EQ(value_0, GpuIdManager::TfToCudaGpuId(key_0));
     33 
     34   // Map a different TfGpuId to a different value.
     35   TfGpuId key_1(3);
     36   CudaGpuId value_1(2);
     37   GpuIdManager::InsertTfCudaGpuIdPair(key_1, value_1);
     38   EXPECT_EQ(value_1, GpuIdManager::TfToCudaGpuId(key_1));
     39 
     40   // Mapping a different TfGpuId to the same value is ok.
     41   TfGpuId key_2(10);
     42   GpuIdManager::InsertTfCudaGpuIdPair(key_2, value_1);
     43   EXPECT_EQ(value_1, GpuIdManager::TfToCudaGpuId(key_2));
     44 
     45   // Mapping the same TfGpuId to a different value will crash the program.
     46   ASSERT_DEATH(GpuIdManager::InsertTfCudaGpuIdPair(key_2, value_0),
     47                "Mapping the same TfGpuId to a different CUDA GPU id");
     48 
     49   // Getting an nonexistent mapping will crash the program.
     50   ASSERT_DEATH(GpuIdManager::TfToCudaGpuId(TfGpuId(100)),
     51                "Could not find the mapping for TfGpuId");
     52 }
     53 
     54 }  // namespace test
     55 }  // namespace tensorflow
     56