Thursday, December 21, 2017

SSE optimization

https://www.youtube.com/watch?v=GwII1AJzKN4




26:45 : (Visual studio) 디스어셈블리 디버깅
32:36 : go to disassembly


Tuesday, November 7, 2017

Boost python / Cython from ROS catkin build

* 프로젝트에서는 사용했으나, 아래 예제코드로 패키지를 새로 생성해보진 않음.

1. Boost python
1.1  package.xml

<?xml version="1.0"?>
<package format="2">
  <name>some_boost_pkg</name>
  <version>0.0.0</version>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>cmake_modules</build_depend>  # 꼭 필요한지 여부 아직 확인 못함
  <export>
  </export>
</package>

1.2  CMakelists.txt

cmake_minimum_required(VERSION 2.8.3)
project(some_boost_pkg)
add_compile_options(-std=c++11) # boost python 컴파일에 c+11이 필요했던걸로 기억함. 아마도.

find_package(catkin REQUIRED COMPONENTS #0
   ~~~~
)

# 아래의 find_package는 윗줄의 #0 이후에 호출할것.
# 버그인지 모르겠으나, ${Boost_LIBRARIES} 등이 공백으로 덮어씌워지는걸 피하기 위해.
# message(${Boost_LIBRARIES}) 로 확인함.
find_package(cmake_modules REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem thread python)


include_directories(include
  ${Boost_INCLUDE_DIRS}

   ${PYTHON_INCLUDE_DIRS}
)

 catkin_package(
  LIBRARIES
    my_boost_lib  # 1
)
add_library(my_boost_lib ${~ boost python source codes ~} )
target_link_libraries(my_boost_lib
    ${PYTHON_LIBRARIES}
    ${Boost_LIBRARIES}
)
set_target_properties(my_boost_lib PROPERTIES
    PREFIX ""
    LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
) #2

# 1, #2 가 있어야  compile destination이 CATKIN_WORKSPACE/devel/.private/some_boost_pkg/lib/python2.7/dist-packages/some_boost_pkg/my_boost_lib.so 가 된다.
prefix를 안비우면 파일명이 libmy_boost_lib.so 가 된다.

${~ boost python source codes ~}의 소스코드는 부스트 파이선 튜토리얼 참고.
http://www.boost.org/doc/libs/1_62_0/libs/python/doc/html/tutorial/index.html

2. Cython
2. 1 package.xml

boost python과 같음. 패키지 명만 some_boost_pkg 대신 some_cython_pkg 으로 명명했다고 가정하고 진행.

2. 2 CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(some_cython_pkg)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED)
find_package(cmake_modules REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)

include_directories(includ
  ${catkin_INCLUDE_DIRS}
  ${PYTHON_INCLUDE_DIRS}
)
catkin_package(
  LIBRARIES
      my_cython_lib   # 1
)

catkin_python_setup() # Generate cython_build directory and .c, cxx source codes.
add_library(my_cython_lib
    "cython_build/src/my_cython_codes.c" #3
)
set_target_properties(my_cython_lib PROPERTIES
    PREFIX ""
    LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})  #2

2.3 setup.py

http://wiki.ros.org/rospy_tutorials/Tutorials/Makefile 의 setup.py 파일을 아래와 같이 작성해서 package.xml과 같은 폴더에 저장하면 된다.

#!/usr/bin/python
# -*- coding:utf-8 -*-
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
from Cython.Build import cythonize

#from catkin_tools.context import Context
#ctx = Context.load()
#build_path = ctx.build_space_abs + "/cython_build" # 경로는 취향에 따라.
build_path = 'cython_build'

setup_args = generate_distutils_setup(
    packages=['some_boost_pkg'], # ROS package name
    package_dir={'': 'src'},
    requires=['std_msgs', 'rospy'], # 만약 코드에서 필요하다면
    ext_modules = cythonize("./src/my_cython_codes.pyx", build_dir=build_path) #3의 경로에 c코드를 생성하게함.
)
setup(**setup_args)

