place_test.cc 1.4 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()));
T
tensor-tang 已提交
24 25
  EXPECT_TRUE(
      paddle::platform::is_mkldnn_place(paddle::platform::default_mkldnn()));
Y
Yi Wang 已提交
26

27
  paddle::platform::set_place(paddle::platform::CPUPlace());
Y
Yi Wang 已提交
28
  EXPECT_TRUE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
T
tensor-tang 已提交
29 30 31 32

  paddle::platform::set_place(paddle::platform::MKLDNNPlace());
  EXPECT_FALSE(paddle::platform::is_cpu_place(paddle::platform::get_place()));
  EXPECT_TRUE(paddle::platform::is_mkldnn_place(paddle::platform::get_place()));
Y
Yi Wang 已提交
33 34 35 36 37
}

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