Cache or cores? Biscuit or cake?
It's about three years since I built my Ryzen system. It's a Ryzen 5 3600 (Zen 2, Socket AM4) with 32GB RAM.
Since dual core became a thing I have been meaning to take over the world with cunning multi-threaded code but about as far as I've got is some shell scripts that do things in parallel.
I figured I should upgrade the machine while AM4 CPUs are still available. I noted that AMD had some CPUs out with this newfangled 3D cache, and that they were pretty fast on certain workloads.
So my decision was biscuit or cake? Cache or cores?
It's taken me a few weeks, and much deliberation but today I decided to go for the cake. I think it will be more fun to have more cores to play with. I have ordered a Ryzen 9 5000X (12 core/24 thread Zen 3) and a cooler with two great big fans and fancy quiet bearings to go with it.
I'll need to revisit my old tests from three years ago and see what sort of a difference all those extra cores make. Obviously, there will be more contention for memory bandwidth. If I get around to it, I might post the results together with the results for the old CPU.
Meantime, I have been writing a little bit of C, finally getting around to something I've been meaning to do for 15 years. One day I'll write something about procrastination. I have an anecdote.
The National Conservatives had a rally in London this week. I wanted to write something, but the Guardian summary will suffice.
It's barely disguised now.
From the fine article:
Perhaps the speech most reported on was by the Tory backbencher Miriam Cates, who part-channelled Viktor Orbán and Giorgia Meloni in describing low birthrates as an existential crisis for the west. The populist leaders of Hungary and Italy are explicit in wanting more domestic-born children as against immigrants, a point Cates did not make, although it was arguably implicit. More striking still was her argument that the lack of babies was down to “cultural Marxism that is systematically destroying our children’s souls”.
This was also the conference where Jacob Rees-Mogg (a member of the current UK government) spoke and admitted that recent changes to electoral law in England and Wales were an attempt at gerrymandering, to disenfranchise people who might vote for parties other than his, but that it had backfired. The Conservatives appear to have disenfranchised many of their own voters.
It's in plain sight now. These are National Conservatives, the NatCs.
There is not much more to be said.
Update: Judging by the discourse below, there certainly is more to be said. Once again I will not say it myself. Instead I'll post a link to SNP MP Mhairi Black's f-word speech given to Parliament last year.
Pro-republic demonstrators were arrested in London on Saturday ahead of King Charles III's coronation ceremony, despite having planned their protest in cooperation with the Metropolitan Police several months in advance.
Asked if he thought his arrest before the event was premeditated, Smith said: “Absolutely. I have no doubt about that at all, simply because there was nothing that we did do that could possibly justify even being detained and arrested and held.”
Other arrests were made.
The Met said it arrested 64 people on Saturday, including members of Westminster city council’s women’s safety campaign Night Stars, who hand out rape alarms and other items. Police claimed intelligence had indicated people were planning to use rape alarms to disrupt the coronation procession.
We have a constitutional Monarch who is effectively powerless. We need a proper democratically-elected head of state. This medieval pantomime has no place in the 21st Century.
New anti-protest laws were very recently brought in further curtailing our rights and freedoms.
The UK is becoming very authoritarian and the police are being given more and more powers. Human rights organisation Liberty has a good article on the recent changes to the law.
Prince Charles became King Charles III on 8th September 2022 upon the death of his mother, Queen Elizabeth II, that day. However, despite this, there will be a coronation ceremony next Saturday 6th May which is estimated to cost £100M and will be paid for out of public money, i.e. our taxes. This is against a backdrop of 10% inflation, fuel, food and housing poverty, and public services such as education and the National Health Service on their knees.
We, the people of the UK, his subjects, are being invited to swear an oath of allegiance to our king as follows:
“I swear that I will pay true allegiance to Your Majesty, and to your heirs and successors according to law. So help me God.”
There are a number of problems with this as you can see. I will not be swearing such an oath. As an atheist, I do not believe that there is a God to help me. I do not believe that the King derives any sort of power from this God, I do not believe in blind obedience, and I do not believe in an unelected hereditary head of state. It is fundamentally incompatible with a modern democracy.
The UK constitution, such as it is, a hotch-potch collection of customs and documents handed down through history, hasn't really changed much since the Norman Conquest of 1066.
We have the Houses of Parliament, the House of Commons (the nominally democratic bit), and the House of Lords (the appointed/hereditary second chamber).
We elect our Members of Parliament every five years using a First Past the Post system. Effectively this limits our governments to the two main political parties, Conservative (the "establishment party") and Labour (formerly the radical left but now watered-down conservatives). Very occasionally one party does not get an outright majority, and has to form a coalition with the third largest party (the Liberal Democrats), which the Conservatives did in 2010. At that time, the Liberal Democrats were economically on the right and supported many right-wing economic policies that disadvantaged ordinary people, such as regarding university tuition fees. Their reputation has never recovered and they were nearly wiped out in subsequent elections.
Nominally the Monarch is Head of State. All laws passed by Parliament have to be scruitinised by the Lords and then sent to the Monarch to be given Royal Assent. At this point, there may be secret changes to the laws often to benefit Royalty and this has been well documented in the press in recent years.
What happens if a government misbehaves or breaks the law? The British system has relied on government ministers and MPs being decent chaps, who would always do the right thing, and resign if they made a serious mistake. However there is nothing written down in our constitution, no laws. MPs can be banned from Parliament, and they can be deselected forcing a byelection if banned for long enough, but who decides when to ban them and for how long?
The unlawful prorogation of Parliament in 2019, in a proper democracy, might have resulted in a change of government via a general election. It did not.
Under the UK constitution, such as it is, the Monarch has the power to dismiss the government. The last time a Monarch (Charles I) did this in the 17th Century (for autocratic reasons), there was a revolution, led by Oliver Cromwell. The King was put on trial, found guilty and beheaded. Britain became a republic under Puritan rule via Parliament for several years. Eventually, the people tired of the Puritans and restored the monarchy.
As a result, the Monarch is banned from entering Parliament, and there are archaic protocols and traditions to prevent the Monarch or the Lords interfering in Parliament (see Black Rod).
There is also an important legal precedent. When the Monarchy was restored, it was on the condition that it would not interfere with democracy. The short story is that the Monarch still retains the power to dismiss Parliament and therefore call a general election, however, to do so would result in the end of the Monarchy. Obviously it would not result in an execution, which would be abhorrent, but politically it would be suicide.
We find ourselves in a situation where our democracy has a major flaw in its "checks and balances." The code of decent chaps has been broken in these times of Faragism and National Conservatism and there is nothing to stop it.
Freedom of speech is not officially codified in our written laws but it is a custom which is generally defended and upheld. What if you want to abolish the Monarchy and live in a republic with a democratically-elected head of state (president) who has a maximum time in office and can be replaced regularly and frequently via free and fair elections?
There is an organisation called Republic which is organising a peaceful protest in London on the day of the Coronation.
Coincidentally, some new anti-protest laws will come into force just in time for it and intimidatory letters have been sent to the protestors.
Graham Smith, the campaign group’s chief executive, described the letter as “very odd” and said the group was seeking assurances from the police that nothing had changed in relation to its plans to protest on coronation day.
Shami Chakrabarti, the former shadow attorney general, said: “During the passage of this illiberal and headline-grabbing legislation, ministers admitted that the new offence of ‘locking on’ is so broad as to catch peaceful protesters who link arms in public.
Perhaps I should start using a VPN, eh?
Update: Anti-monarchy campaigners have been arrested in London preparing to protest peacefully.
Graham Smith, the chief executive of Republic, had been collecting drinks and placards for demonstrators at the main site of the protest on Trafalgar Square when he was stopped with five others by police on St Martin’s Lane in central London.
And:
Harry Stratton, a director at Republic, who arrived as Smith and the others were detained, said: “They were collecting the placards and bringing them over when the police stopped them. The guys asked why and they were told: ‘We will tell you that once we have searched the vehicle.’ That’s when they arrested the six organisers.
It seems that the new anti-protest laws are being applied, particulary regarding "lock-on devices."
Stratton said the organisers of the protest had not possessed lock-on devices. “What would we lock on to? We are just protesting.” He added that one protestor at Trafalgar square had been taken away by police as he had string on him. “It’s string that was part of his placard, he said. “What was he going to do with that?”
Is this our new National Conservatism in action?
I was looking at CPUs the other day and I noticed that there is an AMD Ryzen 7 5800X and a Ryzen 7 5800X3D. The 3D version has three times (96MB) the level three cache as the non-3D version, but runs several hundred megahertz slower. cpubenchmark.net has almost identical CPU Mark scores for the two but some articles I've seen say that the 3D version has far better performance for gaming workloads.
Are there any other workloads the 3D version is better at? Does this tell us anything about the way our software is written in particular, or does it just tell us that games are not particularly good at exploiting more cores?
There must come a point of diminishing returns where adding more cache makes little difference, however three times the cache making a significant difference is interesting.
Why haven't I been abducted by aliens?
I'd really appreciate a flight to Sirius, Alpha Centauri, Betegeuse or Vega. I'd settle for the Moon or Mars, actually. Saturn's moons would be fun. I'd like to examine their antigravity/warp drives and ask them all sorts of questions about the Maths and Physics they needed to discover to make it all work, plus how they create the convex curvature of spacetime.
It would be the trip of a lifetime. It always happens to someone else, though.
It's not fair!
Update: I still haven't been abducted by aliens.
Have you ever written an interpreter or compiler for your own toy programming language?
I was bored one afternoon a long time ago and wrote a little C program to emulate an imaginary RISC CPU and invented an instruction set for it. I never got around to writing an assembler, but the disassembler was trivial.
Some years later I wrote a completely crazy stack-based language where the only data type was a string and used it for drawing pictures with a home-made graphics library.
I also wrote an incredibly simple, but entirely serious, scripting interpreter to write regression test scripts for an API for a device driver I had written.
One of these days I will get around to doing another one, for my own amusement.
What crazy ideas have you had? What have you tried? What would your ideal or ideal absurd language be like, and could you implement it?
I wrote recently asking for advice about how to help a newbie tactfully.
I have been very surprised since then about some of the things our newbie has asked me and what I have had to explain to him. Is it a "young people today" thing, am I completely out of touch?
The first thing is when code reviewing this young guy's C. As you probably know, when you are working in a programming team there are certain things you have to agree on, such as the format of the code. It may sound trivial, but if different people format the code differently, it makes tools like diff harder to use, and it makes it harder to spot structural and functional changes on the code. We use spaces for indentation. Tabs were creeping in!
More seriously, though, I found out that he didn't know about git diff. I found out from someone else that he didn't know about branching in git. I would have thought a trivial search online would have given some clues?
Function prototypes are there for a reason. They define the public interface to functions in a source module. That's why they go in a separate header, and if your program wants to call the functions in the other module, you #include that header. I found redefined function prototypes in the program source (not the module where the functions were implemented) and they had the wrong argument lists for the functions! Why?
The other strange thing was I had to explain the difference between ASCII and binary. I had to explain, with an ASCII chart (which he didn't understand), that NUL has code 0. I also had to explain why editing binary data in a text editor was not a great idea.
Also, you don't need to terminate a binary array with '\0'. Certainly not outside the array bounds.
I've tried to keep it polite, professional and helpful, but the other day he informed me that he is only used to getting one or two code review comments and they're only about "the functionality."
Kids today? He has nearly 10 years of experience. Am I too harsh? It's a lot of code, so it's got a steep learning curve, and it's for an important job.
Memory safe languages are coming back into fashion nowadays.
Back into fashion? They're not new?
That raises the question as to why the world's software is built on memory unsafe languages such as C and C++.
In a word, efficiency. If we look back in history a bit to where high level languages were becoming common, we can see why.
My experience with programming begins in the 1980s, so I have no direct experience of how things were prior to that, but I did start out on 8-bit microcomputers with BASIC interpreters.
To give you some context, these machines had CISC CPUs that ran at a few MHz (1 to 4 usually) and took several clock cycles to complete a single machine instruction. The primitive BASIC interpreter lived in a few kB of ROM and was written in machine code.
Those BASIC interpreters were slow, but they were fairly user-friendly. When you declared or even just used a new variable (integer, floating-point or string) for the first time it would be initialised. When you concatenated strings, it happened as if by magic. You could insert and delete substrings. You could take input from the user in strings of arbitrary length that would adjust dynamically. There was no such thing as overflow. Array bounds were checked. The program would stop with an error code if you tried to read or write out out bounds.
In previous decades, compiled languages were developed to run on mainframe and minicomputers. A typical 1970s vintage minicomputer was about as big (RAM) and powerful (speed) as a 1980s home microcomputer. Compilers were always complex and notoriously arcane, unreliable and generally mysterious. They were usually buggy and not to be trusted, apart from in some very specialised and expensive cases.
Along came languages like C and Pascal. Pascal was nice but considered a "toy." It needed extensions to be useful. However, in the 1970s C came along. It was simple and powerful. A C compiler could run on a relatively small machine (a few tens of k or RAM) and produce usefully efficient machine code, fast enough that writing in plain machine code or assembly language wasn't really worth it any more. There was also the advantage of portability. The compiler could target different architectures so one piece of source code could compile and run on very different hardware.
This simplicity and efficiency came at a price. The language and the compiler did not support such things as array bounds checking, variables were not automatically initialised and strings were effectively static, not dynamic. Library routines were provided to supply some of that functionality.
The run-time checking (and safety) was eliminated in favour of the programmer being all knowing and all seeing and infallible.
With hindsight, better choices might have been made but remember that the machines of the day were so small and slow that it was the only way to get efficient enough software out the door in a reasonable timeframe.
Most computers were not networked. The Internet wasn't even a thing. Security wasn't so important. A lot of the shortcomings in the languages and their libraries weren't that much of an issue.
Other things did come along but the "good enough" solutions had become entrenched. Ada was one such alternative. It didn't catch on because compilers were expensive (to call a compiler Ada it had to go through an expensive validation process) and there was a bit of a reaction against "strict" languages (for all the wrong reasons).
Programming languages are there to express mathematical concepts. They need to be precise and unambiguous. The human brain is neither. Experience tells us that we should chose languages and compilers that help us reduce ambiguity and express with greater precision that which we wish to achieve.
There is no perfect programming language. It always used to be that you would use your programming language to build up a framework of "subroutines" to help you solve your problem. FORTH was great fun for doing this. LISP looks eveen better, and is indeed the essence of programming it seems.
Back to my original point: memory safety got sidelined for efficiency. Efficiency was important because forty years ago hardware was so slow and primitive. I haven't been on a slow computer in over ten years. I have computers from over ten years ago that aren't slow.
Efficiency, in compilers or in the runtime, is not a problem any more. Why are we not programming with memory safe languages as a matter of course? What wheels is Rust reinventing?