2.4  *.pyx

패키지/src 폴더의 my_cython_codes.pyx 파일은 다음 링크의 hello.pyx 코드 참고해서 작성.

3. Result / Test

위와 같은 방법으로 패키지를 생성하고 catkin build를 수행하면, python에서 다음과 같이 함수 호출 가능.

$ python
>>  import some_boost_pkg.my_boost_lib as m1
>>  import some_cython_pkg.my_cython_lib as m2
>> m1.function1()
>> m2.function2() 




Sunday, October 15, 2017

CLi booting + boot prorgram

https://askubuntu.com/questions/826325/how-to-revert-usb-wifi-interface-name-from-wlxxxxxxxxxxxxx-to-wlanx


https://linux.m2osw.com/boot-command-line-console-ubuntu-1604

$ sudo vim /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX="text"
GRUB_TERMINAL=console

$ update-grub
$ systemctl set-default multi-user.target
$ reboot 

Thursday, August 24, 2017

파이썬+ boost python cpu 프로파일

## Profile
* kcachegrind 를 설치한다. 프로파일 뷰어. 이는 파이썬,c++ 모두에 유효.
  ``` bash
  sudo pip install pyprof2calltree
  sudo apt-get install kcachegrind # call tree viewer
  ```

  ### C++ profile
  * [CMakeLists.txt](./lib/CMakeLists.txt)와 같이 -pg flag를 추가해서 profile에 필요한 정보를 생성하도록 컴파일 옵션을 세팅해야한다.

    ```
    set(CMAKE_CXX_FLAGS `"${CMAKE_CXX_FLAGS} -pg" )
    ```

  ### Python  profile
  1) cProfile
      * Profile
        ``` bash
        python -m cProfile -o prof.out scripts/vo.py
        pyprof2calltree -i prof.out -k
        ```
      * 한계 : boost python 의 함수는 어쨰선지 profile에 안잡힌다. gperf tools 사용 시도중.

  2) Yappi
      * 멀티 쓰레드 분석 특화.
      * 이번에는 다시 c++ 부분이안됨. 사용 안함.

        ```
        sudo pip install yappi
        python -m yappi -o prof.out -f callgrind scripts/vo.py && kcachegrind prof.out
        ```
  3) line_profiler
    * 파이썬 프로파일러중 가장 강력하다!. 프로파일 대상인 함수 def 위에 @profile 을 붙여줘야하는 단점이 있지만, 대상 스코프는 라인단위로 확실하게 분석함.
      ``` python
      @profile
      def some_target_function(p1, p2):
        p3 = p1+p2
        p4 = p3 * p3
        return p4
      ```

      ``` bash
      sudo pip install line_profiler
      kernprof -l scripts/vo.py && python -m line_profiler vo.py.lprof
      ```

### Profile python-c extension
* google perftools가 잘 안되서,. yep을 쓰기로함.
  ```bash
  python -m yep -c -o prof.out scripts/vo.py && kcachegrind prof.out
  ```
  python에서 library로 불러온 c++ 부분만 나온다.
  python profile결과에서 공백인 부분만, yep에서 인식된다고 보면 되겠음.
  * -c는 kcachegrind가 읽는 callgrind 포맷으로 output 파일을 만드는 옵션.

* 결론 : cProfile로 overview를 분석하고, line_profiler로 세부 병목을 찾으면 됨.  해당 병목이 boost python으로 불러온 c++ 함수일 경우, c++  코드 분석은 yep로 처리하면 코드를 정확하게 분석할수 있음.
  * 한번에 분석이 안끝나는게 번거롭지만, 현재 내가 찾은 차선.
  * google perftools는 이런 문제가 없는것같은데, 아직 어떻게 쓰는지 이해를 못함.

* https://www.youtube.com/watch?v=DUCMjsrYSrQ

Friday, August 11, 2017

Debugging boost python shared lib of python ROS node, with gdb

At some_ros_package/scripts/some_node.py
Add next break points for python.

```
if __name__ == '__main__':
    from os import getpid
    print 'pid = ', getpid()
    import pdb;
    pdb.set_trace()
