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

Fix compile on raspberry pi #1835

Merged
merged 5 commits into from
May 17, 2017
Merged

Conversation

hedaoyuan
Copy link
Contributor

No description provided.

@hedaoyuan hedaoyuan requested a review from Xreki April 20, 2017 11:00
Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

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

有两个关于文档建议:

  • 这个是关于编译的文档,是不是应该放在getstarted/build_and_install目录下
  • 文档的用词是不是需要更书面化一些,然后,所有arm相关的编译文档都可以放在一个文件里面吧


这里考虑的是交叉编译方式,即在Linux-X86环境下构建raspberry pi下可运行的paddle。

## 下载较差编译环境
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: 较差 -> 交叉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

@hedaoyuan hedaoyuan left a comment

Choose a reason for hiding this comment

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

getstarted目前定位是新手入门,这个文档放新手入门不是很合适。

所有arm相关的编译文档都可以放在一个文件里面吧

这个是可以的,后续有新的嵌入式相关的文档后,可以新增一个目录,将这个文档一并移过去。

@@ -0,0 +1,45 @@
# 如何构建raspberry pi下运行的paddle
Copy link
Collaborator

Choose a reason for hiding this comment

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

raspberry pi => Raspberry Pi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,45 @@
# 如何构建raspberry pi下运行的paddle
Copy link
Collaborator

Choose a reason for hiding this comment

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

paddle => PaddlePaddle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,45 @@
# 如何构建raspberry pi下运行的paddle

这里考虑的是交叉编译方式,即在Linux-X86环境下构建raspberry pi下可运行的paddle。
Copy link
Collaborator

Choose a reason for hiding this comment

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

X86 => x86

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done



## 编译第三方库
Paddle在cmake会在编译paddle的时候自动编译依赖的第三方库,不过openblas和protobuf最好还是在编译paddle之前先编译好,这样可以保证编译paddle的时候更加顺畅。
Copy link
Collaborator

Choose a reason for hiding this comment

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

Paddle在cmake会在编译paddle的时候自动编译依赖的第三方库

==>

cmake会自动下载PaddlePaddle依赖的第三方库。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done



## 编译第三方库
Paddle在cmake会在编译paddle的时候自动编译依赖的第三方库,不过openblas和protobuf最好还是在编译paddle之前先编译好,这样可以保证编译paddle的时候更加顺畅。
Copy link
Collaborator

Choose a reason for hiding this comment

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

不过openblas和protobuf最好还是在编译paddle之前先编译好,这样可以保证编译paddle的时候更加顺畅。

为什么最好?和依赖cmake去下载和编译OpenBLAS和protobuf有什么区别?我理解这个工作应该是让在Raspberry
Pi上编译和在其他平台编译的用户体验尽量一致。如果可以依赖cmake去下载所有依赖,貌似更合理?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

在交叉编译方式下,直接依赖cmake去下载和编译中间会断掉,不能一次cmake & make成功。比如,编译protobuf时编译出来的protoc是arm版本的,在后续用到protoc的地方编译过程就崩溃了,需要用一个x86版本的protoc去替换掉,然后再继续make。
如果,直接在Pi编译,应该是直接cmake & make就可以了,不过编译耗时会比较长。

## 编译第三方库
Paddle在cmake会在编译paddle的时候自动编译依赖的第三方库,不过openblas和protobuf最好还是在编译paddle之前先编译好,这样可以保证编译paddle的时候更加顺畅。

### 编译openblas
Copy link
Collaborator

Choose a reason for hiding this comment

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

