parent
a8d072c769
commit
f188e22b33
@ -1,5 +0,0 @@
|
||||
if(WITH_GPU)
|
||||
nv_library(math_functor SRCS math_functor.cc math_functor.cu DEPS device_context)
|
||||
else()
|
||||
cc_library(math_functor SRCS math_functor.cc DEPS device_context)
|
||||
endif()
|
@ -1,42 +0,0 @@
|
||||
/* 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. */
|
||||
|
||||
#include "paddle/operators/functor/math_functor.h"
|
||||
#include "paddle/framework/eigen.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace operators {
|
||||
namespace functor {
|
||||
|
||||
template <typename T>
|
||||
struct Set<platform::CPUPlace, T> {
|
||||
void operator()(const T alpha, framework::Tensor* Y,
|
||||
platform::DeviceContext* context) {
|
||||
int N = product(Y->dims());
|
||||
T* YData = Y->mutable_data<T>(context->GetPlace());
|
||||
if (alpha == static_cast<T>(0)) {
|
||||
memset(YData, 0, N * sizeof(T));
|
||||
} else {
|
||||
framework::EigenVector<T, Eigen::RowMajor, Eigen::DenseIndex>::Flatten(*Y)
|
||||
.setConstant(alpha);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template struct Set<platform::CPUPlace, float>;
|
||||
template struct Set<platform::CPUPlace, double>;
|
||||
|
||||
} // namespace functor
|
||||
} // namespace operators
|
||||
} // namespace paddle
|
@ -1,42 +0,0 @@
|
||||
/* 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. */
|
||||
|
||||
#include "paddle/operators/functor/math_functor.h"
|
||||
#include "paddle/platform/cuda_helper.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace operators {
|
||||
namespace functor {
|
||||
|
||||
template <typename T>
|
||||
__global__ void SetKernel(const int N, const T alpha, T* Y) {
|
||||
CUDA_1D_KERNEL_LOOP(i, N) { Y[i] = alpha; }
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct Set<platform::GPUPlace, T> {
|
||||
void operator()(const T alpha, framework::Tensor* Y,
|
||||
platform::DeviceContext* context) {
|
||||
int N = product(Y->dims());
|
||||
T* YData = Y->mutable_data<T>(context->GetPlace());
|
||||
SetKernel<<<(N + 512 - 1) / 512, 512>>>(N, alpha, YData);
|
||||
}
|
||||
};
|
||||
|
||||
template struct Set<platform::GPUPlace, float>;
|
||||
template struct Set<platform::GPUPlace, double>;
|
||||
|
||||
} // namespace functor
|
||||
} // namespace operators
|
||||
} // namespace paddle
|
@ -1,32 +0,0 @@
|
||||
/* 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 "paddle/framework/tensor.h"
|
||||
#include "paddle/platform/device_context.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace operators {
|
||||
namespace functor {
|
||||
|
||||
template <typename Place, typename T>
|
||||
struct Set {
|
||||
void operator()(const T alpha, paddle::framework::Tensor* Y,
|
||||
paddle::platform::DeviceContext* context);
|
||||
};
|
||||
|
||||
} // namespace functor
|
||||
} // namespace operators
|
||||
} // namespace paddle
|
Loading…
Reference in new issue