Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Laya the open source version of Jev(convaiinnovations.com ↗)
    46comments
  2. AI-generated posters don’t have to be horrible(john.hartnup.uk ↗)
    328comments
  3. Human brain is two separate organs, Stanford Medicine-led research finds(stanford.edu ↗)
    155comments
  4. “The Secret Life of Circuits” is here(coredump.cx ↗)
    33comments
  5. What Zig felt like, coming from Rust(besok.github.io ↗)
    1comments
  6. Tin: full-text search for Postgres(planetscale.com ↗)
    1comments
  7. Android 17 is the first since 3.x to add new APIs without releasing to the AOSP(grapheneos.social ↗)
    508comments
  8. GPT-6 Astra Solves a WWI German Radio Cipher(prinzai.com ↗)
    114comments
  9. San Francisco Onion Futures Company(onionfutures.com ↗)
    91comments
  10. A graphical desktop for the ZX Spectrum(github.com/mindbox77 ↗)
    1comments
  11. Black Holes or Black Hole Stars? Astronomers Spar over 'Little Red Dots'(quantamagazine.org ↗)
    1comments
  12. If math is more than proof, we need to better celebrate the rest of it(terrytao.wordpress.com ↗)
    152comments
  13. Communication by means of modulated Johnson noise(pnas.org ↗)
    17comments
  14. From Stonemasons to Carpenters(thelastsoftwareengineer.substack.com ↗)
    4comments
  15. Cloudflare Quick Tunnels(cloudflare.com ↗)
    296comments
  16. How to Write with an LLM(sockpuppet.org ↗)
    355comments
  17. You can run Git on object storage if you re-make packfiles(tigrisdata.com ↗)
    22comments
  18. Asking Authors About Their Own Papers(medium.com/tmlrorg ↗)
    discuss
  19. SDCC – Small Device C Compiler(sourceforge.net ↗)
    21comments
  20. Saving another 100TB of RAM(cloudflare.com ↗)
    86comments
  21. Science Is Open Software(jepedersen.dk ↗)
    46comments
  22. How OpenAI Used Its Own LLMs to Design Its Jalapeño Chip(ieee.org ↗)
    109comments
  23. Why building a Rust LSP is hard(rust-glancer.github.io ↗)
    42comments
  24. NASA-IBM Lunar Foundation open-Source Geospatial AI Model(usra.edu ↗)
    5comments
  25. Ray Ozzie and the Optimism of Being Early(reproof.app ↗)
    4comments
  26. Ctenophores: Wonders of Biology(quantamagazine.org ↗)
    6comments
  27. The first new cat species discovered in 100 years(nationalgeographic.com ↗)
    116comments
  28. OpenJev(openjev.com ↗)
    274comments
  29. Goroutine Leak Profiles(go.dev ↗)
    6comments
  30. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    89comments

How to Use AVX512 in Golang

98 pointsby 3y agogorse.io
33 comments
3y agoHN ↗

For someone experts assembly, avo is a better tool to write assembly in hand.

3y agoHN ↗

Cgo is a real option here, or at least would be an interesting comparison. The function is likely called with large enough data to amortize the (few ns) overhead and it's certainly more maintainable.

Another option is GOAMD64=v3 / v4 which will enable AVX2 / AVX512 on the regular Go output, although the compiler does almost no autovectorization compared to gccgo/gollvm.

3y agoHN ↗

It is a pity that CGO isn't in the final benchmark. >_<

3y agoHN ↗

Granted I don't know what will happen between now and March 1st, but there are some inaccuracies in this article... is this a GPT product?

- Encoding Machine Code[0] Not sure what "Go assembly provides three instructions for representing binary machine code" is intended to mean, but go supports register moves/actions for Byte(1)/Word(2)/Long(4)/Quad(8)/Octo(16), both aligned and unaligned (depending on architecture/processor). The next section literally references a quad action (`movq`). Note O/Octo and DQ/Double Quad mean the same thing depending on instruction/arch (sigh)

- When you're using specialized features you have other commands for larger register features (eg in AVX512 on AMD64 asm:`MULPS`, goasm:`VMULPS`)

- Redirect Jump Instruction[1], what is the value of this conversion recommendation if this article is recommending an auto converter that should do this for you? Go-asm can support jumping to addresses (routine scoped), or labels.. labels can be in any case, perhaps goat requires only upper case?

- Generate Go Function Definitions[2].. err isn't this the value prop of goat[3], the point of this article, that this can be done for you? Why are `cznic`, and `cc` being introduced here?

- Function Calls[4] The "complete wrapper" won't compile (typos), I think it's supposed to be closer to [5] (in the repo)

- Function Calls[4] the "Note" makes no sense given the code is go only (missing go-asm paste?)

- The summary benchmark[6], demonstrates AVX2 (far more common) is often faster, and doesn't explain what was measured, nor on what architecture, whether it was aligned, whether any steps were taken to improve performance on the architecture. Based on the repo [7], there's no attempt at alignment, if you can't do AVX512, or AVX2, you can still do 64bit/quad operations rather than going straight to 8bit/byte ops.

- The assembly (.s) files seemingly produced by GOAT[8] are far from human readable go-asm files (the comments in the file could be go-asm source code), don't follow the convention of <file>_<arch>.s, and don't support all platforms that C/golang do (although ARM64 & AMD64 is a large market share)

