Skip to content

Commit

Permalink
add cmake external project for eigen
Browse files Browse the repository at this point in the history
  • Loading branch information
QiJune committed Jun 27, 2017
1 parent 4db23bb commit ab91232
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions cmake/external/eigen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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)
44 changes: 44 additions & 0 deletions paddle/framework/ddim_test.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#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"

Expand Down Expand Up @@ -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);
}

0 comments on commit ab91232

Please sign in to comment.