```

if pid number is 1234, type next commands at other terminal,

```
$  sudo gdb
gdb) attach 1234
gdb) break ~~~~
gdb) continue
```

After make break point at cppfile, continue python ros node.

```
pdb)  continue
```


* If you need symbol file,.
https://stackoverflow.com/questions/20380204/how-to-load-multiple-symbol-files-in-gdb

```
gdb) add-symbol-file filename address
```

Thursday, August 10, 2017

3D Vision geometry course

https://www.coursera.org/learn/robotics-perception/lecture/yuawM/bundle-adjustment-iii

Friday, July 14, 2017

Thursday, June 8, 2017

boostpython at ros

https://github.com/luator/boost_python_catkin_example

Sunday, April 23, 2017

Installing ubuntu on Legion Y520

This is a review for how I install ubuntu and drivers on Legion Y520.
  • Ubuntu 
    • On my case, I installed ubuntu 16.04
  • Kernel upgarde for latest version
  • Nvidia graphic card driver 
    • For GTX1050(Ti)
  • Solution for missing wireless connection

1. Install ubuntu with usb boot disk .
https://www.ubuntu.com/download/desktop/create-a-usb-stick-on-ubuntu

2. Fix missing wireless connection
Thanks for https://askubuntu.com/questions/587743/wifi-hard-blocked/587760

When Install ubuntu  16.04 LTS at Legion Y520, OS can't detect wifi.
To fix this, just command

$ sudo tee /etc/modprobe.d/ideapad.conf <<< "blacklist ideapad_laptop"
and then reboot.



Before do that, "rfkill list" shows Wireless LAN hard blocked: Yes.
But after rebooting, no more hard block and no more problem with wifi.


That's all. Missing Wifi is fixed with just two commands.


3. Install nvidia driver (Update on 2018/ 4/ 17. Thanks to Leonardo Gonzales for comment.)


After connect internet (wifi or with ethernet wire), type following command

$ software-properties-gtk --open-tab=4

And select nvidia driver as follow.



This is also solution for freezing when shutdown/reboot/restart ubuntu 16.04.4.
When you try to shutdown ubuntu on cui-mode (ctrl+alt+f1), if you see message including "nouveau drm failed to idle channel ~~", then just installing nvidia driver instead of using xorg will solve your problem.

https://askubuntu.com/questions/600467/blackscreen-failed-to-idle-channel


Wednesday, March 29, 2017

CNN

http://cs231n.github.io/convolutional-networks/

vggnet : https://www.slideshare.net/ckmarkohchang/applied-deep-learning-1103-convolutional-neural-networks

http://mourafiq.com/2016/08/10/playing-with-convolutions-in-tensorflow.html

faster - rcnn :
https://leonardoaraujosantos.gitbooks.io/artificial-inteligence/content/object_localization_and_detection.html

https://adeshpande3.github.io/adeshpande3.github.io/The-9-Deep-Learning-Papers-You-Need-To-Know-About.html

구글 강좌
https://www.youtube.com/watch?v=eBbEDRsCmv4

opencv - python - ml tutorial

http://docs.opencv.org/trunk/d6/de2/tutorial_py_table_of_contents_ml.html

p.s SVM scoring : http://mccormickml.com/2013/04/16/trivial-svm-example/

Wednesday, March 15, 2017

개발환경 설정

0) 듀얼부팅 설치
https://www.lifewire.com/ultimate-windows-7-ubuntu-linux-dual-boot-guide-2200653

윈도우 설치 -> 제어판, 관리자 설정 , 디스크 관리자, 볼륨 축소 (미지정 공간 확보)
우분투 설치 -> 빈공간 볼륨에 +버튼 파티션 추가로 우분투 설치.

0) 우분투 verbose boot
https://askubuntu.com/questions/615397/no-verbose-output-on-startup-after-upgrade-to-15-04

$ sudo vim /etc/default/grub
파일 내에서,.
GRUB_TIMEOUT=   # 시간 단축 지정.
# GRUB_CMDLINE_LINUX_DEFAULT="quite splash" # 주석처리. 삭제.

터미널에서 다시
$ sudo update-grub
$ sudo reboot

1) 멀티부팅 실패 문제
http://askubuntu.com/questions/371559/grub-not-showing-on-startup-for-windows-8-1-ubuntu-13-10-dual-boot

윈도우 실행 후, 관리자 권한으로 실행한 command 창에서
bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi
입력.
우분투에서 sudo update-grub을 실행하면 grub2가 다른 디스크 파티션에 설치된 윈도우를 발견,
이후 부팅시에 grub2에서 윈도우 진입 가능함.

TODO : 나는 각 os를 다른 하드디스크에 설치해서, grub에서 진입 안될때, 부팅디스크를 bios에서 지정해서 진입이 가능했지만, 그게 안되서 아예 윈도우를 실행 못하면, 어떻게 해결할지 아직 모름.


3) 우분투 설치후 세팅
sudoer 사용자 추가
https://askubuntu.com/questions/7477/how-can-i-add-a-new-user-as-sudoer-using-the-command-line
$ sudo adduser <username> sudo


 3-1)  SSH

``` 서버
$ sudo apt-get install openssh-server
$ sudo vim /etc/ssh/sshd_config
```

Port 1234                                  # Port 에 사용할 port 지정

``` 클라이언트
$ ssh-keygen
$ ssh-copy-id -i ~/.ssh/id_rsa.pub USER_ID@SERVER_IP -p PORTNUM
```
공개키를 서버에 복사한 다음, 서버의 /etc/ssh/sshd_config 파일에서

PubkeyAuthentication yes        # 공개키 접속만 허용. 보안강화.
PasswordAuthentication no


```서버
$ sudo systemctl daemon-reload              # systemd 의 daemon 설정 불러오기
$ sudo systemctl enable ssh.service         # 앞으로 재부팅시 자동으로
$ sudo systemctl start ssh.service            # 재부팅 없이, 지금당장
$ sudo systemctl status ssh                      # ssh 상태 확인
$ ps -ef | grep ssh                                     # 프로세스 확인
```

3-2) VNC

``` 서버
$ sudo apt-get install x11vnc
$ sudo su
root$ x11vnc -storepasswd          # vnc login passwd. passwd 파일 경로가 service에 작성하는 passwd 경로와 같아야함.
ctrl+D
$ x11vnc -rfb 1235                 # rfb 포트 지정해서 실행$ sudo vim /lib/systemd/system/x11vnc.service
```
[Unit]
Description= 
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /root/.vnc/passwd -rfbport PORTNUM -shared# vnc의 default port 5900은 방화벽으로 막고, ssh 터널을 통한, loalhost 접근만 허용한다.
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /root/.vnc/passwd -localhost -shared

[Install]
WantedBy=multi-user.target

``` 서버
$ sudo systemctl daemon-reload              # systemd 의 daemon 설정 불러오기
$ sudo systemctl enable x11vnc.service  # 앞으로 재부팅시 자동으로 x11vnc service 시작
$ sudo systemctl start x11vnc.service      # 재부팅 없이, 지금당장 x11vnc service 시작
```


``` 클라이언트
$ sudo apt-get install
$ sudo apt-get install openjdk-8-jre
$ sudo apt-get install tightvnc-java
$ jtightvncviewer SERVER_IP::RFBPORT_NUM

