Archive

Author Archive

饭否博客导入测试

December 2nd, 2011 2 comments

这是饭否blog测试测试

 

所以啦。。一会就删 了。。。

Categories: Other Tags:

21, only half of everything

November 1st, 2011 12 comments

这篇文章在我20岁时就已经在draft里,可是一直没有写出来,现在改成21岁生日小记吧

好久没有写了,不代表我忘了这个地方,服务器总是要用的,不是在写blog,就是有更重要的用途

记得去年和6系师兄一起调程序到深夜,看着他申请就想到一年后的自己,忽然一年就这么过去,他已经毕业,突然得知送他走时,心里各种滋味,这一年对他来说,对我来说又是什么呢,人生中一年很多,很多都被淡忘,然而,这一年却每一天都充斥在我心中的,是一种无法释怀与忘记的感觉。

记得去年的生日,我在WC里想着什么呢,20岁,什么都没固定,未来,是飘渺,就这样,我过完了20岁,觉得未来很大,人生很长,奋斗也才刚开始。当时,饭否还没有归来,我还在推上活跃,还在嘀咕上只fo了xbq,围观1000+fo的人,当时也有半年了,只fo了她一个人,其中也间或有几个人fo我,因为想做为一个秘密的吐槽场所,于是也就没有回fo了。

上天注定不会让我孤独,在2010-11-11号,这个日期,很特殊的日期,出现一个人,我不知道她为什么要fo我,我也不知道为什么会fo她,她居然还是加密的信息,要是普通时候,不管你加密不加密,我都不会回fo。或许是总fo一个人没意思了,也想加入新鲜的事情,或许是命中注定,我点了回fo,我不知道这意味着什么,后面的事情会告诉我一切的答案。

开始fo时讲了2句话,看到她的TOEFL书(这本书已经在我手里啦^o^),表示也在看TOEFL,同讨厌班级活动,就这样过了20多天,到12-02,转发了一条消息,得知她也有豆瓣,饭否等等,无聊就顺手搜了下豆瓣,然后她问我qq呢,我表示搜不到,她给我了。当时我称自己为清心寡欲,生活就是如此平淡,有点小惊喜,但并无大波澜,我也不期待什么。当时正是班级组织聚餐,我表示无聊,和她说着这些事。然后的然后,事情的发展出乎我们的意料,每天都会不停的聊天,仿佛有说不完的话,是另一个自己,共鸣。

巧合与注定,如果我像以前一样,不fo她,如果不转发那条消息,如果我不去人肉她豆瓣,如果她不给我qq,如果当时不是我讨厌的班级活动,或许一切都不会发生,但是一切又都是注定的。或许吧,即使这些事不发生,该认识的还是要认识,该在一起的还是要在一起,命运,就是如此吧。

To be continued

PS. Do you know what the title means? :P

Categories: Thinking Tags: , , , , ,

A Primitive Thought on Heterogeneous and Many Core Architecture

November 23rd, 2010 3 comments

Several years ago, when Intel tried to increase CPU frequency over 4GHz, some obstacles encountered. The main problem is that power and temperature increase rapidly. The commonly used air/fan cooling does not work. It is not feasible to force desktop computer users to use air-conditioner or water cooling to cool down CPU. To overcome this obstacle, Intel integrates more cores on one die. If two or more cores work together, workload of every core is decline thereby the frequency is down.

Figure 1: Performance and Application range

This method works well now. But it is not the final solution. Current commodity computers have to address more complex situations. Even if we integrate loads of same type of cores together, applications beyond center of normal distribution still cannot have a good performance (Figure 1, Red curve). This is the shortage of homogeneous architecture. We can see that different processors are suitable for different situations. Such as: CPU for common computation, GPU for graph processing. What if we combine different type of processors together? The answer is yellow curve in figure 1. Each processor has high throughput in particular area(Blue curves in figure 1). When they are united, application range is wider and performance is higher. Heterogeneous architecture is indubitable more competitive than homogeneous in multi-core design.

A professor from Technion gave us a primitive thought on heterogeneous architecture last Monday in Tsinghua University. The main points are: cache/share memory design, multi-core or multi-thread and scheduling in operating system.

Figure 2: City of Nahalal

Figure 3: circular cache/share memory

Previously we put core and share memory in separate place. However, it is not a good way to place cores together in multi-core architecture design. If a core wants to access data far from it (that means data has to go through more nodes between cores), that needs lots of time. A brilliant idea comes from a city named Nahalal (Figure 2). In Nahalal, factories and products serve in the middle of city. Residents live around center of city. They have their own farms around their house. The share memory in computer is like products in Nahalal. Every core needs it. And every core has its own private data which is similar to farms around house. A new model is proposed as figure 3.

