레이블이 build인 게시물을 표시합니다. 모든 게시물 표시
레이블이 build인 게시물을 표시합니다. 모든 게시물 표시

2020년 2월 20일 목요일

POWER9 (RHEL 8.1, ppc64le)에서 MariaDB MaxScale을 source로부터 build하기



MaxScale은 MariaDB의 앞단에서 HA 및 query routing, CDC 등을 처리해주는 솔루션입니다.  MariaDB는 물론, mariadb-server-galera도 Red Hat Software Collections (RHSCL)에 포함되어 있습니다만, 현재로서는 MaxScale은 포함되어 있지 않습니다.

하지만 MaxScale은 open source이므로 source로부터 쉽게 build할 수 있습니다.

[cecuser@p606-kvm1 ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.1 (Ootpa)

먼저 일반적인 개발 환경을 위해 필요한 package들을 설치합니다.

[cecuser@p606-kvm1 ~]$ sudo yum  groupinstall -y "Development Tools"

다음으로는 아래 OS package들을 설치하고, Rambbit-MQ와 Jansson 등의 open source SW를 source로부터 build합니다.  원래 이 과정들은 MaxScale source code package 중에서 포함된 install_build_deps.sh를 수행하면 자동으로 되는 것입니다만, ppc64le에서는 일부 수행 오류가 나는 것이 있어서 다음과 같이 수동으로 수행하면 됩니다.

[cecuser@p606-kvm1 ~]$ sudo yum install -y libtool openssl-devel libaio libaio-devel libedit systemtap-sdt-devel rpm-sign wget gnupg pcre-devel flex rpmdevtools git wget tcl tcl-devel openssl libuuid-devel xz-devel sqlite sqlite-devel pkgconfig lua lua-libs rpm-build createrepo yum-utils gnutls-devel libgcrypt-devel pam-devel libcurl-devel nodejs-devel


[cecuser@p606-kvm1 ~]$ git clone https://github.com/alanxz/rabbitmq-c.git

[cecuser@p606-kvm1 ~]$ cd rabbitmq-c

[cecuser@p606-kvm1 rabbitmq-c]$ git checkout v0.7.1

[cecuser@p606-kvm1 rabbitmq-c]$ sudo make install

[cecuser@p606-kvm1 rabbitmq-c]$ cd ..


[cecuser@p606-kvm1 ~]$ git clone https://github.com/akheron/jansson.git

[cecuser@p606-kvm1 ~]$ cd jansson

[cecuser@p606-kvm1 jansson]$ git checkout v2.9

[cecuser@p606-kvm1 jansson]$ mkdir build && cd build

[cecuser@p606-kvm1 build]$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS=-fPIC -DJANSSON_INSTALL_LIB_DIR=/usr/lib64

[cecuser@p606-kvm1 build]$ make

[cecuser@p606-kvm1 build]$ sudo make install

[cecuser@p606-kvm1 build]$ cd ../..


[cecuser@p606-kvm1 ~]$ wget -q -r -l1 -nH --cut-dirs=2 --no-parent -A.tar.gz --no-directories https://downloads.apache.org/avro/stable/c/

[cecuser@p606-kvm1 ~]$ tar -zxf avro-c-1.9.2.tar.gz

[cecuser@p606-kvm1 ~]$ cd avro-c-1.9.2

[cecuser@p606-kvm1 avro-c-1.9.2]$ mkdir build && cd build

[cecuser@p606-kvm1 build]$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS=-fPIC -DCMAKE_CXX_FLAGS=-fPIC

[cecuser@p606-kvm1 build]$ make && sudo make install

[cecuser@p606-kvm1 build]$ cd ../..


이제 MaxScale의 source를 download 받습니다.

[cecuser@p606-kvm1 ~]$ git clone https://github.com/mariadb-corporation/MaxScale

[cecuser@p606-kvm1 ~]$ cd MaxScale/

[cecuser@p606-kvm1 MaxScale]$ mkdir build && cd build

원래 manual에는 아래와 같이 install_build_deps.sh를 수행하라고 되어 있지만, 하지 마십시요.  위에서 이미 수동으로 다 처리했으며, 이걸 수행하면  x86용 binary를 download 받아서 멀쩡한 nodejs 관련 파일을 망쳐놓는 오작동을 합니다.

[cecuser@p606-kvm1 build]$ ../BUILD/install_build_deps.sh    --> Don't Run !


cmake를 수행합니다.

[cecuser@p606-kvm1 build]$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr


그리고 다음 파일에서 ppc64만 있고 ppc64le가 없어서 발생하는 error가 있으므로, 아래와 같이 수정합니다.

[cecuser@p606-kvm1 build]$ vi ../query_classifier/qc_sqlite/sqlite-src-3110100/config.guess
...
    ppc64:Linux:*:*)
        echo powerpc64-unknown-linux-${LIBC}
        exit ;;
    ppc64le:Linux:*:*)   # 추가
        echo powerpc64le-unknown-linux-${LIBC}  # 추가
        exit ;;   # 추가
...

다음은 make를 수행하면 됩니다.

