Thursday, February 21, 2013

PlayStation 4, With x86 Architecture and GDDR5

Playstation 4 is already unveiled and we're looking at a very fast and open system here. Seriously, I still remember playing Playstation 1 like it was yesterday. Oh wait, was it 10 years ago? Time flies, but technology flies damn faster.

Final Fantasy IX was my favorite game back then in PS1, and every time an FMV (a pre-rendered video happens in the middle of the game) showed up I'd go "Oh shit, so cooool!!" while jumping on my bed.  Well now, with this monster console, you'll be able to play the whole game as if it were an FMV. Oh no, does that mean I have to jump endlessly while playing the game?

Sony also took a big leap by moving from Power to x86 architecture. Most of home PCs out there use x86 architecture. So what does that mean? That means someday you might be able to make your own Playstation console games with your own computer now, without any virtualization whatsoever.

Well, if you are a game designer, get ready and fasten your seatbelt for a more competitive market. If you are a gamer, get ready for the new habit saying "Meh" to all the crappy games produced by new startups/game maker companies. Yes, just like what's happening now at the iOS and Android apps market.

According to this site, PS4 will be shipped with AMD APU -- most likely with a Jaguar core. Well I'm not that fond of AMD products so I'm gonna skip the part where I say "Intel's Ivy Bridge will definitely be far better on this machine". Ah damn, I just did it. Also according to the same site, the AMD cores are 1400% slower than an Intel's Ivy Bridge chip. What gives? But OK, I'm pretty sure Sony had their own reasons for this.

But anyway, I can't wait to get one and play around with it. Hurry up, Sony!

Saturday, July 21, 2012

Coding with Emacs and e2wm, a brilliant emacs windows manager

I've been using emacs for a while now and never intend to move on to vi, and especially other gui IDEs, because I simply just cant move my pinky finger from ctrl, it just automatically gets stuck there lol. and the IDEs editors are just too fancy for me.

Anyway the most annoying problem when developing with emacs is the project management, right? Since I believe you don't wanna ctrl+x ctrl+c to grep for some stuffs, and just split the emacs window to then do some shell stuffs there. It's pretty troublesome when you quit your emacs and then you have to split the windows to your preference again. Times like these, you have to define the splitting functions to .emacs and it's gonna suck more of your precious time again.

Well brace yourself, this tool is the perfect tool for project management for emacs, e2wm! Basically there are 5 kinds of perspectives you can choose for splitting the windows, Code, Two, Doc, Dashboard, and Array perspective, which is respectively equipped with various emacs tools.

