提交 ab91232c 编写于 作者: Q qijun

add cmake external project for eigen

上级 4db23bba
......@@ -92,6 +92,7 @@ include(external/openblas) # download, build, install openblas
include(external/swig) # download, build, install swig
include(external/warpctc) # download, build, install warpctc
include(external/any) # download libn::any
include(external/eigen) # download eigen3
include(generic) # simplify cmake module
include(package) # set paddle packages
......
INCLUDE(ExternalProject)
SET(EIGEN_SOURCE_DIR ${THIRD_PARTY_PATH}/eigen3)
INCLUDE_DIRECTORIES(${EIGEN_SOURCE_DIR}/src/)
ExternalProject_Add(
eigen3
${EXTERNAL_PROJECT_LOG_ARGS}
URL "https://bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz"
URL_MD5 "4645c66075982da6fa0bcf6b20f3e8f7"
PREFIX ${EIGEN_SOURCE_DIR}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
LIST(APPEND external_project_dependencies eigen3)
\ No newline at end of file
#include <sstream>
#include <vector>
#include "eigen3/Eigen/Core"
#include "eigen3/Eigen/Dense"
#include "eigen3/unsupported/Eigen/CXX11/Tensor"
#include "gtest/gtest.h"
#include "paddle/framework/ddim.h"
......@@ -61,3 +64,44 @@ TEST(DDim, Print) {
ss << ddim;
EXPECT_EQ("2, 3, 4", ss.str());
}
template <typename T>
using Vec =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>,
Eigen::Aligned>;
template <typename T>
using Matrix =
Eigen::TensorMap<Eigen::Tensor<T, 2, Eigen::RowMajor, Eigen::DenseIndex>,
Eigen::Aligned>;
template <typename T>
void print(T* input, int size) {
for (int i = 0; i < size; i++) {
std::cout << input[i] << " ";
}
std::cout << std::endl;
}
TEST(Eigen, start) {
int size = 4;
float* t_a = (float*)malloc(size * sizeof(float));
float* t_b = (float*)malloc(size * sizeof(float));
float* t_c = (float*)malloc(size * sizeof(float));
for (int i = 0; i < size; i++) {
t_a[i] = i;
t_b[i] = i;
}
Vec<float> a(t_a, size);
Vec<float> b(t_b, size);
Vec<float> c(t_c, size);
Eigen::DefaultDevice dd;
c.device(dd) = a + b;
print<float>(t_c, size);
free(t_a);
free(t_b);
free(t_c);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册