提交 3a46f4b9 编写于 作者: G GaoWei8 提交者: GitHub

Replace GRU RowWiseAdd Eigen with c implementation (#2712)

* replace gru RowWiseAdd Eigen with c implementation
test=develop
上级 e38ea30a
......@@ -110,11 +110,11 @@ void set_constant(const lite::Context<Target>& context,
lite::Tensor* tensor,
float value) {
TensorSetConstantWithTarget<Target> func(context, tensor, value);
//#ifdef PADDLE_WITH_CUDA
// #ifdef PADDLE_WITH_CUDA
// tensor->target().apply_visitor(func);
//#else
// #else
func();
//#endif
// #endif
}
template <typename T>
......@@ -128,12 +128,14 @@ struct RowwiseAdd<lite::TargetType::kX86, T> {
PADDLE_ENFORCE_EQ(vector.numel(), size);
PADDLE_ENFORCE_EQ(output->dims(), in_dims);
auto in = lite::fluid::EigenMatrix<T>::From(input);
auto vec = lite::fluid::EigenVector<T>::Flatten(vector);
auto out = lite::fluid::EigenMatrix<T>::From(*output);
const T* input_data = input.data<T>();
const T* vector_data = vector.data<T>();
T* output_data = output->mutable_data<T>();
for (int64_t i = 0; i < in_dims[0]; ++i) {
out.chip(i, 0) = in.chip(i, 0) + vec;
for (int64_t j = 0; j < size; ++j) {
output_data[i * in_dims[0] + j] =
input_data[i * in_dims[0] + j] + vector_data[j];
}
}
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册