[0]: https://gorse.io/posts/avx512-in-golang.html#encoding-machin... [1]: https://gorse.io/posts/avx512-in-golang.html#redirect-jump-i... [2]: https://gorse.io/posts/avx512-in-golang.html#generate-go-fun... [3]: https://github.com/gorse-io/gorse/tree/master/cmd/goat [4]: https://gorse.io/posts/avx512-in-golang.html#function-calls [5]: https://github.com/gorse-io/gorse/blob/master/base/floats/fl... [6]: https://gorse.io/posts/avx512-in-golang.html#summary [7]: https://github.com/gorse-io/gorse/tree/master/base/floats [8]: https://github.com/gorse-io/gorse/blob/master/base/floats/fl...

3y agoHN ↗

I am the author and I am really regret about this title. I think a better title should be "How to Use AVX512 in Golang via the C Compiler" :O

3y agoHN ↗

The graph at the end is not readable on the dark theme background. The labels are almost the same colour.

3y agoHN ↗

Another suggestion for the title: Go, not Golang.

3y agoHN ↗

If faced with a co-worker who uses 'Golang', try pronouncing it 'Gol-ang' at regular intervals, liable to annoy them sufficiently to persuade them to desist ...

3y agoHN ↗

They’ll more likely ask if your code is still compiling, since you have so much free time.

3y agoHN ↗

For that sort of problem I'd generally use C, so laugh in their face :-)

3y agoHN ↗

This is a hill I am also willing to die on.

Last time this annoyed me, I did a thorough look at the Go source code to figure out how accurate calling the language "Go" is. Basically, aside from the mailing lists and bug tracker URLs, "golang" only appears in one place; the ppc64 port contributed by IBM. Everywhere else in the code, it refers to itself as "Go".

3y agoHN ↗

"Go" matches to many things unrelated to the programming language. Golang is more likely to match specifically the programming language.

3y agoHN ↗

Similar to how many people back in the day used "csharp" instead of C# so search engines could actually find things.

3y agoHN ↗

It didn’t help that search engines would “helpfully” ignore the sharp symbol (octothorp) and show results for just “c”

3y agoHN ↗

Is discarding the primary communications channels for the project a valid decision? In addition, the main website of the project was "golang.org" for over a decade. That domain still redirects to the current homepage at go.dev.

3y agoHN ↗

Ruby is at ruby-lang.org but I've never heard anyone call it Rubylang. You can't always get the domain name (or Google Group) you want.

3y agoHN ↗

They're out there: https://github.com/topics/rubylang

I get that these people are not in your circle or whatever, but the term 'golang' appears nine times on Go's own case studies mood board: https://go.dev/solutions/#case-studies

Personally I suspect people more readily adopt 'golang' because all the mailing lists used it as the prefix, the domain was golang (as opposed to go-lang), the official subreddit is /r/golang, and the developers have such a habit of prefixing things with 'go' (as in GOPATH, goroutines, etc). I used to believe it was because there was another programming language with the same name, but I never did find examples of its use in the wild, so I'm no longer sure that affected anything.

3y agoHN ↗

March 1, 2023

What? Did a timetraveller write this?

3y agoHN ↗

Or it's a US/normal date format confusion?

3y agoHN ↗

Aliens are really sloppy these days. A real human would never do AVX512 in Golang and travel in time.

3y agoHN ↗

I've been trying to make this clear to every one who whines about "oh no the clock rate goes down a little if you use this":

AVX-512 is VERY fast, time even gets ripped asunder.

3y agoHN ↗

Not really related to golang but: AVX512 is THE sweet spot to go for that for vector instructions as 512bits=64bytes=x86_64 cache line size.

3y agoHN ↗

Dumb question but do you have to do anything manually to ensure it’s actually aligned to a single cache line or does it just happen because of the way things work?

3y agoHN ↗

Not a dumb question. In theory, yes you want it to be aligned for performance reasons, and you can do this with one of the _aligned_malloc()/aligned_alloc() variants. In reality though, for any non-trivial algorithm, you may not be able to always enforce this.

3y agoHN ↗

Usually you alloc some slack memory to be able to re-align on a cache line. But yeah, it seems better if the allocator can cleanely deal with that.

3y agoHN ↗

Upcoming .NET 8 will get native support for Vector512 (AVX512) in runtime, and you can write platform-independent code today with Vector<T> for length-agnostic algorithms that will automatically take advantage of it. No need to ever write assembly, or some other special syntax - just pure C#.

3y agoHN ↗

That is fantastic. Swift in the Mac has something similar thanks to the Accelerate framework. What I’ve seen, however, is that if you are targeting a very specific platform (for example, the M1 family), you get better performance by directly using the intrinsics supported by that platform. In the real world, you are unlikely to actually have such a specific target, so this may not be so important.

I look forward to seeing some benchmarks with .NET - Microsoft needs to support a pretty wide variety of platforms. It will be interesting to see if their implementation is better!

3y agoHN ↗

Accelerate is a bit different in being both overall more high level API and specific to Apple (and abstracts away the usage of AMX and ANE too). On the other hand, Vector<T>/Vector128/256/512<T> in .NET is what is 'portable-simd' to Rust except it is not in preview and widely used across standard library where applicable.

As of now, Vector<T> automatically targets AVX2, SSE4.2 and AdvSimd (NEON). Vector256<T> targets AVX2 (for the lack of ARM counterpart) and Vector128<T> targets SSE / AdvSimd respectively.