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) {
Y
Yi Wang 已提交
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

Y
Yi Wang 已提交
25 26
  paddle::platform::set_place(paddle::platform::CpuPlace());
  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;
Y
Yi Wang 已提交
32
    ss << paddle::platform::GpuPlace(1);
Y
Yi Wang 已提交
33 34 35
    EXPECT_EQ("GpuPlace(1)", ss.str());
  }
  {
L
liaogang 已提交
36
    std::stringstream ss;
Y
Yi Wang 已提交
37
    ss << paddle::platform::CpuPlace();
L
liaogang 已提交
38
    EXPECT_EQ("CpuPlace", ss.str());
Y
Yi Wang 已提交
39 40
  }
}