# 클라이언트 terminal 1 (클라이언트 포트 5903과 서버의 포트 5900을 연결.)
$ ssh -gL 5903:localhost:5900 username@server_ip -p server_ssh_port

# 클라이언트 terminal 2
$ jtightvncviewer localhost::5903
```

터미널1,2의 localhost는 다른 변수가 아니라, 글자 localhost 그대로 쓴다.

4) 한글설정
14.04   settings -> langauges -> update. $ setup-ibus add hangul
16.04
$ sudo apt install fcitx-hangul
system setting -> language -> keyboard input method system -> fcitx
system setting -> text entry -> Hangul

5-1) git 설치
$ sudo apt install git
$ git config --global push.default matching
## 새로운 branch를 remote repository와 강제로 동기화 시키기 위해 필요!
## matching 대신 simple로 하면, 깜빡하고 포맷했다가 branch 를 통째로 날리는 참사 발생.

* Remote 저장소에 특정 branch를 올리려고하면
*  git push -u origin [some_branch]

5-2) vim + plugin 설치-------------------------------

YouCompleteMe 설치를 고려하고 있으므로,
https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source
에서 언급한것과 같이 기존 vim을 모두 제거(제거방법은 위 링크에서 참고)하고, 직접 vim을 빌드한다.

$sudo apt install libncurses5-dev libgnome2-dev libgnomeui-dev \
    libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
    libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
    python3-dev ruby-dev lua5.1 lua5.1-dev libperl-dev git
$cd ~
$git clone https://github.com/vim/vim.git


클립보드도 사용하려하므로 (http://stackoverflow.com/questions/11416069/compile-vim-with-clipboard-and-xterm)
$sudo apt install libxtst-dev

$cd vim
$./configure --with-features=huge \
--enable-fail-if-missing \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-pythoninterp=yes \
--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-gui=gtk2 \
--enable-cscope --prefix=/usr/local\

( 아래 취소선 옵션은 이제는 안씀. 파이썬 2, 3 충돌일으키므로.
            --enable-python3interp=yes \
            --with-python3-config-dir=/usr/lib/python3.5/config \ )

# make install 대신 checkinstall 호출가능. uninstall이 쉬워짐. 나는 잘안되서 포기.

  • $ sudo apt install checkinstall$cd ~/vim
  • $ sudo checkinstall

# 위에 방법대신 나는 그냥 make install 사용

  • $ sudo make install

기본 에디터 지정
sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim 1 && \
sudo update-alternatives --set editor /usr/bin/vim && \
sudo update-alternatives --install /usr/bin/vi vi /usr/bin/vim 1 && \
sudo update-alternatives --set vi /usr/bin/vim

# python 2, python 3 지원여부 확인.  그런데, 'wiki - Building-Vim-from-source'에 의하면, 이젠 하나만 지원되도 작동한다고 함.
$vim --version

$cd ~ && mkdir -p .vim/bundle
$cd ~/.vim/bundle && git clone https://github.com/VundleVim/Vundle.vim.git
$sudo apt install exuberant-ctags # for taglist

$cd ~/.vim
$mkdir colors
*molokai.vim at colors
https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim

$vim ~/.vimrc


아래 옵션을 적어 vundle 플러그인 패키지 관리 툴이 작동하게끔 해준다.
"plugin
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#rc()
Plugin 'gmarik/Vundle.vim'

이후 플러그인들은 사용할 플러그인들을 골라서 추가해주면됨. 그중 ycm과 Ultisnips의 옵션은

let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
을 추가로 적어야 된다. (작성순서 무관)

Plugin 'Valloric/YouCompleteMe'
Plugin 'SirVer/ultisnips'

을 추가한다음 vim을 종료한다.
$ vim +PluginInstall
bundle이 플러그인들을 자동으로 인스톨(= git clone 소스코드 다운로드) 해주고있다. 
YCM(YouCompleteMe)는 추가적으로 설치 필요

$ cd ~/.vim/bundle/YouCompleteMe
$ sudo apt install cmake
$ ./install.py --clang-completer

$ vim ~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py
파일 내에서, 빨간색과 같이 경로 추가.
compilation_database_folder = '${user계정에 해당하는 절대경로}/.vim/'  # .vim 폴더의 절대경로가 맞기만 하면됨. ~  명령어는 인식이 안되는듯함.

Eigen3는 compile_commands.json 으로부터 파싱이 잘 안되던데, .ycm_extra_conf.py의
flags 리스트에 '-isystem','/usr/include/eigen3' 를 추가해주면 자동완성이 잘됨.

* 주의 : import cv2; cv2.imr 에서 자동완성이 안되는데
pip3로 opencv설치해서 해결.(https://github.com/ycm-core/YouCompleteMe/issues/3418)
$sudo pip3 install opencv-python

이는 ~/.vimrc에 아래 문장 추가하면서 해결함.
let g:ycm_python_binary_path = '/usr/bin/python2.7' "python 3에서 실행시킬 코드면 그에 맞게..
* 단, 이것만 추가하면 되는지, 아니면 sudo apt install clang후 컴파일, sudo pip install jedi 도 추가도 필요한건지는 모르겠음. 다음 포맷때 이것들 없이 재실험
* python2.7에서 import cv2 가 실행 안되는데, 즉 opencv 설치안됬는데 시도해봤자, 당연히 실행안됨. 설치됬는지부터 확인


Ycm 사용법
  • 파이썬은 그냥 쓰면되고, c/c++의 경우 cmake에서 -DCMAKE_COMPILE_COMMANDS=On 옵션을 추가해서 compile_commands.json이 생성되게 한다음, 이 파일을 compilation_database_folder 경로로 지정한 '~/.vim'에 복사해주면 된다. YCM은 c/c++에 대해서 compile_commands.json을 파싱해서 작동하므로 경로를 지정 안해주면 작동 안함을 주의.
    • 나는 매번 빌드때마다 작업해주는게 귀찮아서 bash파일로 해당 명령을 적어두고 씀.
이상 5) vim 설치 끝 ------------------

6) cuda 설치
텐서플로우는 현재 cuda 8.0 toolkit에서 성능이 가장 잘나온다. (https://www.tensorflow.org/install/install_linux)

하드웨어의 cuda 지원 여부 확인
http://haanjack.github.io/cuda/2016-02-29-cuda-linux/ 드라이버 cuda 지원문제
https://developer.nvidia.com/cuda-gpus https://devtalk.nvidia.com/default/topic/982791/gtx-1050-ti-do-not-support-cuda-/

nvidia에서 cuda를 다운로드 받는다. (시간이 오래소요되니 미리 다운로드 받아둘것)
https://developer.nvidia.com/cuda-downloads
$ sudo dpkg -i cuda-repo-*.deb # 해당 deb파일
$ sudo apt update

cui모드(ctrl+alt+f1)에서
$ sudo service lightdm stop
$ sudo apt install nvidia-smi
# 이러면 알아서 적당한버전, 18/3/21에는 nvidia-384 로 설치해줌.

libEGl 이 시뮬링크가 아니라고 에러 발생하는경우.

https://stackoverflow.com/questions/43016255/libegl-so-1-is-not-a-symbolic-link

$ sudo reboot


$ sudo apt install cuda-8-0
$ sudo reboot

설치후 .bashrc에 환경변수 지정 추가.
$ vim ~/.bashrc
파일 마지막에 (사실 어디에 적어도 상관없으나, 찾기 쉽기 위해서) 다음 문장 추가.
아래와 같이 경로를 추가할때 실제로 해당 디렉토리가 있는지 확인정도는 해줄것.

export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH


LD_LIBRARY_PATH는
$ldd some_executable
$ldd some_lib.so

에서 의존하는 shared 라이브러리를 찾아볼 경로가 된다.

cuda 다음으로 cuDNN(https://developer.nvidia.com/cudnn)을 설치한다.
텐서플로우가 언급한((https://www.tensorflow.org/install/install_linux) cunDNN5.1  Runtime과 Developer 다운로드 및 설치. (텐서플로우 업데이트에 따라 버전 확인 필요해보임)
$sudo dpkg -i libcudnn5_5.1.10*.deb # runtime 먼저.
$sudo dpkg -i libcudnn5-dev_*.deb
설치여부 확인
$ldconfig -p | grep cudnn


$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt install nvidia-387 nvidia-387-dev
$ sudo reboot
$ sudo nvidia-smi


7) 텐서플로우 설치
텐서플로우 설치전 주의사항
  • 우선 gcc 버전을 정할것.
    • 내 경우에는 텐서플로우와 opencv를 한 프로젝트에서 사용하는데, opencv는 gcc 5에서만 컴파일 가능? 서로 다른 major 버전의 gcc에서 컴파일된 cv2 모듈과 tensorflow 모듈이 한 프로그램에서 사용되면 segment fault error를 일으키므로 pip 모듈들을 설치하기전에 gcc 버전을 통일해두는게 이롭다.
      $ gcc --version
      $ g++ --version
      모두 major version이 5이면 문제 없다. (우분투 16.04 LTS의 default 컴파일러가 5라 문제없음. 16.10 이후에는 6이 default라 gcc-5, g++5를 설치하고  update-alternatives 명령어를 이용해 기본 gcc, g++을 5로 지정해주어야 한다.)
    • 어쩌면 cmake {opencv}  에서 아래 옵션(CUDA_HOST_COMPILER)만 바꿔주면 gcc 6에서도 문제없이 될지도 모르겠다. 시도는 안해봐서 모름.
  • pip 명령어를 이용한 패키지 설치.
    다른 라이브러리는 에러메시지 보면서 pip 로 디폴트 버전의 패키지를 설치하면 되지만, protobuf만은 따로 텐서플로우가 권장하는 방식대로 storage를 지정해서 설치해야한다. 10배에서 50배는 느려지므로 지시대로 설치해야함. https://www.tensorflow.org/install/install_linux#protobuf_pip_package_31
    • $ sudo pip install --upgrade pip && \
      sudo pip install --upgrade \ pip install --upgrade \ https://storage.googleapis.com/tensorflow/linux/cpu/protobuf-3.1.0-cp27-none-linux_x86_64.whl
  • 프로세스를 지원하지 않는 kernel에서는 tensorflow가 특히 느려진다. kernel이 적절한 버전으로 업그레이드 되있는지 확인 필요. 특히 Ryzen 의 경우 linux kernel 4.10 이후에나 지원되므로 주의.


텐서플로우 설치
마지막 {TF_URL} 의 실제값은 다음 메뉴얼 읽어보고, 개발환경에 맞는 주소 지정 : https://www.tensorflow.org/install/install_linux#TF_PYTHON_URL

$ sudo apt install libcupti-dev python-pip python-dev && \
sudo pip install --upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl


텐서플로우 설치여부 확인
$ python
>>> import tensorflow as tf

8) qt5 + opencv + Sophus + boost 등 개발관련 라이브러리 설치
sudo apt install qtbase5-dev libeigen3-dev libboost-all-dev
cd ~/ws/
git clone https://github.com/opencv/opencv.git
git clone https://github.com/strasdat/Sophus.git
cd opencv
ccmake -DCMAKE_BUILD_TYPE=Release ..
cp ~/ws/directmethod/directmethod/cmake/SophusConfig.cmake.in ~/ws/Sophus/ ## Let FindPackage(Sophus) work.
* with Qt 설정 후 빌드.

8) WOL 설정
WOL  (Wake on LAN,  대기전력으로 켜져있는 LAN카드를 이용한 원격부팅)
BIOS -> (MSI 기준)
setting-> advanced -> LAN option ROM -> Network boot Enable  (reboot 필요?)
setting-> advanced -> Wake up Event setup -> Resume by PCI-E device

우분투에서의 WOL 실행
$ powerwake -m wol xxx.xxx.xxx.xxx #ip 주소를 이용한 부팅
$ powerwake xx:xx:xx: ...  #MAC 주소를 이용한 부팅


9) 기타 개발환경 설정관련, 개인적인 노트용.

faster rcnn, compile issue
https://github.com/smallcorgi/Faster-RCNN_TF/issues/50

tegra-tx2 개발환경설정??
https://github.com/tensorflow/tensorflow/issues/5179
llvm 설치및 upgrade한 다음, tf를 컴파일하면 되나? 모르겟음.

파이썬 개발환경 안전하게 분리, 가상화
http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/

$ sudo apt install pkg-config # 종종 사용함

베드섹터 체크
$ sudo badblocks -n /dev/sdx

# vsftpd, ftp 서버 설정 및 사용법 ---------------------------------------------------ㄱ
$ sudo apt install vsftpd
$ sudo vim /etc/vsftpd.conf
listen=YES
listen_port=$DESIRED_PORT
port_enable=YES
ftp_data_port=$DESIRED_DATA_PORT # it should be different with $DESIRED_PORT
listen_ipv6=NO
write_enable=YES
$ man vsftpd.conf # reference, manual

# ip 접속제한
$ vim /etc/hosts.allow
vsftpd:123.456.789.1 123.456.789.2
$ vim /etc/hosts.deny
vsftpd: ALL

$ sudo service vsftpd restart

이상 서버에서의 세팅,
이하는 클라이언트에서 접속
방법 1) 그냥 ftp 
$ sudo apt install ftp                               # ftp 클라이언트
$ ftp 123.456.789.012 $DESIRED_PORT     # 접속후, ls 등의 명령은 passive 모드로 변환해야 가능.
ftp> pass

* mput 명령어가 다음과 같이 실패하는 경우
00 PORT command successful. Consider using PASV. 
553 Could not create file.


ftp 접속전, pwd가 업로드 하려는 파일이 있는 디렉토리가 되도록 이동한 다음, ftp에 접속해서 파일 업로드. (http://www.linuxquestions.org/questions/linux-newbie-8/ftp-error-553-could-not-create-file-4175446865/)

방법 2) ncftp
그냥 ftp 보다 이쪽이 좀더 편해보임. recursive upload 옵션도 있고, 업로드 진행사항도 표시해줌.

$ sudo apt install ncftp
$ ncftp -u $ID -P $DESIRED_PORT $IP_ADDRESS 
$ >> get -R some_folder # or
   >> get -T some_folder # to download

ㄴ---------------------------------------------------------------------------------------------

ROS master/slave 설정
master의 .bashrc에서 환경변수 지정

tmp=$(hostname -I)
export ROS_IP=${tmp%% *} # master의 환경변수 ROS_IP에 master의 ip주소 설정

slave 컴퓨터의 .bashrc에서는
export ROS_MASTER_URI=http://${IP_OF_MASTER_PC}:11311

링크 깨진 파일 찾기, 삭제 :
$ symlinks ./
$ symlinks -d ./



키보드 비활성화
https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard

$ xinput list # tranlated keyboard id 찾기
$ xinput float ${id} #비활성화
$ xinput reattach ${id} # 활성화


dependency lib install
sudo apt -f install
(https://flight-manual.atom.io/getting-started/sections/installing-atom/)


가젯(메모리/터치패드 비활성화)
https://www.howtogeek.com/118908/10-awesome-indicator-applets-for-ubuntus-unity-desktop/

Wednesday, March 8, 2017

Linux shared library dependency check

http://stackoverflow.com/questions/2991572/linux-shared-library-that-uses-a-shared-library-undefined-symbol

Friday, February 17, 2017

Installing Find*.cmake

On terminal $cmake --find-package then error message show where is the directory with error message, cmake looking for search Find*.cmake. On my case /usr/share/cmake-2.8/Modules/. then copy the FindMyLibrary.cmake to there. $sudo cp FindMyLibrary /usr/share/cmake-2.8/Modules/ Then, find_package(MyLibrary REQUIRED) will work.