op_kernel_type_test.cc 1.9 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Q
qiaolongfei 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14

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 已提交
15
#include "paddle/fluid/framework/op_kernel_type.h"
Q
qiaolongfei 已提交
16 17 18 19 20
#include <gtest/gtest.h>
#include <iostream>

TEST(OpKernelType, ToString) {
  using OpKernelType = paddle::framework::OpKernelType;
21
  using DataType = paddle::framework::proto::VarType;
Q
qiaolongfei 已提交
22 23 24 25 26 27 28
  using CPUPlace = paddle::platform::CPUPlace;
  using DataLayout = paddle::framework::DataLayout;
  using LibraryType = paddle::framework::LibraryType;

  OpKernelType op_kernel_type(DataType::FP32, CPUPlace(), DataLayout::kNCHW,
                              LibraryType::kCUDNN);

C
chengduoZH 已提交
29
  ASSERT_EQ(paddle::framework::KernelTypeToString(op_kernel_type),
Y
yuyang18 已提交
30
            "data_type[float]:data_layout[NCHW]:place[CPUPlace]:library_type["
C
chengduoZH 已提交
31
            "CUDNN]");
Q
qiaolongfei 已提交
32 33 34 35
}

TEST(OpKernelType, Hash) {
  using OpKernelType = paddle::framework::OpKernelType;
36
  using DataType = paddle::framework::proto::VarType;
Q
qiaolongfei 已提交
37
  using CPUPlace = paddle::platform::CPUPlace;
D
dzhwinter 已提交
38
  using CUDAPlace = paddle::platform::CUDAPlace;
Q
qiaolongfei 已提交
39 40 41 42 43
  using DataLayout = paddle::framework::DataLayout;
  using LibraryType = paddle::framework::LibraryType;

  OpKernelType op_kernel_type_1(DataType::FP32, CPUPlace(), DataLayout::kNCHW,
                                LibraryType::kCUDNN);
D
dzhwinter 已提交
44
  OpKernelType op_kernel_type_2(DataType::FP32, CUDAPlace(0), DataLayout::kNCHW,
Q
qiaolongfei 已提交
45 46 47 48
                                LibraryType::kCUDNN);

  OpKernelType::Hash hasher;
  ASSERT_NE(hasher(op_kernel_type_1), hasher(op_kernel_type_2));
D
dzhwinter 已提交
49
}