Live data from Hacker News

Cray-1 vs Raspberry Pi

roylongbottom.org.uk

171–180 of 193 posts

Re: Cray-1 vs Raspberry Pi

#171

Earlier quoted context omitted.

A lot of the stuff that took hours back then can now be done in sub-seconds. Think about mechanical engineering: Back then they might have simulated how cars deform in a crash. Now we can perform similar simulations in real-time for fun in our video games. Afaik it's hardly ever done because no one actually needs physically accurate models in games, but it could be done. Same goes for rendering back then they rendere…

> Think about mechanical engineering: Back then they might have simulated how cars deform in a crash. Now we can perform similar simulations in real-time for fun in our video games. Afaik it's hardly ever done because no one actually needs physically accurate models in games, but it could be done. BeamNG is basically that.

You beat me to it! Such a fun game

Re: Cray-1 vs Raspberry Pi

#172

Earlier quoted context omitted.

That design seems like a reasonable thing for a high level language that could then be converted to different architectures’ simd widths. But I’m kinda surprised it’s good at the ISA level. Eg for something like a vectorized strlen, mightn’t one worry that the cpu would choose vlen[1] too large causing you to load from cache lines (or pages!) that turn out to be unnecessary for finding the length of the string. With…

I'm not sure it is difficult to see why variable length SIMD makes sense. If you want to process 15 elements with a width of 8, you will need the function twice, once with SIMD processing whole batches of 8 elements and a scalar version of the same function to process the last 7 elements. This makes it inherently difficult to write SIMD code even in the simple and happy case of data parallelism. With RISC-V all you d…

I wonder if you’re using a different definition of ‘vectorized’ from the one I would use. For example glibc provides a vectorized strlen. Here is the sse version: https://github.com/bminor/glibc/blob/master/sysdeps/x86_64/m...

It’s pretty simple to imagine how to write an unoptimized version: read a vector from the start of the string, compare it to 0, convert that to a bitvector, test for equal to zero, then loop or clz and finish.

I would call this vectorized because it operates on 16 bytes (sse) at a time.

There are a few issues:

1. You’re still spending a lot of time in the scalar code checking loop conditions.

2. You’re doing unaligned reads which are slower on old processors

3. You may read across a cache line forcing you to pull a second line into cache even if the string ends before then.

4. You may read across a page boundary which could cause a segfault if the next page is not accessible

So the fixes are to do 64-byte (ie cache line) aligned accesses which also means page-aligned (so you won’t read from a page until you know the string doesn’t end in the previous page). That deals with alignment problems. You read four vector registers at a time but this doesn’t really cost much more if the string is shorter as it all comes from one cache line. Another trick in the linked code is that it first finds the cache line by reading the first 16 bytes then merging in the next 3 groups with unsigned-min, so it only requires one test against a zero vector instead of 4. Then it finds the zero in the cache line. You need to do a bit of work in the first iteration to become aligned. With AVX, you can use mask registers on reads to handle that first step instead.

Re: Cray-1 vs Raspberry Pi

#173

Earlier quoted context omitted.

One of the early customers was the European Centre for Medium-Range Weather Forecasts, so, wild guess, they probably used it for medium-range weather forecasts.

> they probably used it for medium-range weather forecasts in europe

Only centred on Europe.

Re: Cray-1 vs Raspberry Pi

#174
As interesting as this article is as a comparison to a 40 year old supercomputer, the reality is that computers really are artifacts of an era and their place in the progress or regress of technology is possibly valid. Today's world's fastest computer is a Cray:

https://www.top500.org/news/frontier-remains-no-1-in-the-top...

So, how does the Raspberry Pi stack-up against today's computers?

Re: Cray-1 vs Raspberry Pi

#175

Earlier quoted context omitted.

That design seems like a reasonable thing for a high level language that could then be converted to different architectures’ simd widths. But I’m kinda surprised it’s good at the ISA level. Eg for something like a vectorized strlen, mightn’t one worry that the cpu would choose vlen[1] too large causing you to load from cache lines (or pages!) that turn out to be unnecessary for finding the length of the string. With…

> what do you even pass to vsetvl in this case as you don’t know your string length. To the maximum, of course, `vsetvl x , x0, ...` will do that for you. You might read over a page boundery, but there is an instruction for that `vle8ff.v`, it's a fault-only-first uni-stride load. That is, it doesn't fault when one of the later elements goes outside our page, and adjusts the vector length accordingly. [0] > With the…

Thanks for all the detailed information! That answers a bunch of my questions and the implementation of strlen is nice.

The instruction I was thinking of is pshufb. An example ‘weird’ use can be found for detecting white space in simdjson: https://github.com/simdjson/simdjson/blob/24b44309fb52c3e2c5...

This works as follows:

1. Observe that each ascii whitespace character ends with a different nibble.

2. Make some vector of 16 bytes which has the white space character whose final nibble is the index of the byte, or some other character with a different final nibble from the byte (eg first element is space =0x20, next could be eg 0xff but not 0xf1 as that ends in the same nibble as index)

3. For each block where you want to find white space, compute pcmpeqb(pshufb(whitespace, input), input). The rules of pshufb mean (a) non-ascii (ie bit 7 set) characters go to 0 so will compare false, (b) other characters are replaced with an element of whitespace according to their last nibble so will compare equal only if they are that whitespace character.

I’m not sure how easy it would be to do such tricks with vgather.vv. In particular, the length of the input doesn’t matter (could be longer) but the length of white space must be 16 bytes. I’m not sure how the whole vlen stuff interacts with tricks like this where you (a) require certain fixed lengths and (b) may have different lengths for tables and input vectors. (and indeed there might just be better ways, eg you could imagine an operation with a 256-bit register where you permute some vector of bytes by sign-extending the nth bit of the 256-bit register into the result where the input byte is n).