openblas => OpenBLAS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -26,7 +26,7 @@ FILE(GLOB PY_PADDLE_PYTHON_FILES ${PROJ_ROOT}/paddle/py_paddle/*.py)
SET_SOURCE_FILES_PROPERTIES(Paddle.i PROPERTIES CPLUSPLUS ON)

SET(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
SET(CMAKE_CXX_FLAGS "-std=c++11 -fPIC -Wall")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall")
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@wangkuiyi
Copy link
Collaborator

赞这个文档和code两全的PR!有一些建议都是针对文档写作的。

@Xreki
Copy link
Contributor

Xreki commented Apr 28, 2017

刚刚按照文档走了一下流程,在编译OpenBLAS和protobuf时出现了两个错误。
OpenBLAS: make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-gnueabihf-gcc NOFORTRAN=1 USE_THREAD=0
git clone下来应该是develop上的最新提交,应该是最新的提交引入了些bug。错误如下:

arm-linux-gnueabihf-gcc -O2 -DMAX_STACK_ALLOC=2048 -Wall -DF_INTERFACE_GFORT -fPIC -DNO_LAPACK -DNO_LAPACKE -DNO_WARMUP -DMAX_CPU_NUMBER=12 -marm -mfpu=vfpv3  -mfloat-abi=hard -march=armv7-a -DASMNAME= -DASMFNAME=_ -DNAME=_ -DCNAME= -DCHAR_NAME=\"_\" -DCHAR_CNAME=\"\" -DNO_AFFINITY -I..  -w -o linktest linktest.c ../libopenblas_armv7-r0.2.20.dev.so -L/home/liuyiqun01/.jumbo/lib -L/home/liuyiqun01/.jumbo/lib -L -Wl,-rpath,/home/liuyiqun01/.jumbo/opt/gcc48/lib64 -L/home/liuyiqun01/.jumbo/opt/gcc48/lib/gcc/x86_64-unknown-linux-gnu/4.8.3 -L/home/liuyiqun01/.jumbo/opt/gcc48/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/liuyiqun01/.jumbo/opt/gcc48/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../..  -lgfortran -lm -lquadmath -lm -lc   && echo OK.
/home/liuyiqun01/.jumbo/opt/gcc48/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../lib64/libgfortran.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make[1]: *** [../libopenblas_armv7-r0.2.20.dev.so] Error 1
make[1]: Leaving directory `/home/liuyiqun01/github/raspberrypi/OpenBLAS/exports'
make: *** [shared] Error 2

不过到这个时候,libopenblas_armv7-r0.2.20.dev.a已经生成了。

protobuf:cmake ../protobuf/cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib; make
出现如下错误:

[ 19%] Building CXX object CMakeFiles/libprotobuf.dir/src/google/protobuf/io/gzip_stream.cc.o
In file included from /home/liuyiqun01/github/raspberrypi/protobuf/src/google/protobuf/io/gzip_stream.cc:38:0:
/home/liuyiqun01/github/raspberrypi/protobuf/src/google/protobuf/io/gzip_stream.h:48:18: fatal error: zlib.h: No such file or directory
 #include <zlib.h>
                  ^
compilation terminated.
make[2]: *** [CMakeFiles/libprotobuf.dir/src/google/protobuf/io/gzip_stream.cc.o] Error 1
make[1]: *** [CMakeFiles/libprotobuf.dir/all] Error 2
make: *** [all] Error 2

protobuf的编译依赖zlib。
我正在写自动编译protobuf和OpenBLAS的cmake,看这里是否需要先修订一下吧。

@Xreki Xreki added this to In Progress in Embedded and Mobile Deployment Apr 28, 2017
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.

按照大家的约定,响应了reviwers的comemnts之后,应该至少写一个“Done”。这是对reviwers工作的尊重。

#1835 (review) 这批comments的响应都没有回复。

注意:这样编译出来的`libprotobuf.a`和`protoc`都是ARM版本的,而我们需要的是一个x86-64版本的`protoc`,所以需要用host gcc再编译一遍protobuf然后使用其中的`protoc`。


## 编译Paddle
Copy link
Collaborator

Choose a reason for hiding this comment

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

Paddle ==> PaddlePaddle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

@hedaoyuan hedaoyuan left a comment

Choose a reason for hiding this comment

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

抱歉,之前没有对comemnts回复,下次一定注意。

注意:这样编译出来的`libprotobuf.a`和`protoc`都是ARM版本的,而我们需要的是一个x86-64版本的`protoc`,所以需要用host gcc再编译一遍protobuf然后使用其中的`protoc`。


## 编译Paddle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,45 @@
# 如何构建raspberry pi下运行的paddle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,45 @@
# 如何构建raspberry pi下运行的paddle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,45 @@
# 如何构建raspberry pi下运行的paddle

这里考虑的是交叉编译方式,即在Linux-X86环境下构建raspberry pi下可运行的paddle。
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


这里考虑的是交叉编译方式,即在Linux-X86环境下构建raspberry pi下可运行的paddle。

## 下载较差编译环境
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done



## 编译第三方库
Paddle在cmake会在编译paddle的时候自动编译依赖的第三方库,不过openblas和protobuf最好还是在编译paddle之前先编译好,这样可以保证编译paddle的时候更加顺畅。
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

## 编译第三方库
Paddle在cmake会在编译paddle的时候自动编译依赖的第三方库,不过openblas和protobuf最好还是在编译paddle之前先编译好,这样可以保证编译paddle的时候更加顺畅。

### 编译openblas
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

@hedaoyuan hedaoyuan left a comment

Choose a reason for hiding this comment

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

@Xreki #1835 (comment)
这两个问题,是否在 #1973 里面已经解决了?另外,应该基于 #1973 从新写一下这个文档是吗?

@Xreki
Copy link
Contributor

Xreki commented May 4, 2017

@hedaoyuan

这两个问题,是否在 #1973 里面已经解决了?

#1973 可以可以自动编译第三方库了(host、target的protobuf,opneblas),但是需要一些cmake配置告诉cmake正在交叉编译。cmake默认是配置了CMAKE_SYSTEM_NAME这个变量,就认为是在交叉编译。Android配置CMAKE_SYSTEM_NAME=Android,Raspberry Pi配置CMAKE_SYSTEM_NAME=RPi

另外,应该基于 #1973 从新写一下这个文档是吗?

在这个PR里改是不是不太合适?

Copy link
Contributor Author

@hedaoyuan hedaoyuan left a comment

Choose a reason for hiding this comment

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

好的,那这个PR就先这样,后续Build相关工作可以继续优化。
@wangkuiyi comemnts已经都回复了,请review一下。

@wangkuiyi wangkuiyi merged commit 0fdbd40 into PaddlePaddle:develop May 17, 2017
@Xreki Xreki moved this from In Progress to Done in Embedded and Mobile Deployment May 18, 2017
lizexu123 added a commit to lizexu123/Paddle that referenced this pull request Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Embedded and Mobile Deployment
Build System & Build Optimize
Development

Successfully merging this pull request may close these issues.

None yet

3 participants