Showing posts with label processing. Show all posts
Showing posts with label processing. Show all posts

Tuesday, 10 January 2023

Prodj, Praw or Pro?

I've just had one of those moments, I speak with an accent from the British Midlands.  I've been told my accent is fairly neutral, but I know I have a Nottingham twang to certain words, and when I'm being lazy I can sound right common (that is lower-class).

The vowel constructs I know I'm worst at are "Op" such as "Open" and "Operation" and "Ov" as in "Over", and I often made even my wife's eyes twitch when I say "it's upen uver there" pointing at a shop or parking space.

Today however I'm picking on "Pro".... Now, as a British English speaker I've never had this issue locally, we all say "project" with a "prodject" sound, we don't stress the "pro"... It's a prodject, not a PROject to my ear.  It's like saying "podge" as in stuffed full of food, but with an 'r'.

Right or wrong this distinguishes that word with "Projector" and "projection", you know the habit of shining light through something to put an image on a screen or wall... that is "PROjection" when I say it.  And this has been automatic to me all my life and I've known what my peers at school, home and work meant we were all very local, so we all knew the distinction and never really thought about it.

However, working in game development with a very wide range of folks I've just been called out.

Talking about a project with graphics the projection matrix came up.... And yes, you guessed it, in the meeting I said (something like) "the prodject is coming along well, I'm using the inverse PROjection matrix to check a ray intersection".

I literally got called out at that point, never noticed it before, I've heard folks saying "PROject" but ignored them... The problem?

One of the folks happened to be from the North West of England (Manchester I believe) and he said... "PRAWject".... and "PRAWcessing".... Yeah, even I was twitching then.

Either way, it was an interesting moment.

Thursday, 5 May 2016

Software Engineering with 252117761

What's with this strange number Xel?... Well, this is a very useful number to help you determine how a remote system, or your network, is presenting numeric values.

When we program, we generally stick to one system or one platform at a time, however, life is never always so vanilla, and we've had a problem in the office today of talking to a raw network connection from a remote system.  We didn't know anything about this remote system, through a combination of lingual differences and a total lack of documentation (SNAFU).

So, we didn't know what endianess the remote processor was treating numbers as, and we also didn't know if the network was doing conversion between endian settings.

Apparently someone else had puzzled over this for a few weeks before giving up.

I however, channelled the power of the number 252117761.

What's so special about this number?... Well, it's a 32bit number, so we have four 8 bit bytes in there, and it's binary pattern is:

00001111000001110000001100000001

If you can't see the use of this pattern already in checking your networking and endieness, then you might have a problem.

It helps you check out the received values back, if you know you assign a value on one side as this integer, and we call for it across the link, we can see whether we get the above, or a change of order:

00000001000000110000011100001111

For example was the return we had, which is a change or ordering.

But you can also see whether you get:

00000011000000010000111100000111

Which is a short reordering.

Why 32 bit?... Well in this case, because we did know that the word size of the remote system was 32bits, but you can use this trick with any number of bits, just total up your values...

111111101111111001111110001111100001111000001110000001100000001

Might be a good 64bit pattern, and has the value 9187131167487755009.



Friday, 30 May 2014

Virtual CPU - Signed Addition Clean Up & ROM Discussed

In today's CPU post I want to just clean up the signed addition example, we've covered the electronics but I've had a couple of messages asking how I might integrate switching into the CPU.

Well, simply for our Virtual CPU I'm going to include the signed addition based on the signed mode flag... We already had this signed mode flag in the CPU, and we default the flag to false or "off".

So that is a simple "if" statement within the "Add" function.

To integrate the switching we invent two new OP Codes, one to switch into Signed processing and one to switch to Unsigned processing.


I'll leave you guys to think about how the programmer has to remember which mode they were in, and hence what the bit patterns they have represent.

I'm also going to leave multiplication whilst in Signed Mode as an exercise for you to address yourselves, if you want to mail me your solutions, I'll happily take a look (if I find a minute).

So our op codes now run from zero to twenty-seven.  So with 28 operations what could a machine do?

You might think not very much, but the real 4004 (though not yet the same instruction codes as our virtual code) operated with just 46 instructions total, more than our code at present, but still not a lot.  Intel have kindly published scanned copies of their original datasheets and so we can peek into the depths of their instruction set here:


Numerically we can see almost immediately their instructions 2 and 3, are about Fetching... Fetching Immediate and Fetching Indirect (from ROM)... What is Fetching?  Well, in other machines, many assemblers and in our Virtual CPU the concept of Fetching is called "Loading" and we Load0 and Load1.  Both those instructions load from memory into the CPU, this is "Immediate" it immediately moves a value from volatile storage into the processor.

Indirect for our CPU would actually be the main program loading a program from a file, the file is our ROM or non-volatile storage and we load it into the RAM to use it.  However, we don't fetch from ROM.

I had been asked to add a ROM to the Virtual CPU, however, all a ROM is is addressable memory which can't be changed, so if you wanted to create a ROM yourself you can, create a byte array in your program, load from a disk file, or just insert data into the array upon construction.

And then add two new Op Codes you want to fetch from the ROM.  You can then add the ROM to your CPU as a reference...

I hope this gives you some ideas and you go a head and try to write a small ROM.

