Merge pull request #2805 from QiJune/tensor_to_EigenTensor
Add method converting Tensor to Eigen TensorMapcblas_new
commit
3208914b56
@ -0,0 +1,67 @@
|
||||
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
|
||||
|
||||
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. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "unsupported/Eigen/CXX11/Tensor"
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
|
||||
// Helper to define Tensor types given that the scalar is of type T.
|
||||
template <typename T, int NDIMS = 1, typename IndexType = Eigen::DenseIndex>
|
||||
struct TTypes {
|
||||
// Rank-<NDIMS> tensor of scalar type T.
|
||||
typedef Eigen::TensorMap<Eigen::Tensor<T, NDIMS, Eigen::RowMajor, IndexType>,
|
||||
Eigen::Aligned>
|
||||
Tensor;
|
||||
typedef Eigen::TensorMap<
|
||||
Eigen::Tensor<const T, NDIMS, Eigen::RowMajor, IndexType>, Eigen::Aligned>
|
||||
ConstTensor;
|
||||
|
||||
// Scalar tensor (implemented as a rank-0 tensor) of scalar type T.
|
||||
typedef Eigen::TensorMap<
|
||||
Eigen::TensorFixedSize<T, Eigen::Sizes<>, Eigen::RowMajor, IndexType>,
|
||||
Eigen::Aligned>
|
||||
Scalar;
|
||||
typedef Eigen::TensorMap<Eigen::TensorFixedSize<const T, Eigen::Sizes<>,
|
||||
Eigen::RowMajor, IndexType>,
|
||||
Eigen::Aligned>
|
||||
ConstScalar;
|
||||
|
||||
// Rank-1 tensor (vector) of scalar type T.
|
||||
typedef Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, IndexType>,
|
||||
Eigen::Aligned>
|
||||
Flat;
|
||||
typedef Eigen::TensorMap<
|
||||
Eigen::Tensor<const T, 1, Eigen::RowMajor, IndexType>, Eigen::Aligned>
|
||||
ConstFlat;
|
||||
typedef Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, IndexType>,
|
||||
Eigen::Aligned>
|
||||
Vec;
|
||||
typedef Eigen::TensorMap<
|
||||
Eigen::Tensor<const T, 1, Eigen::RowMajor, IndexType>, Eigen::Aligned>
|
||||
ConstVec;
|
||||
|
||||
// Rank-2 tensor (matrix) of scalar type T.
|
||||
typedef Eigen::TensorMap<Eigen::Tensor<T, 2, Eigen::RowMajor, IndexType>,
|
||||
Eigen::Aligned>
|
||||
Matrix;
|
||||
typedef Eigen::TensorMap<
|
||||
Eigen::Tensor<const T, 2, Eigen::RowMajor, IndexType>, Eigen::Aligned>
|
||||
ConstMatrix;
|
||||
};
|
||||
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
@ -1,5 +1,6 @@
|
||||
#include <paddle/operators/add_op.h>
|
||||
#include <paddle/framework/op_registry.h>
|
||||
#include "paddle/operators/add_op.h"
|
||||
#include "paddle/framework/op_registry.h"
|
||||
|
||||
typedef paddle::operators::AddKernel<::paddle::platform::GPUPlace, float> AddKernel_GPU_float;
|
||||
REGISTER_OP_GPU_KERNEL(add_two,
|
||||
paddle::operators::AddKernel<paddle::platform::GPUPlace>);
|
||||
AddKernel_GPU_float);
|
Loading…
Reference in new issue