<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AmmarkoV  `s  Personal Website</title>
	<atom:link href="http://ammar.gr/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://ammar.gr</link>
	<description>I would love to change the world , but they won`t give me the source code</description>
	<lastBuildDate>Fri, 19 Apr 2013 15:19:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>URL Shortners , my take using AmmarServer</title>
		<link>http://ammar.gr/?p=786</link>
		<comments>http://ammar.gr/?p=786#comments</comments>
		<pubDate>Fri, 19 Apr 2013 14:16:23 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=786</guid>
		<description><![CDATA[Hello World, been quite a long time since my last post here.. This blog post is about URL shortners and specifically my URL shortner (MyURL) based on the infrastructure of AmmarServer For more information on AmmarServer you can read this URL shortners are internet tools that take long and impossible to remember URL strings like [...]]]></description>
				<content:encoded><![CDATA[<p>Hello World,<br />
been quite a long time since my last post here.. <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This blog post is about URL shortners and specifically <a href="https://github.com/AmmarkoV/AmmarServer/tree/master/src/MyURL">my URL shortner (MyURL)</a> based on <a href="https://github.com/AmmarkoV/AmmarServer/">the infrastructure of AmmarServer</a><br />
For <a href="https://github.com/AmmarkoV/AmmarServer/wiki">more information on AmmarServer you can read this</a></p>
<p>URL shortners are internet tools that take long and impossible to remember URL strings like http://www.youtube.com/watch?v=lR9mNuLIPBU and add an easier to remember (or a random) alias that makes it shorter..! <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  like http://tinyurl.com/d69n5sr or http://myurl.ammar.gr/fadetoblack  ..</p>
<p>This web-service of course is a pretty straightforward one since it is just a lookup table with aliases pointing to strings and thats about it ,on the server side.. Thats also the reason why it is one of the first &#8220;service applications&#8221; of AmmarServer..</p>
<p>The code itself is <a href="https://github.com/AmmarkoV/AmmarServer/blob/master/src/MyURL/main.c#L32">simple</a> and at the time around 420LOC , though I would like to reduce them even more.. </p>
<p>The whole server executable is around 90KB ( taking efficiency seriously  ;P )<br />
 and apart from the server binary there is also a plain-text file called myurl.db which contains the aliases and real links. Literally these are the two things you need and you got yourself a URL shortner.<br />
Of course the db file is read only one time on startup and it is written every time a new alias is added from a user.</p>
<p>Basically what we do is spawn an AmmarServer instance on port 8080 and use an apache proxy to redirect traffic going to myurl.ammar.gr to 127.0.0.1:8080 . This can be easily done by enabling mod_proxy ( sudo a2enable mod_proxy , sudo a2enable mod_proxy_http ) and by adding a virtual host like the next code segment </p>
<blockquote><p>
&lt;VirtualHost *:80><br />
  ServerName myurl.ammar.gr<br />
  &lt;Proxy *><br />
     Order deny,allow<br />
     Allow from all<br />
  &lt;/Proxy><br />
  ProxyPass / http://127.0.0.1:8080/<br />
  ProxyPassReverse / http://127.0.0.1:8080/<br />
&lt;/VirtualHost>
</p></blockquote>
<p>( Note : I would really like to make a proxy based on AmmarServer and probably will do to be able to get rid of apache completely )</p>
<p>Of course as I do with most things I tested MyURL against other popular URL Shortners , ( namely tinyurl.com , bit.ly , goo.gl , tr.im and ow.ly ) and found out a good performance advantage .. </p>
<p>As demonstrated below :</p>
<blockquote><p>
Task Shortening -></p>
<p><iframe width="500" height="375" src="http://www.youtube.com/embed/lR9mNuLIPBU?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>time wget http://www.youtube.com/watch?v=lR9mNuLIPBU<br />
2013-04-19 17:05:03 (840 KB/s) &#8211; `watch?v=lR9mNuLIPBU.1&#8242; saved [232418]<br />
real	0m0.755s<br />
user	0m0.000s<br />
sys	0m0.008s</p>
<p>time wget http://myurl.ammar.gr/fadetoblack<br />
2013-04-19 17:50:19 (12.7 MB/s) &#8211; `fadetoblack.7&#8242; saved [127/127]<br />
real	0m0.066s<br />
user	0m0.000s<br />
sys	0m0.000s</p>
<p>time wget http://tinyurl.com/d69n5sr<br />
2013-04-19 16:15:08 (815 KB/s) &#8211; `d69n5sr&#8217; saved [232370]<br />
real	0m1.082s<br />
user	0m0.000s<br />
sys	0m0.008s</p>
<p>time wget http://bit.ly/plIyZu<br />
2013-04-19 16:18:03 (716 KB/s) &#8211; `plIyZu&#8217; saved [232383]<br />
real	0m1.038s<br />
user	0m0.000s<br />
sys	0m0.008s</p>
<p>time wget http://goo.gl/XAQqU<br />
2013-04-19 16:19:22 (742 KB/s) &#8211; `XAQqU&#8217; saved [232387]<br />
real	0m0.825s<br />
user	0m0.004s<br />
sys	0m0.008s</p>
<p>time wget http://tr.im/42d2q<br />
2013-04-19 16:23:29 (825 KB/s) &#8211; `42d2q&#8217; saved [232693]<br />
real	0m1.218s<br />
user	0m0.000s<br />
sys	0m0.012s</p>
<p>time wget http://ow.ly/kdVRX<br />
2013-04-19 16:36:15 (806 KB/s) &#8211; `kdVRX&#8217; saved [232907]<br />
real	0m1.209s<br />
user	0m0.004s<br />
sys	0m0.008s
</p></blockquote>
<p>Of course this is not an accurate benchmark since myURL currently only has around 30 aliases while the other services have possibly millions , and also I am testing this from Crete , Greece , and the myURL server is in Athens Greece , while most of the others are on the US ( which implies a lot of &#8220;jet&#8221;lag ) , and network congestion might vary from time to time..</p>
<p>Then I took a look on the filesizes of the responses , which to my amazement was ~300KB .. Turns out that due to the Redirection using 301 headers wget was actually going on and retrieving the full youtube page so i then went on subtracting this time from each of the responses which yielded</p>
<blockquote><p>
myURL 0.066s <- myURL performance<br />
tinyurl 0.327s<br />
bit.ly 0.283s<br />
goo.gl 0.07s <- this is also awesome<br />
tr.im 0.463<br />
ow.ly 0.454s
</p></blockquote>
<p>So that being said , considering my non-special hardware server , my plain DSL connection , my DynDNS DNS , my D-Link ADSL modem doing NAT and serving the data , myURL performance is overall superfast <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  !</p>
<p>One question is how the f*$# is google going &#8220;as&#8221; fast ( and while providing a better service , analytics , user based &#8220;tracking&#8221; ;P etc ) and another one is how much faster could I go <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  !<br />
When running a test through a local loopback connection I get </p>
<blockquote><p>
time wget http://127.0.0.1:8080/fadetoblack<br />
2013-04-19 17:27:05 (5.55 MB/s) &#8211; `fadetoblack.1&#8242; saved [127/127]<br />
real	0m0.010s
</p></blockquote>
<p>which is the maximum throughput the server can go at ( it is 7 times less than google&#8217;s net time ) If I only knew a little bit about how fast goo.gl go from inside their LAN , or what their software architecture is like <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   </p>
<p>You can find MyURL here -> <a href="http://myurl.ammar.gr/">http://myurl.ammar.gr/</a> , although it is in alpha stage and thus will probably not be always online ( as I am performing tests on it , recompiling ,restarting etc ) ..!<br />
Also ammar.gr is not exactly a <a href="http://en.wikipedia.org/wiki/High_availability#Percentage_calculation">high-availiability</a> site , mainly thanks to my ISP <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
Of course as mentioned above myurl.ammar.gr is the same as calling http://ammar.gr:8080 . Of course calling myurl.ammar.gr also adds an overhead for the proxy thing to take place but for now it will have todo , Also I might change ports in the future so myurl.ammar.gr will be the thing to remember..</p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=786</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Picture of the day ;P</title>
		<link>http://ammar.gr/?p=779</link>
		<comments>http://ammar.gr/?p=779#comments</comments>
		<pubDate>Thu, 14 Mar 2013 13:30:52 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=779</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="http://ammar.gr/wp-content/uploads/2013/03/i_wish_party2.png"><img src="http://ammar.gr/wp-content/uploads/2013/03/i_wish_party2.png" alt="The Feeling when .. " width="1000" height="673" class="aligncenter size-full wp-image-780" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=779</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenNI and ROS</title>
		<link>http://ammar.gr/?p=775</link>
		<comments>http://ammar.gr/?p=775#comments</comments>
		<pubDate>Wed, 13 Mar 2013 19:57:18 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[openni]]></category>
		<category><![CDATA[primesense]]></category>
		<category><![CDATA[Problems]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ros]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=775</guid>
		<description><![CDATA[I&#8217;ve been doing my first steps using ROS for the last week I have mixed feelings about it both as an architecture and implementation , I guess I will post them extensively another time.. What I wanted to record somewhere for someone that might face the same problem is the very strange behaviour of OpenNI [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been doing my first steps using ROS for the last week<br />
I have mixed feelings about it both as an architecture and implementation , I guess I will post them extensively another time..</p>
<p>What I wanted to record somewhere for someone that might face the same problem is the very strange behaviour of OpenNI  after I installed ROS and its OpenNI libraries.. ( sudo apt-get install ros-groovy-openni-camera ros-groovy-openni-launch   ) </p>
<p>I&#8217;ve been getting some really weird behaviour , namely an Error (&#8221;  Bad Parameter sent to the device! &#8221; ) <a href="https://github.com/AmmarkoV/RGBDAcquisition/blob/master/openni1_acquisition_shared_library/OpenNI1Acquisition.cpp#L156">after the<br />
StartGenerating call on the image generator</a>.. This happens everywher including standard binaries of the PrimeSense codebase like NiViewer , but as well as my own wrapper ( <a href="https://github.com/AmmarkoV/RGBDAcquisition">https://github.com/AmmarkoV/RGBDAcquisition</a> )</p>
<p>After some extensive tinkering it turns out that after ROS gets installed it takes over the &#8220;OpenNI stuff&#8221; and in order to use it as usual you have to first initialize it the ros way.. The weird thing is that this does not impact getting Depth frames that work correctly..</p>
<p>If you want to use it you should first initiate :</p>
<p>roscore<br />
roslaunch openni_launch openni.launch &#038;</p>
<p>and test if it works using -> rosrun rqt_reconfigure rqt_reconfigure </p>
<p>The same library with no modifications works correctly after the steps mentioned </p>
<p>I have also found some similar problems that might be different manifestations of the same problem..<br />
So I really hope this helps someone,  it took me almost two days to find the solution ..! <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
<a href=" http://answers.ros.org/question/54907/openni-error-opening-video-stream/"></p>
<p>http://answers.ros.org/question/54907/openni-error-opening-video-stream/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=775</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Advanced Image Search for Linux!</title>
		<link>http://ammar.gr/?p=759</link>
		<comments>http://ammar.gr/?p=759#comments</comments>
		<pubDate>Wed, 27 Feb 2013 00:34:24 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[image processing]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=759</guid>
		<description><![CDATA[Ok the title is an overkill , but it is actually advanced when compared to plain search categorization using filenames and it &#8220;feels&#8221; a lot like google image search , so I thought if google calls it that way , why shouldn&#8217;t I..! The idea is a tool for console based content-aware image searching much [...]]]></description>
				<content:encoded><![CDATA[<p>Ok the title is an overkill , but it is actually advanced when compared to plain search categorization using filenames and it &#8220;feels&#8221; a lot like google image search , so I thought if google calls it that way , why shouldn&#8217;t I..!</p>
<p>The idea is a tool for console based content-aware image searching much like the experience when using <a href="https://www.google.com/advanced_image_search?hl=en&#038;biw=1354&#038;bih=941&#038;q=test&#038;tbm=isch">google advanced image search</a>.. All this from the comfort and privacy of your terminal screen..<br />
Of course such a cli tool could be leveraged by a GUI application to provide additional searching services in a more &#8220;user-friendly&#8221; way , and with that beeing said I am planning to make use of it <a href="https://github.com/AmmarkoV/FlashySlideshows/wiki">in my FlashySlideshows project</a> ..!  </p>
<p>At last my huge random 4chan image folder will become automatically arranged! <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I litteraly don&#8217;t know what I will do with all the time this will free ;P</p>
<p>sample queries using the library/tool are :</p>
<p><center><br />
<a href="http://ammar.gr/wp-content/uploads/2013/02/lsimg_test.jpg"><img src="http://ammar.gr/wp-content/uploads/2013/02/lsimg_test-300x204.jpg" alt="Click to see lsimg in action" width="300" height="204" class="aligncenter size-medium wp-image-760" /></a><br />
</center></p>
<p><strong>Gathering all the images that &#8220;look like&#8221; 1360273766703.jpg ( a meme from meme generator ) into the Downloads/MemeTest dir..!</strong> </p>
<p>mv `lsimg -likeExt ~/Downloads/1360273766703.jpg 30 60 ~/Downloads/` ~/Downloads/MemeTest/  </p>
<p><center><br />
<a href="http://ammar.gr/wp-content/uploads/2013/02/lsimg_working.jpg"><img src="http://ammar.gr/wp-content/uploads/2013/02/lsimg_working-300x123.jpg" alt="Click to see lsimg in action" width="300" height="123" class="aligncenter size-medium wp-image-761" /></a><br />
</center></p>
<p><strong>Querying all &#8220;red&#8221; images </strong><br />
by using<br />
lsimg -color red ~/Downloads/</p>
<p><strong>Querying all images big enough for being used as a wallpaper</strong><br />
by using<br />
lsimg -minDims 1920 1080 ~/Downloads/</p>
<p>Of course you can combine filters together for more complex queries and there are more parameters coming up ( like face detection , containers , GPS EXIF info parsing etc )  </p>
<p>The project is licensed under GPLv3 , it is only targeted for the Linux platform<br />
and you can download it from here : <a href="https://github.com/AmmarkoV/AdvancedImageSearch">https://github.com/AmmarkoV/AdvancedImageSearch</a></p>
<p>(or by issuing)</p>
<blockquote><p>
git clone https://github.com/AmmarkoV/AdvancedImageSearch.git<br />
cd AdvancedImageSearch<br />
./get-dependencies.sh<br />
./install.sh
</p></blockquote>
<p>The project currently only works on jpeg images (since it is in early alpha stage) and there are no other dependecies except libjpeg for now<br />
I will probably have to add openCV linkage for use of the composite openCV face detectors and misc other stuff I want to include..</p>
<p>That&#8217;s it for now..!<br />
Hope you enjoy..!</p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=759</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few thoughts on the PS4</title>
		<link>http://ammar.gr/?p=743</link>
		<comments>http://ammar.gr/?p=743#comments</comments>
		<pubDate>Thu, 21 Feb 2013 17:59:23 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[playstation]]></category>
		<category><![CDATA[ps4]]></category>
		<category><![CDATA[sony]]></category>
		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=743</guid>
		<description><![CDATA[Actual Sony patented technology Playstation 4 was announced today after a show that was broadcasted live over the internet.. Unfortunately I can&#8217;t seem to find a recording of it somewhere , but when I do I will append it here.. Although I grew up playing with PS1 played only a little with PS2 and owned [...]]]></description>
				<content:encoded><![CDATA[<p><center><img src="http://ammar.gr/wp-content/uploads/2013/02/ps4-300x254.jpg" alt="ps4" width="300" height="254" class="alignnone size-medium wp-image-751" /><br />Actual Sony patented technology</center></p>
<p><a href="https://en.wikipedia.org/wiki/PlayStation_4">Playstation 4</a> was announced today after a show that was broadcasted live over the internet..<br />
Unfortunately I can&#8217;t seem to find a recording of it somewhere , but when I do I will append it here..</p>
<p>Although I grew up playing with PS1 played only a little with PS2 and owned a PS3 it is now apparent that I will not be getting the PS4 <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ..</p>
<p>The main things that I didn&#8217;t like about it are..</p>
<p>- The controller &#8220;share&#8221; button! ( I wonder who came up with that idea.. )<br />
- <del datetime="2013-02-27T00:54:21+00:00">The fact that you can&#8217;t &#8220;share&#8221; your games with your friends any more <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  (literally share by lending them the disc)</del><br />
It appears this will not be the case , or so I read from news sites on the internet<br />
- The social media , free advertisment on your friends , on you , on everyone attitude<br />
- The &#8220;it will be solved in the cloud&#8221; approach on backwards compatibility with older generation devices ( let alone games you already purchased )<br />
- The fact that you can&#8217;t turn your own device off unless you pull the plug.<br />
- The mandatory social media logins , with everything this implies..<br />
- The secondary &#8220;custom-chip&#8221; that performs &#8220;background-processing&#8221; , linked to your social media :p<br />
- The fact that it will download things that it will decide its user might want in the future <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ( I bet it could also torrent-like share them with other users all in the name of &#8220;better performance&#8221; and at the users bandwidth cost  )<br />
- The playstation eye having a proprietary auxilary connection to the console and not a USB one..<br />
- There were no price reports or &#8220;hands on&#8221; view..<br />
- The marketing glossary of the presentation..</p>
<p>What I do like is :<br />
- The video encoding &#8220;co-processor&#8221; for remote-operation ( although the PSVita sucks and it is a Wii-U ripoff idea )<br />
I believe &#8220;hardware accelerated graphics output forwarding&#8221; would be a great platform-agnostic addon to modern digital devices , along with a way to transmit control messages it could definately be useful. Of course  ssh and X-Forwarding are great but if you want to stream 3D graphics and full-hd movies they are kind of problematic..<br />
- The stereo approach on 3d viewing , it will be nice in a future with <a href="http://www.kickstarter.com/projects/1523379957/oculus-rift-step-into-the-game"> devices like oculus rift </a> or <a href="http://www.youtube.com/watch?v=v1uyQZNg2vE">google glasses</a> , if PS4 eye is of the same quality as PS3 eye it will be a great device , properly calibrated and synchronized , I really hope it will be usable by non PS4 hardware..<br />
- The developers will probably have an easier job optimizing their code for all their platforms ( since there is basically only one common platform architecture <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ) , although if the playstation SDK and the black box it comes with costs nearly as much as the PS3 one ( 7500Euro+ )  , I still don&#8217;t think PS4 games will become easier to develop </p>
<p>What I&#8217;d like to note is that everything from Mac&#8217;s to Consoles is a PC nowadays..<br />
As I said being a PS3 owner , I will not buy a PS4. I would like to buy its camera system if there was a way to connect it with a normal pc <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>That being said I am really looking forward to the Microsoft answer ( X-Box 720 probably streaming to their Surface tablets or w/e <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />   ) and the Steambox or &#8220;Piston&#8221; which  is the platform that hopefully will win the 8th generation console wars..  </p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=743</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing around with GCC and AVX SIMD</title>
		<link>http://ammar.gr/?p=733</link>
		<comments>http://ammar.gr/?p=733#comments</comments>
		<pubDate>Wed, 20 Feb 2013 22:11:45 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[avx]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gcc 4.7]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[optimizations]]></category>
		<category><![CDATA[simd]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=733</guid>
		<description><![CDATA[I&#8217;ve started playing around with assembly once again and trying out AVX extensions on my 2month old Laptop&#8217;s Intel CPU.. ( I had forgotten it had a new CPU ) AVX instructions support 256bit payloads and that is fantastic , the newest versions of gcc automatically utilize the new instructions ( when gcc is configured [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve started playing around with assembly once again and trying out <a href="http://en.wikipedia.org/wiki/Advanced_Vector_Extensions">AVX extensions</a> on my 2month old Laptop&#8217;s Intel CPU.. <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ( I had forgotten it had a new CPU <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  )</p>
<p><a href="http://en.wikipedia.org/wiki/Advanced_Vector_Extensions">AVX instructions</a> support 256bit payloads and that is fantastic , the newest versions of gcc automatically utilize the new instructions ( when gcc is configured to produce output for this architecture ) and senses loops that can be &#8220;vectorized&#8221; , what is very handy is that you can monitor this kind of optimizations using -ftree-vectorizer-verbose=1 which prints out messages that indicate where the optimizations take place ( providing a high level optimization overview <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ) </p>
<p>I have <a href="https://github.com/AmmarkoV/CodeExperiments/">created a new repo on my github account</a>  so that anyone who might want to test these kind of things will find a codebase that might make it easier.. </p>
<p>One thing that I also found extremely useful is the <a href="http://software.intel.com/en-us/articles/intel-intrinsics-guide">Intel Intrinsics Guide</a> which is a very helpful guide for looking up CPU OPcodes , and intrinsics with very simple explanations and plain code equivalents..!</p>
<p>My first test was a frame subtraction scenario repeated 1000 times for two FullHD frames..<br />
Its code is the following ..</p>
<blockquote><p>
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h></p>
<p>int SubtractImages(char * imageA,char *imageB,unsigned int elements)<br />
{<br />
    char * imageA_Ptr = imageA;<br />
    char * imageA_Limit = imageA + elements;<br />
    char * imageB_Ptr = imageB;<br />
    while (imageA_Ptr<imageA_Limit)<br />
    {<br />
        if (*imageA_Ptr>*imageB_Ptr)<br />
        {<br />
            *imageA_Ptr-=*imageB_Ptr;<br />
        }<br />
        else<br />
        {<br />
            *imageA_Ptr=*imageB_Ptr-*imageA_Ptr;<br />
        }</p>
<p>        ++imageA_Ptr;<br />
        ++imageB_Ptr;<br />
    }<br />
    return 1;<br />
}</p>
<p>int main()<br />
{<br />
    unsigned int width = 1920;<br />
    unsigned int height = 1080;<br />
    unsigned int frameSize = width*height*3;</p>
<p>    char * imageA = (char * ) malloc(frameSize);<br />
    char * imageB = (char * ) malloc(frameSize);</p>
<p>    unsigned int benchTimes=0;<br />
    for (benchTimes=0; benchTimes<1000; benchTimes++)<br />
     {<br />
       memset(imageA,123,frameSize);<br />
       memset(imageB,123,frameSize);</p>
<p>      SubtractImages(imageA,imageB,frameSize);<br />
     }</p>
<p>    return 0;<br />
}
</p></blockquote>
<p>Running <a href="https://github.com/AmmarkoV/CodeExperiments/blob/master/FrameSubtraction/make.sh">./make.sh ( see here )</a><br />
produced the following two assemblies and binaries for the same &#8220;job&#8221; , one plain and unoptimized and one automatically optimized for core i7 AVX CPUs </p>
<p>Running the two binaries ( <a href="https://github.com/AmmarkoV/CodeExperiments/blob/master/FrameSubtraction/test.sh ">using ./test.sh</a> ) the results where </p>
<blockquote><p>
Running AVX binary<br />
	Command being timed: &#8220;./SubtractionAVX&#8221;<br />
	User time (seconds): 0.76<br />
	System time (seconds): 0.00<br />
	Percent of CPU this job got: 99%<br />
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.77<br />
	Average shared text size (kbytes): 0<br />
	Average unshared data size (kbytes): 0<br />
	Average stack size (kbytes): 0<br />
	Average total size (kbytes): 0<br />
	Maximum resident set size (kbytes): 12588<br />
	Average resident set size (kbytes): 0<br />
	Major (requiring I/O) page faults: 0<br />
	Minor (reclaiming a frame) page faults: 3189<br />
	Voluntary context switches: 1<br />
	Involuntary context switches: 67<br />
	Swaps: 0<br />
	File system inputs: 0<br />
	File system outputs: 0<br />
	Socket messages sent: 0<br />
	Socket messages received: 0<br />
	Signals delivered: 0<br />
	Page size (bytes): 4096<br />
	Exit status: 0
</p></blockquote>
<p>AND</p>
<blockquote><p>
Running Normal binary<br />
	Command being timed: &#8220;./Subtraction&#8221;<br />
	User time (seconds): 22.74<br />
	System time (seconds): 0.00<br />
	Percent of CPU this job got: 99%<br />
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:22.79<br />
	Average shared text size (kbytes): 0<br />
	Average unshared data size (kbytes): 0<br />
	Average stack size (kbytes): 0<br />
	Average total size (kbytes): 0<br />
	Maximum resident set size (kbytes): 12592<br />
	Average resident set size (kbytes): 0<br />
	Major (requiring I/O) page faults: 0<br />
	Minor (reclaiming a frame) page faults: 3191<br />
	Voluntary context switches: 1<br />
	Involuntary context switches: 1920<br />
	Swaps: 0<br />
	File system inputs: 0<br />
	File system outputs: 0<br />
	Socket messages sent: 0<br />
	Socket messages received: 0<br />
	Signals delivered: 0<br />
	Page size (bytes): 4096<br />
	Exit status: 0
</p></blockquote>
<p>A 30x speed up! The SIMD architecture is a great tool indeed! <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
After this first run I wanted to try and write my own hand &#8220;optimized&#8221; calls and see if I could go better than the gcc compiler , but after taking a look on the optimized assembly it appears that I wouldn&#8217;t be able to do better <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  , so I will have to come with a more complex original code segment that will not be so efficiently auto-optimized and then try my luck there.. </p>
<p>An example of operations that would be more difficult to auto-optimize with gcc <a href="http://software.intel.com/en-us/articles/motion-estimation-with-intel-streaming-simd-extensions-4-intel-sse4#Motion%20Estimation%20Using%20MPSADBW%20and%20PHMINPOSUW">is this block matching comparison using SSE4 and comparisons for using up to 16&#215;16 windows</a>  </p>
<p>Another great article on the Intel site is <a href="http://software.intel.com/en-us/articles/bkm-coaxing-the-compiler-to-vectorize-structured-data-via-gathers">this  &#8220;vectorizing for struct&#8221; advice </a></p>
<p>To go back to my main topic though <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  , here are the two assemblies :<br />
<a href="https://github.com/AmmarkoV/CodeExperiments/blob/master/FrameSubtraction/assembly.asm">Plain Assembly , without SIMD optimizations</a><br />
<a href="https://github.com/AmmarkoV/CodeExperiments/blob/master/FrameSubtraction/assemblyAVX.asm">AVX , highly optimized assembly ..!</a></p>
<p>The difference of course is made by this segment which utilizes the better instruction set on the second binary</p>
<blockquote><p>
&#8230;<br />
	vmovdqu	(%rdi,%rcx), %xmm1<br />
	addq	$1, %r9<br />
	vmovdqu	(%rsi,%rcx), %xmm0<br />
	vpsubb	%xmm0, %xmm1, %xmm3<br />
	vpsubb	%xmm1, %xmm0, %xmm2<br />
	vpcmpgtb	%xmm0, %xmm1, %xmm0<br />
	vpblendvb	%xmm0, %xmm3, %xmm2, %xmm0<br />
	vmovdqu	%xmm0, (%rdi,%rcx)<br />
	addq	$16, %rcx<br />
	cmpq	%r9, %rax<br />
	ja	.L4<br />
	leaq	(%rdi,%r10), %rax<br />
	cmpq	%r10, %r11<br />
	leaq	(%rsi,%r10), %r8<br />
	je	.L11<br />
&#8230;
</p></blockquote>
<p>Using the <a href="http://software.intel.com/en-us/articles/intel-intrinsics-guide">Intel Intrinsics Guide ( mentioned again above )</a><br />
we see that </p>
<blockquote><p>Instruction: vmovdqu<br />
CPUID Feature Flag: AVX<br />
Description<br />
Load 256-bits of integer data from memory into dst. mem_addr does not need to be aligned on any particular boundary.<br />
Operation<br />
dst[255:0] := MEM[mem_addr+255:mem_addr]<br />
dst[MAX:256] := 0</p>
<p>Instruction: vpsubb<br />
CPUID Feature Flag: AVX2<br />
Description<br />
Subtract packed 8-bit integers in b from packed 8-bit integers in a, and store the results in dst.<br />
Operation<br />
FOR j := 0 to 31<br />
    i := j*8<br />
    dst[i+7:i] := a[i+7:i] &#8211; b[i+7:i]<br />
ENDFOR<br />
dst[MAX:256] := 0</p>
<p>Instruction: vpcmpgtb<br />
CPUID Feature Flag: AVX2<br />
Description<br />
Compare packed 8-bit integers in a and b for greater-than, and store the results in dst.<br />
Operation<br />
FOR j := 0 to 31<br />
  i := j*8<br />
  dst[i+7:i] := ( a[i+7:i] > b[i+7:i] ) ? 0xFF : 0<br />
ENDFOR<br />
dst[MAX:256] := 0</p>
<p>Instruction: vpblendvb<br />
CPUID Feature Flag: AVX2<br />
Description<br />
Blend packed 8-bit integers from a and b using mask, and store the results in dst.<br />
Operation<br />
FOR j := 0 to 31<br />
    i := j*8<br />
    IF mask[i+7]<br />
        dst[i+7:i] := b[i+7:i]<br />
    ELSE<br />
        dst[i+7:i] := a[i+7:i]<br />
    FI<br />
ENDFOR<br />
dst[MAX:256] := 0
</p></blockquote>
<p>GCC did  a great job indeed <img src='http://ammar.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=733</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Steam for Linux Official Launch</title>
		<link>http://ammar.gr/?p=722</link>
		<comments>http://ammar.gr/?p=722#comments</comments>
		<pubDate>Fri, 15 Feb 2013 14:24:47 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[bumblebee]]></category>
		<category><![CDATA[counter strike]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[NVIDIA]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[optimus]]></category>
		<category><![CDATA[optirun]]></category>
		<category><![CDATA[sale]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[steam]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=722</guid>
		<description><![CDATA[Steam for linux launched today with some very low prices on a &#8220;games special offer&#8221; for the next week.. Although I already have many of the games that are featured on steam ( and I have them DRM free from humble bundle ) , counter strike source priced at 3.6 euro was really a bargain [...]]]></description>
				<content:encoded><![CDATA[<p><center><img src="http://ammar.gr/wp-content/uploads/2013/02/steam_for_linux-300x168.jpg" alt="Steam For Linux" width="300" height="168" class="alignnone size-medium wp-image-723" /> </center></p>
<p>Steam for linux launched today with some very low prices on a &#8220;games special offer&#8221; for the next week..</p>
<p>Although I already have many of the games that are featured on steam ( and I have them DRM free from humble bundle ) , counter strike source priced at 3.6 euro was really a bargain so I purchased it and played a little like old times..</p>
<p>Unfortunately NVIDIA optimus users will have issues with steam as its model of launching games doesnt take into account optirun , etc..</p>
<p>One quick fix that makes everything work out of the box for optirun users , but does so using the Intel card is the following</p>
<blockquote><p>
 ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 ~/.steam/steam/ubuntu12_32/
</p></blockquote>
<p>The intel card  is more than enough for Counter Strike Source</p>
<p>I also tried to launch the game as stated below ( Using bumblebee and the NVIDIA card ) but it would start in LAN only mode , and since I don&#8217;t have someone to play localy it there wasn&#8217;t much point in it..</p>
<blockquote><p>cd &#8220;~/.steam/steam/SteamApps/ammarkov/Counter-Strike Source/&#8221; &#038;&#038;<br />
export LD_LIBRARY_PATH=~/.steam/steam/ubuntu12_32:&#8221;~/.steam/steam/SteamApps/ammarkov/Counter-Strike Source/bin/&#8221; &#038;&#038;<br />
optirun ./hl2_linux -game cstrike -console -dev -numericping -noipx</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=722</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Ascent of Money &#8211; Documentary</title>
		<link>http://ammar.gr/?p=721</link>
		<comments>http://ammar.gr/?p=721#comments</comments>
		<pubDate>Wed, 13 Feb 2013 21:38:39 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=721</guid>
		<description><![CDATA[A great documentary about money , banks , loans , securities and a retrospect for the financial situation today See it @ Youtube IMDB Wikipedia]]></description>
				<content:encoded><![CDATA[<p><iframe width="560" height="315" src="http://www.youtube.com/embed/4Xx_5PuLIzc" frameborder="0" allowfullscreen></iframe></p>
<p>A great documentary about money , banks , loans , securities and a retrospect for the financial situation today</p>
<p><a href="http://www.youtube.com/watch?v=4Xx_5PuLIzc">See it @ Youtube</a><br />
<a href="http://www.imdb.com/title/tt1358383/">IMDB</a><br />
<a href="http://en.wikipedia.org/wiki/The_Ascent_of_Money">Wikipedia</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=721</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Pirate Bay , AFK Film</title>
		<link>http://ammar.gr/?p=717</link>
		<comments>http://ammar.gr/?p=717#comments</comments>
		<pubDate>Fri, 08 Feb 2013 18:55:24 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=717</guid>
		<description><![CDATA[The Pirate Bay AFK , Torrent The Pirate Bay AFK @ Youtube]]></description>
				<content:encoded><![CDATA[<p><iframe width="560" height="315" src="http://www.youtube.com/embed/eTOKXCEwo_8" frameborder="0" allowfullscreen></iframe></p>
<p><a href="https://thepiratebay.se/user/SimonKlose/">The Pirate Bay AFK , Torrent</a><br />
<a href="http://www.youtube.com/watch?feature=player_embedded&#038;v=eTOKXCEwo_8<br />
">The Pirate Bay AFK @ Youtube</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=717</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing CUDA on Ubuntu 12.10</title>
		<link>http://ammar.gr/?p=701</link>
		<comments>http://ammar.gr/?p=701#comments</comments>
		<pubDate>Sun, 13 Jan 2013 15:17:42 +0000</pubDate>
		<dc:creator>Ammar Qammaz</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[12.10]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[CUDA]]></category>
		<category><![CDATA[CUDA 4.2]]></category>
		<category><![CDATA[cuda 5]]></category>
		<category><![CDATA[gcc 4.7]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[Installing]]></category>
		<category><![CDATA[NVIDIA]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[ubuntu 12.10]]></category>

		<guid isPermaLink="false">http://ammar.gr/?p=701</guid>
		<description><![CDATA[If you are running Ubuntu 12.10 and want to install CUDA as mentioned in one of my earlier posts by default you can&#8217;t due to gcc 4.7 beeing incompatible with every availiable ( up to the time of writing this ) CUDA SDK The good news is that you can work around this by installing [...]]]></description>
				<content:encoded><![CDATA[<p>If you are running Ubuntu 12.10 and want to install CUDA as mentioned in one of my earlier posts by default you can&#8217;t due to gcc 4.7 beeing incompatible with every availiable ( up to the time of writing this ) CUDA SDK </p>
<p>The good news is that you can work around this by installing an older version of the gcc compiler , and the even better news is that you can do everything with two small scripts I wrote that handle all the fuss for you and that you can download below..<br />
Please note that the scripts will automatically check your machine capabilities ( x64 x86 ) , download the SDK you want from NVIDIA if you dont have it , and even set-up the correct LD_LIBRARY_PATH and PATH strings on your .bashrc file.. <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
Come on , what more can you ask for ?</p>
<p>I <strong>strongly</strong> suggest <strong>not downloading  new drivers when the CUDA installation will ask you for it</strong> but use your distribution packaged ones (nvidia-current)..  The repository drivers on Ubuntu 12.10 are fully equiped for CUDA so there is no reason to change them . You should also be aware that if you are running on an Optimus Laptop GPU ( see an <a href="http://ammar.gr/?p=679">older post here on configuring bumblebee for optimus cards</a> ) installing standalone new drivers will most likely break your graphics setup.. So once again <strong> this time specifically you Optimus users dont download new drivers when the cuda installation asks you because you will break graphics on your Ubuntu installation</strong> <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
Also in case you are curious Optimus systems ( just like mine <img src='http://ammar.gr/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ) will run the script with no problems just as the rest of the NVIDIA systems  .. The only difference on Optimus Chips is that after you compile an executable with nvcc you will have to run it using optirun ./yourexecutable ..</p>
<p><strong>CUDA 5</strong> ( <a href="https://github.com/AmmarkoV/MyScripts/blob/master/Setup/install_cuda5">if you want to take a look on the script click here</a> )<br />
To install CUDA5 type the following commands on your terminal :<br />
<code>wget https://raw.github.com/AmmarkoV/MyScripts/master/Setup/install_cuda5<br />
chmod +x install_cuda5<br />
./install_cuda5</code></p>
<p><strong>CUDA 4.2</strong> ( <a href="https://github.com/AmmarkoV/MyScripts/blob/master/Setup/install_cuda4.2">if you want to take a look on the script click here</a> )<br />
To install CUDA4.2 type the following commands on your terminal :<br />
<code>wget https://raw.github.com/AmmarkoV/MyScripts/master/Setup/install_cuda4.2<br />
chmod +x install_cuda4.2<br />
./install_cuda4.2</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ammar.gr/?feed=rss2&#038;p=701</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
