ksummit.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Arnd Bergmann <arnd@arndb.de>, Dave Airlie <airlied@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Greg KH <greg@kroah.com>, Leon Romanovsky <leon@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Josh Triplett <josh@joshtriplett.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	ksummit@lists.linux.dev, dev@tvm.apache.org
Subject: Re: [MAINTAINER SUMMIT] User-space requirements for accelerator drivers
Date: Tue, 14 Sep 2021 13:47:38 +0300	[thread overview]
Message-ID: <YUB9ypMApWBzHTjK@pendragon.ideasonboard.com> (raw)
In-Reply-To: <CAKMK7uF8doVEPOmm1Do5Qa+JZ7Lji6Runw5F=wrxeVjrsMLLSw@mail.gmail.com>

On Tue, Sep 14, 2021 at 11:23:56AM +0200, Daniel Vetter wrote:
> On Tue, Sep 14, 2021 at 11:09 AM Arnd Bergmann wrote:
> > On Tue, Sep 14, 2021 at 1:33 AM Dave Airlie wrote:
> > > On Tue, 14 Sept 2021 at 08:05, Arnd Bergmann wrote:
> > > > >On Mon, Sep 13, 2021 at 3:54 PM Daniel Vetter wrote:
> > > > > I think BLAS are too high-level for these. Sure fore perfect speed the
> > > > > vendor probably wants to have their own BLAS thing, their own NN
> > > > > optmizer and a heap of other things, but for the low-level userspace
> > > > > we're talking about here that pretty much doesn't matter.
> > > >
> > > > I suppose high-level vs low-level is not the correct distinction here,
> > > > it's more like fixed-function vs programmable.
> > > >
> > > > As a fixed-function interface, something like GEMM is probably as
> > > > low-level as you would want to get, as it's big enough to make sense
> > > > as a single atomic command, but small enough to be able to build on
> > > > top of it.
> > >
> > > The distinctions is more programming model than fixed vs programmable
> > > in rough order of complexity
> > >
> > > a) device is MMIO programmed and can process one thing, kernel needs
> > > to mediate between exclusive users (big lock, initial drm subsystem)
> 
> I think even for these you might want a drm style uapi, where
> drm/sched takes different jobs and hammers them into hw in a kernel
> thread. Ofc it all depends what the programming model is, and
> something more fixed like media might make sense.

For completeness, there's a similar component in the V4L2 M2M framework,
but simpler. Jobs are executed sequentially in the order they are
received. The simplicity is mostly due to the fact that the type of
hardware V4L2 M2M supports doesn't have the ability to run multiple jobs
in parallel.

We also have ISPs that fall in this category, and use the V4L2 API in
memory-to-memory mode but without any scheduling, because context
switching doesn't exist at the hardware level and is too expensive to
implement in software. For those we restrict operation to a single
process at a time.