[cecuser@p606-kvm1 build]$ make && sudo make install


테스트를 해보면 모두 정상 수행되는 것을 보실 수 있습니다.

[cecuser@p606-kvm1 build]$ make test
Running tests...
Test project /home/cecuser/MaxScale/build
      Start  1: test_mxb_log
 1/62 Test  #1: test_mxb_log ........................   Passed    0.01 sec
      Start  2: test_semaphore
 2/62 Test  #2: test_semaphore ......................   Passed   12.01 sec
      Start  3: test_worker
...
61/62 Test #61: test_hintparser .....................   Passed    0.01 sec
      Start 62: test_masking_rules
62/62 Test #62: test_masking_rules ..................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 62

Total Test time (real) = 108.24 sec



2020년 2월 18일 화요일

POWER9에서 sysbench를 source로부터 build하기



sysbench는 주로 DBMS의 성능 benchmark test를 할 때 사용되는 tool입니다.  IBM POWER9 즉 ppc64le 아키텍처의 Redhat에서 이를 build하는 방법은 간단합니다.

먼저 필요한 OS package들을 설치합니다.

(base) [cecuser@p663-kvm1 sysbench]$ sudo yum -y install make automake libtool pkgconfig libaio-devel

MariaDB 그리고 PostgreSQL과 연계 테스트를 위해서는 아래와 같은 OS package들도 함께 설치합니다.

(base) [cecuser@p663-kvm1 sysbench]$ sudo yum -y install mariadb-devel openssl-devel postgresql-devel

이제 source code를 download 받습니다.

(base) [cecuser@p663-kvm1 ~]$ git clone https://github.com/akopytov/sysbench.git

(base) [cecuser@p663-kvm1 ~]$ cd sysbench

여기서 travis_ppc64le branch로 checkout 합니다.  이걸 하지 않으면 "error: ‘GG_State’ {aka ‘struct GG_State’} has no member named ‘J’ "라는 error를 겪게 되는데, 이에 대해서는 https://github.com/akopytov/sysbench/pull/234 를 참조하십시요.

(base) [cecuser@p663-kvm1 sysbench]$ git checkout travis_ppc64le

다음으로 autogen,sh을 수행하여 configure script를 생성합니다.

(base) [cecuser@p663-kvm1 sysbench]$ ./autogen.sh

만약 postgresql이나 mariadb로 sysbench 테스트를 하실 거라면 아래와 같이 '--with-pgsql --with-mysql' 옵션과 함께 configure를 돌리시면 됩니다.  Default로는 mysql을 찾습니다.

(base) [cecuser@p663-kvm1 sysbench]$ ./configure --with-pgsql --with-mysql

만약 mysql이나 postgresql을 쓸 것이 아니라면 다음과 같이 하면 됩니다.

(base) [cecuser@p663-kvm1 sysbench]$ ./configure --without-mysql

그 다음으로는 make, sudo make install을 수행하면 됩니다.

(base) [cecuser@p663-kvm1 sysbench]$ make -j4

(base) [cecuser@p663-kvm1 sysbench]$ sudo make install

(base) [cecuser@p663-kvm1 sysbench]$ cd ..

sysbench는 아래 위치에 설치됩니다.

(base) [cecuser@p663-kvm1 ~]$ ls -l `which sysbench`
-rwxr-xr-x 1 root root 1384488 Feb 18 08:00 /usr/local/bin/sysbench

--without-mysql로 build된 sysbench 파일을 편의를 위해 아래의 Google drive에 올려놓았습니다.

https://drive.google.com/open?id=1tH9bbgQaipoAqxWFHAHVL3F4QPFSlcdG

혹시 몰라, 아래와 같이 위에서 "make -j4"까지 해놓은 sysbench directory 전체를 tgz로 묶어서 아래의 Google drive에 올려놓았습니다.  여기서는 --without-mysql로 build된 버전을 올렸습니다.

https://drive.google.com/open?id=1ircTWDzOKuZzglvz5cn-Wr2vEg0q0i3a

새로 build를 해야 하는 경우, 이 file을 아래와 같이 푸시고 sudo make install 만 수행하시면 됩니다. 

(base) [cecuser@p628-kvm1 ~]$ tar -zxf sysbench_ppc64le.tgz

(base) [cecuser@p628-kvm1 ~]$ cd sysbench

(base) [cecuser@p628-kvm1 sysbench]$ sudo make install

또는 postgresql 등의 옵션을 줘서 다시 build해야 한다면 맨 첫줄의 autoconf.sh부터 새로 시작하시면 됩니다.

2019년 10월 10일 목요일

SRILM을 IBM POWER (ppc64le) 아키텍처의 Redhat에서 build하기


SRILM은 음성인식 등에 쓰이는 statistical language model(LM)들을 쉽게 구축하고 적용할 수 있는 toolkit입니다.  이것을 IBM POWER 서버에 설치된 Redhat이나 Ubuntu 등 linux OS에서도 build해서 사용할 수 있느냐에 대한 답변은 "Yes, 된다" 입니다.