With this kind of memory location, each core accesses data in share memory easily and private data area gives them more flexibility.

Figure 4: Performance and core number

The second is about multi-core and multi-thread selection. The difference between multi-core and multi-thread, in short, is that the former has shared cache but the latter doesn’t have. Multi-thread only uses private data and its own status register to maintain data and status. Multi-thread is a form of many cores. As shown in figure 4, when core number increase, performance first increases and then decreases. At last, performance increases again. There are three distinct stages in this curve. In the first stage, performance increase as core number increases. This is normal situation. But at some point, when we increase core number, locality of cache cannot be guaranteed. Cache is useless thus performance declines. This is the second stage of curve. At last stage, core number is large enough to conceal memory request latency so that performance increases again. A better way to solve performance loosing in the second stage is changing cache to share memory at the beginning of it.

The last thing is about process scheduling in operating system level. I didn’t catch the point, nothing to say. :)

给 @milandroid 上一堂课-8086使用偏移(分段管理)原因

October 16th, 2010 2 comments

呃,原来本来只想写后面副标题的,后来题目被 milandroid 提议, 然后就这样吧,上课这词用得太大了。

milandroid 说8086为什么有移4位那什么的,下午和她说了下,感觉说快了,不一定懂,后来自己理了下本来想写点简明的易理解文字发过去,結果写了好多,就发上来吧,正好已经好久没看这东西。。不过CSIC指令集的寻址方式真的好多。

以下是原文:

20位,每位就是0/1如下
19 18 17 16———> 1 0
0000 0000 0000 0000 0000

而因为8086是16位的处理器,所以一个寄存器只能存储16个2进制即上面的0-15位,所以用一种算法来表示20位,这是种类似一个只能存2位数的东西想表示234一样,一个存20,一个存34,最后用 20*10+34来表示 (总感觉这例子哪有问题,果然是,该是一个存2,一个存34,然后是2*100+34,相当于左移2位,而不是上面那组合)

而存20(2)的东西,在8086里面就是DS,然后用[34]来表示这个东西需要用DS*10+34来表示,当然如果AX=34,可以 用[AX]表示同样的东西

所以,如果转到2进制上,就是想表示1011 0111 1111 0001 0101
就是 1011 0111 1111 0001 * 10000 + 0101

这个东西太长,习惯上用16进制表示, 这个转成16进制表示法就是 B7F1 * 10 + 5 ,注意10是指16进制的10,10进制时为16,如果上面表达式按10进制为:47089 * 16 + 5
DS = B7F1 AX = 5
MOV BX, [AX] 就把B7F15地址的东西复制到BX里了。

注意,关于转换16-2转换以下东西需要知道
a. 16进制与2进制的对应
16 2
1 0001
2 0010
3 0011
4 0100
. ……….
. ………
. ……..
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
10 10000
A-F分别代表10进制的10-15,注意,16进制的10代表10进制的16

b. 16进制与2进制转化
2进制从低位起每4位可以转成一个16进制,比如
11 1011 = 0011 1011 = 3B
所以1011 0111 1111 0001 0101
就是B—–7—–F—-1—–5—-

P.S. 既然一个寄存器只能有16bit,那为什么要搞这么复杂非要来表示20bit呢?因为16bit能表示地址是2^16=64KB大小内存,而这显然太小了,于是设计了20bit的地址线,就有了2^20=1MB内存,所以~

–上篇文章提到的Truth and Faith 还没写好,中间先插一篇…

Categories: Architecture Tags: , ,

所谓”终极答案”

September 24th, 2010 8 comments

《霍金構思的宇宙》算是个科教片,还是很深击中内心。

霍金认为大爆炸之前时空并不存在,没有所谓的因果,讨论此前时间并无意义。作为一个所有规律都建立在观察的基础上的科学来说,确实,我们只是在讨论现在的宇宙,所谓的万有引力常数G只能说在这个宇宙是这个数,所有的规律亦如此。然而,实际问题在于,我上面说的可能是一种唯一的情况,亦即生命认识到的所谓规律该是如此,没有第二个G,或者说第二个G的宇宙存在概率为0亦或生命无法认知。这又引出一个新问题,是认识创造了这世界还是这世界导致了我们的认识?当然这问题引出了更复杂的东西,暂不去讨论。

作为爆炸之前的东西,所有现存的物理规律或常数全坍塌,作为一个没有理论基础支撑的东西,时间空间人类所有认知全不存在,这并不是有无意义,而是一个认知无法达到的地方,时间的经验?3维空间的经验?全不顶用。另一个问题是,认知有没有极限? 如果有,所谓未知给人类总带来恐怖;如果无,那么,我们需要的终极答案是什么? 可见,无这点是悖论,我们总无法认知到认知的极限这件事情。

