2017年2月14日 星期二

Nvidia driver install


  1. http://www.nvidia.com/Download/index.aspx
  2. sudo init 3
  3. sudo sh <filename>
  4. all choose yes
  5. check nvcc --version 
  6. check nvidia-smi

2016年3月7日 星期一

CentOS - Basic Command

  •  Add user
    Issue the useradd command to create a locked user account:
    useradd <username>

    Unlock the account by issuing the passwd command to assign a password and set password aging guidelines:
    passwd <username>
     
  • Rename a folder
    mv /home/user/oldname /home/user/newname

     
  • Mount
  1. get root
  2. mkdir /mnt/iso
  3.  mount -t iso9660 -o loop /home/tecmint/Fedora-18-i386-DVD.iso /mnt/iso/
  4. cd /mnt/iso
  5. ls -l
  • Unmount
  1. umount /mnt/iso
  • t : This argument is used to indicate the given filesystem type.
  • ISO 9660 : It describes standard and default filesystem structure to be used on CD/DVD ROMs.
  • -o : Options are necessary with a -o argument followed by a separated comma string of options.
  • loop: The loop device is a pseudo-device that often used for mounting CD/DVD ISO image and makes those files accessible as a block device.
 
  • Open PDF file
xdg-open install_guide.pdf
  • Change password
  1. must login as root user 
  2.  $ passwd (user's id)
  • Change sudo file
  • http://www.liquidweb.com/kb/how-to-add-a-user-and-grant-root-privileges-on-centos-6-5/

  • How to install gcc 

           https://www.vultr.com/docs/how-to-install-gcc-on-centos-6


  • Check hostname
         $ hostname

  • List all the user

           $ cut -d: -f1 /etc/passwd
  • VNC setting
VNC软件在Linux环境中可以使用文本模式进行配置,即可以用putty登录Linux,然后开启和关闭vnc,
在有图形界面的Terminal也可以这样配置。

这样做的好处是可以同时在putty(文本模式)和vnc(图形界面)中使用Linux,比较方便
另外,VNC会调用远程机器的GPU,而Windows的远程桌面无法启动GPU,因此当用到GPU时要用VNC(或向日葵)

具体操作如下:

1、用putty登录Linux,或在有图形界面的Linux中用Ctrl+Alt+T启动一个新的Terminal
      或者: 对于图形界面的Linux, 按CTRL+ALT+F1也可进入纯文本模式, 按CTRL+ALT+F7回到图形界面模式
2、安装VNC: 解压缩VNC安装包 (VNC-Server 通用版本就行了),然后执行 sudo ./vncinstall
3、输入license: sudo vnclicense -add license号码
4、启动VNC的Service方式(让VNC随机器一起启动,即变为Daemon守护进程):
     sudo /etc/init.d/vncserver-x11-serviced (start|stop)
     sudo update-rc.d vncserver-x11-serviced defaults
     然后重新启动计算机(sudo reboot)
5、用putty登录Linux,或在有图形界面的Linux中用Ctrl+Alt+T启动一个新的Terminal
6、测试vnc是否已成为守护进程:
      ps -A|grep "vnc"
      若有名称里包含vnc的进程出现,就证明成功了
7、启动一个VNC,可以指定编号和分辨率(能启动的个数受license的限制):
     vncserver :1 -geometry 1920x1080 (编号可以自己随便输入,分辨率要根据自己显示器的实际分辨率设置)
8、关闭一个VNC:
     vncserver -kill :X (X就是当初自己编的一个序号)     
9、实际用VNC Viewer远程访问时,输入"IP地址:编号",其中的编号就是刚才自己输入的编号,然后输入的用户名
     和密码就是linux用户名和密码(如果)

close x server
cd /tmp
ls -al
delete all .x log file   

2015年10月11日 星期日

C assignments in ARM instructions - (A+B)-C

This article is about how to translate basic operation from C code to ARM assembly code.
By doing this practice, you will understand some basic instructions, such as ADD, SUB, ADR, etc.

Background knowledge: Arm is a load-store architecture, which means data operands must be store in the register first. After the arithmetic, Stored back the result to main memory. ARM can be indirect addressing. 


So, let's translate it!
C code: x = (a +b) - c ;
The first thing we are going to do is getting the address of a, then ask a, "what's your value?"
And do the same thing to b and c.
The instruction we need is shown in the following chart.


ARM codemeaning
ADDadd
AUBsubstract
ADRSet register to address
LDR Load

Register is like a temporary house for "address" or "value" to live.
So if you want to store the data from memory, give them a temporary house, register.
There are four operands a, b, c and x. therefore, we need four registers to stored them. Let's say, r0 (register 0) for a, r1 (register 1) for b, r2 (register 2) for c,  r3 (register 3) for x.
We also need a register to store address which is reusable. Let's say r4 (register 4) for x.



1:  ADR r4,a          ; get address for a  
2:  LDR r0,[r4]       ; get value of a  
3:  ADR r4,b          ; get address for b, reusing r4  
4:  LDR r1,[r4]       ; load value of b  
5:  ADD r3,r0,r1      ; set intermediate result for x to a + b  
6:  ADR r4,c          ; get address for c  
7:  LDR r2,[r4]       ; get value of c  
8:  SUB r3,r3,r2      ; complete computation of x  
9:  ADR r4,x          ; get address for x  
10:  STR r3,[r4]      ; store x at proper location  


  • From line 1 to 4, 6, 7 is to get address from variable to register, and then get the value which is store in the address. 
  • Line 5 is arithmetically plus r0 and r1 and store in r3. Line 8 is similar to line5. 
  • Line 10 is a little different, because the destination register is the second one, [r4]. 
  • STR r3,[r4] would store the contents of r3 in the memory location whose address is given in r4.
Reference:
[1]computer as components 2nd addition.








2015年9月23日 星期三

Image Processing Tutorial-histogram & Canny’s edge detection


The mission is to practice using histogram function in MATLAB,
In this MATLAB code turorial, we choose a gray level Lena image. Of course, you can use any picture you want.

Here are three practices we are going to do
(a)     Compute and plot its histogram.
(b)     Apply histogram equalization to obtain a transformed image.
(c)      Apply Canny’s edge detection method to the given image (with two sigma
        values of the Gaussian filter) to show the two edge maps that you obtain.

Procedure:

Practice (a)
By using the function ‘imhist’, a histogram of Lena can be shown. This histogram shows that the image has dark pixel rather than bright pixel. And there is no extremely bright pixels shown in this picture. 
Practice (b)
By calling the function ‘histeq’, the original image is adjusted to the one with obvious contrast. There are more white pixels shown in the new image. Besides, it is easier to identify every single part from the new image.
Practice (c)
At first, we apply 2 kinds of Gaussian filters with different sigma to the image. And then use Canny’s edge detection method on them. According to the theory, the bigger the sigma, more blurred will be the image. And it is also validated by the result shown above. From the picture we can see that the image with lower sigma can be identified more boundaries and edges. The image with higher sigma cannot be detected much silhouette.

Let's see how do we complete it by useing Matlab :)
1:  %%     
2:  %%%%%%%%%%%%%%%%%%%%%%% (a)      Compute and plot its histogram.  %%%%%%%%%%%%%%%%%%%%%%%  
3:  im_GrayLena=imread('431.JPG');  % read image  
4:  %figure,imshow(im_GrayLena);       % show image  
5:  %title('gray Lena');           % imgae title gray_lena  
6:  twoD_Lena=rgb2gray(im_GrayLena);    %convert to 2D  
7:  figure,imhist(twoD_Lena);        % process histogram and show  
8:  title('Histogram of Lena')         
9:  xlabel('Grayvalue')  
10:  ylabel('Probality Of Occurence')  
11:  %%  
12:  %%%%%%%%%%%%%%%%%%%%%%% (b) Apply histogram equalization to obtain a transformed image. %%%%%%%%%%%%%%%%%%%%%%%  
13:  histeq_lena = histeq(twoD_Lena);    % histogram equalization   
14:  figure, imshow(histeq_lena)       % show image after histogram equalization   
15:  title('Lena after Equalization')         
16:  figure,imhist(histeq_lena);    
17:  title('Histogram of Lena after Equalization')  % Histogram of Lena after Equalization   
18:  xlabel('Grayvalue')  
19:  ylabel('Probality Of Occurence')  
20:  %%  
21:  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
22:  %%%%%%%%%%%%%%%%(c)Apply Canny’s edge detection method to the given image                  %%%%%%  
23:  %%%%%%%%%%%%%%%%  (with two sigma values of the Gaussian filter)to show the two edge maps that you obtain.%%%%%%  
24:  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
25:  I=twoD_Lena;  
26:  Iblur02 = imgaussfilt(I, 0.2);  
27:  figure,imshow(Iblur02);  
28:  title('Guassian Sigma=0.2');  
29:  BW_canny02=edge(Iblur02,'canny');  
30:  figure,imshow(BW_canny02);  
31:  title('Guassian&canny edge Sigma=0.2');  
32:  Iblur4 = imgaussfilt(I, 4);  
33:  figure,imshow(Iblur4);  
34:  title('Guassian Sigma=4');  
35:  BW_canny4=edge(Iblur4,'canny');  
36:  figure,imshow(BW_canny4);  
37:  title('Guassian&canny edge Sigma=4');  
38:  %figure;  
39:  %imshowpair(BW_canny1,BW_canny4, 'diff')  

The result is shown below





Please email me if you have any question
Email: HSC38@pitt.edu

2015年9月22日 星期二

2.2.2 Assembly language

下列的ARM code是一個最基礎的組合語言

label1     ADR r4,c            
               LDR r0,[r4]              ; a comment            
               ADR r4,d            
               LDR r1,[r4]            
               SUB r0,r0,r1            ; another comment

組合語言通常有以下的特徵

  • 一個指令一行
  • Labels, 通常在first column給memory loacation名字
  • 指令必須從second column或second column之後開始,才能區分跟Label的不同
組合語言通常follow這樣的結構,如此才能方邊一行一行的分析。



上圖是ARM data processing instruction ,這個例子是ADD

  這個指令 ADDGT r0,r3,#5


  • cond   會依照f GT   condition  (1100) 來設定[註1]
  • GT的意思是Greater than (signed). (Z==0) && (N==V)
  • opcode   會顯示二進制 ADD 指令 (0100
  • 第一個operand  register Rn  會被設為 3 來代表 r3 ,
  • destination register Rd  會被設為0 for r0
  • the operand 2  field 會被設為 immediate value of 5.[註2]






[註1]cond 就是 Condition codes透過查表(請搜尋關鍵字ARM Cortex­A Series Programmer’s Guide for ARMv8­A Version: 1.0)

[註2]Many ARM and Thumb general data processing instructions have a flexible second operand. This is shown as Operand2 in the descriptions of the syntax of each instruction.Operand2 can be a:constantregister with optional shift.


Reference:
[1]Computers as Components - Principles of Embedded Computing Sy
stem Design Ch.2

2015年9月21日 星期一

2.2.1Computer architecture taxonomy

了解microprocessors之前我們必須先知道instruction sets 書本上的定義是 the programmer’s interface to the hardware. The instruction set is the key to analyzing the performance  of  programs.


電腦最基本的架構是什麼?  下圖就是一個最基本電腦的架構(圖例為von Neumann architectures)



計算機系統架構有最基本的
1. central processing unit (CPU)
2. memory- 包含了data還有instructions,當給定記憶體位置時可以被read, write
當一個計算機系統的memory包含了data及instructions就稱為von Neumann  manchine

CPU有許多內部的佔存器可以存取值
其中一種暫存器-program counter (PC),稱為暫存器那他存什麼呢? 存指令的地址(address)
舉例來說: CPU從memory擷取指令,經過解碼,再執行他。program counter並沒有直接的決定反而是間接的告訴這台機器下一個指令是什麼。透過改變指令我們可以決定CPU的動作


其中另一種可以取代von Neumann style的是Harvard architecture(幾乎跟von Newmann一樣老)
下圖即為Harvard 架構

In Harvard architecture, we can see that it has separate memories for data and program.
那麼Harvard架構中的Program Counter要指到哪裡呢? 他是指到program memory而不是data memory. 因此在這種架構中很難寫self-modifying programs(programs 寫進data值然後直接把值當作instruction)





Reference:
[1]Computers as Components - Principles of Embedded Computing Sy
stem Design Ch.2