-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split reduce op into multiple libraries, accelerate the compiling (#1…
…1029) * "split into multiple .ccl" * "refine file structure" * "refine files" * "remove the cmakelist" * "fix typo" * "fix typo" * fix ci
- Loading branch information
Showing
20 changed files
with
789 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_min_max_op.h" | ||
|
||
REGISTER_REDUCE_OP(reduce_max); | ||
REGISTER_OP_CPU_KERNEL( | ||
reduce_max, ops::ReduceKernel<paddle::platform::CPUDeviceContext, float, | ||
ops::MaxFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, double, | ||
ops::MaxFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, int, ops::MaxFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, int64_t, | ||
ops::MaxFunctor>); | ||
REGISTER_OP_CPU_KERNEL( | ||
reduce_max_grad, ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, | ||
float, ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, double, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, int, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, int64_t, | ||
ops::MaxOrMinGradFunctor>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_min_max_op.h" | ||
|
||
REGISTER_OP_CUDA_KERNEL(reduce_max, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
float, ops::MaxFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
double, ops::MaxFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
int, ops::MaxFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
int64_t, ops::MaxFunctor>); | ||
REGISTER_OP_CUDA_KERNEL( | ||
reduce_max_grad, ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, | ||
float, ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, double, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int64_t, | ||
ops::MaxOrMinGradFunctor>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_mean_op.h" | ||
|
||
REGISTER_REDUCE_OP(reduce_mean); | ||
REGISTER_OP_CPU_KERNEL(reduce_mean, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, | ||
float, ops::MeanFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, | ||
double, ops::MeanFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, | ||
int, ops::MeanFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, | ||
int64_t, ops::MeanFunctor>); | ||
REGISTER_OP_CPU_KERNEL(reduce_mean_grad, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, | ||
float, ops::MeanGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, | ||
double, ops::MeanGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, | ||
int, ops::MeanGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, | ||
int64_t, ops::MeanGradFunctor>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_mean_op.h" | ||
|
||
REGISTER_OP_CUDA_KERNEL(reduce_mean, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
float, ops::MeanFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
double, ops::MeanFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
int, ops::MeanFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
int64_t, ops::MeanFunctor>); | ||
REGISTER_OP_CUDA_KERNEL( | ||
reduce_mean_grad, ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, | ||
float, ops::MeanGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, double, | ||
ops::MeanGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int, | ||
ops::MeanGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int64_t, | ||
ops::MeanGradFunctor>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_op.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
|
||
struct MeanFunctor { | ||
template <typename DeviceContext, typename X, typename Y, typename Dim> | ||
void operator()(const DeviceContext& place, X* x, Y* y, const Dim& dim) { | ||
y->device(place) = x->mean(dim); | ||
} | ||
}; | ||
|
||
struct MeanGradFunctor { | ||
template <typename DeviceContext, typename X, typename Y, typename DX, | ||
typename DY, typename Dim> | ||
void operator()(const DeviceContext& place, X* x, Y* y, DX* dx, DY* dy, | ||
const Dim& dim, int size) { | ||
dx->device(place) = dy->broadcast(dim) / dx->constant(size); | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_op.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
|
||
struct MaxFunctor { | ||
template <typename DeviceContext, typename X, typename Y, typename Dim> | ||
void operator()(const DeviceContext& place, X* x, Y* y, const Dim& dim) { | ||
y->device(place) = x->maximum(dim); | ||
} | ||
}; | ||
|
||
struct MinFunctor { | ||
template <typename DeviceContext, typename X, typename Y, typename Dim> | ||
void operator()(const DeviceContext& place, X* x, Y* y, const Dim& dim) { | ||
y->device(place) = x->minimum(dim); | ||
} | ||
}; | ||
|
||
struct MaxOrMinGradFunctor { | ||
template <typename DeviceContext, typename X, typename Y, typename DX, | ||
typename DY, typename Dim> | ||
void operator()(const DeviceContext& place, X* x, Y* y, DX* dx, DY* dy, | ||
const Dim& dim, int size) { | ||
auto equals = (*x) == y->broadcast(dim); | ||
auto ones = dx->constant(1); | ||
auto zeros = dx->constant(0); | ||
// If there are multiple minimum or maximum elements, the subgradient of | ||
// each is the set [0, 1], and we pass gradient to all of them here. | ||
dx->device(place) = dy->broadcast(dim) * equals.select(ones, zeros); | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_min_max_op.h" | ||
|
||
REGISTER_REDUCE_OP(reduce_min); | ||
REGISTER_OP_CPU_KERNEL( | ||
reduce_min, ops::ReduceKernel<paddle::platform::CPUDeviceContext, float, | ||
ops::MinFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, double, | ||
ops::MinFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, int, ops::MinFunctor>, | ||
ops::ReduceKernel<paddle::platform::CPUDeviceContext, int64_t, | ||
ops::MinFunctor>); | ||
REGISTER_OP_CPU_KERNEL( | ||
reduce_min_grad, ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, | ||
float, ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, double, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, int, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, int64_t, | ||
ops::MaxOrMinGradFunctor>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2018 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/fluid/operators/reduce_min_max_op.h" | ||
|
||
REGISTER_OP_CUDA_KERNEL(reduce_min, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
float, ops::MinFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
double, ops::MinFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
int, ops::MinFunctor>, | ||
ops::ReduceKernel<paddle::platform::CUDADeviceContext, | ||
int64_t, ops::MinFunctor>); | ||
REGISTER_OP_CUDA_KERNEL( | ||
reduce_min_grad, ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, | ||
float, ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, double, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int, | ||
ops::MaxOrMinGradFunctor>, | ||
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int64_t, | ||
ops::MaxOrMinGradFunctor>); |
Oops, something went wrong.