Technology

Why I Hate the #debill

0

Well, the ayes have it, the ayes have it; the Digital Economy Bill looks set to become the Digital Economy Act.  A bad day for all users of the internet throughout the UK.

My upset has nothing to do with my support for legalised filesharing — though I do believe that copyright is in dire need of reform and that filesharing creates rather than destroys markets, that’s an issue to be covered another day in a different blog post.

I am more concerned with the fact that the measures outlined in the bill will not work.  Thanks to anonymity networks like Tor, illegal filesharing through otherwise legal technologies (such as BitTorrent and YouTube), the “dynamic” IP addresses in use by most ISPs and an inability to adequately protect ones own wireless connection from serious attacks, we’ve been placed at the top of a slippery slope.

All that this bill will accomplish is pushing illegal filesharing further underground, forcing it to invent new untrackable technologies and/or abuse existing old ones.  It is only a matter of time before the big “creative industries” realise that their sales have not gone up and that their profits have not increased. It is only a matter of time before they claim that nobody purchased Lily Allen’s new album because of people trading files via e-mail, posting DVDs and USB sticks to one another via smail mail, and recording their own MP3s from low-quality media streams.  The suggestion that people don’t want to buy crap music they can hear for free every day on the radio is apparently too radical.

The answer to these problems?  More legislation pushed through by people who do not understand the internet and less freedom for its users.

I’m also very uncomfortable with the way that copyright infringement through non-filesharing means are not mentioned (or, if they are, I’ve yet to hear about it).  Where is the crackdown on the lending of books and CDs?  Where is the legislation that says it is illegal to create copies of television shows you have watched and distribute them to your friends?  Presumably the bill would not have passed, had the elderly been aware they’d have their VHS players confiscated.

Excuse me, whilst I write another letter to my MP.

Variadic Macros and CUDA

0

Again, a relatively obvious tool for those who are more experienced with C than I, but this is something I recently stumbled across and found very useful.

One of my major annoyances with CUDA is the way that device emulation works — you go through your code, writing printf statements here and there, compile for device emulation and everything’s fine.  But remove your -deviceemu and everything goes horribly wrong, as device functions cannot call host functions.  Until now, my only way around the error has been to comment out all of my print statements, which is pretty arduous.

The answer lies with a variadic macro.  Define something like this at the top of your CUDA files, or the top of a generic header file included everywhere:

#ifdef DEVICEEMU
#define debug(format, ...) printf(format, ## __VA_ARGS__)
#else
#define debug(format, ...)
#endif

With this in place, where you would have used printf("Some output = %d.\n", variable), debug("Some output = %d.\n", variable) will do exactly the same thing.  If -D DEVICEEMU is passed as an argument to nvcc, all calls to debug will be replaced by suitable (and working) printf statements. If it isn’t, they are all replaced by empty lines and the compiler just skips over them.

A few quick changes to your Makefile and everything’s pretty much automatic.  Thanks, variadic macros!

Samsung YP-P3

2

After years of convincing myself that an MP3 player was something that wouldn’t benefit me in the slightest, I decided to treat myself to a Samsung YP-P3 as a “post-Christmas, hurray it’s 2010″ present.  Since starting my PhD, I have found myself walking alone and sitting on trains far more often than I have at any other time in my life; it ‘s become more and more important to drown out the noise of other people’s music and inane chatter. Part impulse buy, part “necessity”, I’m quite impressed so far.

Here it is, in all of its “taking ages to transfer files” glory…

Sorry I didn't take a photo of it doing something more interesting...

Sorry I didn't take a photo of it doing something more interesting...

You might be wondering why, since this is my first MP3 player purchase, I jumped in with something quite so expensive (£200 for the 32GB model) that wasn’t manufactured by Apple.  The reasons are many, and the most important are outlined below:

  • File Formats
    The YP-P3 supports: MP3/WMA/OGG/AAC/FLAC/WAV/ASF
    Yup.  OGG and FLAC.  Since most of the music I have ripped is in OGG (being an open-source Linux advocate), one of my biggest problems with Apple’s iPods and their “rivals” is their seeming inability to play anything but MP3.  Sure, you can flash the firmware, but the point is that you shouldn’t have to.
  • Linux!
    Okay, so the YP-P3 doesn’t “support” Linux.  It comes bundled with a piece of software called EmoDio that you’re supposed to use to transfer your music to and from the player (and thus keep your library synced), but it’s by no means compulsory.  In fact, the first thing I did upon turning on the YP-P3 was to switch it from MTP to UMS — a switchover that was no hassle at all.
    This essentially causes the player to appear as a removable drive when it’s plugged in, meaning that rearranging the library is a drag-and-drop job.  Perfect.

The interface is pretty, it’s skinnable, has widgets, and the touch screen is very responsive.  It even vibrates when you touch something, providing the tactile feedback that is often missing from this sort of interface.

I only have one niggle with the YP-P3 so far, and admittedly it is a rather minor one.  It seems to me, based on my admittedly limited research, that the album cover system is implemented solely through ID3 tags.  This is a minor annoyance for MP3 and OGG files, since getting album art to appear requires manually tagging each and every MP3 and OGG on my system.  It’s an even bigger problem for WMA, M4A and FLAC, since I haven’t found any way to edit their tags.

