Skip to content

Commit

Permalink
【Hackathon 6th Fundable Projects 3 No.90】fluid operator depend (#64206)
Browse files Browse the repository at this point in the history
  • Loading branch information
co63oc committed May 16, 2024
1 parent 8cef847 commit a246d2c
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 106 deletions.
106 changes: 0 additions & 106 deletions paddle/fluid/operators/controlflow/depend_op.cc

This file was deleted.

6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3902,6 +3902,12 @@
outputs:
{param_out : ParamOut, moment_out : MomentOut}

- op: depend
inputs:
{x : X, dep : Dep}
outputs:
out : Out

- op: detection_map
backward: detection_map_grad
inputs:
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/api/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,15 @@
backend : place
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : depend
args: (Tensor x, Tensor[] dep)
output: Tensor (out)
infer_meta:
func : UnchangedInferMeta
param : [x]
kernel:
func: depend

- op : depthwise_conv2d
args : (Tensor input, Tensor filter, int[] strides={1, 1}, int[] paddings={0, 0}, str padding_algorithm="EXPLICIT", int groups=1, int[] dilations={1, 1}, str data_format="NCHW")
output : Tensor(out)
Expand Down
29 changes: 29 additions & 0 deletions paddle/phi/kernels/cpu/depend_kernel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 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.

#include "paddle/phi/kernels/depend_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/depend_kernel_impl.h"

PD_REGISTER_KERNEL(depend,
CPU,
ALL_LAYOUT,
phi::DependKernel,
float,
double,
int,
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
26 changes: 26 additions & 0 deletions paddle/phi/kernels/depend_kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024 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

#include "paddle/phi/core/dense_tensor.h"

namespace phi {

template <typename T, typename Context>
void DependKernel(const Context& dev_ctx,
const DenseTensor& x,
const std::vector<const DenseTensor*>& dep,
DenseTensor* out);
} // namespace phi
30 changes: 30 additions & 0 deletions paddle/phi/kernels/gpu/depend_kernel.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024 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.

#include "paddle/phi/kernels/depend_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/depend_kernel_impl.h"

PD_REGISTER_KERNEL(depend,
GPU,
ALL_LAYOUT,
phi::DependKernel,
float,
double,
int,
int64_t,
phi::dtype::float16,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
35 changes: 35 additions & 0 deletions paddle/phi/kernels/impl/depend_kernel_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024 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

#include "paddle/phi/core/dense_tensor.h"

namespace phi {
template <typename T, typename Context>
void DependKernel(const Context& dev_ctx,
const DenseTensor& x,
const std::vector<const DenseTensor*>& dep,
DenseTensor* out) {
auto x_name = &x;
auto out_name = out;
PADDLE_ENFORCE_EQ(x_name,
out_name,
phi::errors::PreconditionNotMet(
"Input(X) and Output(Out) variable should be the "
"same, but got Input is %s and Output is %s.",
x_name,
out_name));
}
} // namespace phi

0 comments on commit a246d2c

Please sign in to comment.