Archive for September, 2010

C++ is a hack

Posted in code with tags , , , , , on September 12, 2010 by maxpower3141

If you are reading this, you probably knew it already.

Basically C++ is just a set of semi-clever preprocessor hacks on top of C – I seem to remember that actually the first C++ compilers were just an extra preprocessing pass on top of a C-compiler!

In themselves, hacks are not evil, but they do normally always cause some undesired side-effects that limits usability. In this case as C++ is basically just a hack on top of C, it means that it actually works by doing a lot of odd name-mangling in the preprocessing steps in order to get the names correct and here in lies the problem.

I recently began using thrust and with it some template programming on C++ and while thrust is great, C++ itself is not so much.

Firstly the template syntax is kind of awkward, but that’s not so much of an issue – the issue is the following:

Using function-objects (types that just overload the “function-call”-operator ()), I can abstract my CUDA-algorithms, by making them template-based on the different function-object types.

For example the SAXPY-call using thrust (this computes result = a X + Y, for vectors X,Y and scalar a) is as I had earlier written:

struct saxpy_functor
{
const float a;

saxpy_functor(float _a) : a(_a) {}

__host__ __device__
float operator()(const float& x, const float& y) const {
return a * x + y;
}
};

void saxpy_fast(float A, thrust::device_vector& X, thrust::device_vector& Y)
{
// Y <- A * X + Y
thrust::transform(X.begin(), X.end(), Y.begin(), Y.begin(), saxpy_functor(A));
}

This is ok, but I have started to like the idea of keeping the code close to where it is executed (guess I’m getting old or something) so I though that I would like to create a small macro that creates me a transformation-functor type on the fly so I could actually semi-transparently embed CUDA-code with my host code! That Would just rock! Something like:


void saxpy_fast(float A, thrust::device_vector& X, thrust::device_vector& Y)
{
struct saxpy_functor
{
const float a;
saxpy_functor(float _a) : a(_a) {}
__host__ __device__
float operator()(const float& x, const float& y) const {
return a * x + y;
}
};
// Y <- A * X + Y
thrust::transform(X.begin(), X.end(), Y.begin(), Y.begin(), saxpy_functor(A));
}

and hopefully wrap the silly stuff inside some macro to get:


{
DEFINE_XFORM_CALL(saxpy, data, input1, input2)
{
return data.a * x + y;
};
CALL_XFORM(saxpy, data, in1, in2);
}

Sweet no? Local types are supported by C++, except not in template parameters! And this causes:

“error: a template argument may not reference a local type” – compilation error!

Nice – what’s the freaking problem now? Can’t deduce the name of the type? Oh dear… SW sucks.

There has been a proposition to fix this in the standard itself, but of course this will never be fixed there – I guess MS supports this as compiler extension, but NVCC does not – I’ll request this feature and hope that NVIDIA listens – they do need all the user-friendliness they can get and this would be really friendly for me!

I’ll keep you posted if I ever hear from my request again 🙂 (not filed yet, sorry – TBD tomorrow)

Also I really think it is starting to be high time to switch to D Programming Language – as soon as NVCC supports it, I’m there!

Here’s a sneak-peek for a reduction:

import std.algorithm, std.range, std.stdio;

int main()
{
int[] a1 = [0,1,2,3,4,5,6,7,8,9];
int[] a2 = [6,7,8,9];
int sentinel = 5;

int mysum(int a, int b) {
if (b <= sentinel) // access outside variable
return a + b;
else
return a;
}

auto result = reduce!(mysum)( chain(a1, a2) ); // pass in a delegate (closure)
writeln("Result: ", result);

return 0;
}

Kristofer Columbus in Barcelona pointing

Linux Sucks!

Posted in code with tags , , , on September 12, 2010 by maxpower3141

Just trying to get a snappy title.

A short post, no rant, about some Linux silliness I run into constantly. Recently I ranted about Eclipse.

Now a couple of observations with KDE4 – the Vista of Linux. 🙂

a) When I have another user logged on, I’m logged on to my account and I want to let the other user use his session for some reason clicking “switch user” on the launcher, it doesn’t display at all the existing sessions – how convenient is that? I have to lock screen and then select switch user to do it – end result: 2-4 sessions open by each user – go KDE4!

b) When another user-session is going on, it is actively hogging computer resources! Like 20% of one CPU – hello? The worst offender is the plasma-desktop so my question is, why on earth aren’t the processes sleeping?? I could forgive something like firefox offending this, but plasma is a system service! Surely the system knows nobody’s using it!

These two are quite minor rants, but running into this kind of silly problems all the time seems depressing – I mean, it’s 2010? Shouldn’t the sw start working some day soon? 🙂

Zoom to Alligator

It’s not your program!

Posted in politics with tags , , , on September 12, 2010 by maxpower3141

I’ve been busy lately – all work and no posts make Max a dull boy.

Oh well, anyways I just bumped into this case on one of my favorite websites; To put the story short for you the idea is that a guy was selling autodesk CAD (tm, C, R whatnot) sw he found in some garage-sale of a bankrupt company on ebay (or something equivalent). The sw had never been used and autodesk sued the guy for “selling something that wasn’t his”.

So, what’s going on here? Once you buy something shouldn’t you be able to resell it always? Especially if you didn’t use the product yourself? For example if you buy a cd with music you can sell it later, provided you didn’t make copies of it for yourself. Is there a difference here? Well, the SW company will say that you did not buy the product, but merely a license to use it – therefore they could have a different price for those who want to license over to those who want to resell it – retail anyone? Makes sense?

How about concert tickets? You buy a “license” to listen to the musical performance once, but you are always allowed to sell this license to somebody else in case you can’t make it. On the other hand the cheapest levels of airline tickets are such that you must use the ticket yourself – why? I guess any changes to airline tickets cause some costs to airlines (the name, well the identity, of the user is important here, so they have to do something actively if it changes), but on the other hand this should be a minor cost (that could be put on the licensee). On the other hand airliners say that this way they can differentiate themselves on pricing, but again everybody knows that airline ticket-pricing algorithms are just CRAZY, with some tickets actually ending up costing to the airline, where other tickets then compensate the difference – this means that if you are buying your ticket on the last minute you get high price fighting for the last seats of the airplane and end up paying part of the trip of your fellow travelers that did buy their tickets on time – nice no?

So what’s the end-result? Consumer benefit? Uh, maybe not exactly. One of the issues here is that big companies have way too much money compared to their employees and hence big companies should pay more for the same sw (/other stuff as well) than the employees as individual consumers. This is because the companies themselves know this (of course – they are not dumb). The field is littered with examples.

So the verdict you are waiting for? Uh, the thing is that this situation sucks – basically I think that this is a variation of the issue of durable products I touched on my post about why Capitalism Sucks. It is in the best interest of the sw-company to get into a situation where the client has to pay a tax-like small license fee preferably as often as possible and buying this service on discount on ebay constitutes cheating this system. Putting aside utopian fixes to problem of capitalism (and human happiness) I think this problem would be solvable inside a capitalistic system as well – just make the rules clear: if your company sells products as services then make the customer go to your website to get the license – selling this kind of license in a box is equivalent to entrapment and should not be allowed – you sell a box means you give rights to the client to resell the box. I mean, should people really start reading the EULAs? 🙂 Come on.. 🙂

Ok, back to sleep – I leave you with this photo:

Odd CG-scene by me a looong time ago