SRILM의 현재 최신버전인 1.7.3 버전에서는 ppc64 (big-endian) 만 지원하는 것처럼 되어 있습니다만, 이는 그냥 ppc64le가 template에 아직 update가 안되었을 뿐이며, template만 약간 수정하면 ppc64le (little-endian)에서도 쉽게 build 하실 수 있습니다. 

먼저, 필요 OS fileset들을 설치합니다.  여기서는 Redhat 7.5를 기준으로 했습니다.

[user612@p612-met1 ~]$ sudo yum install -y gawk tcl-devel libticonv-devel bzip2

SRILM의 최신 버전 1.7.3을 아래 URL에서 download 받고, POWER 서버에 upload 합니다.

http://www.speech.sri.com/projects/srilm/download.html

압축을 해제합니다.

[user612@p612-met1 ~]$ mkdir srilm

[user612@p612-met1 ~]$ cd srilm

[user612@p612-met1 srilm]$ tar -xvf ../srilm-1.7.3.tar.gz

먼저 source에 포함된 machine-type 이라는 shell script를 수행해보면 MACHINE_TYPE을 못 찾겠다는 error가 납니다.  이는 아래와 같이 shell script를 약간만 수정하면 해결됩니다.

[user612@p612-met1 srilm]$ ./sbin/machine-type
could not determine MACHINE_TYPE

[user612@p612-met1 srilm]$ vi ./sbin/machine-type
...
            *)
                case "`uname -m`" in
                ppc64)  MACHINE_TYPE=ppc64
                        ;;
                ppc64le) MACHINE_TYPE=ppc64le    # Newly added
                        ;;                                       # Newly added
                i686)   MACHINE_TYPE=i686
                        ;;

이제 잘 됩니다.

[user612@p612-met1 srilm]$ ./sbin/machine-type
ppc64le

이어서 Makefile에서 SRILM home directory를 update 합니다.  사실 이건 ppc64le 아키텍처에서만 수정해야 하는 것이 아니라 x86 등 모든 아키텍처에서 다 환경에 맞게 수정해야 하는 부분입니다.

[user612@p612-met1 srilm]$ vi Makefile
...
# SRILM = /home/speech/stolcke/project/srilm/devel
SRILM = /home/user612/srilm    # Update per environment

ppc64le 아키텍처가 지원 안되는 것처럼 보이는 것은 아래의 common/Makefile.machine.* 파일들에 ppc64만 있고 ppc64le가 없기 때문입니다.  그냥 기존의 ppc64를 ppc64le로 copy해줍니다.

[user612@p612-met1 srilm]$ cp common/Makefile.machine.ppc64 common/Makefile.machine.ppc64le

그리고 여기서 LINK할 library에 pthread를 추가해줍니다.  (이를 안 해주면 어떤 error가 나는지는 맨 아래에 적었습니다.)

[user612@p612-met1 srilm]$ vi common/Makefile.machine.ppc64le
...
#   ADDITIONAL_LIBRARIES = -lm -ldl
   ADDITIONAL_LIBRARIES = -lm -ldl -lpthread   # Added -lpthread
...

이제 그냥 make를 수행하시면 됩니다.  아무 error 없이 잘 build 됩니다.

[user612@p612-met1 srilm]$ make -j16

이제 PATH를 잡아주고 ngram 명령을 수행해봅니다.  아래와 같이 잘 수행되는 것을 보실 수 있습니다.

[user612@p612-met1 srilm]$ pwd
/home/user612/srilm

[user612@p612-met1 srilm]$ export PATH=$PATH:/home/user612/srilm/bin/ppc64le

[user612@p612-met1 srilm]$ ngram -help
Usage of command "ngram"
 -version:                print version information
 -order:                  max ngram order
                Default value: 3
 -debug:                  debugging level for lm
                Default value: 0
 -skipoovs:               skip n-gram contexts containing OOVs
...



** 만약 위에서 common/Makefile.machine.ppc64le 속의 "ADDITIONAL_LIBRARIES = -lm -ldl -lpthread" 부분을 고치지 않는다면 다음과 같은 error를 겪게 되실 것입니다.  이 error가 나는 이유는 /usr/lib64/libpthread.so.0 가 참조되지 않기 때문이니, 위와 같이 common/Makefile.machine.ppc64le을 수정하시면 해결됩니다.

...
g++ -Wreturn-type -Wimplicit -DINSTANTIATE_TEMPLATES    -I. -I../../include   -u matherr -L../../lib/ppc64le  -g -O3 -o ../bin/ppc64le/ngram-merge ../obj/ppc64le/ngram-merge.o ../obj/ppc64le/liboolm.a -lm -ldl ../../lib/ppc64le/libflm.a ../../lib/ppc64le/libdstruct.a ../../lib/ppc64le/libmisc.a ../../lib/ppc64le/libz.a -ltcl -lm   2>&1 | c++filt
/usr/bin/ld: ../obj/ppc64le/liboolm.a(Vocab.o): undefined reference to symbol 'pthread_getspecific@@GLIBC_2.17'
//usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
test -f ../bin/ppc64le/ngram-merge
make[2]: *** [../bin/ppc64le/ngram-merge] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory `/home/user612/srilm/lm/src'
make[1]: *** [release-programs] Error 1
make[1]: Leaving directory `/home/user612/srilm'
make: *** [World] Error 2