I hope that somebody somewhere comes up with a way of forcing the YP-P3 to look for a “folder.jpg” image, or at least an easier way of making sure it knows where the images are.  If that happened, I wouldn’t be able to fault it at all.  An iPod beater?  I certainly think so.

Good Results, Bad Timing

0

As is often the way with these things, as soon as I had presented a clearly broken and spiky graph at the CUDA conference the solution became obvious.  With relatively little work this morning, I produced a much prettier graph:

The Graph I Wanted to Present

I remain skeptical of the numbers, of course, but I’m fairly certain that my results are correct.  It’s re-taught me a pretty valuable lesson about CUDA, too; the memory access pattern is very, very important. Though my error seems obvious in hindsight, it was not so obvious at the time!

When dividing a two (or three) dimensional array into blocks, it is tempting to simply calculate one’s indices using something like this:

(threadIdx.z*N + threadIdx.y)*N +threadIdx.x.

Perhaps surprisingly, this significantly increases the number of memory accesses for a given warp. Though the entire array has been placed in contiguous memory, cells that appear close to one another within a block are often quite far apart in reality. For example, in the first “tile” of a 2D 128 x 128 grid of floats, cell 0′s  south “neighbour” is a massive 512 bytes away.  If we assign one thread to each cell in a 4 x 4 tile, then, fetching the four rows requires at least four memory transactions, even on a Tesla.

If we think about this a little bit, we see that rearranging memory such that blocks lie in contiguous memory is relatively easy and, given the impressive speedup, definitely worth considering.  An alternative solution is to ensure that tiles are at least 16 x 16, but this may not always be possible due to shared memory constraints.

Since this is something that I somehow managed to overlook for so long, I thought it was worth writing about.  Hopefully it might help somebody with similar issues.

OpenCL from AMD

2

Having spent the last four weeks struggling to debug my OpenCL kernels (to the point that it was often easier to re-write them in CUDA and use nvcc’s -deviceemu flag) I finally took the plunge and installed AMD’s Stream SDK.

I was surprised to find it was actually much easier to install and configure than NVIDIA’s solution… except for its assumption that I had both an AMD CPU and ATI GPU. Hopefully anybody with similar problems will stumble across this blog post, and it will save them some time.

I should note that this guide will be completely useless unless you are using a Linux distribution.

  1. First, download the AMD Stream SDK here. (You will need to sign up.)
  2. Make sure to grab the OpenCL driver as well.
  3. Extract the SDK files from their .zip file, and follow the instructions contained in the “docs” folder.
  4. Extract the .run file from the OpenCL driver .zip file, and run it with the –extract option; this extracts the contents of the .run file to another directory (of your choosing).
  5. Copy the contents of /ati/arch/lib/x86 (or /at/arch/lib/x86_64) into the /lib/x86 (or /lib/x86_64) directory of your SDK install.

And you’re done! Why AMD chose to package some libraries necessary for libOpenCL.so to work with their GPU-specific drivers I don’t know, but they did!

If you’ve followed the steps here (and in AMD’s documentation) correctly, then all should work properly. Enjoy the ability to use printf in a kernel — I know I am.

Yo Ho Ho and a Bottle of Rum

4

As with some of my other entries, this one was brought about by some ridiculous news reported by the BBC.

Yet again, the pirates of the web are being blamed for the “death” of the music and film industries. The solution? Cracking down on teenagers pirating in their bedrooms.

Yup, that’s right. According to this article, the corporations are aware that they’ll be unlikely to crack down on “real” pirates that are capable of encrypting their internet traffic; attacking people who download the odd film or album is obviously a much better way of doing things!

What somebody needs to do is make it clear to the older generation that “piracy” is nothing new. When I was growing up (and before I had internet access) it was commonplace to record things off of the TV to VHS or to record things off of the radio to cassette. Despite actually being illegal, I can’t remember ever seeing a court case about somebody lending some VHS tapes to their friends, or making a mix tape for their beau.

Piracy doesn’t even harm the big corporations, so why do they care? Take a film like Wolverine, for example. Even though it was leaked online and millions of people apparently downloaded it, it still “clawed” £107m at the box office.

This entry isn’t particularly well structured, but I’m supposed to be revising; just having a bit of a rant.

Amazon Kindle

0

Maybe this is something that I missed, but I just stumbled across a new Amazon product whilst looking for anime DVDs. Interestingly enough, it was only advertised on Amazon.com, so there’s a possibility that any non-Americans reading this have no idea what Kindle is either.

It’s essentially an electronic book that you can carry around with you, which displays one page at a time. The pages act just like they were made of paper, and you can dog-ear a corner to mark a page, or click a button either side of the Kindle to go forwards or backwards.

The stuff you read is downloaded wirelessly, so you can buy books of Amazon.com or carry around your own word documents and the like.

…cool, huh?

I’m pretty proud of myself, ‘caus I saw this coming. Only a few weeks ago I was having a discussion with my housemates about the death of books and how it was only a matter of time before somebody released some sort of electronic book or electronic paper. Unsurprisingly, Amazon have already sold out of Kindle.

Way to go Amazon.

There’s a pretty cool video and some extra info on their site, which I recommend people look into. The technology is simple, so its probably not really worth the “WOW” that I’ve attributed to it, but I think its a good demo of how technology is going to become an even more integral part of our lives.

Go to Top