2020/12/26

cuDNN

cuDNN 下載頁面,會要求輸入,完成後,確認一些...
最後就會出現 cuda versio -- 對應的 cuDNN 版本的頁面。

所以 cuDNN 不能亂裝,跟 cuda 的版本有關。

像我的cuda 是 10.2,所以:
Download cuDNN v8.0.5 (November 9th, 2020), for CUDA 10.2
Library for Linux, Ubuntu(x86_64 & PPC architecture)
cuDNN Library for Linux (x86)
cuDNN Library for Linux(Power)
cuDNN Library for Windows10 (x86)
cuDNN Runtime Library for Ubuntu18.04 (Deb)
cuDNN Developer Library for Ubuntu18.04 (Deb)
cuDNN Code Samples and User Guide for Ubuntu18.04 (Deb)
cuDNN Runtime Library for Ubuntu16.04 (Deb)
cuDNN Developer Library for Ubuntu16.04 (Deb)
cuDNN Code Samples and User Guide for Ubuntu16.04 (Deb)
所以可以知道..cuda10.2 跟 cuDNN 只有 support 到 ubuntu 18.04
ubuntu20.04 要用 cuda11.x
要選下面:cuDNN Archive,才會有對應Cuda 版本跟各平台的 lib, sample dev 的 deb 可以下載。


下載了 runtime library 跟 developer library

然後下載畫面說,到install guide 去看 cuDNN 安裝說明。
其中 deb 的安裝...
2.3.2. Debian Installation
Before issuing the following commands, you'll need to replace x.x and 8.x.x.x with your specific CUDAand cuDNN versions and package date.

Procedure:

Navigate to your <cudnnpath> directory containing the cuDNN Debian file.

Install the runtime library, for example:

 $ sudo dpkg -i libcudnn8_x.x.x-1+cudax.x_amd64.deb

Install the developer library, for example:

 $ sudo dpkg -i libcudnn8-dev_8.x.x.x-1+cudax.x_amd64.deb

Install the code samples and the cuDNN library documentation, for example:

 $ sudo dpkg -i libcudnn8-samples_8.x.x.x-1+cudax.x_amd64.deb

安裝後,驗證測試的方法(一樣是cuDNN官網
Copy the cuDNN samples to a writable path.

 $cp -r /usr/src/cudnn_samples_v8/ $HOME

Go to the writable path.

 $ cd  $HOME/cudnn_samples_v8/mnistCUDNN

Compile the mnistCUDNN sample.
 
 $make clean && make

Run the mnistCUDNN sample.

 $ ./mnistCUDNN

If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:

 Test passed!
有一個 example 缺 freeimage,所以要 install : libfreeimage3 libfreeimage-dev

ubuntu 18.04 之後的 apt 已經support install local deb.
所以可以用 apt install ./xxx.deb 來安裝,然後一樣,用apt purge 來 remove

另外,caffe 只support cudnn7,用cudnn8 會build error..

2020/12/25

shell script 中處理字串的符號

字串處理、字串合併、字串大小寫轉換

#!/bin/bash
test="0123aabbcc!q1234.ww" 
filename="Jerry_20130731.tar.gz" 
echo "原始字串 $test" 
echo "取出字元位置 2 開始取 5 的字元 : ${test:2:5}" 
echo "尋找符合的字串 12 -> #*12 = ${test#*12}.... #*12 = ${test##*12}" 
echo "取出檔名 %%.* = ${filename%%.*} ... %.* = ${filename%.*}" 
echo "取出特定特徵 %%!q* = ${test%%!q*}" 
echo "取出特定特徵 ##*. = ${test##*.}" 
xcombine=${test%%!q*}"---"${test##*.} 
echo "字串合併 %%!q* + ##*. = $xcombine" 
echo "大小寫轉換"ABcD | tr [A-Z] [a-z]
執行的結果:

原始字串 0123aabbcc!q1234.ww
取出字元位置 2 開始取 5 個字元 : 23aab
尋找符合的字串 12 -> #*12 = 3aabbcc!q1234.ww.... #*12  = 34.ww
取出檔名 %%.* = Jerry_20130731 ... %.* = Jerry_20130731.tar
取出特定特徵 %%!q* = 0123aabbcc
取出特定特徵 ##*. = ww
字串合併 %%!q* + ##*. = 0123aabbcc---ww
大小寫轉換abcd

2020/12/15

GPIO, blocking read with poll.

ref:
sys 裡面的 gpio property 有一項:edge。
用來設定 interrupt
配合 poll( ) ,可以作到 blocking read,這樣就不用一直 read (polling)

gpio 的 edge 有以下幾個可以設:
  • rising
  • falling
  • both
  • none
對 edge 寫入這幾個以外的值,會回報 error

實測結果,falling 跟 both 的效果一樣。

設完之後,對 gpio 的 value 做 polling 舊可以。

就像這一篇 的說明一樣:
# echo 4      >/sys/class/gpio/export
# echo in     >/sys/class/gpio/gpio4/direction
# echo rising >/sys/class/gpio/gpio4/edge
然後舊可以 poll..

有幾項要注意:
  • 先 read 一次,把上次 trigger 的 event 清空,之後再 poll
  • poll 的 event 是 POLLPRI,不是 POLLIN
  • 要清除 event 要做 read,之前要先 seek 回 file begin

修改好,test OK 的 example 在

2020/12/4

ulimit, core dump and gdb

Black 教的。想不到,很古老以前就有了。

程式執行錯誤,core dump 時,會受dump file 大小限制。
這是 kernel 的 參數。
用 ulimit 可以列出一堆 kernel 參數。
其中 -c 就是 core dump 的 size limit
$ulimit -c
0
$ulimit -c unlimited
unlimited
-- 系統原來是 0 (不存 core dump file),改成 unlimited, 全部都存下來。

然後寫一個 會 core dump 的程式:
#include <stdio.h>
#include <stdlib.h>

int main()
{
   int *A = NULL;
   
   *A = 0x01;
   
   return 0;
}

compile with -g option (debug ON)..
gcc -g main.c
然後執行 a,out,產生 core dump..
之後,啟動 gdb 吃下 core dump file (core) 跟 執行檔(含 debug symbol):
gdb -c core a.out
...
..
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000aaaaac4a66f4 in main () at main.c:8
8		*A = 10;
會停在發生 core dump 的 code..
然後舊可以用 gdb command 來看 source (l), backstrace (bt), 看變數 (p *A)...

這個 core 跟平台有關,所以在 arm 上產生的 core file,拿到 x86 來看的畫,要用 cross-tool 的 arm gdb 來啟動。


一些 gdb 的操作

2020/12/2

Makefile = := ?=

這一篇 說的很仔細。

make 是先解析完整個 Makefile。
然後再去執行 target 的 rule。

所以變數的值就會隨著..解析的到的位置,rule 的時間,而不一樣。
這些 = := ?= 就是來決定變數要怎麼決定(什麼時間決定)內容。

=  解析中可以改變
:= 當下決定