2019년 4월 25일 목요일

RAPIDS.ai on IBM POWER9 : ppc64le 환경에서 cuDF를 source로부터 build하기



RAPIDS.ai는 NVIDIA가 요즘 공을 들이고 있는 GPU를 이용한 data science platform입니다.  그 핵심 모듈이 cuDF와 cuML입니다.  이 모듈들은 최근 발표된 IBM PowerAI toolkit에도 포함되어 있습니다.  ( https://www.ibm.com/support/knowledgecenter/en/SS5SF7_1.6.0/navigation/pai_getstarted_rapids.html 참조)

다만 IBM PowerAI는 CUDA 10.1만을 지원하는 등 제약 사항이 일부 있기 때문에 모든 환경에서 유연하게 사용하시기가 곤란한 부분이 있을 수 있습니다.  그래도 어차피 RAPIDS는 open source니까, ppc64le 아키텍처 위에서 그냥 source로부터 build하시면 됩니다.  이번 posting에서는 cuDF를 Ubuntu 18.04 ppc64le에서 build하는 방법을 보시겠습니다.

일단 아래와 같이 cuda 10.0을 설치합니다.

~/files$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/ppc64el/cuda-repo-ubuntu1804_10.0.130-1_ppc64el.deb

~/files$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/ppc64el/7fa2af80.pub

~/files$ sudo apt-get update

~/files$ sudo apt-get install cuda

~/files$ sudo tar -xvf ./cudnn-10.0-linux-ppc64le-v7.5.0.56.solitairetheme8 -C /usr/local

~/files$ sudo tar -xvf ./nccl_2.4.2-1+cuda10.0_ppc64le.txz -C /usr/local

Python은 Anaconda3를 설치하여 Python 3.6.8을 사용했습니다. 

~/files$  which python
/home/u0017649/anaconda3/bin/python

먼저 conda install 명령으로 아래 package들을 설치합니다.

~/files$ conda install numpy six setuptools cython pandas pytest cmake flatbuffers rapidjson boost boost-cpp thrift snappy zlib gflags brotli lz4-c zstd arrow -c conda-forge

먼저 유의하실 것은 Ubuntu 18.10의 기본 gcc 버전인 gcc-8은 CUDA 10.0을 지원하지 않습니다.  그런데 또 현재 cudf v0.7.0은 아직 CUDA 10.1을 지원하지 않습니다.  그래서 해결책은 Ubuntu에 gcc-7과 g++-7을 설치해야 합니다.

~/files$ sudo apt-get install -y gcc-7 gcc-7-base gcc-7-powerpc-linux-gnu libgcc-7-dev g++-7

~/files$ sudo rm /usr/bin/gcc /usr/bin/g++

~/files$ sudo ln -s /usr/bin/gcc-7 /usr/bin/gcc

~/files$ sudo ln -s /usr/bin/g++-7 /usr/bin/g++

먼저, RMM을 설치합니다.

~/files$ git clone --recursive  https://github.com/rapidsai/rmm.git

~/files$ cd rmm

~/files/rmm$ rm -rf build

~/files/rmm$ mkdir build && cd build

~/files/rmm/build$ cmake ..

~/files/rmm/build$ make -j2

~/files/rmm/build$ sudo make install

~/files/rmm/build$ cd ../python

~/files/rmm/python$ python setup.py install


다음으로는 custrings를 설치합니다.

~/files$ git clone --recursive https://github.com/rapidsai/custrings.git

~/files$ cd custrings/cpp

~/files/custrings/cpp$ mkdir build && cd build

~/files/custrings/cpp/build$ cmake ..

~/files/custrings/cpp$ make -j2

~/files/custrings/cpp$ sudo make install

다음으로는 thrift를 설치합니다. 

~/files$ git clone --recursive https://github.com/apache/thrift

~/files$ cd thrift/

~/files/thrift$ sudo apt-get install libssl-dev

~/files/thrift$ ./bootstrap.sh

~/files/thrift$ ./configure

~/files/thrift$ cd build

~/files/thrift/build$ cmake ..

~/files/thrift/build$ make -j2

~/files/thrift/build$ sudo make install

다음으로는 Arrow를 설치합니다. 

~/files$ sudo apt-get install libdouble-conversion1 libghc-double-conversion-dev libdouble-conversion-dev libgoogle-glog-dev libgoogle-glog0v5 thrift-compiler libthrift-java

~/files$ git clone https://github.com/apache/arrow.git

~/files$ cd arrow/cpp

~/files/arrow/cpp$ mkdir build && cd build

여기서 특정 header 파일을 아래와 같이 일부 수정해야 합니다.  이 error는 꼭 ppc64le 환경에서만 나는 것은 아니고, 나중에 patch가 될 예정입니다.   ( error: there are no arguments to ‘DCHECK’ that depend on a template parameter, so a declaration of ‘DCHECK’ must be available 이라는 error 방지용.  https://github.com/apache/arrow/issues/4014 참조)

~/files/arrow/cpp/build$ vi ~/files/arrow/cpp/src/arrow/util/sse-util.h
...
#include "logging.h"   # 이 include 문을 삽입해야 함


~/files/arrow/cpp/build$ cmake -DCMAKE_BUILD_TYPE=release -DARROW_PYTHON=on -DARROW_PLASMA=on -DARROW_BUILD_TESTS=OFF  -DARROW_PARQUET=ON ..

~/files/arrow/cpp/build$ make -j2

~/files/arrow/cpp/build$ sudo make install

~/files/arrow/cpp/build$ cd ../../python

~/files/arrow/python$ export ARROW_HOME=/usr/local

기본으로 설치되는 Cython 버전이 맞지 않으므로, 반드시 0.29 버전으로 새로 설치해야 하더라고요.

~/files/arrow/python$ pip install Cython==0.29

~/files/arrow/python$ MAKEFLAGS=-j2 python setup.py build_ext --build-type=release --with-parquet --inplace

~/files/arrow/python$ MAKEFLAGS=-j2 python setup.py build_ext --build-type=release --with-parquet --bundle-arrow-cpp bdist_wheel

위에서 생성되는 wheel file을 아래와 같이 설치하시면 됩니다.

~/files/arrow/python$ pip install dist/pyarrow-0.13.1.dev40+g6907d972.d20190408-cp37-cp37m-linux_ppc64le.whl


이제 비로소 cudf를 설치할 수 있게 되었습니다.

~/files$ git clone --recursive https://github.com/rapidsai/cudf.git

~/files$ cd cudf

~/files/cudf$ git submodule update --init --remote --recursive

여기서 역시 아래의 file 하나를 수정해야 합니다.  이 역시 ppc64le에 국한된 문제는 아니고, 아래 link에서 해결된 것인데, 나중에 patch로 반영될 예정입니다.  ( https://github.com/rapidsai/cudf/issues/1384 참조)

~/files/cudf$ vi cpp/tests/hashing/hash_partition_test.cu
...
  // The indices of the columns that will be hashed to determine the partitions
  constexpr static const std::array<int, sizeof...(cols)> cols_to_hash{{cols...}};
};
 template< typename tuple_of_vectors       # 이하 4줄의 line을 추가하시면 됩니다.
           gdf_hash_func hash,
           int... cols>
 constexpr const std::array<int, sizeof...(cols)> TestParameters<tuple_of_vectors, hash, cols...>::cols_to_hash;


그 다음은 아래와 같이 build하시면 됩니다.

~/files/cudf$ cd cpp

~/files/cudf/cpp$ mkdir build && cd build

~/files/cudf/cpp/build$ cmake .. -DCMAKE_INSTALL_PREFIX=~/anaconda3

~/files/cudf/cpp/build$ make -j2

~/files/cudf/cpp/build$ sudo make install

root@8f2f82cf3e22:/mnt/cudf# cd python

root@8f2f82cf3e22:/mnt/cudf/python# python setup.py build_ext --inplace

root@8f2f82cf3e22:/mnt/cudf/python# python setup.py install
...
Best match: numpy 1.16.2
Adding numpy 1.16.2 to easy-install.pth file
Installing f2py script to /opt/anaconda3/bin
Installing f2py3 script to /opt/anaconda3/bin
Installing f2py3.6 script to /opt/anaconda3/bin

Using /opt/anaconda3/lib/python3.6/site-packages
Finished processing dependencies for cudf==0.7.0.dev0+679.g97833593.dirty

2018년 5월 4일 금요일

ppc64le 환경에서 gcc7과 cmake3을 source로부터 build


제목 그대로입니다.  gcc7과 cmake3을 source code로부터 build하는 방법은 비교적 간단합니다.   여기서는 Redhat 7.4 ppc64le 환경입니다.

단, gcc를 build할 때 make 부분은 (CPU power가 약하다면) 시간이 매우 오래 걸린다는 점에 유의하세요. 

먼저 사전에 필요한 package 설치합니다.

[u0017649@sys-93214 ~]$ sudo yum install yum install gmp-devel mpfr-devel libmpc-devel

gcc 7.2 source code부터 download 합니다.

[u0017649@sys-93214 ~]$ wget https://ftp.gnu.org/gnu/gcc/gcc-7.2.0/gcc-7.2.0.tar.gz

[u0017649@sys-93214 ~]$ tar -zxvf gcc-7.2.0.tar.gz

[u0017649@sys-93214 ~]$ cd gcc-7.2.0

[u0017649@sys-93214 gcc-7.2.0]$ mkdir build && cd build

[u0017649@sys-93214 build]$ ../configure --enable-languages=c,c++,fortran

[u0017649@sys-93214 build]$ make -j 8

[u0017649@sys-93214 build]$ sudo make install

[u0017649@sys-93214 build]$ which gcc
/usr/local/bin/gcc

g++도 함께 설치됩니다.

[u0017649@sys-93214 build]$ which g++
/usr/local/bin/g++

다음으로 cmake 3.11 source code를 download 합니다.

[u0017649@sys-93214 ~]$ wget https://cmake.org/files/v3.11/cmake-3.11.1.tar.gz

[u0017649@sys-93214 ~]$ tar -zxvf cmake-3.11.1.tar.gz

[u0017649@sys-93214 ~]$ cd cmake-3.11.1

[u0017649@sys-93214 cmake-3.11.1]$ ./configure

[u0017649@sys-93214 cmake-3.11.1]$ make

[u0017649@sys-93214 cmake-3.11.1]$ sudo make install

[u0017649@sys-93214 cmake-3.11.1]$ which cmake
/usr/local/bin/cmake

[u0017649@sys-93214 cmake-3.11.1]$ cmake --version
cmake version 3.11.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).

2018년 1월 19일 금요일

AC922 Redhat 환경에서 source code로부터 caffe build하기


AC922 Redhat 환경에서는 아직은 정식으로 PowerAI가 full 지원되지 않으며, 이는 2018년 2Q로 예정되어 있습니다.   그러나 source code로부터 빌드하는 것은 언제나 하기 나름입니다.

지난 포스팅에서는 AC922에서 Tensorflow 1.4.1을 빌드하는 것을 보여드렸는데, 이번에는 caffe (물론 bvlc-caffe)를 빌드합니다.   이번에는 IBM 이보란 과장께서 수고해주셨습니다.  본문은 아래 이보란 과장이 운영하는 블로그를 click 하십시요.

http://shareithw.blogspot.kr/2018/01/bvlc-caffe-rhel-power9-ppc64le.html

2017년 3월 16일 목요일

Ubuntu 16.04 ppc64le에서, source로부터 tensorflow를 build하는 방법

PowerAI 속에 tensorflow가 들어 있긴 합니다만, 간혹 customizing 때문에 source에서 build할 필요도 있을 수 있습니다.   여기서는 CUDA 8.0과 PowerAI가 이미 다 설치된 상태에서, build를 시작하는 것으로 하겠습니다.  먼저, 기반 OS package를 설치합니다.

test@k8002:~$ sudo apt-get install make automake autoconf gfortran-4.8-multilib-powerpc-linux-gnu libgfortran-4.8-dev-powerpc-cross gfortran libgfortran-4.8-dev gcc-powerpc-linux-gnu g++ pkg-config cmake-curses-gui zlib1g-dev zip unzip libtool openjdk-8-jdk python python-all-dev swig python-numpy g++-4.8 g++-4.8-multilib-powerpc-linux-gnu zlibc re2c libre2-dev libcupti-dev

Tensorflow를 github에서 download 받습니다.

test@k8002:~$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow

이제 tensorflow에 어떤 버전의 branch들이 있는지 확인합니다.

test@k8002:~$ cd tensorflow
test@k8002:~/tensorflow$ git branch -a
* master
  remotes/origin/0.6.0
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/r0.10
  remotes/origin/r0.11
  remotes/origin/r0.12
  remotes/origin/r0.7
  remotes/origin/r0.8
  remotes/origin/r0.9
  remotes/origin/r1.0

이중에서 일단은 master 버전을 build해보겠습니다.

test@k8002:~/tensorflow$ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.

여기서 일단 환경 변수 확인을 해보겠습니다.

test@k8002:~/tensorflow$ env | grep PATH
LD_LIBRARY_PATH=/usr/local/cuDNN:/usr/local/cuda-8.0/lib64
PATH=/home/test/bin:/home/test/.local/bin:/usr/local/cuda-8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Github에서 download 받은 tensorflow를 build할 때도, PowerAI에 포함된 bazel을 사용하면 편리합니다.  그를 위해, 현재의 PATH 환경변수들을 PowerAI 기준으로 고쳐줘야 하는데, 그를 위해서는 아래와 같이 PowerAI에 포함된 script 하나만 수행해주면 됩니다.

test@k8002:~/tensorflow$ source /opt/DL/tensorflow/bin/tensorflow-activate

이제 아래와 같이 PATH에 /opt/DL/tensorflow/bin가 추가되고, PYTHONPATH가 추가된 것을 보실 수 있습니다.

test@k8002:~/tensorflow$ env | grep PATH
LD_LIBRARY_PATH=/usr/local/cuDNN:/usr/local/cuda-8.0/lib64
PATH=/home/test/bin:/home/test/.local/bin:/usr/local/cuda-8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/DL/tensorflow/bin
PYTHONPATH=/opt/DL/tensorflow/lib/python2.7/site-packages

여기에 추가로 bazel의 PATH도 잡아줘야 합니다.  Tensorflow의 build를 위해서는 먼저 bazel을 build해야 하는데, 사실 그것이 tensorflow build보다 더 힘듭니다.  여기서는 PowerAI에 포함된 bazel을 간편하게 사용하겠습니다.

test@k8002:~/tensorflow$ export PATH=/opt/DL/bazel/bin:$PATH

이제 configure부터 시작하여 build에 들어갑니다.

test@k8002:~/tensorflow$ ./configure
Please specify the location of python. [Default is /usr/bin/python]:
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Do you wish to use jemalloc as the malloc implementation? [Y/n]
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N]
No Hadoop File System support will be enabled for TensorFlow
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Found possible Python library paths:
  /opt/DL/tensorflow/lib/python2.7/site-packages
  /usr/local/lib/python2.7/dist-packages
  /usr/lib/python2.7/dist-packages
