place_test.cc 942 字节
Newer Older
1
#include "paddle/majel/place.h"
Y
Yi Wang 已提交
2
#include <sstream>
L
liaogang 已提交
3
#include "gtest/gtest.h"
L
liaogang 已提交
4
#include "paddle/utils/Logging.h"
Y
Yi Wang 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

TEST(Place, Equality) {
  majel::CpuPlace cpu;
  majel::GpuPlace g0(0), g1(1), gg0(0);

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

  EXPECT_NE(g0, g1);

  EXPECT_TRUE(majel::places_are_same_class(g0, gg0));
  EXPECT_FALSE(majel::places_are_same_class(g0, cpu));
}

TEST(Place, Default) {
L
liaogang 已提交
22 23 24
  EXPECT_TRUE(majel::is_gpu_place(majel::get_place()));
  EXPECT_TRUE(majel::is_gpu_place(majel::default_gpu()));
  EXPECT_TRUE(majel::is_cpu_place(majel::default_cpu()));
Y
Yi Wang 已提交
25 26

  majel::set_place(majel::CpuPlace());
L
liaogang 已提交
27
  EXPECT_TRUE(majel::is_cpu_place(majel::get_place()));
Y
Yi Wang 已提交
28 29 30 31 32 33 34 35 36
}

TEST(Place, Print) {
  {
    std::stringstream ss;
    ss << majel::GpuPlace(1);
    EXPECT_EQ("GpuPlace(1)", ss.str());
  }
  {
L
liaogang 已提交
37 38 39
    std::stringstream ss;
    ss << majel::CpuPlace();
    EXPECT_EQ("CpuPlace", ss.str());
Y
Yi Wang 已提交
40 41
  }
}