Live data from Hacker News

Hello World on the GPU (2019)

acko.net

11–20 of 44 posts

Re: Hello World on the GPU (2019)

#11
post #5
post #4

"Graphics programming can be intimidating. It involves a fair amount of math, some low-level code, and it's often hard to debug. Nevertheless I'd like to show you how to do a simple "Hello World" on the GPU. You will see that there is in fact nothing to be afraid of." 57 created objects later "Hm. Damn" Well .. there is a reason it is usually "hello triangle" on GPU tutorials. Spoiler alert, GPUs ain't easy.

Well if you use glBegin it's pretty easy. glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); And there you go you got a triangle. It's great for beginners because they can see the results very fast and once they want to start having crazy graphical effects or need more performance you can move to shaders.

The hardware was designed to display triangles, not to do 'Hello world'.

So it's not all that surprising that the one is easier than the other, in a way it is surprising that the other can be done at all. But as CPUs and GPUs converge it's quite possible that NV or another manufacturer eventually slips enough general purpose capacity onto their cards that they function as completely separate systems. And then 'Hello world' will be trivial.

Re: Hello World on the GPU (2019)

#12
post #10
post #4

"Graphics programming can be intimidating. It involves a fair amount of math, some low-level code, and it's often hard to debug. Nevertheless I'd like to show you how to do a simple "Hello World" on the GPU. You will see that there is in fact nothing to be afraid of." 57 created objects later "Hm. Damn" Well .. there is a reason it is usually "hello triangle" on GPU tutorials. Spoiler alert, GPUs ain't easy.

3D APIs were easier back in the yearly days. Nowadays using "legacy" APIs is relatively easy, however it requires a background knowledge on how GL became GL 4.6, DX became DX 11 and so. Modern APIs are super low level, they are designed as GPU APIs for driver writers basically. Since they cut the fat legacy API drivers used to take care for the applications, now everyone has to deal with such complexity directly, or…

What's wrong with using middleware engines? That was pretty much the expected case for people who didn't /need/ the level of control exposed by APIs like vulkan or dx12.

It's pretty much what OpenGL "drivers" were doing past the introduction of hardware shaders anyway - acting as a pretty thick middleware translating that to low-level commands, only having the user API being locked into a design from decades ago.

And considering how hard it was to get Khronos to eventually agree on vulkan in the first place (that effectively being a drop from AMD in "Mantle" then only tweaked by the committee), I'm not surprised they haven't standardized a higher-level API. So third party middleware it is.

Re: Hello World on the GPU (2019)

#13

As of this year (ish), `int main() {puts("hello, world\n");}` stands a decent chance of running on a GPU and doing the right thing if you compile it with clang. Terminal application style. Should be able to spell it printf shortly, variadic functions turn out to be a bit of a mess.

Do you happen to have a link to these developments?

Re: Hello World on the GPU (2019)

#14
post #8

There's a degree of GPU-style going on here, but its not OpenGL or DirectX. for y in 0..height { for x in 0..width { // Get target position let tx = x + offset; let ty = y; So this code, in a language I'm not too familiar with, is clearly a GPU concept. Except, this 2-dimensional for-loop is executed in parallel on modern GPUs in the so-called pixel-shader. A Pixel-shader is all sorts of complications in practice tha…

It is a Rust application making use of wgpu, Rust's WebGPU native library.

Nope.

Pixel shaders in WebGPU / wgpu are written in WGSL. The above 2-dimensional for-loop is _NOT_ a proper pixel shader (but it is written in a "Pixel Shader style", very familiar to any GPU programmer).

Re: Hello World on the GPU (2019)

#15
post #10
post #4

"Graphics programming can be intimidating. It involves a fair amount of math, some low-level code, and it's often hard to debug. Nevertheless I'd like to show you how to do a simple "Hello World" on the GPU. You will see that there is in fact nothing to be afraid of." 57 created objects later "Hm. Damn" Well .. there is a reason it is usually "hello triangle" on GPU tutorials. Spoiler alert, GPUs ain't easy.

3D APIs were easier back in the yearly days. Nowadays using "legacy" APIs is relatively easy, however it requires a background knowledge on how GL became GL 4.6, DX became DX 11 and so. Modern APIs are super low level, they are designed as GPU APIs for driver writers basically. Since they cut the fat legacy API drivers used to take care for the applications, now everyone has to deal with such complexity directly, or…