真实是什么? 这几乎是我现在思想的阻碍,当谈到真实时,我根本没办法再想下去,我所认知到的世界是真实?不同人不同的活着的思想体系,他们的呢?人总会对自己世界产生怀疑,正如 Inception 里面女主,或许她回到了自己的真实世界,然而,对于不同梦境中的人来说,活在那里对他们自己来说也是一种真实。或者可以说一切都是虚幻,人生何不是虚幻一场,不管是在什么信念之下。正如那些信念和谐的人来说,这样活到死到不是什么事情,只是造梦者太离谱,梦该坍塌了。。这会在下一篇,Truth and Faith 里面再说。再一个问题:如果没有确实的真实,我们的认知意义在哪?

以上是自己很小或现在脑中的问题,以前和Yubei聊过,他认为所谓真正的做Research是研究终极的问题,比如我是谁之类。但是,所谓一个人,终究有被生活物质所困时刻,一个比较糟糕情况是,天天为明天吃饭钱还房钱担忧,希望我的物质足够我挥霍,去搞些无聊的事情,却是我认识对整个人类最有意义的事情。不要希望自己是那个人,那毕竟是天注少数。但是持续不断的想还是挺有意思的一件事情。 下面谈下与这个片有直接关系的东西。

如果时间放到宇宙这个级别上,那么,一切都会宽广起来,片中说如果今年发生核战毁灭地球概率是百万分之一,但放到宇宙时间呢?10万年就是十分之一,十分之一!多可怕的概率。视野开阔到这个级别,思想才会打开。正如人生规划,20岁的人,或许可以规划明天做什么,一周做什么,但一个月?一年?10年?30年?1代?2代?不敢想象,明天都管不好何谈这些。推上看到,当谈论到某事与过去对比时,人总是把思想局限在过去30年,当然我认为这是40岁的人才能做的,他们才有得记忆,20岁的人能与2000年左右比较就算很不错的事情。人的一生,对宇宙来说,如蜉蝣,我们所做得与应该做的,正如蜉蝣,在短暂一生里,做些对下代有用的事情,供上百万年后的人类(如果有的话)做所该做的。

在片中,更现实的问题,不是奇点前是什么——或许真是认知的极限,时空因果不存在,对于由因果来推理的人类无意义——而是宇宙为什么存在?爆炸的驱动与之后的宇宙的路,每想到这些,大脑就像撞到什么,感到无限阻力,不好受,我还是洗洗睡觉想想mm来得实际>_<。。。

PS: Catt 的 GF 分享了一个做红警磁暴线圈的过程,我说给我足够多时间与物质就可以去做,看完这个,发现,所谓足够多的时间与物质,宇宙,生命及一切都可以造出来了,人生如果无限长,看似一切都有解了(A Bunch of Rocks),惭愧。不过那个做磁暴线圈确实很诱惑,点这里:磁暴线圈啊啊 看制作过程= =

Categories: Thinking Tags: , , , ,

Eyes on me

September 15th, 2010 1 comment

依然经典-

Eyes On Me


Whenever sang my songs
On the stage, on my own
Whenever said my words
Wishing they would be heard
I saw you smiling at me
Was it real or just my fantasy
You’d always be there in the corner
Of this tiny little bar

My last night here for you
Same old songs, just once more
My last night here with You ?
Maybe yes, maybe no
I kind of liked it you’re your way
How you shyly placed your eyes on me
Oh, did you ever know ?
That I had mine on you

Darling, so there you are
With that look on your face
As if you’re never hurt
As if you’re never down
Shall I be the one for you
Who pinches you softly but sure
If frown is shown then
I will know that you are no dreamer

So let me come to you
Close as I wanted to be
Close enough for me
To feel your heart beating fast
And stay there as I whisper
How I loved your peaceful eyes on me
Did you ever know
That I had mine on you

Dailing, so share with me
Your love if you have enough
Your tears if you’re holding back
Or pain if that’s what it is
How can I let you know
I’m more than the dress and the voice
Just reach me out then
You will know that you’re not dreaming

Darling, so there you are
With that look on your face
As if you’re never hurt
As if you’re never down
Shall I be the one for you
Who pinches you softly but sure
If frown is shown then
I will know that you are no dreamer

Categories: Other Tags:

清华开会小结

September 7th, 2010 18 comments

下午去了清华和Steve, Yubei, Ming 开了一次会, 虽然很普通, 但是想法很多很多.