Please input the desired Python library path to use.  Default is [/opt/DL/tensorflow/lib/python2.7/site-packages]
/usr/lib/python2.7/dist-packages

Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-8.0
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5
Please specify the location where cuDNN 5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-8.0]: /usr/lib/powerpc64le-linux-gnu  
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 6.0    (--> P100은 6.0, K80의 경우 3.7)
Extracting Bazel installation...
.............
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
............
WARNING: /home/test/.cache/bazel/_bazel_test/3a51eda24c560ebddf29b66b8fa0460e/external/protobuf/protobuf.bzl:90:19: Variables HOST_CFG and DATA_CFG are deprecated in favor of strings "host" and "data" correspondingly.
WARNING: /home/test/.cache/bazel/_bazel_test/3a51eda24c560ebddf29b66b8fa0460e/external/protobuf/protobuf.bzl:96:28: Variables HOST_CFG and DATA_CFG are deprecated in favor of strings "host" and "data" correspondingly.
INFO: Downloading http://pilotfiber.dl.sourceforge.net/project/boost/boost/1.6\
1.0/boost_1_61_0.tar.gz: 104,733,800 bytes
...
INFO: All external dependencies fetched successfully.
Configuration finished

configure가 끝나면 이제 bazel build를 합니다.

test@k8002:~/tensorflow$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
...
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
  bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 256.806s, Critical Path: 203.45s

