未验证 提交 5fc8bbf7 编写于 作者: C chentianyu03 提交者: GitHub

[pten]Move dot, conj, sign dev_api into kernel.h (#38862)

* move dot_dev api into dot_kernel.h

* add infermate header

* modify to dotkerel in dot_op.h

* mvoe conj dev api into complex_kernel.h

* move sign dev api into  sign_kernel.h
上级 4640955c
......@@ -39,7 +39,7 @@ class ConjKernel : public framework::OpKernel<T> {
auto pt_out = paddle::experimental::MakePtenDenseTensor(*out);
// call new kernel
pten::ConjKernel<T>(dev_ctx, *pt_x.get(), pt_out.get());
pten::ConjKernel<T, DeviceContext>(dev_ctx, *pt_x.get(), pt_out.get());
}
};
......
......@@ -46,7 +46,8 @@ class DotKernel : public framework::OpKernel<T> {
auto pt_out = paddle::experimental::MakePtenDenseTensor(*out);
// call new kernel
pten::DotKernel<T>(dev_ctx, *pt_x.get(), *pt_y.get(), pt_out.get());
pten::DotKernel<T, DeviceContext>(dev_ctx, *pt_x.get(), *pt_y.get(),
pt_out.get());
}
};
......
......@@ -39,7 +39,7 @@ class SignKernel : public framework::OpKernel<T> {
auto pt_out = paddle::experimental::MakePtenDenseTensor(*out);
// call new kernel
pten::Sign<T>(dev_ctx, *pt_x.get(), pt_out.get());
pten::SignKernel<T, DeviceContext>(dev_ctx, *pt_x.get(), pt_out.get());
}
};
......
......@@ -17,5 +17,4 @@ limitations under the License. */
// developer apis
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/include/linalg.h"
#include "paddle/pten/include/math.h"
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// 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
// See Note: [ How do we organize the kernel directory ]
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/dot_kernel.h"
namespace pten {
template <typename T, typename ContextT>
DenseTensor Dot(const ContextT& dev_ctx,
const DenseTensor& x,
const DenseTensor& y) {
auto out_meta = DotInferMeta(x.meta(), y.meta());
pten::DenseTensor dense_out(
pten::make_intrusive<paddle::experimental::SharedStorage>(
dev_ctx.GetPlace()),
std::move(out_meta));
DotKernel<T, ContextT>(dev_ctx, x, y, &dense_out);
return dense_out;
}
} // namespace pten
......@@ -17,22 +17,10 @@ limitations under the License. */
// See Note: [ How do we organize the kernel directory ]
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/complex_kernel.h"
#include "paddle/pten/kernels/scale_kernel.h"
namespace pten {
template <typename T, typename ContextT>
DenseTensor Sign(const ContextT& dev_ctx, const DenseTensor& x) {
auto out_meta = UnchangedInferMeta(x.meta());
pten::DenseTensor dense_out(
pten::make_intrusive<paddle::experimental::SharedStorage>(
dev_ctx.GetPlace()),
std::move(out_meta));
Sign<T>(dev_ctx, x, &dense_out);
return dense_out;
}
template <typename T, typename ContextT>
DenseTensor Scale(const ContextT& dev_ctx,
const DenseTensor& x,
......
......@@ -15,6 +15,8 @@ limitations under the License. */
#pragma once
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/empty_kernel.h"
#include "paddle/pten/infermeta/unary.h"
#include "paddle/pten/kernels/empty_kernel.h"
......@@ -27,7 +29,7 @@ void ConjKernel(const Context& dev_ctx, const DenseTensor& x, DenseTensor* out);
template <typename T, typename Context>
DenseTensor Conj(const Context& dev_ctx, const DenseTensor& x) {
auto out_meta = UnchangedInferMeta(x.meta());
auto dense_out = Empty<T, Context>(dev_ctx, std::move(out_meta));
auto dense_out = pten::Empty<T, Context>(dev_ctx, std::move(out_meta));
ConjKernel<T>(dev_ctx, x, &dense_out);
return dense_out;
}
......
......@@ -21,4 +21,5 @@ limitations under the License. */
// See Note [ Why still include the fluid headers? ]
#include "paddle/fluid/platform/bfloat16.h"
PT_REGISTER_CTX_KERNEL(sign, CPU, ALL_LAYOUT, pten::Sign, float, double) {}
PT_REGISTER_CTX_KERNEL(sign, CPU, ALL_LAYOUT, pten::SignKernel, float, double) {
}
......@@ -15,7 +15,8 @@
#pragma once
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/infermeta/binary.h"
#include "paddle/pten/kernels/empty_kernel.h"
namespace pten {
template <typename T, typename Context>
......@@ -24,4 +25,13 @@ void DotKernel(const Context& dev_ctx,
const DenseTensor& y,
DenseTensor* out);
template <typename T, typename Context>
DenseTensor Dot(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& y) {
auto out_meta = DotInferMeta(x.meta(), y.meta());
auto dense_out = pten::Empty<T, Context>(dev_ctx, std::move(out_meta));
DotKernel<T, Context>(dev_ctx, x, y, &dense_out);
return dense_out;
}
} // namespace pten
......@@ -24,4 +24,4 @@ limitations under the License. */
using float16 = paddle::platform::float16;
PT_REGISTER_CTX_KERNEL(
sign, GPU, ALL_LAYOUT, pten::Sign, float, double, float16) {}
sign, GPU, ALL_LAYOUT, pten::SignKernel, float, double, float16) {}
......@@ -21,14 +21,14 @@
namespace pten {
template <typename T, typename Context>
void ConjKernel(const Context& context,
void ConjKernel(const Context& dev_ctx,
const DenseTensor& x,
DenseTensor* out) {
auto numel = x.numel();
auto* x_data = x.data<T>();
auto* out_data = out->mutable_data<T>();
paddle::platform::ForRange<Context> for_range(context, numel);
paddle::platform::ForRange<Context> for_range(dev_ctx, numel);
paddle::operators::math::ConjFunctor<T> functor(x_data, numel, out_data);
for_range(functor);
}
......
......@@ -23,7 +23,9 @@ limitations under the License. */
namespace pten {
template <typename T, typename Context>
void Sign(const Context& dev_ctx, const DenseTensor& x, DenseTensor* out) {
void SignKernel(const Context& dev_ctx,
const DenseTensor& x,
DenseTensor* out) {
out->mutable_data<T>();
auto eigen_out = pten::EigenVector<T>::Flatten(*out);
auto eigen_x = pten::EigenVector<T>::Flatten(x);
......
......@@ -15,10 +15,20 @@ limitations under the License. */
#pragma once
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/empty_kernel.h"
namespace pten {
template <typename T, typename Context>
void Sign(const Context& dev_ctx, const DenseTensor& x, DenseTensor* out);
void SignKernel(const Context& dev_ctx, const DenseTensor& x, DenseTensor* out);
template <typename T, typename Context>
DenseTensor Sign(const Context& dev_ctx, const DenseTensor& x) {
auto out_meta = UnchangedInferMeta(x.meta());
auto dense_out = pten::Empty<T, Context>(dev_ctx, std::move(out_meta));
SignKernel<T, Context>(dev_ctx, x, &dense_out);
return dense_out;
}
} // namespace pten
......@@ -15,7 +15,7 @@ limitations under the License. */
#include <gtest/gtest.h>
#include <memory>
#include "paddle/pten/include/math.h"
#include "paddle/pten/kernels/complex_kernel.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/core/dense_tensor.h"
......
......@@ -15,7 +15,7 @@ limitations under the License. */
#include <gtest/gtest.h>
#include <memory>
#include "paddle/pten/include/linalg.h"
#include "paddle/pten/kernels/dot_kernel.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/core/dense_tensor.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册