Next on our agenda will be "Interupts"... Stay Tuned.

Tuesday, 20 May 2014

Virtual CPU - Adders & Signing Discussed

Let us review the physical electronics our code emulated for addition, we created the function "AddTwoBytes" which in
turn used "Adder", the adder being the code:

Sum = Cin ^ (A ^ B);
Cout = (A & B) | (Cin & (A ^ B));
This is of course the code representation of electronic logic gates "AND" "OR" and "XOR", we could have gon further and rather than use "XOR" as a single operation we could have broken it down into separate "AND" and "OR" gates itself.  This is how the first computers worked after all.  A good electronics primer is a good place to start looking at logic gates in more detail.

But the use of "XOR" as a single unit, rather than a more complex set of other logic gates is what we programmers would call encapsulation.

We Encapsulated this whole logic into a call called "Adder" and we encapsulated its use to add each bit of two bytes into yet another function.

Luckily electronics engineers have been at this encapsulation lark as long as us programmers, and so instead of representing the adder logic like this:


They've gone a head and made the Adder look like this:

And then if we think about wiring each bit of two bytes through adders, each adder passing its carry out to the carry in of the next we get this wonderfully complex diagram:


Do not be scared by this, yes I drew it by hand so there maybe bugs, but all I want you to gleam from this is how complex the electronics are, because remember this mass of wires and adders and inside each adder the logic gates equates to the simple loop in the "AddTwoBytes" code!

This is one of the reasons many people emulate electronics or CPU's or just this kind of gated logic in software, because creating the hardware can be so much more complex, costly and hard to get right first time, but code we can change with a wave of the hand.

This representation, wiring each bit from the registers, is purposefully complex however, and there are other adders you can look at.

So how does all this get us signed numbers in our CPU?

When we enter signed mode in the CPU we want to consider the top most bit of our bytes as a sign, when this bit is off (0) then the number is a positive, when the bit is on (1) then the number is negative.

The flag doesn't really mean "and now this is negative", it is actually that we change the meaning of the value, so the top most bit changes from having a value of +128, to having a value of -128.

Hence the binary, 00000111 is still 7... but 1000111 is now ( -128 + 4 + 2 + 1 ) holding the value -121.

Back to our electronics then, if you have the top most bit set and you over flow, do we want to just throw it away as an error?... Well no, because it maybe that the number has just gone from being a negative to a positive, or its gone from a positive to a negative... So we want to carry the overflow back to the first adder...


But, of course this won't work, because you can't have an input to a process which is that very same process's output...

So what do those sneaky electronics chaps do?

Well... I'm not going to tell you... Go find out...

Tuesday, 27 August 2013

OpenACC

Previously on these pages I talked about getting into GPU processing, well I'm officially setting off on this project for reasons of exploration, but also to help you guys out there – the average programmer – get an easy grasp on the topic step by step.

I've no idea how this all works, so my first port of call has been the nVidia Developer Zone regarding Cuda... https://developer.nvidia.com/what-cuda … And I've spent a fair amount of time reading up on things.

My immediate problem was the dropping of library names and buzz words, which I have no idea what they are, and the page does not directly explain “MKL BLAS, “IPP”, “FFTW” all obfuscating abbreviations which in this days of rich information content on the internet its inexcusible to see them listed with no references.

Another item talked about is “OpenACC” directives, which as the page explains can speed up your loops in Fortran or C... But again there's no link to what “OpenACC” is.

Stepping forward to the “Getting Started” page and firm information is still obfuscated, I think perhaps nVidia's page – as informative as it is on the whole – is trying to not drop too much technical information on the programmer too quickly.  However, this is an advanced programming topic, anyone wondering in to attempt this has to be of a calibre able to soak up more information more quickly than this site seems to dole it out.  Though I have an expectation for there to be a sudden and deep learning curve begin any second.

Our first step is going to be what appears to be the simpler of the items listed, GPU Directives, which are part of the already mentioned “OpenACC”.  These are going to help parallelise loops in code – C code for us.

The page explaining this is fairly well featured, and this tantalising image is presented:



The immediate problem with this “open” standard however is that the companies supporting it are turning it into proprietory tool chains.

Without the tool chain – the compiler and linker – understanding what you're asking of it, your code won't contain or leverage the GPU for you, it'll just be plain old CPU driven code.  The page presented even goes so far as to present trials of software compilers to help gain access to the technology.

Unfortunately a 30 day trial isn't really what I'm after, and not really what I think an “Open” project should end up as.

Indeed crawling the net searching for further details one finds a plethora of content deriding Compilers for their lack of OpenACC acceptance, or even posts prophesying the arrival of OpenACC or even OpenMP support “in 2013”.  But it seems here now in 2013, its still not arrived:



Without tools readily available it leaves you rather stuck as to how to proceed investigating OpenACC.  My next step was this PDF document, explaining the directives: http://www.nvidia.com/docs/IO/117377/directives-tips-for-c.pdf

This is really a nuts and bolts approach to getting your C application to use OpenACC loop practices.  A good introduction.

The big problem with this however, is that it all references back to the Portland Group's proprietary compiler.  To which one can only get a 30 day trial.  Something I'm not open to signup up for just yet, at least not without a whole series of OpenACC code to run through it in short order.