윗 단계가 성공적으로 끝나면 다음과 같이 /tmp/tensorflow_pkg directory에 pip package를 build합니다.

test@k8002:~/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Thu Mar 16 15:03:32 KST 2017 : === Using tmpdir: /tmp/tmp.LCBvnwu8ZZ
~/tensorflow/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles ~/tensorflow
~/tensorflow
/tmp/tmp.LCBvnwu8ZZ ~/tensorflow
Thu Mar 16 15:03:33 KST 2017 : === Building wheel
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
~/tensorflow
Thu Mar 16 15:03:44 KST 2017 : === Output wheel file is in: /tmp/tensorflow_pkg

이제 /tmp/tensorflow_pkg directory에 생성된 wheel file을 이용하여 pip install을 하면 tensorflow 설치가 완료됩니다.

test@k8002:~/tensorflow$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.0.1-cp27-cp27mu-linux_ppc64le.whl
...
  Downloading funcsigs-1.0.2-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): pbr>=0.11 in /usr/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==1.0.1)
Installing collected packages: werkzeug, protobuf, funcsigs, mock, tensorflow
  Found existing installation: protobuf 2.6.1
    Not uninstalling protobuf at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: funcsigs 0.4
    Not uninstalling funcsigs at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: mock 1.3.0
    Not uninstalling mock at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed funcsigs-1.0.2 mock-2.0.0 protobuf-3.2.0 tensorflow-1.0.1 werkzeug-0.12.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