To use e2wm is simple, what you have to do is just download e2wm-config.el, e2wm-vcs.el, and e2wm.el and then put it in your emacs path, and then add:
(require 'e2wm)
(global-set-key (kbd "M-+") 'e2wm:start-management)
to your .emacs file!

this is the link to kiwanami's github (the author of e2wm, thanks!):
and this is the link to e2wm's github repo:

Intel OpenCL Implicit Vectorizer

OpenCL compiler differs depending on its vendor, and Intel optimizes its compiler to auto-vectorize some loops that may take the advantage of the SSE and AVX instructions.
For example, the Black-Scholes equation when executed with single thread C99 and single thread OpenCL thread gives the execution time as below:
  • Input: 10MB of data
  • calculates both call and put option
  • both uses -O3 compiler option of gcc-4.4
c99 : 1612.203 ms
OpenCL : 673.248 ms
This 'hidden' optimization is kinda cool, isn't it?

Wednesday, July 18, 2012

Let's parallelize everything

Who does not want to see his programs run faster? Using exactly the same machine, same cpu, same gpu, same programming language? Many parallel programming frameworks/APIs have been developed and released recently, and with the help of many amazing programmers worldwide, these APIs have also been wrapped beautifully into many front-end languages such as Python, Ruby, or even Javascript. Some also are under development to be ported to more delicate programming languages such as Haskell, Scala, or Clojure. Soo for those of you who haven't seen/experienced the elegance of parallel computing, what are you waiting for? Let's parallelize everything!

Let me share here some of the parallel programming frameworks I know, and I believe they are famous enough to not get disappointed when using it.

First of all, there is CUDA, developed by NVIDIA, a leading company in the Graphics Processing Unit devices. I have been developing some programs using CUDA for 2 years now, and the API itself is pretty simple and straightforward to use, and I am amazed with the number of sample programs they provided inside the CUDA Toolkit, makes us incredibly easy to learn some stuffs, not only how to use CUDA API but also some important algorithms and tuning-up for developing a parallel executed program. Having said so, actually it was pretty hard to develop using CUDA back then (when it was still version 1.x), but NVIDIA just released a new version of CUDA (CUA 4.2 going to CUDA 5) and everything just became easier, to understand, to install, and to develop with that. Most important thing, note that since NVIDIA is the developer and it is not an open source software, CUDA is only available for NVIDIA's GPUs (from GeForce 8800 to the newest one). The technique of having your computation that is supposed to run sequentially on CPU is basically called a GPGPU (General Purposed GPU) computing.

And then there is OpenCL, derived from Open Computing Language, initially developed Apple and Khronos Group. OpenCL is a framework for parallelization and is aimed to be able to execute  in many platforms. At first OpenCL was only released with the standard C99 API but then they added the C++ wrappers to the runtime API, hence makes us easier to do some OOP stuffs. OpenCL can run on some major vendors' devices: AMD, Intel, and NVIDIA, where each vendor has its own compiler (or library) to interpret and/or optimize the standardized OpenCL runtime API. afaik it is Khronos who's been leading the OpenCL development and standardizing the API. Since every vendor has different technology equipped to its device, each of them releases its own OpenCL programming SDK and this can be seen inside the website respectively: AMD OpenCL SDK, Intel OpenCL SDK, and NVIDIA OpenCL SDK which comes with the CUDA Toolkit. Each SDK is provided with a unique library and some sample programs, and each vendor's compiler has its own way to optimize in compile time. IMO, learning OpenCL will not be that hard if you have previously done some CUDA programming.

Those two above are the APIs I've been using for a while to do some parallel stuffs, and there are plenty more out there and you can get some of them for free (or maybe even already installed in your computer) but some aren't.
Examples for free APIs: OpenMP, Intel's TBB, Intel's ArBB, Pthreads
Not free: PGI's Compiler with OpenACC, CAPS' Compiler with OpenACC

Sunday, April 15, 2012

Facebook is blocked in your office? Maybe this will help you a bit ;)

I think there aren't few of you who want to access your facebook page, but the page is being blocked by the server and you can't visit it.

Maybe this will give you a hint to backdoor the security!

First of all, you should know that every website has its own ip address, which will give you a unique identifier so your system will make sure that it visits the right page, even though there are two websites with the same name.

For example, Twitter's IP address is
If you hit to your address bar, then boom, twitter page will show up.

But that is not only it, this IP address will then be translated again to a 'human' number which is the true unique identifier.

How? First we translate the IP address to a sequence of binary numbers.
Twitter's IP address above will be translated to:

11000111 . 00111011 . 10010110 . 00100111
(Learn how to convert a number to binary)

And then, the dots exist in between will vanish and all sequences will be joined.


Guess what, this will also be the unique identifier if you convert it back again to the decimal number,
which will give us:


Try to check it out!
hit http://3342571047 to your address bar.

Anyway, all of these conversions can be done in python within 2 lines.

#!/usr/bin/env python

import sys
print 'http://%i' % int(''.join([bin(int(x)+256)[3:] for x in sys.argv[1].split('.')]),2)

And run the program with an ip address as the argument:

$ python

ipython-0.12 installation in Cygwin

ipython with numpy+scipy+matplotlib Installation Procedures: (as of April 2012)

1. Install some packages from cygwin setup.exe:
   * liblapack
   * fortran compilers and some fortran packages (best to download all related to fortran)
   * libgfortran
   * python packages
   * libpng
   * freetype2
   * c/c++ compilers
   * libboost

2. Install libffi (required for ipython)
   * Download libffi-3.0.11
   * Extract folder
   * Configure the installation
   * Install
     make install

3. Install ATLAS (Automatic Tuned Linear Algebra Software) (required for numpy+scipy)
   * caution: this installation may cause stress due to the installation time, which may take all day.
   * Download atlas-3.8.4
   * Extract folder
   * Make build folder (Installation procedure is written inside INSTALL.txt)
     mkdir cygwin_build
   * Configure (there is only 32-bit version)
     ../configure -b 32
   * Install
     make check
     make ptcheck
     make time
     make install

4. Install nose (testing package for scipy+numpy)
   * Download nose-1.1.2
   * Extract folder
   * Build file
     python build
   * Install
     python install

5. Install numpy (required for matplotlib and for.... python programmer.)
   * Download numpy-1.6.1
   * Extract folder
   * Build file (I faced some bugs when doing this, if you also happen to face them, I'll try my best to help)
     python build
   * Install
     python install

6. Install scipy (required for.... python programmer.)
   * Download scipy-0.10.1
   * Extract folder
   * Build file
     python build (also some bugs here)
   * Install
     python install

7. Install matplotlib (required for ipython)
   * Download matplotlib-1.1.0
   * Extract folder
   * Copy the setup.cfg.template to setup.cfg
     cp setup.cfg.template setup.cfg
   * Uncomment line 70
     tkagg = False
   * Try to build the program
     python build
   * If there is an error saying unable to remap a dll file or such, we have to run the rebase command of cygwin, using CO\MMAND PROMPT:
     cd C\cygwin\bin
     PATH=. rebaseall -v

     ...wait until it finishes

   * Try to build the program once again
     python build
   * Look at the pkg_config, if it says it's not configured right for libffi package, put this in your .bashrc:
     export PKG_CONFIG_PATH=/usr/local/lib/pkconfig (after making sure that libffi.pc is here)
   * And also make sre that you satisfied all dependencies.
   * After the build succeed, install
     python install

8. FINALLY. Install ipython.
   * Download ipython-0.12
   * Extract folder
   * Build file
     python build (also some bugs here)
   * Install
     python install

9. Now that we finished all installations, let's run some tests.
   * open ipython
     ipython --pylab
   * show a sin(x) figure     
      x = arange(-5,5,0.1)
      y = sin(x)
   * And that code should have shown you a figure of a beautiful sin(x) wave:

cygwin + ipython. a perfection.

I'm one of those programmer who just loves anything about Unix, but just feels weird about using Linux GUI hence stuck with Windows 7.

The most perfect tool for us is ofcourse, Cygwin.

However, there are some (many, actually) weaknesses in Cygwin such as sometime you have to manually figure out how to install some softwares manually, instead of just invoking sudo apt-get in a Linux system.

I recently just faced this problem when trying to install ipython with numpy+scipy+matplotlib in my system in Cygwin, and had to waste all-saturday to finally have it installed correctly.

Nevertheless, It was really worth the time.

Cygwin + Ipython. is. just. amazing.
 You can literally do anything you want since there are ridiculously many amazing python libraries that you can invoke anytime you want anything you need.

I seriously recommend to every python programmer who uses Cygwin out there.