> now everyone has to deal with such complexity directly, or make use of a middleware engine instead

You don't really have to though, you can still use the higher-level older graphics APIs. It wouldn't have made much sense for Vulkan to include a high-level graphics API as well, as those APIs already exist and have mature ecosystems.

Similarly, in Windows land, you aren't forced to use D3D12, you can still use D3D11 or even D3D9.

Re: Hello World on the GPU (2019)

#16

As of this year (ish), `int main() {puts("hello, world\n");}` stands a decent chance of running on a GPU and doing the right thing if you compile it with clang. Terminal application style. Should be able to spell it printf shortly, variadic functions turn out to be a bit of a mess.

Do you happen to have a link to these developments?

Documentation is lagging reality a bit, we'll probably fix that around the next llvm release. Some information is at https://libc.llvm.org/gpu/using.html

That GPU libc is mostly intended to bring things like fopen to openmp or cuda, but it turns out GPUs are totally usable as bare metal embedded targets. You can read/write to "host" memory, on that and a thread running on the host you can implement a syscall equivalent (e.g. https://dl.acm.org/doi/10.1145/3458744.3473357), and once you have syscall the doors are wide open. I particularly like mmap from GPU kernels.

Re: Hello World on the GPU (2019)

#17

Earlier quoted context omitted.

Do you happen to have a link to these developments?

Documentation is lagging reality a bit, we'll probably fix that around the next llvm release. Some information is at https://libc.llvm.org/gpu/using.html That GPU libc is mostly intended to bring things like fopen to openmp or cuda, but it turns out GPUs are totally usable as bare metal embedded targets. You can read/write to "host" memory, on that and a thread running on the host you can implement a syscall equivale…

This is super interesting, thanks!

Re: Hello World on the GPU (2019)

#18
post #12
post #10

Earlier quoted context omitted.

3D APIs were easier back in the yearly days. Nowadays using "legacy" APIs is relatively easy, however it requires a background knowledge on how GL became GL 4.6, DX became DX 11 and so. Modern APIs are super low level, they are designed as GPU APIs for driver writers basically. Since they cut the fat legacy API drivers used to take care for the applications, now everyone has to deal with such complexity directly, or…

What's wrong with using middleware engines? That was pretty much the expected case for people who didn't /need/ the level of control exposed by APIs like vulkan or dx12. It's pretty much what OpenGL "drivers" were doing past the introduction of hardware shaders anyway - acting as a pretty thick middleware translating that to low-level commands, only having the user API being locked into a design from decades ago. And…

Nothing, middleware is exactly why most game studios hardly care about religious discussions regarding 3D APIs, as in FOSS circles.

I guess the problem is the expectation exactly by those that feel GL and DX 11 are done, and they need to directly use their replacements.

Re: Hello World on the GPU (2019)

#19
post #9
post #5

Earlier quoted context omitted.

Well if you use glBegin it's pretty easy. glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); And there you go you got a triangle. It's great for beginners because they can see the results very fast and once they want to start having crazy graphical effects or need more performance you can move to shaders.

Erm yes. A triangle is quite easy .. but here they tried a simple tutorial to actually print "Hello World" .. and surprise, it wasn't easy and in the end just stops.

It's not as easy as drawing triangles but glut which was a part of old school opengl had the function glutBitmapString which made it pretty easy to draw text in a few lines.

Re: Hello World on the GPU (2019)

#20
post #10

Earlier quoted context omitted.

3D APIs were easier back in the yearly days. Nowadays using "legacy" APIs is relatively easy, however it requires a background knowledge on how GL became GL 4.6, DX became DX 11 and so. Modern APIs are super low level, they are designed as GPU APIs for driver writers basically. Since they cut the fat legacy API drivers used to take care for the applications, now everyone has to deal with such complexity directly, or…

> now everyone has to deal with such complexity directly, or make use of a middleware engine instead You don't really have to though, you can still use the higher-level older graphics APIs. It wouldn't have made much sense for Vulkan to include a high-level graphics API as well, as those APIs already exist and have mature ecosystems. Similarly, in Windows land, you aren't forced to use D3D12, you can still use D3D11…

Kind of, many developers feel they are using legacy deprecated APIs, especially given how they are referred to in some circles.

Naturally that leads to some uncomfort.

Post reply on HN