이제 tensorflow의 버전을 확인해보겠습니다.

test@k8002:~/tensorflow$ pip show tensorflow
---
Metadata-Version: 2.0
Name: tensorflow
Version: 0.12.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
Installer: pip
License: Apache 2.0
Location: /opt/DL/tensorflow/lib/python2.7/site-packages
Requires: numpy, mock, six, protobuf, wheel
Classifiers:
  Development Status :: 4 - Beta
  Intended Audience :: Developers
  Intended Audience :: Education
  Intended Audience :: Science/Research
  License :: OSI Approved :: Apache Software License
  Programming Language :: Python :: 2.7
  Topic :: Scientific/Engineering :: Mathematics
  Topic :: Software Development :: Libraries :: Python Modules
  Topic :: Software Development :: Libraries
Entry-points:
  [console_scripts]
  tensorboard = tensorflow.tensorboard.tensorboard:main
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


위와 같이 version이 방금 설치한 v1.0이 아니라 v0.12로 나오는 것은 환경변수 PYTHONPATH가 아직 /opt/DL/tensorflow/lib/python2.7/site-packages으로 잡혀 있기 때문에, 이전에 PowerAI 설치 때 함께 설치된 tensorflow 0.12가 보이는 것입니다.  이를 configure할 때 주었던 값인 /usr/local/lib/python2.7/dist-packages으로 바꾼 뒤 다시 해보겠습니다.


test@k8002:~/tensorflow$ export PYTHONPATH=/usr/local/lib/python2.7/dist-packages:$PYTHONPATH

