place_test.cc 1.3 KB
Newer Older
1
//  Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
D
dzhwinter 已提交
2 3 4 5 6 7 8 9 10 11 12 13
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Y
Yi Wang 已提交
14
#include "paddle/fluid/platform/place.h"
Y
Yi Wang 已提交
15
#include <sstream>
Y
Yi Wang 已提交
16
#include "gtest/gtest.h"
Y
Yi Wang 已提交
17 18

TEST(Place, Equality) {
19
  paddle::platform::CPUPlace cpu;
D
dzhwinter 已提交
20
  paddle::platform::CUDAPlace g0(0), g1(1), gg0(0);
Y
Yi Wang 已提交
21 22 23 24 25 26 27 28

  EXPECT_EQ(cpu, cpu);
  EXPECT_EQ(g0, g0);
  EXPECT_EQ(g1, g1);
  EXPECT_EQ(g0, gg0);

  EXPECT_NE(g0, g1);

Y
Yi Wang 已提交
29 30
  EXPECT_TRUE(paddle::platform::places_are_same_class(g0, gg0));
  EXPECT_FALSE(paddle::platform::places_are_same_class(g0, cpu));
Y
Yi Wang 已提交
31 32 33 34 35
}

TEST(Place, Print) {
  {
    std::stringstream ss;
D
dzhwinter 已提交
36 37
    ss << paddle::platform::CUDAPlace(1);
    EXPECT_EQ("CUDAPlace(1)", ss.str());
Y
Yi Wang 已提交
38 39
  }
  {
L
liaogang 已提交
40
    std::stringstream ss;
41 42
    ss << paddle::platform::CPUPlace();
    EXPECT_EQ("CPUPlace", ss.str());
Y
Yi Wang 已提交
43 44
  }
}