Live data from Hacker News

Multi-Core by Default

rfleury.com

51–60 of 61 posts

Re: Multi-Core by Default

#51
I genuinely think that writing things in a message-passing/channel-based concurrency setup is often easier than doing things in single-core.

Obviously it's hard to get right, but a lot of the time doing a concurrent-first setup allows for a very clear separation of concerns (at least if you have a proper green threading solution). You can have one thread whose sole job is to do one thing, and then spit back the response onto a channel or respond to a pid. It's elegant and for me I find it fairly straightforward to reason about.

I do a lot of Clojure for my personal projects, and I will import core.async to a lot of projects, even for stuff that could be handled single-threaded, simply because I find it easier to reason about.

Re: Multi-Core by Default

#52
> programmers leave an enormous amount of performance on the table by ignoring the fundamentally multi-core reality of their machines.

It's left on the user's table for them to use to run other things.

Re: Multi-Core by Default

#54
post #19

If the author has not already, I would commend to them a search of the literature (or the relevant blog summaries) for the term "implicit parallelism". This was an academic topic from a few years back (my brain does not do this sort of thing very well but I want to say 10-20 years go) where the hope was that we could just fire some sort of optimization technique at normal code which would automatically extract all th…

Back about 20 years, DO CONCURRENT went into FORTRAN. It says that the programmer claims all the iterations of a DO look are non-interfering. This was never really that useful. It holds for matrix multiply, but not much else. It's exactly what you want for the article's use case of adding things up in parallel.

There are a few standard cases for parallelism:

- There's no interaction between tasks at all for long periods. Easiest case. Use case is codebreaking and crypto mining. Best done on special purpose hardware.

- You're running a service with a large number of incoming connections. The connections are essentially independent of each other. This is easy to do concurrently, because the threads don't talk to each other. For N > 1000 or so, this is the useful case for server-side async.

- You have some big area or volume oriented computation, like weather prediction, where there are many local regions being computed, and the regions talk to their neighbors a bit. This is the classic supercomputer application.

- You have lots of little tasks going on, queuing up events for each other. This was the vision Alan Kay had for Smalltalk. It sometimes shows up inside games, and inside discrete event simulations. The internals of some operating systems work this way.

- Anything that runs on a GPU. Very limited interaction between tasks. Until you get to shadows, lighting, occlusion culling, reflections, and anything where you don't want to do N lights x M meshes processing. Vulkan gives you the low-level tools to deal with the interlocking needed to do that, which is why Vulkan is so complicated.

(I can't speak to LLM training; haven't been inside that.)

Re: Multi-Core by Default

#55
post #19

If the author has not already, I would commend to them a search of the literature (or the relevant blog summaries) for the term "implicit parallelism". This was an academic topic from a few years back (my brain does not do this sort of thing very well but I want to say 10-20 years go) where the hope was that we could just fire some sort of optimization technique at normal code which would automatically extract all th…

Games have tons of opportunities for parallelism (outside of rendering which is obviously embarrassingly parallel) if they are designed for it from the getgo. Unfortunately, most game engines make decisions up front that force much of their game logic to be inherently serial for no good reason. It is definitely true that the sort of parallelism you get from architecting for it from the beginning bears little resemblance to what a compiler would be able to extract with an automatic semantics-preserving pass.

Re: Multi-Core by Default

#56

I think a common blindspot that makes it difficult to fully take advantage of modern silicon is making distinctions between parallelism and concurrency in code that are in actuality ambiguous. The canonical overly reductive examples are parallelism as trivial SIMD loop parallelism and concurrency as multiple threads working on different but related tasks. If those are your only models the opportunities will be limite…

> particularly if you don't rely on shared task queues or work stealing to balance load.

Anywhere I can read up on better load balancing techniques? Or, are we talking about “Know ahead of time how long each task will reliably run so you can statically schedule everything”?

Re: Multi-Core by Default

#57
post #54
post #19

