Skip to content
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

[ Phi ] svd transfer #44392

Merged
merged 8 commits into from
Jul 21, 2022
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
65 changes: 0 additions & 65 deletions paddle/fluid/operators/svd_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,71 +45,6 @@ template <typename T,
typename IndexType = Eigen::DenseIndex>
using EigenVector = framework::EigenVector<T, MajorType, IndexType>;

template <typename T>
void LapackSvd(
const T* X, T* U, T* VH, T* S, int rows, int cols, int full = false) {
char jobz = full ? 'A' : 'S';
int mx = std::max(rows, cols);
int mn = std::min(rows, cols);
T* a = const_cast<T*>(X);
int lda = rows;
int ldu = rows;
int ldvt = full ? cols : mn;
int lwork = full ? (4 * mn * mn + 6 * mn + mx) : (4 * mn * mn + 7 * mn);
std::vector<T> work(lwork);
std::vector<int> iwork(8 * mn);
int info;
phi::funcs::lapackSvd<T>(jobz,
rows,
cols,
a,
lda,
S,
U,
ldu,
VH,
ldvt,
work.data(),
lwork,
iwork.data(),
&info);
if (info < 0) {
PADDLE_THROW(platform::errors::InvalidArgument(
"This %s-th argument has an illegal value", info));
}
if (info > 0) {
PADDLE_THROW(platform::errors::InvalidArgument(
"DBDSDC/SBDSDC did not converge, updating process failed. May be you "
"passes a invalid matrix."));
}
}

template <typename T>
void BatchSvd(const T* X,
T* U,
T* VH,
T* S,
int rows,
int cols,
int batches,
int full = false) {
// NOTE: this function is row major, because this function called the lapack.
int stride = rows * cols;
int k = std::min(rows, cols);
int stride_u = full ? rows * rows : k * rows;
int stride_v = full ? cols * cols : k * cols;
for (int i = 0; i < batches; ++i) {
LapackSvd<T>(X + i * stride,
U + i * stride_u,
VH + i * stride_v,
S + i * k,
rows,
cols,
full);
}
return;
}

template <typename T>
struct PowFunctor {
PowFunctor(const T* input, T* output, int64_t numel, T exp)
Expand Down
11 changes: 1 addition & 10 deletions paddle/fluid/operators/svd_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/fluid/operators/svd_op.h"

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/ddim.h"
#ifdef PADDLE_WITH_MKLDNN
#include "paddle/fluid/platform/mkldnn_helper.h"
Expand Down Expand Up @@ -167,11 +166,3 @@ REGISTER_OPERATOR(svd,
ops::SvdGradMaker<paddle::imperative::OpBase>);

REGISTER_OPERATOR(svd_grad, ops::SvdGradOp);

REGISTER_OP_CPU_KERNEL(svd,
ops::SvdCPUKernel<float>,
ops::SvdCPUKernel<double>);

REGISTER_OP_CPU_KERNEL(svd_grad,
ops::SvdGradKernel<phi::CPUContext, float>,
ops::SvdGradKernel<phi::CPUContext, double>);
269 changes: 0 additions & 269 deletions paddle/fluid/operators/svd_op.cu

This file was deleted.

Loading