-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
CPU forward calculation replaces Eigen with Lapack;Modify linalg exposure rules #35916
Conversation
Thanks for your contribution! |
input_tensor = dito.Transpose(input); | ||
math::DeviceIndependenceTensorOperations<platform::CPUDeviceContext, T>( | ||
ctx); | ||
*eigen_vectors = dito.Transpose(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- lapack输入是列优先的?最好加一些注释说明,这里为什么要transpose。
- 看了下svd_helper.h里面实现的Transpose,既然只针对最好2维进行transpose,其实没必要区分2-6 D,eigvals_op.h里面
SpiltBatchSquareMatrix
这种实现方式比较好。 EigvalsKernel
里面,math::lapackEig<T, Real<T>>
这种调用方式也比较好,能够清楚的体现values、vectors的数据类型的关系。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果has_vectors
为false
,好像是否转置得到的特征值都是一样的,所以这里可能不需要transpose?
@@ -128,37 +50,74 @@ struct MatrixEighFunctor<platform::CPUDeviceContext, ValueType, T> { | |||
void operator()(const framework::ExecutionContext &ctx, const Tensor &input, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functor里面不再需要从ctx里面获取运行时信息,最好传DeviceContext
。
int liwork = -1; | ||
int iwork_opt = -1; | ||
T lwork_opt = static_cast<T>(-1); | ||
ValueType rwork_opt = static_cast<ValueType>(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些参数都是啥意思?-1代表什么?lapack函数中会写这些参数吗?可以加一些注释说明下。
auto *infos_data = info_tensor.mutable_data<int>( | ||
framework::make_ddim({batch_size}), ctx.GetPlace()); | ||
|
||
math::lapackEvd<T, ValueType>(jobz, uplo, n, out_vector, lda, out_value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加个注释说明单独这一次lapack函数调用的目的是什么。
*info_ptr)); | ||
} | ||
if (has_vectors) { | ||
*eigen_vectors = dito.Transpose(*eigen_vectors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确认下,前后2个Transpose
是必须的吗?
auto *value_data = out_value + i * values_stride; | ||
auto *vector_data = out_vector + i * vector_stride; | ||
int *info_ptr = &infos_data[i]; | ||
math::lapackEvd<T, ValueType>(jobz, uplo, n, vector_data, lda, value_data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evd
是什么意思,会被用到别的计算吗,是否直接叫lapackEigh
比较好?
T lwork_opt = static_cast<T>(-1); | ||
ValueType rwork_opt = static_cast<ValueType>(-1); | ||
|
||
Tensor info_tensor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果一次只计算1个矩阵,貌似不用定义一个info_tensor
,而是直接用int info
就够?
PADDLE_ENFORCE_EQ( | ||
*info_ptr, 0, | ||
platform::errors::PreconditionNotMet( | ||
"For batch [%d]: the [%d] argument had an illegal value", i, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个报错信息不太具有实际含义。
} | ||
|
||
template <> | ||
void lapackEvd<paddle::platform::complex<float>, float>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可不必加paddle::
d4df8ec
to
a0c1b49
Compare
// lapack is a column-first storage, transpose make the eigen_vectors to | ||
// have a continuous memory layout | ||
*eigen_vectors = dito.Transpose(input); | ||
auto *out_vector = eigen_vectors->mutable_data<T>(ctx.GetPlace()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_vectors
为false
时,eigen_vectors
为nullptr,不应该调mutable_data
。
input_tensor = dito.Transpose(input); | ||
math::DeviceIndependenceTensorOperations<platform::CPUDeviceContext, T>( | ||
ctx); | ||
// lapack is a column-first storage, transpose make the eigen_vectors to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般是说column-major storge
。
input_tensor = dito.Transpose(input); | ||
math::DeviceIndependenceTensorOperations<platform::CPUDeviceContext, T>( | ||
ctx); | ||
*eigen_vectors = dito.Transpose(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果has_vectors
为false
,好像是否转置得到的特征值都是一样的,所以这里可能不需要transpose?
// Call lapackEigh to get the optimal size of work data | ||
math::lapackEigh<T, math::Real<T>>(jobz, uplo, n, out_vector, lda, | ||
out_value, &lwork_opt, lwork, &rwork_opt, | ||
lrwork, &iwork_opt, liwork, &info); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不需要检查info
吗?
int iwork_opt = -1; // The optimal length of the array liwork | ||
T lwork_opt = static_cast<T>(-1); // The optimal length of the array work | ||
ValueType rwork_opt = | ||
static_cast<ValueType>(-1); // The optimal length of the array rwork |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以using ValueType = math::Real<T>;
,这样模板里面不用传ValueType
。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Others
PR changes
OPs
Describe
Eigh算子前向计算将eigen库替换为Lapack库实现,修改linalg暴露规则。