> > > b) device has a queue that can process untrusted userspace command
> > > with no memory safety (old drm drivers, in-kernel command stream
> > > parsing)
> > > c) device has queues, contexts, memory safety, virtual address space
> > > (newer drm drivers)
> > > d) device has full preempt on all hw blocks, is fully coherent, can
> > > trigger paging sanely, userspace can submit directly (pipe dream).
> > >
> > > What the device processes is of little consequence to the kernel
> > > driver model. the uAPI of course needs to reflect the above along with
> > > what the device can program. Since there could be a queue for a DMA
> > > device that isn't specificed but can be programmed to DMA random
> > > system memory.
> >
> > Thank you for the useful overview!
> >
> > > Devices in category (a) are the sort of things that can need kernel
> > > interfaces like a GEMM or BLAS level, however there is no point having
> > > an interface at that level for any of the b/c/d device. That interface
> > > needs to be in userspace somewhere, level0 or something like is
> > > probably where things will end up, and the type (a) devices will die
> > > out.
> >
> > I can see two reasons why one would want to support a type (a)
> > interface even with the more versatile devices:
> >
> > - It can be done in a generic way so that simply adding a kernel
> >   driver and loading some firmware into it makes existing user space
> >   software work out of the box.
> >
> > - It gives the manufacturer a way to get an upstream kernel driver
> >   without open sourcing their firmware (a.k.a. compiler and user
> >   space driver). Whether you consider this a good or bad thing is
> >   of course a matter of perspective.
> 
> I think for some embedded use-case this makes sense, especially around
> media stuff.
> 
> I don't think it's BLAS, because on the compute side you really want a
> compiler that sees through the entire thing and can optimize it. Afaik
> BLAS is for some quick prototype of matrix algorithms and most
> importantly, for the top500 list :-)
> 
> > > > I realize that fixed-function is not fashionable on GPUs, but they
> > > > are widely used in other areas (video codecs, crypto, ...) even when
> > > > you are running precompiled code on the accelerator hardware.
> > > > This would of course replace the question of open source user space
> > > > with the question of open-source firmware, as the user side would
> > > > become mostly while the accelerator goes from dynamically created
> > > > to a firmware blob.
> > >
> > > We have lots of fixed function on GPUs, video codecs are on most x86
> > > GPUs. It's how you program them that matters, most of them are behind
> > > queues similar to the 3D engine, so you program them the same way.
> >
> > So these would go through /dev/dri instead of /dev/media0? I can definitely
> > see a lot of codec drivers in the kernel that use a /dev/media interfaces,
> > and the tradeoffs between those two seem very similar to the tradeoffs
> > you get for machine learning accelerators.
> 
> Yeah we have plenty of codes running on top of /dev/dri0, with all the
> magic in userspace.
> 
> They are all very far away from anything that is a machine learning accelerator.
> 
> > > What isn't fashionable on GPUs is programmable blocks that are single
> > > user that only the kernel can program one user on at a time, since hw
> > > has long since left that model as desirable. There are some AI
> > > accelerators going doing the same path, but eventually they'll have to
> > > be shareable and catch up with GPU programming models to remain
> > > competitive.
> >
> > I'm not convinced by this at all. While I totally understand this argument
> > for GPUs and general-purpose users (phone, PC, server, ...), I also see
> > a lot of cheap SoC hardware with much simpler requirements. If the chip
> > is built for an embedded application (face detection, smart speaker, ...)
> > you would never need to have two processes access the same
> > accelerator hardware, or even just load a new model into it after
> > boot. Adding any complexity to the hardware increases the cost, so
> > you would only do it if absolutely necessary, or if the cheapest
> > off-the-shelf solution already includes it.
> 
> Yeah for those I think a more fixed uapi like drivers/media has a lot
> of makes sense. What I don't like is when vendors then use that excuse
> of "oh you only upload a fixed model at boot" to shovel in an acccel
> driver with full generic interface, but not all the userspace
> bits&pieces. There's unfortunately another accel driver in
> drivers/misc for qualcom soc, which really should be either a media
> driver (for the fixed function use-case) or a drm driver (for the
> fully programmable) use-case.
> 
> I think for the fixed-function interface case you can also make a
> reasonable argument that just documenting that fixed interface and all
> the parameters is good enough. But as soon as the interface becomes a
> generic "submit workload" style thing because you want to make it work
> for an entire set of "firmware" compiled by your closed stack, that's
> out of the window.
> 
> So yeah there's another driver in misc which managed to bypass review
> of two subsystem, not just one :-/

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2021-09-14 10:48 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 21:00 [MAINTAINER SUMMIT] User-space requirements for accelerator drivers Jonathan Corbet
2021-09-10 21:32 ` Josh Triplett
2021-09-13 13:50   ` Christian Brauner
2021-09-13 13:57     ` Daniel Vetter
2021-09-14  2:07       ` Laurent Pinchart
2021-09-14 14:40   ` Jani Nikula
2021-09-14 14:45     ` Geert Uytterhoeven
2021-09-14 14:59       ` Jani Nikula
2021-09-14 15:10         ` Geert Uytterhoeven
2021-09-10 21:51 ` James Bottomley
2021-09-10 21:59   ` Alexandre Belloni
2021-09-10 22:35     ` James Bottomley
2021-09-11 14:51       ` Jonathan Corbet
2021-09-11 15:24         ` James Bottomley
2021-09-11 21:52           ` Laurent Pinchart
2021-09-14 13:22             ` Johannes Berg
2021-09-11  0:08   ` Laurent Pinchart
2021-09-10 22:52 ` Mauro Carvalho Chehab
2021-09-10 23:45   ` Josh Triplett
2021-09-10 23:48     ` Dave Hansen
2021-09-11  0:13       ` Laurent Pinchart
2021-09-10 23:55     ` Thomas Gleixner
2021-09-11  0:20       ` Laurent Pinchart
2021-09-11 14:20         ` Steven Rostedt
2021-09-11 22:08           ` Laurent Pinchart
2021-09-11 22:42             ` Steven Rostedt
2021-09-11 23:10               ` Laurent Pinchart
2021-09-13 11:10               ` Mark Brown
2021-09-11 22:51           ` Mauro Carvalho Chehab
2021-09-11 23:22           ` Mauro Carvalho Chehab
2021-09-11 10:31       ` Leon Romanovsky
2021-09-11 11:41         ` Laurent Pinchart
2021-09-11 12:04           ` Leon Romanovsky
2021-09-11 22:04             ` Laurent Pinchart
2021-09-12  4:27               ` Leon Romanovsky
2021-09-12  7:26                 ` Greg KH
2021-09-12  8:29                   ` Leon Romanovsky
2021-09-12 13:25                     ` Greg KH
2021-09-12 14:15                       ` Leon Romanovsky
2021-09-12 14:34                         ` Greg KH
2021-09-12 16:41                           ` Laurent Pinchart
2021-09-12 20:35                           ` Dave Airlie
2021-09-12 20:41                           ` Dave Airlie
2021-09-12 20:49                             ` Daniel Vetter
2021-09-12 21:12                               ` Dave Airlie
2021-09-12 22:51                                 ` Linus Walleij
2021-09-12 23:15                                   ` Dave Airlie
2021-09-13 13:20                                   ` Arnd Bergmann
2021-09-13 13:54                                     ` Daniel Vetter
2021-09-13 22:04                                       ` Arnd Bergmann
2021-09-13 23:33                                         ` Dave Airlie
2021-09-14  9:08                                           ` Arnd Bergmann
2021-09-14  9:23                                             ` Daniel Vetter
2021-09-14 10:47                                               ` Laurent Pinchart [this message]
2021-09-14 12:58                                               ` Arnd Bergmann
2021-09-14 19:45                                                 ` Daniel Vetter
2021-09-14 15:43                                             ` Luck, Tony
2021-09-13 14:52                                     ` James Bottomley
2021-09-14 13:07                                     ` Linus Walleij
2021-09-13 14:03                           ` Mark Brown
2021-09-12 15:55                       ` Laurent Pinchart
2021-09-12 16:43                         ` James Bottomley
2021-09-12 16:58                           ` Laurent Pinchart
2021-09-12 17:08                             ` James Bottomley
2021-09-12 19:52                   ` Dave Airlie
2021-09-12  7:46                 ` Mauro Carvalho Chehab
2021-09-12  8:00                   ` Leon Romanovsky
2021-09-12 14:53                     ` Laurent Pinchart
2021-09-12 15:41                       ` Mauro Carvalho Chehab
2021-09-10 23:46   ` Laurent Pinchart
2021-09-11  0:38     ` Mauro Carvalho Chehab
2021-09-11  9:27       ` Laurent Pinchart
2021-09-11 22:33         ` Mauro Carvalho Chehab
2021-09-13 12:04         ` Mark Brown
2021-09-12 19:13 ` Dave Airlie
2021-09-12 19:48   ` Laurent Pinchart
2021-09-13  2:26     ` Dave Airlie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YUB9ypMApWBzHTjK@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=arnd@arndb.de \
    --cc=corbet@lwn.net \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dev@tvm.apache.org \
    --cc=greg@kroah.com \
    --cc=josh@joshtriplett.org \
    --cc=ksummit@lists.linux.dev \
    --cc=leon@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=mchehab@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).