Re: Cray-1 vs Raspberry Pi

#176
post #174

As interesting as this article is as a comparison to a 40 year old supercomputer, the reality is that computers really are artifacts of an era and their place in the progress or regress of technology is possibly valid. Today's world's fastest computer is a Cray: https://www.top500.org/news/frontier-remains-no-1-in-the-top... So, how does the Raspberry Pi stack-up against today's computers?

[deleted]

Re: Cray-1 vs Raspberry Pi

#177
post #46

Years ago when my daughter was around 5 I was showing her a raspberry Pi zero I had just picked up. I told her - years ago before Daddy was your age a computer like this used to be as big as a house. Her response was - “houses were that small?”

:) Did showing raspPi to your daughter have any result (like interested in tech or anything)?

Honestly she loves all her subjects in school. I’d say the “engineering tendency” that she picked up from her mom and I (both eng) is the desire the go deep on learning something. I see it when it comes to math, but equally see it when it comes to music or history.

Re: Cray-1 vs Raspberry Pi

#178

Earlier quoted context omitted.

> what do you even pass to vsetvl in this case as you don’t know your string length. To the maximum, of course, `vsetvl x , x0, ...` will do that for you. You might read over a page boundery, but there is an instruction for that `vle8ff.v`, it's a fault-only-first uni-stride load. That is, it doesn't fault when one of the later elements goes outside our page, and adjusts the vector length accordingly. [0] > With the…

Thanks for all the detailed information! That answers a bunch of my questions and the implementation of strlen is nice. The instruction I was thinking of is pshufb. An example ‘weird’ use can be found for detecting white space in simdjson: https://github.com/simdjson/simdjson/blob/24b44309fb52c3e2c5... This works as follows: 1. Observe that each ascii whitespace character ends with a different nibble. 2. Make some ve…

I'm actually doing something quite similar in my, in progress, unicode conversion routines.

For utf8 validation there is a clever algorithm that uses three 4-bit look-ups to detect utf8 errors: https://github.com/simdutf/simdutf/blob/master/src/icelake/i...

Aside on LMUL, if you haven't encountered it yet: rvv allows you to group vector registers when configuring the vector configuration with vsetvl such that vector instruction operate on multiple vector registers at once. That is, with LMUL=1 you have v0,v1...v31. With LMUL=2 you effectively have v0,v2,...v30, where each vector register is twice as large. with LMUL=4 v0,v4,...v28, with LMUL=8 v0,v8,...v24.

In my code, I happen to read the data with LMUL=2. The trivial implementation would just call vrgather.vv with LMUL=2, but since we only need a lookup table with 128 bits, LMUL=1 would be enough to store the lookup table (V requires a minimum VLEN of 128 bits).

So instead I do six LMUL=1 vrgather.vv's instead of three LMUL=2 vrgather.vv's because there is no lane crossing required and this will run faster in hardware: (see [0] for a relevant mico benchmark)

        # codegen for equivalent of that function
        vsetvli a1, zero, e16, m2, ta, ma
        vsrl.vi v16, v10, 4
        vsrl.vi v12, v12, 4
        vsetvli zero, a0, e8, m2, ta, ma
        vand.vi v16, v16, 15
        vand.vi v10, v10, 15
        vand.vi v12, v12, 15
        vsetvli a1, zero, e8, m1, ta, ma
        vrgather.vv     v18, v8, v16
        vrgather.vv     v19, v8, v17
        vrgather.vv     v16, v9, v10
        vrgather.vv     v17, v9, v11
        vrgather.vv     v8, v14, v12
        vrgather.vv     v9, v14, v13
        vsetvli zero, a0, e8, m2, ta, ma
        vand.vv v10, v18, v16
        vand.vv v8, v10, v8



This works for every VLEN greater than 128 bits, but an implementation with larger VLENs do have to do a theoretically more complex operation.

I don't think this will be much of a problem in practice though, as I predict most implementations with a smaller VLEN (128,256,512 bits) will have a fast LMUL=1 vrgather.vv. Implementations with very long VLENs (e.g. 4096 bits, like ara) could have a special fast path optimizations for smaller lookup ranges, although it remains to be seen what the hardware ecosystem will converge to.

I'm still contemplating whether or not to add a non vrgather version and runtime dispatch based on large VLENs or quick performance measurements. In my case this would require almost >30 instructions when done trivially. Your example would require about about 8 eq + 8 and vs 4 shuffle + 4 eq, that isn't that bad.

vrgather.vv is probably the most decisive instruction when it comes to scaling to larger vector lengths.

[0] https://camel-cdr.github.io/rvv-bench-results/canmv_k230/byt...

PS: I just looked over my optimized strlen implementation and realized it had a bug. That's fixed now, and the hot path didn't change, just the setup didn't work correctly.

Re: Cray-1 vs Raspberry Pi

#180
post #108

Earlier quoted context omitted.

You want the stored carbon in plastics to escape?? The best outcome for plastics, would be to bury them very deep (like nuclear waste), where they could eventually become some new oil like substance. No carbon escape.

Yeah but no one is burying the plastic, it’s too expensive. So realistically I’d much rather have the plastic breakdown so it’s not everywhere for 10k years.

A lot of plastic actually gets buried. For example, in Washington’s King County non-recycled waste is buried. Perhaps this needs to be done world-wide.
Post reply on HN