Yubei 作为一位强悍的美藉华人, 明显眼光不一样. 虽然同为大三, 但是差距巨大已完全不是一个层面上的了. 同时提到了周冬大神, 没想到, 高中OI之后居然还会与当年的OI大牛们有丁点交集.

Ming 6系的, 就感觉完全比我们系强一个等级, 他们学了好多. 我的模电没学, 数电虽然考得很高, 但实际呢, 我们系数电根本什么都没学嘛. 需要到其它系补一下这2门课的说.

和Ming吃饭时, 说到SRTP, 可以直接拿这边项目申请, 当然技术上没什么问题, 但是又说到了学校关系云云, 真是无奈, 再说吧.

需要做的事情:
1. GPGPU-Sim的代码需要通读
2. 认真读书(量化, OSC, etc)
3. 开始小准备TOEFL
4. 找机会补模电数电, 尽量吧
5. 数据统计看样还是少了不Matlab, Lennie 在上, 本来想去听, 被劝退. 可想我们学校的课, 有机会自学点就好了吧..

Actually, I am very afraid. When I talk to these ‘nubility’ people, I know I am nothing. Many things need to be done. Remember your goal, do real things!

Categories: Thinking Tags:

终端提示符的配置

August 9th, 2010 9 comments

原来一直对终端命令提示符感到不满, 默认就是没什么特别颜色, 想回去看命令时输出与命令混在一起, 一直以为是终端模拟器问题, 从gnome-terminal换成其它也一样, 后来发现这篇文章 <8个实用而有趣Bash命令提示行> #1(原文在此#2)原来是设置PS1变量的问题, 在~.bashrc 里面相应位置加入/换成如下代码:

1
2
3
4
5
6
7
8
if [ $color_prompt=yes ]; then
    PS1='\n\[\e[1;31m\][\w]\[\e[0m\] \[\e[1;35m\][ \[\e[1;36m\]$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed "s: ::g") files \[\e[1;33m\]$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed "s/total //")b\[\e[0m\] \[\e[1;35m\]]\n`a=$?;if [ $a -ne 0 ]; then echo -ne "\[\e[01;36;41m\]{$a}"; fi`\[\e[01;36m\][\t \u]\[\e[00m\] \[\e[01;34m\]\W`[[ -d .git ]] &amp;&amp; echo -ne "\[\e[33;40m\](branch:$(git branch | sed -e "/^ /d" -e "s/* \(.*\)/\1/"))\[\e[01;32m\]\[\e[00m\]"`\[\e[01;34m\] \$ \[\e[00m\]'
    # PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='\n[\w] [ $(/bin/ls -1 | /usr/bin/wc -l | /bin/sed "s: ::g") files $(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed "s/total //")b ]\n`a=$?;if [ $a -ne 0 ]; then echo -ne "{$a}"; fi`[\t \u] \W`[[ -d .git ]] &amp;&amp; echo -ne "(branch:$(git branch | sed -e "/^ /d" -e "s/* \(.*\)/\1/"))"` \$ '
    # PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt

效果如下:

