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

Add cmake for majel #2118

Merged
merged 7 commits into from
May 12, 2017
Merged

Add cmake for majel #2118

merged 7 commits into from
May 12, 2017

Conversation

gangliao
Copy link
Contributor

issue the command: ctest -V -R majel_tests

 ctest -V -R majel_tests
UpdateCTestConfiguration  from :/Users/liaogang/baidu/Paddle/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/Users/liaogang/baidu/Paddle/build/DartConfiguration.tcl
Test project /Users/liaogang/baidu/Paddle/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 53
    Start 53: majel_tests

53: Test command: /Users/liaogang/baidu/Paddle/build/paddle/majel/test/majel_tests
53: Test timeout computed to be: 9.99988e+06
53: [==========] Running 3 tests from 1 test case.
53: [----------] Global test environment set-up.
53: [----------] 3 tests from Place
53: [ RUN      ] Place.Equality
53: [       OK ] Place.Equality (0 ms)
53: [ RUN      ] Place.Default
53: [       OK ] Place.Default (0 ms)
53: [ RUN      ] Place.Print
53: [       OK ] Place.Print (0 ms)
53: [----------] 3 tests from Place (0 ms total)
53:
53: [----------] Global test environment tear-down
53: [==========] 3 tests from 1 test case ran. (0 ms total)
53: [  PASSED  ] 3 tests.
1/1 Test #53: majel_tests ......................   Passed    0.00 sec

The following tests passed:
        majel_tests

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.01 sec

@@ -0,0 +1,15 @@
set(MAJEL_CXX_FILES place.cpp)
Copy link
Contributor Author

@gangliao gangliao May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PADDLE includes both CPU and GPU versions. Majel is built with GPU only if it equipped one.

If CMake detects the host machine equipped GPUs, it will invoke cuda_add_library to generate the library, vice visa.

NOTE: The suffix of unit test files should strictly limit to *.cpp, because it doesn't contain any CUDA syntaxes and semantics.

Copy link
Collaborator

@wangkuiyi wangkuiyi May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CMake detects the host machine equipped GPUs, it will invoke cuda_add_library to generate the library, vice visa.

If we are going to port Majel to Paddle, I think we will have to enable GPU and CPU versions. Also, we'll have to be able to specify which one to build, as we do with Paddle. Also, I think we shouldn't assume that the development computer having a GPU means that the runtime environment would have GPUs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: The suffix of unit test files should strictly limit to .cpp, because it doesn't contain any CUDA syntaxes and semantics.

I agree that if a source file doesn't include CUDA code, the suffix shouldn't be .cu. But I personally prefer .cc over .cpp following Google C++ Style Guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

@helinwang
Copy link
Contributor

我看到paddle/CMakeLists.txt也有更改。现在能够单独编译majel吗(不编译paddle,实在太慢了)?

@gangliao
Copy link
Contributor Author

@helinwang @wangkuiyi 现在两种模式都支持了。

  1. 快速开发模式
cd Paddle/paddle/majel
mkdir build && cmake ..
make
ctest -V -R majel_tests
  1. majel in paddle
cd Paddle
mkdir build && cmake ..
make
ctest -V -R majel_tests

@@ -0,0 +1,15 @@
set(MAJEL_CXX_FILES place.cpp)
Copy link
Collaborator

@wangkuiyi wangkuiyi May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CMake detects the host machine equipped GPUs, it will invoke cuda_add_library to generate the library, vice visa.

If we are going to port Majel to Paddle, I think we will have to enable GPU and CPU versions. Also, we'll have to be able to specify which one to build, as we do with Paddle. Also, I think we shouldn't assume that the development computer having a GPU means that the runtime environment would have GPUs.

@@ -0,0 +1,15 @@
set(MAJEL_CXX_FILES place.cpp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: The suffix of unit test files should strictly limit to .cpp, because it doesn't contain any CUDA syntaxes and semantics.

I agree that if a source file doesn't include CUDA code, the suffix shouldn't be .cu. But I personally prefer .cc over .cpp following Google C++ Style Guide.

@@ -0,0 +1,6 @@
#include "gtest/gtest.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this file? I think we can just link -lgtest_main to have the main function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

#include "majel/place.h"
#include <sstream>
#include "gtest/gtest.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I forgot to reorder the include files following https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes. You can do that in this PR.

I think the right order is:

#include "majel/place.h"

#include <sstream>

#include "gtest/gtest.h"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.0)

if(GTEST_INCLUDE_DIR AND GTEST_LIBRARIES)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we are building Docker container, we can assume in CMakeLists.txt that we have boost and gtest already installed and don't need conditions like this, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# enable gtest
set(THIRD_PARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
Copy link
Contributor

@helinwang helinwang May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

third_party要不要放到运行cmake的目录(比如./build/)里面,而不是${CMAKE_CURRENT_SOURCE_DIR}里面?这样用户如果删了./build/就肯定是一个clean build。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

@@ -9,6 +9,14 @@ add_subdirectory(pserver)
add_subdirectory(trainer)
add_subdirectory(scripts)

find_package(boost QUIET)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我记得design doc里说用轻量级的boost替代品,这里仍然是用的boost吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是boost,不是替代品。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122


if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我对cmake不是很熟悉,为何这里要把当前目录给include了?repo/paddle下面貌似没有source code呀。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

# enable gtest
set(THIRD_PARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
set(WITH_TESTING ON)
include(external/gtest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain where does "external" directory come from (have not found any directory named "external" after building majel)? This line works, but I don't understand how it works...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

file(GLOB_RECURSE ALL_TEST_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cpp" "*.cc")

add_executable(majel_tests ${ALL_TEST_FILES})
add_dependencies(majel_tests majel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问为何既然有了

add_dependencies(majel_tests majel)

还需要

target_link_libraries(majel_tests     
                       ...
                       majel
                      )

感觉不是重复地指定依赖了?
我试了一下删掉add_dependencies,貌似也能编译。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #2122

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this PR is moving some source files. My recent work on malloc depends on the source tree structure, so I am approving and merging this PR. But please @gangliao take a look at the discussions and raise new issues if viable. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants