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 7
  paddle::platform::CPUPlace cpu;
  paddle::platform::GPUPlace 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

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

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