Skip to content

【Hackathon 6th Fundable Projects 3 No.52】[fluid_ops] c_sync_calc_stream #66796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions paddle/fluid/operators/collective/c_sync_calc_stream_op.cc

This file was deleted.

27 changes: 0 additions & 27 deletions paddle/fluid/operators/collective/c_sync_calc_stream_op.cu.cc

This file was deleted.

68 changes: 0 additions & 68 deletions paddle/fluid/operators/collective/c_sync_calc_stream_op.h

This file was deleted.

43 changes: 0 additions & 43 deletions paddle/fluid/operators/collective/c_sync_calc_stream_op.kps

This file was deleted.

28 changes: 0 additions & 28 deletions paddle/fluid/operators/collective/c_sync_calc_stream_op_xpu.cc

This file was deleted.

1 change: 0 additions & 1 deletion paddle/fluid/pir/dialect/operator/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const std::unordered_set<std::string> LegacyOpList = {
LoadCombineOp::name(),
CConcatOp::name(),
CBroadcast_Op::name(),
CSyncCalcStream_Op::name(),
CSyncCommStream_Op::name(),
DistributedPushSparseOp::name(),
SendV2Op::name(),
Expand Down
26 changes: 26 additions & 0 deletions paddle/phi/kernels/gpu/sync_calc_stream_kernel.cu
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.

#include "paddle/phi/kernels/impl/sync_calc_stream_kernel_impl.h"

PD_REGISTER_KERNEL(sync_calc_stream,
GPU,
ALL_LAYOUT,
phi::SyncCalcStreamKernel,
float,
double,
int,
int64_t,
phi::dtype::float16,
phi::dtype::bfloat16) {}
42 changes: 42 additions & 0 deletions paddle/phi/kernels/impl/sync_calc_stream_kernel_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 <string>

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

namespace phi {

template <typename T, typename Context>
void SyncCalcStreamKernel(const Context &dev_ctx,
const DenseTensor &x,
DenseTensor *out) {
#if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && !defined(_WIN32)
phi::backends::gpu::GpuStreamSync(dev_ctx.stream());
#elif defined(PADDLE_WITH_XPU_BKCL)
auto place = dev_ctx.GetPlace();
PADDLE_ENFORCE_EQ(place.GetType() == phi::AllocationType::XPU,
true,
phi::errors::PreconditionNotMet(
"Sync stream op can run on xpu place only for now."));
dev_ctx.Wait();
#else
PADDLE_THROW(
phi::errors::PreconditionNotMet("PaddlePaddle should compile with GPU."));
#endif
}
} // namespace phi
38 changes: 38 additions & 0 deletions paddle/phi/kernels/kps/sync_calc_stream_kernel.kps
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

#ifdef PADDLE_WITH_XPU_KP

// Please do not modify the following code
#if defined(__CUDA_ARCH__)
#undef __CUDA_ARCH__
#endif

#if defined(__CUDACC__)
#undef __CUDACC__
#endif

#if defined(__CUDA__)
#undef __CUDA__
#endif

#if defined(__NVCC__)
#undef __NVCC__
#endif

#include "paddle/phi/kernels/impl/sync_calc_stream_kernel_impl.h"

PD_REGISTER_KERNEL(
sync_calc_stream, KPS, ALL_LAYOUT, phi::SyncCalcStreamKernel, float) {}
#endif
26 changes: 26 additions & 0 deletions paddle/phi/kernels/xpu/sync_calc_stream_kernel.cc
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.

#include "paddle/phi/kernels/impl/sync_calc_stream_kernel_impl.h"

PD_REGISTER_KERNEL(sync_calc_stream,
XPU,
ALL_LAYOUT,
phi::SyncCalcStreamKernel,
float,
double,
int,
int64_t,
phi::dtype::bfloat16,
phi::dtype::float16) {}
12 changes: 6 additions & 6 deletions paddle/phi/ops/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4082,12 +4082,6 @@
outputs :
out: Out

- op: c_sync_calc_stream
inputs :
x : X
outputs :
out : Out

- op: c_sync_comm_stream
inputs :
x : X
Expand Down Expand Up @@ -4611,6 +4605,12 @@
outputs:
out : Out

- op: sync_calc_stream(c_sync_calc_stream)
inputs :
x : X
outputs :
out : Out

- op: temporal_shift
backward: temporal_shift_grad
inputs :
Expand Down
10 changes: 10 additions & 0 deletions paddle/phi/ops/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4482,6 +4482,16 @@
inplace : (mean -> mean_out), (variance -> variance_out)
optional : reserve_space

- op : sync_calc_stream
args : (Tensor x)
output : Tensor(out)
infer_meta :
func : UnchangedInferMeta
param : [x]
kernel :
func : sync_calc_stream
inplace : (x -> out)

- op : take_along_axis
args : (Tensor arr, Tensor indices, int axis)
output : Tensor
Expand Down