用GPU加速拼音输入法?

看到IBM申请了用GPU加速数据库的专利,想起来自己之前还有过用GPU来加速拼音输入法的想法,当时写在了twitter上,幸亏当初有在google reader里订阅了twitter中有关sunpinyin的关键字搜索,否则还真翻不出来了呢…

Jun/16, 2011:

这几天我一直在想,能否用GPU来加速输入法,我可以把SunPinyin Syllable Graph的所有组合,发到GPU上去开足够多的线程做并行搜索,或者在做viterbi时,栅格间的状态节点转移,也可以放到GPU上来并行运算,可大幅度提高beem宽度… 个人倾向于第一种方式…

http://twitter.com/#!/yongsun/statuses/81130853278822400

当时还和熟悉GPU/OpenCL的@reminisce1989同学探讨来着,reminisce1989同学认为用GPU加速Graph算法是很困难的,不过后来reminisce1989同学好像删推了,没有原推可以refer了。

yongsun: @reminisce1989 @jjgod 既然是基础服务,肯定不能随便down掉,应该是可以想办法避免的… 我的想法主要是,现在sunpinyin的搜索规模还很小,不知道能否借助GPU来大幅提高搜索的规模,回头有问题还要向您请教了 :)

reminisce1989: @yongsun @jjgod 最后提醒一下,GPU是不支持指针的(或者说只能模拟指针)。而我不知道你的sunpinyin用的搜索是什么图算法。如果用到任何常规图论算法,不用说难用OpenCL之类的语言实现,实现了效率也提不上去,因为是非顺序化读取,而且还要考虑拷贝数据的时间。

后来,我仔细阅读了OpenGL的一些文章和书籍,觉得应该是有希望的,不过一直没有时间去做实验,先记录在这里吧…

bitcoin python OpenCL mining setup on Ubuntu 11.04

Credits: Thanks to Syke's article on forum.bitcoin.org!!!

0. Install Ubuntu/Drivers/APPSDK/pyopencl

  • Install Ubuntu 11.04 (desktop edition is recommended) on your disk, and install the 3rd party AMD/ATI graphic driver through "System->Administration->Additional Drivers".
  • $ sudo apt-get install python-pyopencl subversion git
  • Download AMD APP SDK for your platform (either 32bits or 64bits), and extracted to somewhere (referred as $SDK_HOME), remove the symbol link /usr/lib/libOpenCL.so (links to nvidia implementation), and cp the *.so files in $SDK_HOME/lib/x86 to /usr/lib; extract the $SDK_HOME/icd-registration.tgz archive, and copy the *.icd files to /etc/OpenCL/vendors.
  • if you have multiple GPU, run $ aticonfig --adapter=all --initial, and relogin, then run $SDK_HOME/bin/x86/clinfo, to check if you have all GPU recognized.

1. Install python-jsonrpc

  • $ svn checkout http://svn.json-rpc.org/trunk/python-jsonrpc
  • $ cd python-jsonrpc/
  • $ sudo python setup.py install

2. Retrieve and run poclbm mining scripts

  • $ git clone http://github.com/m0mchil/poclbm
  • $ cd poclbm
  • $ python poclbm.py -d 0 --user un --pass pw

3. aticonfig over ssh (the easiest way)

  • $ sudo apt-get install openssh-server
  • set autologin when you install/configure ubuntu gdm display manager
  • export DISPLAY=:0.0 after you connected to remote miner machine via ssh/telnet

4. Useful aticonfig commands

  • $ aticonfig --od-enable (enable overdrive)
  • $ aticonfig --odgc --adapter=all (get clocking information for all adapters)
  • $ aticonfig --odgt --adapter=all (get temperature for all adapters)
  • $ aticonfig --adapter=0 --pplib-cmd 'get fanspeed 0' (get speed of fan #0 on adapter #0)
  • $ aticonfig --odsc=950,1225 --adapter=1 (change the peak clock of adapter #1 to 950MHz)

5. Over-clocking with AMDOverdriveCtrl

  • Download and install the deb package here, and install depended wxgtk packages
  • $ AMDOverdriveCtrl -h (check which graphic card is active, and remember the index)
  • $ AMDOverdirveCtrl -i <card index> (you need to run it in native X11 environment), tune the parameters, and save it as default.
  • move the $HOME/.AMDOverdirveCtrl/default.ovdr to different location, then configure another card
  • add AMDOverdirveCtrl -b -i <card index> <profile_file> in your miner start script, note the profile_file must be in the current working directory.

Note: If you run the miner on multiple GPUs with overclocking, the master branch of poclbm seems not very stable as I experienced, the GPU stops to process anymore after running for a while, that I need a hard reset on my machine. Phoenix (though with poclbm kernel) seems much more stable, and comes up with better performance.