707 points · by akvadrako · 6y ago · 462 comments
However, having a GPU driver not just be open source but in the upstream Linux kernel is a gigantic deal. Kernel development takes a long time, we have millions of lines in the amdgpu driver, and if every one of those dealt with the lengthy review process it would have never made it in the tree.
So it's a necessary evil. I do wish they would clean it up though, I sent a fix to amdgpu once that was the same thing for 3 different files that were largely duplicated. That kind of thing wouldn't fly anywhere else in the kernel
Another way of looking at it is -- I started playing with openwrt for a relatively small router, with 5 ports plus wifi.
I was amazed at not only the amount of openwrt code required to support the different router families and the different router models, but at the sheer amount of stuff turned on by default in the kernel just in case I might need to load a module for some obscure feature or package. I assume the same goes for a gpu driver both at the source level and in the kernel.
Propriatery drivers (especially nvidia), most likely has lots of similar game specific workarounds and optimizations (even going as far as overriding shaders in games with better ones they wrote). [1]
1: https://www.gamedev.net/forums/topic/666419-what-are-your-op...
The Nvidia driver is crappy, doesn't support Optimus, etc, but at least I haven't had any problems with it for as long as I've used it.
Anecdotal data and all that. I'm on a Radeon VII, pretty darn solid, will probably continue to choose AMD cards in the future. Wish the Windows driver were a bit more stable, and it's... frankly weird to be saying that in comparison to the Linux driver for the same card.
I have an AMD 5700XT in my Windows games machine, and the driver is an absolute travesty. And looking over the installed files is a horror show. Qt5WebEngineCore.dll and avcodec-58.dll, because a browser engine and ffmpeg are essential in a device driver. And why does FacebookClient.exe exist? Fuck knows.
I would only use AMD cards in my Linux boxes. The nvidia drivers/cards pale in comparison.
I'm hoping AMD's next gen turns out to be competitive with the RTX3000 series for my next GPU for the same reason.
Apparently AMD doesn't have the resources to debug these millions lines of code, since this has been open for a year now.
Yet people still say NVIDIA on Linux has issue. They don't support Wayland and tend to lag behind with Linux only tech in general, but the driver itself is top notch. I haven't had an nv driver crash on Linux in 10 years. It's only the same echo chamber borne by the famous moment of Linus flipping NVIDIA the bird.
I never had a mentionable issue with AMD cards since switching to the open source driver approx. a decade ago. I have a NVIDIA 1060 card in my workstation for CUDA - every single time I put it in running state again, I have a realistic chance of completely borking my system.
In fact I had an AMD card installed after the first two incidents, simply to have at least a chance of having working video output when the NVIDIA driver once again doesn't want to talk to the kernel.
That and the whole practical implications and idealistic differences of having an (mostly) open source driver vs. a (mostly) closed source driver (I think we can agree that the open source NVIDIA driver is out of the discussion).
Obviously you might run into problems if you try to run very recent hardware right after availability. Kernel driver development is not ideal for cutting edge hardware and some things might break and it might need some time for your distro to ship the newest kernel/driver.
I am, however, very much looking forward to the new AMD GPUs. Hopefully the RX 6000 series will be near a 3080 in more than the 3 hand picked games in their teaser. Would love to use Wayland on my desktop.
Searching for amdgpu bug reports leads to:
https://amdgpu-install.readthedocs.io/en/latest/install-bugr...
which links to a page saying "Bugzilla is no longer in use" :-(
This is under Qubes/Xen, though, so maybe that causes extra problems. If any devs are reading, I did report it here in the end:
The first was that my distro (KDE Neon based on Ubuntu 18.04) shipped an older version of Mesa at the time, which was too old for the AMDGPU driver, so I had to add a PPA with an updated version. Since Neon updated to a 20.04 base, it works straight from a clean install. It also worked with no issues when I switched to openSUSE Leap 15.2.
The second was that DVI output was limited to single-link instead of dual-link. My monitor at the time only supported full 1440p through dual-link DVI or displayport, and the old GPU didn't have displayport. Buying a displayport cable was a quick fix, and I believe the DVI issue is fixed in the driver now.
Aside from those two minor hurdles, it has been smooth sailing, very good OpenGL performance in the games I play.
I bought my RX 5700XT shortly after release, and was using alpha/beta kernel releases and downloading extra files manually for several months after to run, then an upgrade/update may turn into a blank screen on boot for me. It also broke out of the box support for running full VMs, which was pretty painful for me as well, and I wasn't going down that rabbit hole to try and build it myself.
YMMV of course.. but that's just my take on it.. I bought specifically for Linux support, but took a few months to shake out.
Most of the Linux community has a historical hatred of Nvidia because of the driver issue so there’s a lot of relative love out in forums, but just “stable” would be a step up for me for Radeons on windows.
With native performance on official Linux games on par with or better than the Windows equivalent, and more and more games getting Linux ports due to Vulkan, I just about have no need to boot into Windows at home anymore apart from Fusion 360.
As a workstation in Windows, since I don't overclock I don't see any stability issues. Fusion 360 is fast and fluid unlike my 8 year old Sandy Bridge dinosaur at work, even after adding a GT 1030. Good quality Crucial RAM and a no-frills AsRock B450 board make for a rock-solid build. Ditto on Linux as a workstation, everything just works and works well, and it's superb for 3D modeling and music creation (two of my main hobbies).
AMD has incredible CPUs, but just buy an Nvidia GPU - especially if you are using linux.
Also, the open source driver for Nvidia (nouveau) has incredibly poor performance compared to Nvidia's proprietary driver, and lacks essential features such as reclocking for recent hardware generations:
https://nouveau.freedesktop.org/PowerManagement.html
AMD's and Intel's open source drivers are their primary offerings on Linux and have good performance across all hardware generations.
That said I just picked up a quadro (not my choice, came with a prebuilt NUC) and I've been pleased to find that it "just works" on freebsd (I use it to realtime transcode video), so clearly great experiences are possible and I don't want to be needlessly harsh.
Personally, I'm dying for a discrete intel card. I can't recall any hiccups with intel chipsets, ever, and that matters WAY more to me than raw performance.
Could you say more about what specifically makes the driver abominable? Is it just those files with largely duplicated code?
abstraction is one of the main sources of code complexity.
you start with one function used in 3 places, then add boolean args to it to get slightly different functionality at each place, eventually it becomes a mess of complexity
The amdgpu driver has duplicated files for different versions of things, so it'll have thing_v6.c and thing_v7.c and thing_v8.c with a lot of duplicated functions.
The more common way of doing something like this would be to have structs of function pointers that get populated based on what version of GPU you have. You have one file with all the common functions that they can share, in the definitions for each GPU version you set the majority of the function pointers to the common version they all share and for ones that have to be different, you set them to their unique version. That way you can define all the common functions once, and point to them in the structs for each version.
Having a quick flick through the code now, they do use structs of function pointers in each version for common operations but they still don't abstract out the ones that are either identical or have very few differences that you could special case.
Refactoring such a giant driver for no performance gain is going to be extremely low on AMD's todo list, so it'll probably stay like that. It just doesn't look like anything else in the kernel
A big issue also is the use of bitfields as much as reg duplication. Bitfields in c/c++ are a minefield if you don't lock down a known-good compiler version because there's just so much of it that's technically unspecified. Oftentimes you'll also have issues where certain register fields exist for some registers of a series and not the next or where the functionality/sizing/interpretation is context dependent or where certain locks or write orders are needed for correct access and these are often handed with presence checking macros.
IMO, if we want better driver code, it's time for GCC/Clang to nail down the bitfield layouts for the embedded use cases. This has been broken for far too long.
It's one of the unusual circumstances where, unfortunately, abstraction can decrease flexibility and increase development time.
That is, it's better to have duplications than the wrong abstraction. This may also be in reference to C compilation, in that loading header files and dependencies costs more than inlined code. That's one of the goals that the Go language sought to resolve, anyway.
So, it includes many times more register definitions than are ever used (consider there are 8x more register definition lines than actual code lines that could use them) and it includes many sets of 16 or 64 definitions that a software developer would have made one parameterized definition (all the same except for _00, _01, _02, _03, etc). But this is exactly what the hardware guys generated for public release, and it is to be used as-is.
IMHO it's kinda annoying and sad. The rest of the kernel is held to a higher standard, that's why all the other non-trivial multi-arch multi-family multi-generation code in the linux kernel is much more concise / less sloppy. It takes a lot of effort to make it that way, and commercial companies pretty much never bother, except when required by the Linux maintainers.
But, modern graphics drivers are way too complex and way too much work, and most people do want some proper modern GPU support in the kernel, so compromises have to be made. It's not too bad, just a bunch of inert header lines, git and the compiler handle them just fine I guess.
...which is arguably not compatible with the GPL:
"The source code for a work means the preferred form of the work for making modifications to it."
In other words, there's more functionality that they're keeping secret? Sounds like a challenge...
Edit: so the hacker spirit is not welcome here...?
If those headers aren't expected to change then, with regards to accountability, it's far better to have the code checked into the version control and processed as is.
More importantly, if the code is already generated then there's no need to make the build system more brittle by adding a non-standard build target that depends on custom/third-party tools.
In many hardware shops the C definitions for the visible registers are generated automatically from the hardware's source code
Also, their driver is very complex, and they are constantly improving their hardware. They don't want to be dependent on getting new features and performance improvements upstreamed.
[1] https://www.eevblog.com/forum/general-computing/hacking-nvid...
Why are these kind of licenses even allowed. If I buy a product, surely I can do with it as I please?
Also, why doesn't TSMC slap a license on every IC that leaves their fab, taking (say) a 30% profit from every application in which their ICs are being used?
The problem is in the software (the driver) which you never can buy, only license under a long list of conditions which prohibit specific uses.
If e.g. Noveau could implement interfaces needed for CUDA, you could probably try to use a 3050 in a datacenter. I bet NVidia has provisions against this turn of events, too.
Not happy? That is what makes FOSS so appealing.
I don't follow the semiconductor industry closely enough to know anything about TSMC's business practices, but these kind of contracts are far from unheard of in other sectors.
What are they going to do, call you and ask how you are using the GPUs? Don't answer. Message you on Facebook? Don't answer. Visit you? Don't publish your address.
Alternatively, just don't call it a datacenter. Just call it a private internet gaming cafe or something of that sort. NVIDIA doesn't have a right to know what's actually inside.
We no longer buy products these days. We license them. Another form of rent that allows the true owner to maintain control. Somehow this became the norm.
You could try to regulate that what is manufactured is not gimped on it's way to the consumer for ideological reasons but in the end you'd just end up paying more for a separate physical model because the profit margins on these advanced use cases are simply what drives GPU design.
As for the royalty licensing TSMC is ahead in abilities and has captured an enormous portion of the market but it's not so far ahead that it can eat however far into customer income streams as it wants. Other manufacturers still exist and get deals, Nvidia is using Samsung 8nm for the latest round of GPUs for example. If it continues to increase its lead then we may see that type of agreement grow though.
Because companies would stop using TSMC chips...?
Not to mention the logistical problems to attribute "profit" to any chip in particular.
They're not in (some parts of) Europe.
NVIDIA reduces (actually reduced on die) FP64 calculation units and disables ECC RAM support for GeForce (except some Titans) to not to be used in datacenter. Previously it works because most scientific calculations requires FP64 calculation and reliability is matter.
But now is the deep learning era, it won't need FP64 calculation and rare RAM error isn't matter. So they must enforce the EURA to avoid dirt cheap Geforce to be used in datacenter for deep learning.
How much is nvidia single handedly holding back innovation and new discoveries?
The saying is really that free market competition drives innovation.
Obviously patents and copyrights are government-issued monopolies, and monopolies are by definition lacking in competition.
The theory is that by granting the monopolies we get more innovation. Often the theory is wrong.
Especially when we allow the company to leverage the monopoly on the thing they actually invented into a monopoly on ancillary things that are only used in combination with that class of product.
This is the number one usability issue with nouveau: no firmware means no re-clocking, which means bad perf.
[0] https://www.quora.com/What-do-you-think-about-open-sourcing-...
is contradicted by the fact that just recently a version of windows source (old, but still) was leaked, and people did manage to successfully build and boot the leaked windows (xp and server 2003 IIRC) code within days of that source becoming available.
There's a talk by Bryan Cantrill about that.
They basically could not provide a fully functional OS because some marginal yet used-everywhere parts where licensed and proprietary (Bryan cites the internationalization library as an example).
https://www.reddit.com/r/hardware/comments/j217oo/gamers_nex...
while obviously not an official source, that isn't particularly surprising either.
as an additional relatively-well-known-but-possibly-incorrect bit of internet lore, right now their Linux driver is basically a wrapper around their Windows driver, so that explanation makes a lot of sense. They would have to go through and disentangle what parts they own and what needs to be stripped out / replaced for the linux version at an absolute minimum.
Now AMD is opensource? Great! However, it's still very far from perfect. You only have to take a look at the list of AMDGPU issues at freedesktop[1]... because being opensource is easy, but working fine in a stable manner is another.
And what about AMD bug tracker? It's open, so you can see the bugs. That's a plus, not a minus. Nvidia blob has all the bugs hidden somewhere, so you don't see them. It doesn't mean the blob doesn't have them.
I think it's the opposite. Some years ago, Nvidia was your only chance to have accelerated graphics on Linux. ATI/AMD didn't care about it at all, and Intel cards were not for gaming. So Nvidia made it possible to do things in Linux when nobody else allowed you to... how's that hindering the progress of anything? Specially when nobody forces you to get an Nvidia card.
> And what about AMD bug tracker? It's open, so you can see the bugs. That's a plus, not a minus. Nvidia blob has all the bugs hidden somewhere, so you don't see them. It doesn't mean the blob doesn't have them.
Yes, I didn't say Nvidia was bug free. I just said AMD drivers for Linux are, at the moment, far from perfect, despite being opensource. I'd say, for newer cards, they're worse than Nvidia's. I value opensource, but if I have to choose between having an opensource desktop crashing twice a day, vs. the Nvidia blob, of course I'd go for the latter, as much as I'd love to have a fully opensource OS.
They're afraid of patent trolls.
That one is fun.
Meanwhile projects like Sway have a direct "Go to hell if you use nVidia, we won't let you run this code." It's bizarre that you blame nVidia for this.
That frankly seems like horrible software design.
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
This is a case where code is identical not by random chance but due to an underlying logical pattern (in this case: ring buffers for communication between CPU and GPU seem to continue working the same way). Hiding that via code duplication is going to make the code overall less maintainable, because the code lacks implicit knowledge of these patterns.
P.S.: It's interesting how many people missed that my complaint was specifically not about the auto-generated part, but about the part that humans copy&paste.
Your customers will be hella pissed at you if their favorite game suddenly doesn't work on their system after a driver update. So you need to test a representative sample of previously-working software across all hardware that the updated driver applies to.
That sounds like a nightmare, and a capital-intensive one because you need to keep machines up with all of these cards, both in continuous integration and for interactive debugging.
I can understand the impulse to keep the list of hardware that new driver versions support small.
For example, maybe you had a chip bug in the previous hardware generation which caused the system to hang after several days of stress testing. You found a software workaround for the bug, but every time you touch the code you need to re-verify the workaround, which takes days.
Of course, the downsides of forking the code are also very apparent...
I'm not defending them, but sometimes something is good enough and you have to move on.
It's possible that the AMD developers are from a Windows culture where they don't have to worry about this because Microsoft gives them a stable interface. Though even there, I find it questionable whether it's a win. Surely the occasional bug will surface that affects drivers for older hardware as well?
If driver version X worked but X+1 doesn't on your driver - don't update the driver. But when the driver is in the kernel trunk then that option isn't that simple.
The rule of three is not exclusive to the embedded world. It´s far better to have duplicate code around then to have to deal with poor generalizations that affect multiple independent modules, which in this case mean hardware support.
To put it in perspective, how many pieces of hardware would you require to re-test and validate if you decided to refactor bits of drivers that might share a common code path?
abstract class BaseDriver {
abstract commonThing()
}
abstract class BaseDriverV1 extends BaseDriver {
commonThing() {
console.log('This is the common method implementation for all V1 drivers')
}
abstract doThingOnlyV1Does()
}
class DriverV1_1 extends BaseDriverV1 {
doThingOnlyV1Does() {
console.log('This is how Driver V1.1 does the V1 thing')
}
}
This way you can use either an interface or an "abstract" definition that declares the base driver methods and the versioned driver methods, then provide version-dependent implementations where needed, or else share the common implementations by inheritance/extension.Maybe this turns into spaghetti at scale and it actually is easier to just copy-paste all of it, who knows.
Point being, maintain the code generator and not the generated code.
It's a good system. You shouldn't complain. And deleting code is easy since not everything depends on everything
Why? If it's auto-generated and the generated code is never touched by humans, that's not too bad.
This information is sourced by some CAD/synthesis tool and just describes the hardware register layout.
Manually maintaining that would be much worse and error prone.
Care to weight in the impact on developer hours and cycles of having to debug problems caused in how the autogenerated headers are created?
If the code is not expected to change and was already subjected to verification and validation, ensuring that it stays the same is a good way to avoid wasting time tracking bugs on code paths that assuredly were already verified.
I've seen this said a couple of times lately. What is the source?
Here's how I count the size of the code:
So if a codebase is 1 million lines, but 900k was autogenerated using, let's say, a 10k line 'metaprogram' (which is otherwise not included in the source), the real size of the code is 100k + 10k = 110k.
Now, with the stupid vcn_* .c duplication, that I have serious problems with. But what you could do is take a diff of the two vcn_* .c files, keep those diffs as part of the source code, plus only one version of vcn_* .c file, but now add a small script that generates the remaining vcn_* .c files during the build process by using the diffs, e.g., using the patch command. Now the size of the diffs and the size of the patch script, plus the size of one vcn_* .c files, is a better measure of the size of the code.
Of course this is a short-term workaround. There's still a need to refactor the code properly.
In many cases it is more useful to calculate the lines of code according to what was checked into the build system, since those files can drift from the primary source. This is true, even if a million lines of checked-in source originated from 1k lines of meta-source.
I'm talking about the right way (IMO) of assessing the software complexity of the codebase.
And I'm also talking about the fact that it is trivial to make cloc match my definition of source code size "if" ... the developers are willing to do a small amount of work by moving code-gen into the build process and not committing pre-generated code into the source, but the metaprogram scripts instead.
By commercial standards, the Linux kernel is really small. The average enterprise application which has been in development for that long (almost 30 years) usually has at least several million lines of code, if not tens of millions or more.
User facing functionality is HUGE in size compared to tech functionality, usually.
No given person is ever actually running most kernel code. If you took only lines compiled into the core on an average system plus the line count of currently loaded modules, you'd come up with a much smaller number.
https://gitlab.gnome.org/GNOME/mutter/-/issues/1108
Hopefully not for long though with this
https://cgit.freedesktop.org/~agd5f/linux/commit/?h=amd-stag...
However, the new Display Core does not support analog output and it will stay dark.
Fortunately amdgpu.dc=0 is still an option, but I dread the day when this code path is removed (or bit rots away).
You can buy relatively inexpensive active DVI/HDMI to VGA converters if that helps.
Not at all. It's an old 19" with a resolution of 1280x1024, you can get those pretty much for free these days.
But hey, n + 1 screens > n screens :D
I usually just have my browser on it in full screen. And because of the resolution I don't have to worry about overly long lines on websites that aren't restricted in with (like hacker news).
At work I picked up an old 19" TFT from the trash that connects neatly to the unused VGA port of the docking station. It has abysmal ghosting issues, so it's no use for the browser, but still good enough for a terminal.
With modern graphics cards supporting many outputs and monitors that you can literally get for free, you can have the luxury of dedicating a display to a single task or application, so that's pretty cool.
I see random buffer garble when waking the external screen, sometimes the machine freezes with hw video decoding and the resolution switches to low-def on monitor sleep only to switch back on monitor wake. It's a shitshow.
This driver is I believe part of the common codebase that AMD upstreamed to the Linux kernel, it's shared with its proprietary driver on other platforms.
That said, the Linux kernel is not typical code. Great swaths of it are architectures and devices you will not need, so they are rightly ignored.
AWS had a blog post about this topic a few years back. They created a cut-down Linux variant for running Lambda functions that only supported exactly their server architecture, only contained exactly the drivers they actually use, and notably only had 1 keyboard driver for a keyboard with only 1 key, which was mapped to Halt.
EDIT: monocasa points out below that the compiler is not a correct example - true, that does live in e.g. mesa userspace code.
Just for comparison, the whole DOS 2.0 operating system, which was written in assembly entirely, has just 37955.
Apples to oranges.
I mean, how many drivers were shipped with DOS 2.0?
Yes, apples to oranges... but interestingly so not as a knock that DOS was coded better or something.
Except that's not the intent that's conveyed by blindly throwing LoC numbers into the air. The intent is to suggest the exact opposite: bloat. Hence the blind comparisons that mean nothing at all.
And the relevant doc in the kernel source: https://github.com/torvalds/linux/blob/master/Documentation/...
Never looked at a single line of their code, but still presumptious enough to suggest pruning and repotting before watering the beautiful rain of more features :)
-- An idea to be fertilized with several grains of salt
To compare a driver with the kernel proper, seems very strange. There are other large codes in the world too.
Why not offer the driver as additional package / download?
> False positives because def and config are pretty common suffixes:
The driver has had issues for ages with AMDs new cards. Guaranteed if you’re downvoting this you have no used a recent AMD card on Linux.
yes '' | make localmodconfig
will create a config based on current config and loaded modules (lsmod). Disables any module option that is not needed for the loaded modules.Also Hacker News: AMD is evil because they increase the size of the kernel by 10%.
Honestly, I think Nvidia made the right call by just focused on ordinary users who just want the card to work and can just focus on their work.