test@k8002:~/tensorflow$ pip show tensorflow
---
Metadata-Version: 2.0
Name: tensorflow
Version: 1.0.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
Installer: pip
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: werkzeug, six, protobuf, wheel, numpy, mock
Classifiers:
  Development Status :: 4 - Beta
  Intended Audience :: Developers
  Intended Audience :: Education
  Intended Audience :: Science/Research
  License :: OSI Approved :: Apache Software License
  Programming Language :: Python :: 2.7
  Topic :: Scientific/Engineering :: Mathematics
  Topic :: Software Development :: Libraries :: Python Modules
  Topic :: Software Development :: Libraries
Entry-points:
  [console_scripts]
  tensorboard = tensorflow.tensorboard.tensorboard:main
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

위와 같이 v1.0.1로 제대로 보이는 것을 보실 수 있습니다.

이번에는 r0.12를 build해보겠습니다.

test@k8002:~/tensorflow$ git checkout r0.12
Switched to branch 'r0.12'
Your branch is up-to-date with 'origin/r0.12'.

동일하게, configure부터 시작하여 build에 들어갑니다.

test@k8002:~/tensorflow$ ./configure
~/tensorflow ~/tensorflow
Please specify the location of python. [Default is /usr/bin/python]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N]
No Hadoop File System support will be enabled for TensorFlow
Found possible Python library paths:
  /usr/local/lib/python2.7/dist-packages
  /usr/lib/python2.7/dist-packages
Please input the desired Python library path to use.  Default is [/usr/local/lib/python2.7/dist-packages]
/usr/lib/python2.7/dist-packages
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-8.0
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5
Please specify the location where cuDNN 5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-8.0]: /usr/lib/powerpc64le-linux-gnu
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 6.0    (--> P100은 6.0, K80의 경우 3.7)
............
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
............
INFO: All external dependencies fetched successfully.
Configuration finished



test@k8002:~/tensorflow$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
...                                                                                                                                          ^
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-self-assign'
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
  bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 306.555s, Critical Path: 273.68s



test@k8002:~/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Fri Mar 17 16:16:24 KST 2017 : === Using tmpdir: /tmp/tmp.L1dwTgVhwv
~/tensorflow/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles ~/tensorflow
~/tensorflow
/tmp/tmp.L1dwTgVhwv ~/tensorflow
Fri Mar 17 16:16:25 KST 2017 : === Building wheel
~/tensorflow
Fri Mar 17 16:16:41 KST 2017 : === Output wheel file is in: /tmp/tensorflow_pkg


이제 /tmp/tensorflow_pkg를 보시면 아까 build했던 1.0.1 버전의 wheel file과 함께 새로 0.12 버전의 wheel file이 만들어진 것을 보실 수 있습니다.

test@k8002:~/tensorflow$ ls -l /tmp/tensorflow_pkg/
total 109520
-rw-rw-r-- 1 test test 61576804 Mar 17 16:16 tensorflow-0.12.1-cp27-cp27mu-linux_ppc64le.whl
-rw-rw-r-- 1 test test 50565190 Mar 16 15:03 tensorflow-1.0.1-cp27-cp27mu-linux_ppc64le.whl

그것을 pip install 명령으로 설치합니다.   아래와 같이, 기존의 tensorflow-1.0.1을 uninstall하면서 0.12가 설치됩니다.

test@k8002:~/tensorflow$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.12.1-cp27-cp27mu-linux_ppc64le.whl
The directory '/home/test/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/test/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing /tmp/tensorflow_pkg/tensorflow-0.12.1-cp27-cp27mu-linux_ppc64le.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.11.0 in /home/test/.local/lib/python2.7/site-packages (from tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): wheel in /usr/lib/python2.7/dist-packages (from tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): mock>=2.0.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in /home/test/.local/lib/python2.7/site-packages (from tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): protobuf>=3.1.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): funcsigs>=1; python_version < "3.3" in /usr/local/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): pbr>=0.11 in /usr/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==0.12.1)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python2.7/dist-packages (from protobuf>=3.1.0->tensorflow==0.12.1)
Installing collected packages: tensorflow
  Found existing installation: tensorflow 1.0.1
    Uninstalling tensorflow-1.0.1:
      Successfully uninstalled tensorflow-1.0.1
Successfully installed tensorflow-0.12.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


다음과 같이 tensorflow의 버전이 0.12.1로 변경된 것을 확인하실 수 있습니다.

test@k8002:~/tensorflow$ pip show tensorflow
---
Metadata-Version: 2.0
Name: tensorflow
Version: 0.12.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
Installer: pip
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: numpy, wheel, mock, six, protobuf
Classifiers:
  Development Status :: 4 - Beta
  Intended Audience :: Developers
  Intended Audience :: Education
  Intended Audience :: Science/Research
  License :: OSI Approved :: Apache Software License
  Programming Language :: Python :: 2.7
  Topic :: Scientific/Engineering :: Mathematics
  Topic :: Software Development :: Libraries :: Python Modules
  Topic :: Software Development :: Libraries
Entry-points:
  [console_scripts]
  tensorboard = tensorflow.tensorboard.tensorboard:main
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.