place_test.cc 1.1 KB
Newer Older
Y
Yi Wang 已提交
1 2
#include "paddle/platform/place.h"
#include <sstream>
Y
Yi Wang 已提交
3
#include "gtest/gtest.h"
Y
Yi Wang 已提交
4 5

TEST(Place, Equality) {
6
  paddle::platform::CPUPlace cpu;
D
dzhwinter 已提交
7
  paddle::platform::CUDAPlace g0(0), g1(1), gg0(0);
Y
Yi Wang 已提交
8 9 10 11 12 13 14 15

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

  EXPECT_NE(g0, g1);

Y
Yi Wang 已提交
16 17
  EXPECT_TRUE(paddle::platform::places_are_same_class(g0, gg0));
  EXPECT_FALSE(paddle::platform::places_are_same_class(g0, cpu));
Y
Yi Wang 已提交
18 19 20
}

TEST(Place, Default) {
Y
Yi Wang 已提交
21 22 23
  EXPECT_TRUE(paddle::platform::is_gpu_place(paddle::platform::get_place()));
  EXPECT_TRUE(paddle::platform::is_gpu_place(paddle::platform::default_gpu()));
  EXPECT_TRUE(paddle::platform::is_cpu_place(paddle::platform::default_cpu()));
Y
Yi Wang 已提交
24

Q
QI JUN 已提交
25
  EXPECT_FALSE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
26
  paddle::platform::set_place(paddle::platform::CPUPlace());
Y
Yi Wang 已提交
27
  EXPECT_TRUE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
Y
Yi Wang 已提交
28 29 30 31 32
}

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