其中, 为2行, 第一行2个中括号中间分别是 完整路径, 文件数(包括文件夹不含隐藏文件)与文件大小(不包括子文件夹的大小). 第二行是日期, 用户名, 当前文件夹, 如果是git目录话会加上branch信息(此处代码参考Ai.Freedom的文章#3), 然后是提示符, root为# 普通用户为$ 如图.

如果文章到此了, 你肯定自己抓狂不然就是想弄死我了… 因为提供的参考文章与此文都是不讲原理只有效果的. 那代码一坨在那,看着就想死. 而且自己无法定制. 然后经过这2天的乱搞, 终于理清如下:

1. 其实控制提示符变量不止PS1, 还有PS2, PS3, PS4 和PROMPT_COMMAND, 参见 #4
2. 引号内容主要为 命令行提示符的反斜杠转义字符 #5
3. 其中有许多 \e[31m \033[34;40;7m 这种抓狂的东西, 是很老的终端机VT100的转义符, 此网页#6最后有说明, 简要说明下就是 \e 与 \033 是一个东西, 都是Escape 033的8进制在ASCII里面代表ESC. 格式:"\033[字背景颜色;字体颜色m字符串" 来控制颜色,高亮等.

最后说一句, 代码对于可以用有颜色的终端与不能的 分别设了PS1, 对就then 与 else下的代码, else的代码用 正则替换then中等到, 表达式为:
\\\[.*?\\\]

References:

#1: 8个实用而有趣Bash命令提示行 http://coolshell.cn/?p=1399
#2: 8 Useful and Interesting Bash Prompts http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04
#3: Ai.Freedom的PS1的git配置 http://aifreedom.com/technology/155
#4: PS1, PS2, PS3..的说明 http://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/
#5: 命令行提示符的反斜杠转义字符 http://www.unixresources.net/linux/clf/newbie/archive/00/00/19/80/198022.html
#6: VT100终端控制序列 http://www.unixresources.net/linux/clf/newbie/archive/00/00/19/80/198022.html

Categories: Linux Tags: , , , , ,

超有爱的用notify-send提示(基于Wow!Ubuntu 命令修改)

August 7th, 2010 2 comments

Wow!Ubuntu 里面有个用notify-send 提示的小命令(点这儿查看), 但是比较单调, 其实之前看过一个用如 notify [command] 形式的(找不到但是>_<),写了下,把notify写成脚本, 但是感觉这样Gnome-terminal的自动补全与ls等的颜色会丢…于是感觉还是Wow!Ubuntu上更好用些. (使用前请看之前链接, 只是改了 alert 命令) 在.bashrc 里面加入(请先装 sudo apt-get install libnotify-bin )

1
2
3
4
5
6
7
8
9
10
alias alert_helper='history|tail -n1|sed -e "s/^\s*[0-9]\+\s*//" -e "s/;\s*alert$//"'
alias alert='
status=$?;
if [ $status = 0 ]; then
     notify-send -i /usr/share/icons/Breathe/scalable/status/dialog-information.svg "[$status] $(alert_helper) Finished ^_^" ;
elif [ $status = 127 ]; then
     notify-send -i /usr/share/icons/Breathe/scalable/status/dialog-question.svg "[$status] $(alert_helper) Command cannot be found ?_?" ;
else
     notify-send -i /usr/share/icons/Breathe/scalable/status/dialog-error.svg "[$status] $(alert_helper) Error &gt;_&lt;" ;
fi'

截图:
分别是成功\找不到命令\错误的命令的图

其中图标来自一个主题叫Breathe, 位置命令所示的地方,当然也可以自己改下. 文件在此下载: status.tar

Categories: Linux Tags: ,

CUDA深入浅出学习小结(1)

July 31st, 2010 No comments

平方和的并行计算
1. 直接分别使用CPU平方和, 一个Thread 一个Block的计算平方然后CPU计算平方和, 在10^7数据面前, CPU表示毫无压力(0cycle), 9600MGS惨不忍睹(多少cycles没记下)
2. 使用256个Threads后, GPU效率大大提升
3. 使用32blocks后, GPU再次提升效率
4. 此时已经有 32*256 = 8192 个线程在跑, 利用CPU计算和的时间被忽略造成不准确, 把计算和运算放在GPU中, 出现小幅性能下降
5. 计算sum可以并行化, 用树状图表示如下:

大意为第一次把1回到0上, 3加到2上, 因为所有线程都是要发起的, 对于判断哪些线程要执行加法很重要, 一个很简单想法是线程ID对offset的2倍取模看是否为0, 代码如下:

1
2
3
4
5
6
7
8
9
__syncthreads();  //make sure all threads are complete
extern __shared__ share[];
int offset=1
while( offset < THREADNUM ) //THREADNUM is the number of threads per block
{
    if ( threadIdx.x%(offset+offset)==0 )
        share[threadIdx.x] += share[threadIdx.x+offset];
    offset += offset
}

然而时间并没有减少, 发现取模运算太费神, 在深入浅出书上如此写

1
2
3
4
5
6
7
8
9
10
    __syncthreads(); 
    int offset = 1, mask = 1;
    while(offset < THREAD_NUM) { 
        if((tid & mask) == 0) {  // tid = threadIdx.x
            shared[tid] += shared[tid + offset]; 
        } 
        offset += offset; 
        mask = offset + mask; 
        __syncthreads(); 
    }

其中mask在里面的古怪作用正好使得結果如此…还是不太理解= =
6. 据说这方法会有问题..他说后面再说, 而采用另一种更简单方法, 大意是前半与后半相加不断递归…

1
2
3
4
5
6
7
8
    offset = THREAD_NUM >> 1; 
    while(offset > 0) { 
        if(tid < offset) {  //tid = threadIdx.x
            shared[tid] += shared[tid + offset]; 
        } 
        offset >>= 1; 
        __syncthreads(); 
    }

现在看求矩阵乘法了, cudaMemcpy 与 cudaMemcpy2D 区别还是没看懂… C语言2维数组与1维数组不是一样的…吗… int a[N*M] == int a[N][M] 那用cudaMemcpy 一下复制 N*M 不就得了…谁知道为何…