If the author has not already, I would commend to them a search of the literature (or the relevant blog summaries) for the term "implicit parallelism". This was an academic topic from a few years back (my brain does not do this sort of thing very well but I want to say 10-20 years go) where the hope was that we could just fire some sort of optimization technique at normal code which would automatically extract all th…

Back about 20 years, DO CONCURRENT went into FORTRAN. It says that the programmer claims all the iterations of a DO look are non-interfering. This was never really that useful. It holds for matrix multiply, but not much else. It's exactly what you want for the article's use case of adding things up in parallel. There are a few standard cases for parallelism: - There's no interaction between tasks at all for long peri…

The Fortran committee botched DO CONCURRENT badly. The requirements imposed on the program only make it safe to execute its iterations in any serial order, but are not sufficient to allow safe parallel execution. So one can write a perfectly conforming DO CONCURRENT loop that will produce wrong answers when actually run in parallel. The problem in the spec seems to have been inadvertent but they have refused to fix it (and don’t seem to understand the problem either.)

Re: Multi-Core by Default

#58

He's describing the Cuda execition model. More interestingly, it's the same model as Intel's Implicit SPMD Program compiler (ispc, God that name is awful). But ispc works across SIMD lanes.

Yes this is just the GPU programming model without the hw perks (subgroups etc). Im impressed if he came up with it on his own but its pretty clear from the article that he didnt.

The GPU model works because the GPU is just wide SIMD with automagical scheduling.

To apply this to the CPU might be misguided unless you use SIMD aka like ISPC.

Re: Multi-Core by Default

#59

What I have found is that even among talented senior engineers there is massive Dunning-Kruger effect when it comes to performant architecture. They don't know how to do it, and they don't know that they don't know how to do it. I have always wanted reasonable performance (though this might appear like “performance programming” to a concerning proportion of the software industry), This hit me right in the heart. I'm…

> I'm often the only person on the team who cares about performance, so I am drawn to these performance-related challenges... and it has really hurt my career, because I am then often perceived as some kind of person focused on optimization rather than delivering features. Pro tip: always turn that kind of thing into a dollar value you can put on your annual review. "My update to X let us use Y fewer EC2 instances, s…

This is kind of the gold standard and well worth aspiring to for any given situation.

I've often found it hard to achieve in practice.

A typical issue is that for non-trivial performance improvements (the kind that will take several days to several months to achieve) it's hard to estimate the speedup (and therefore, the the corresponding dollar amount) without actually doing a substantial portion of the work and estimating the corresponding speedup.

Another typical issue is where the performance speedup doesn't correspond directly to a dollar amount. At a recent employer we were working on a scientific product. The optimizations would have affected the size of the datasets able to be handled by our product. So there would have been a dollar impact, but it would have not been some kind of relatively simple AWS math. It would have been measured in potential sales dollars.

It's like making your game run at 60fps instead of 30fps. 60fps is clearly better (all other things being equal) and better games tend to sell better, and we'd like to make the best game possible and sell the most copies possible... but how do we quantify the expected return on this work? Many times, I don't think you can.

Re: Multi-Core by Default

#60

Some code should be single core; like for example, a frontend UI for a web application... You don't want to be hoarding all of the user's CPU capacity with your frontend. But I do like implementing my backends as multi-core by default because it forces me to architect the system in a simple way. In many cases, I find it easier to implement a multi-core approach. The code is often more maintainable and secure when you…

In backends, you usually need to solve having concurrent requests from multiple users, regardless if you need it for performance. From that, the step to using multiple cores is sometimes very small. I.e. you don't usually need to make a for loop parallel, you can just make sure different requests are parallel.

True, it is a more natural progression to parallelize on the backend as isolating different requests has multiple benefits besides scalability; e.g. security and maintainability. Also, we have more control over the backend environment so it's easier to add external components (e.g data store like Redis) if needed to help keep track of state; there's no need to store everything in process memory... Not to mention that most backends need/use a database already and so it can be used to keep state with relative ease and efficiency without even adding any new service/component.
Post reply on HN