place_test.cc 1.9 KB
Newer Older
1
//  Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
D
dzhwinter 已提交
2 3 4 5 6 7 8 9 10 11 12 13
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Y
Yi Wang 已提交
14
#include "paddle/fluid/platform/place.h"
W
wanghuancoder 已提交
15

Y
Yi Wang 已提交
16
#include "gtest/gtest.h"
Y
Yi Wang 已提交
17 18

TEST(Place, Equality) {
19
  paddle::platform::CPUPlace cpu;
D
dzhwinter 已提交
20
  paddle::platform::CUDAPlace g0(0), g1(1), gg0(0);
21
  paddle::platform::XPUPlace x0(0), x1(1), xx0(0);
F
fwenguang 已提交
22
  paddle::platform::MLUPlace m0(0), m1(1), mm0(0);
Y
Yi Wang 已提交
23 24 25 26 27

  EXPECT_EQ(cpu, cpu);
  EXPECT_EQ(g0, g0);
  EXPECT_EQ(g1, g1);
  EXPECT_EQ(g0, gg0);
28 29 30
  EXPECT_EQ(x0, x0);
  EXPECT_EQ(x1, x1);
  EXPECT_EQ(x0, xx0);
F
fwenguang 已提交
31 32 33
  EXPECT_EQ(m0, m0);
  EXPECT_EQ(m1, m1);
  EXPECT_EQ(m0, mm0);
Y
Yi Wang 已提交
34 35

  EXPECT_NE(g0, g1);
36
  EXPECT_NE(x0, x1);
F
fwenguang 已提交
37
  EXPECT_NE(m0, m1);
Y
Yi Wang 已提交
38

Y
Yi Wang 已提交
39
  EXPECT_TRUE(paddle::platform::places_are_same_class(g0, gg0));
40
  EXPECT_TRUE(paddle::platform::places_are_same_class(x0, xx0));
Y
Yi Wang 已提交
41
  EXPECT_FALSE(paddle::platform::places_are_same_class(g0, cpu));
42 43
  EXPECT_FALSE(paddle::platform::places_are_same_class(x0, cpu));
  EXPECT_FALSE(paddle::platform::places_are_same_class(g0, x0));
Y
Yi Wang 已提交
44 45 46
}

TEST(Place, Print) {
47 48 49 50 51
  {
    std::stringstream ss;
    ss << paddle::platform::XPUPlace(1);
    EXPECT_EQ("XPUPlace(1)", ss.str());
  }
F
fwenguang 已提交
52 53 54 55 56
  {
    std::stringstream ss;
    ss << paddle::platform::MLUPlace(1);
    EXPECT_EQ("MLUPlace(1)", ss.str());
  }
Y
Yi Wang 已提交
57 58
  {
    std::stringstream ss;
D
dzhwinter 已提交
59 60
    ss << paddle::platform::CUDAPlace(1);
    EXPECT_EQ("CUDAPlace(1)", ss.str());
Y
Yi Wang 已提交
61 62
  }
  {
L
liaogang 已提交
63
    std::stringstream ss;
64 65
    ss << paddle::platform::CPUPlace();
    EXPECT_EQ("CPUPlace", ss.str());
Y
Yi Wang 已提交
66 67
  }
}