Driver of Intel(R) Gaussian & Neural Accelerator
Subsystems (2)
v3 cover Driver of Intel(R) Gaussian & Neural Accelerator
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
For a list of processors equipped with Intel(R) GNA device, please refer to this link:
https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_GNA.html
We think contributing this driver to the upstream kernel project is the best way for developers and users to get the latest Intel(R) GNA support in a Linux kernel, through the mainline to any Linux distributions installed on their systems. Upstreaming also enables contribution from developers around the world to the driver once it is merged.
The driver works with Intel(R) libraries in user space. The Intel(R) driver exposes a few IOCTL interfaces for use by libraries in user space. The libraries are open sourced and are available at:
https://github.com/intel/gna
---
Changelogs:
v1->v2:
- driver's new layout:
- driver name: gna -> intel_gna
- module name: gna -> intel_gna
- device file name: /dev/gnaN -> /dev/intel_gnaN
- driver's source directory: drivers/misc/gna/ -> drivers/misc/intel/gna/
- UAPI: include/uapi/misc/gna.h -> include/uapi/misc/intel/gna.h
- DOC: Documentation/misc-devices/gna.rst -> Documentation/misc-devices/intel/gna.rst
- 'MISC' device framework used
- fixes throughout GNA device's PCI management
- header files' includes and forward declarations cleanup
- ISR made static
- unused comments cleanup
- "_priv_" segment removed from function names
- tested: v5.11-rc3 -> v5.11
- number of other/minor fixes
v2->v3:
- PCI glue driver part split.
- GNA probe fail path made fully implicit.
- 'recovery_timeout' module parameter present under 'CONFIG_DEBUG_INTEL_GNA' flag only.
- build for X86_32 enabled.
- module initialization through 'module_pci_driver()'.
- gna_priv->file_list cleanup.
- 'gna_' prefix removed from source files' names.
- power management handling added.
- tests performed on kernel v5.12
- number of other/minor fixes
---
Maciej Kwapulinski (4):
intel_gna: add driver module
intel_gna: add interrupt handler
intel_gna: add a 'misc' device
intel_gna: add power management
Tomasz Jankowski (10):
intel_gna: add component of hardware operation
intel_gna: read hardware info in the driver
intel_gna: add memory handling
intel_gna: initialize mmu
intel_gna: add hardware ids
intel_gna: add request component
intel_gna: implement scoring
intel_gna: add a work queue to process scoring requests
intel_gna: add ioctl handler
intel_gna: add file operations to a 'misc' device
Documentation/misc-devices/index.rst | 1 + Documentation/misc-devices/intel/gna.rst | 48 ++ .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 7 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/intel/gna/Kbuild | 5 + drivers/misc/intel/gna/Kconfig | 13 + drivers/misc/intel/gna/device.c | 350 +++++++++++++ drivers/misc/intel/gna/device.h | 106 ++++ drivers/misc/intel/gna/hw.c | 118 +++++ drivers/misc/intel/gna/hw.h | 106 ++++ drivers/misc/intel/gna/ioctl.c | 257 ++++++++++ drivers/misc/intel/gna/ioctl.h | 11 + drivers/misc/intel/gna/mem.c | 421 +++++++++++++++ drivers/misc/intel/gna/mem.h | 115 +++++ drivers/misc/intel/gna/pci.c | 149 ++++++ drivers/misc/intel/gna/pci.h | 12 + drivers/misc/intel/gna/request.c | 480 ++++++++++++++++++ drivers/misc/intel/gna/request.h | 67 +++ drivers/misc/intel/gna/score.c | 291 +++++++++++ drivers/misc/intel/gna/score.h | 17 + include/uapi/misc/intel/gna.h | 153 ++++++ 23 files changed, 2730 insertions(+) create mode 100644 Documentation/misc-devices/intel/gna.rst create mode 100644 drivers/misc/intel/gna/Kbuild create mode 100644 drivers/misc/intel/gna/Kconfig create mode 100644 drivers/misc/intel/gna/device.c create mode 100644 drivers/misc/intel/gna/device.h create mode 100644 drivers/misc/intel/gna/hw.c create mode 100644 drivers/misc/intel/gna/hw.h create mode 100644 drivers/misc/intel/gna/ioctl.c create mode 100644 drivers/misc/intel/gna/ioctl.h create mode 100644 drivers/misc/intel/gna/mem.c create mode 100644 drivers/misc/intel/gna/mem.h create mode 100644 drivers/misc/intel/gna/pci.c create mode 100644 drivers/misc/intel/gna/pci.h create mode 100644 drivers/misc/intel/gna/request.c create mode 100644 drivers/misc/intel/gna/request.h create mode 100644 drivers/misc/intel/gna/score.c create mode 100644 drivers/misc/intel/gna/score.h create mode 100644 include/uapi/misc/intel/gna.h
Signature · 1 line
2.28.0
PATCH v3 1/14 intel_gna: add driver module
Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator with basic support like module loading and unloading. The full function of the driver will be added by further changes.
--- Documentation/misc-devices/index.rst | 1 + Documentation/misc-devices/intel/gna.rst | 48 ++++++++++++++++ .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 7 +++ drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/intel/gna/Kbuild | 5 ++ drivers/misc/intel/gna/Kconfig | 13 +++++ drivers/misc/intel/gna/device.c | 56 +++++++++++++++++++ drivers/misc/intel/gna/device.h | 30 ++++++++++ drivers/misc/intel/gna/hw.h | 17 ++++++ drivers/misc/intel/gna/pci.c | 48 ++++++++++++++++ drivers/misc/intel/gna/pci.h | 12 ++++ 13 files changed, 240 insertions(+) create mode 100644 Documentation/misc-devices/intel/gna.rst create mode 100644 drivers/misc/intel/gna/Kbuild create mode 100644 drivers/misc/intel/gna/Kconfig create mode 100644 drivers/misc/intel/gna/device.c create mode 100644 drivers/misc/intel/gna/device.h create mode 100644 drivers/misc/intel/gna/hw.h create mode 100644 drivers/misc/intel/gna/pci.c create mode 100644 drivers/misc/intel/gna/pci.h
Documentation/misc-devices/index.rst +1 -0
@@ -21,6 +21,7 @@ fit into other categories. c2port ibmvmc ics932s401 + intel/gna isl29003 lis3lv02d max6875
Documentation/misc-devices/intel/gna.rst new file +48 -0
48 lines not on this page · raw message
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
@@ -115,6 +115,7 @@ Code Seq# Include File Comments 'B' C0-FF advanced bbus <mailto:[email protected]> 'C' all linux/soundcard.h conflict! 'C' 01-2F linux/capi.h conflict! +'C' 01-5F uapi/misc/intel/gna.h conflict! 'C' F0-FF drivers/net/wan/cosa.h conflict! 'D' all arch/s390/include/asm/dasd.h 'D' 40-5F drivers/scsi/dpt/dtpi_ioctl.h
MAINTAINERS +7 -0
@@ -8972,6 +8972,13 @@ S: Maintained F: Documentation/fb/intelfb.rst F: drivers/video/fbdev/intelfb/ +INTEL GNA PCI DRIVER +M: Maciej Kwapulinski <[email protected]> +S: Maintained +F: Documentation/misc-devices/intel/gna.rst +F: drivers/misc/intel/gna/* +F: include/uapi/misc/intel/gna.h + INTEL GPIO DRIVERS M: Andy Shevchenko <[email protected]> L: [email protected]
drivers/misc/Kconfig +1 -0
@@ -461,4 +461,5 @@ source "drivers/misc/bcm-vk/Kconfig" source "drivers/misc/cardreader/Kconfig" source "drivers/misc/habanalabs/Kconfig" source "drivers/misc/uacce/Kconfig" +source "drivers/misc/intel/gna/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -56,3 +56,4 @@ obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_UACCE) += uacce/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o +obj-$(CONFIG_INTEL_GNA) += intel/gna/
drivers/misc/intel/gna/Kbuild new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only + +intel_gna-y := device.o pci.o + +obj-$(CONFIG_INTEL_GNA) += intel_gna.o
drivers/misc/intel/gna/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +# +# Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA) +# + +config INTEL_GNA + tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)" + depends on X86 && PCI + help + This option enables the Intel(R) Gaussian & Neural Accelerator + (Intel(R) GNA) driver: intel_gna. + User space interface is defined in include/uapi/misc/intel/gna.h, while + information about functionality is in + Documentation/misc-devices/intel/gna.rst
drivers/misc/intel/gna/device.c new file +56 -0
56 lines not on this page · raw message
drivers/misc/intel/gna/device.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef __GNA_DEVICE_H__ +#define __GNA_DEVICE_H__ + +#include <linux/types.h> + +#include "hw.h" + +#define GNA_DV_NAME "intel_gna" + +struct device ; + +struct gna_private { +int index; + +int recovery_timeout_jiffies; + +const char *name; +struct device *parent; + +/* device related resources */ +void __iomem *iobase; +struct gna_dev_info info; +}; + +int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase); + +#endif /* __GNA_DEVICE_H__ */
drivers/misc/intel/gna/hw.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef __GNA_HW_H__ +#define __GNA_HW_H__ + +#include <linux/mm_types.h> + +struct gna_dev_info { +u32 hwid; +u32 num_pagetables; +u32 num_page_entries; +u32 max_layer_count; +u64 max_hw_mem; +}; + +#endif // __GNA_HW_H__
drivers/misc/intel/gna/pci.c new file +48 -0
48 lines not on this page · raw message
drivers/misc/intel/gna/pci.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef __GNA_PCI_H__ +#define __GNA_PCI_H__ + +struct pci_device_id ; +struct pci_dev ; + +int gna_pci_probe (struct pci_dev *dev,const struct pci_device_id *id); + +#endif /* __GNA_PCI_H__ */
Signature · 1 line
2.28.0
Greg Kroah-Hartman
maintainerRe: [PATCH v3 01/14] intel_gna: add driver module
drivers/misc/intel/gna/device.c line 17
Quoted 4 lines · Maciej Kwapulinski
drivers/misc/intel/gna/device.c new file +4
-0+#ifdef CONFIG_DEBUG_INTEL_GNA +module_param (recovery_timeout, int,0644 ); +MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" ); +#endif
This is not the 1990's, please no new module parameters ever. If you only need this for "debugging" then use debugfs, that's exactly what it is for.
But really, shouldn't this "just work" and not require someone to change this by hand?
thanks,
greg k-h
PATCH v3 2/14 intel_gna: add component of hardware operation
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Add definitions and utilities to interact with the hardware device.
--- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/device.h | 16 +++++ drivers/misc/intel/gna/hw.c | 118 ++++++++++++++++++++++++++++++++ drivers/misc/intel/gna/hw.h | 50 ++++++++++++++ include/uapi/misc/intel/gna.h | 47 +++++++++++++ 5 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/intel/gna/hw.c create mode 100644 include/uapi/misc/intel/gna.h
drivers/misc/intel/gna/Kbuild +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := device.o pci.o +intel_gna-y := device.o hw.o pci.o obj-$(CONFIG_INTEL_GNA) += intel_gna.o
drivers/misc/intel/gna/device.h +16 -0
@@ -4,6 +4,7 @@#ifndef __GNA_DEVICE_H__#define __GNA_DEVICE_H__ +#include <linux/io.h> #include <linux/types.h> #include "hw.h"
@@ -27,4 +28,19 @@ struct gna_private {int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase); +static inline u32 gna_reg_read (struct gna_private *gna_priv,u32 reg) +{ +return readl (gna_priv->iobase + reg); +} + +static inline void gna_reg_write (struct gna_private *gna_priv,u32 reg,u32 val) +{ +writel (val, gna_priv->iobase + reg); +} + +static inline struct device *gna_dev (struct gna_private *gna_priv) +{ +return gna_priv->parent; +} +#endif /* __GNA_DEVICE_H__ */
drivers/misc/intel/gna/hw.c new file +118 -0
118 lines not on this page · raw message
drivers/misc/intel/gna/hw.h +50 -0
64 lines not on this page · raw message
include/uapi/misc/intel/gna.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.28.0
Greg Kroah-Hartman
maintainerRe: [PATCH v3 02/14] intel_gna: add component of hardware operation
Quoted 12 lines · Maciej Kwapulinski
drivers/misc/intel/gna/hw.c new file +12
-0+void gna_start_scoring (struct gna_private *gna_priv, +struct gna_compute_cfg *compute_cfg) +{ +u32 ctrl =gna_reg_read (gna_priv,GNA_MMIO_CTRL ); + + ctrl |=GNA_CTRL_START_ACCEL |GNA_CTRL_COMP_INT_EN |GNA_CTRL_ERR_INT_EN ; + + ctrl &= ~GNA_CTRL_COMP_STATS_EN ; + ctrl |=FIELD_PREP (GNA_CTRL_COMP_STATS_EN , + compute_cfg->hw_perf_encoding &FIELD_MAX (GNA_CTRL_COMP_STATS_EN )); + + ctrl &= ~GNA_CTRL_ACTIVE_LIST_EN ;
drivers/misc/intel/gna/hw.c line 78
Quoted 10 lines
drivers/misc/intel/gna/hw.c new file +10
-0+ ctrl |=FIELD_PREP (GNA_CTRL_ACTIVE_LIST_EN , + compute_cfg->active_list_on &FIELD_MAX (GNA_CTRL_ACTIVE_LIST_EN )); + + ctrl &= ~GNA_CTRL_OP_MODE ; + ctrl |=FIELD_PREP (GNA_CTRL_OP_MODE , + compute_cfg->gna_mode &FIELD_MAX (GNA_CTRL_OP_MODE )); + +gna_reg_write (gna_priv,GNA_MMIO_CTRL , ctrl); + +dev_dbg (gna_dev (gna_priv),"scoring started...\n" );
ftrace is your friend, no need for lines like this.
Quoted 14 lines
drivers/misc/intel/gna/hw.c new file +14
-0+void gna_abort_hw (struct gna_private *gna_priv) +{ +u32 val; +int ret; + +/* saturation bit in the GNA status register needs +* to be explicitly cleared. +*/ +gna_clear_saturation (gna_priv); + + val =gna_reg_read (gna_priv,GNA_MMIO_STS ); +dev_dbg (gna_dev (gna_priv),"status before abort: %#x\n" , val); + + val =gna_reg_read (gna_priv,GNA_MMIO_CTRL );
drivers/misc/intel/gna/hw.c line 118
Quoted 10 lines
drivers/misc/intel/gna/hw.c new file +10
-0+ val |=GNA_CTRL_ABORT_CLR_ACCEL ; +gna_reg_write (gna_priv,GNA_MMIO_CTRL , val); + + ret =readl_poll_timeout (gna_priv->iobase +GNA_MMIO_STS , val, + !(val &0x1 ), +0 ,1000 ); + +if (ret) +dev_err (gna_dev (gna_priv),"abort did not complete\n" ); +}
If "abort_hw" can fail, then return an error. What could a user do with an error message in the kernel log like the above one? The driver obviously did not recover from it, so what can they do?
include/uapi/misc/intel/gna.h line 9
Quoted 12 lines
include/uapi/misc/intel/gna.h new file +9
-0@@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef _UAPI_GNA_H_ +#define _UAPI_GNA_H_ + +#if defined(__cplusplus) +extern "C" { +#endif
These C++ things should not be needed in kernel uapi header files, right?
thanks,
greg k-h
PATCH v3 3/14 intel_gna: read hardware info in the driver
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Get the hardware information from register MMIO_IBUFFS
--- drivers/misc/intel/gna/device.c | 4 ++++ drivers/misc/intel/gna/device.h | 1 + drivers/misc/intel/gna/hw.h | 4 ++++ 3 files changed, 9 insertions(+)
drivers/misc/intel/gna/device.c +4 -0
@@ -21,6 +21,7 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemstatic atomic_t dev_last_idx =ATOMIC_INIT (-1 );struct gna_private *gna_priv;const char *dev_misc_name; +u32 bld_reg;int ret; gna_priv =devm_kzalloc (parent,sizeof (*gna_priv),GFP_KERNEL );
@@ -48,6 +49,9 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem } } + bld_reg =gna_reg_read (gna_priv,GNA_MMIO_IBUFFS ); + gna_priv->hw_info.in_buf_s = bld_reg &GENMASK (7 ,0 ); +return 0 ; }
drivers/misc/intel/gna/device.h +1 -0
@@ -24,6 +24,7 @@ struct gna_private {/* device related resources */ void __iomem *iobase;struct gna_dev_info info; +struct gna_hw_info hw_info; };int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase);
drivers/misc/intel/gna/hw.h +4 -0
@@ -47,6 +47,10 @@ struct gna_desc_info {struct gna_mmu_info mmu_info; }; +struct gna_hw_info { +u8 in_buf_s; +}; +struct gna_dev_info {u32 hwid;u32 num_pagetables;
Signature · 1 line
2.28.0
PATCH v3 4/14 intel_gna: add memory handling
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Patch adds memory handling - mapping, DMA, pinning.
The GNA driver maps and unmaps the physical pages for 64-byte aligned buffer allocated by user space program. The pages of mapped memory are being locked only during actual computation.
Patch adds configuration of the DMA scatter gather list for physical pages and generation of page table and page directory to be programmed in the GNA HW at the time of scoring initiation.
GNA’s MMU is being configured based on specific request memory usage. As the MMU can address up to 256MB a single scoring request is limited to this amount of memory being used.
GNA Library can allocate any number of memory regions for GNA usage. Its number and total capacity are limited by the OSs’ resources. Due to GNA MMU restrictions, even when using multiple memory regions, the sum of all the memory regions used within a single inference request must be less than 256MB.
At least a single GNA memory region is needed to be allocated (and can be shared by multiple models). At the other extreme, each GNA tensor (e.g., weights/biases/inputs/outputs) could use its own, separate GNA memory region.
--- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/device.c | 18 ++ drivers/misc/intel/gna/device.h | 28 +++ drivers/misc/intel/gna/mem.c | 418 ++++++++++++++++++++++++++++++++ drivers/misc/intel/gna/mem.h | 115 +++++++++ include/uapi/misc/intel/gna.h | 12 + 6 files changed, 592 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/intel/gna/mem.c create mode 100644 drivers/misc/intel/gna/mem.h
drivers/misc/intel/gna/Kbuild +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := device.o hw.o pci.o +intel_gna-y := device.o hw.o mem.o pci.o obj-$(CONFIG_INTEL_GNA) += intel_gna.o
drivers/misc/intel/gna/device.c +18 -0
@@ -16,6 +16,13 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif +static void gna_devm_idr_destroy (void *data) +{ +struct idr *idr = data; + +idr_destroy (idr); +} +int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase) {static atomic_t dev_last_idx =ATOMIC_INIT (-1 );
@@ -52,6 +59,17 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem bld_reg =gna_reg_read (gna_priv,GNA_MMIO_IBUFFS ); gna_priv->hw_info.in_buf_s = bld_reg &GENMASK (7 ,0 ); +mutex_init (&gna_priv->mmu_lock); + +idr_init (&gna_priv->memory_idr); + ret =devm_add_action (parent, gna_devm_idr_destroy, &gna_priv->memory_idr); +if (ret) { +dev_err (parent,"could not add devm action for idr\n" ); +return ret; + } + +mutex_init (&gna_priv->memidr_lock); +return 0 ; }
drivers/misc/intel/gna/device.h +28 -0
@@ -4,14 +4,29 @@ #ifndef __GNA_DEVICE_H__ #define __GNA_DEVICE_H__ +#include <linux/idr.h> #include <linux/io.h> +#include <linux/list.h> +#include <linux/mutex.h> #include <linux/types.h> #include "hw.h" +#include "mem.h" #define GNA_DV_NAME "intel_gna" struct device; +struct file; + +struct gna_file_private { + struct file *fd; + struct gna_private *gna_priv; + + struct list_head memory_list; + struct mutex memlist_lock; + + struct list_head flist; +}; struct gna_private { int index;
@@ -25,6 +40,14 @@ struct gna_private {void __iomem *iobase;struct gna_dev_info info;struct gna_hw_info hw_info; + +struct gna_mmu_object mmu; +struct mutex mmu_lock; + +/* memory objects' store */ +struct idr memory_idr; +/* lock protecting memory_idr */ +struct mutex memidr_lock; };int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase);
@@ -39,6 +62,11 @@ static inline void gna_reg_write(struct gna_private *gna_priv, u32 reg, u32 val)writel (val, gna_priv->iobase + reg); } +static inline struct device *gna_parent (struct gna_private *gna_priv) +{ +return gna_priv->parent; +} +static inline struct device *gna_dev (struct gna_private *gna_priv) {return gna_priv->parent;
drivers/misc/intel/gna/mem.c new file +418 -0
418 lines not on this page · raw message
drivers/misc/intel/gna/mem.h new file +115 -0
115 lines not on this page · raw message
include/uapi/misc/intel/gna.h +12 -0
@@ -40,6 +40,18 @@ struct gna_compute_cfg {__u8 pad[5 ]; }; +union gna_memory_map { +struct { +__u64 address; +__u32 size; +__u32 pad; + } in; + +struct { +__u64 memory_id; + } out; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.28.0
PATCH v3 5/14 intel_gna: initialize mmu
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Setup mmu in the driver with a new memory component.
--- drivers/misc/intel/gna/device.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/misc/intel/gna/device.c +12 -0
@@ -59,6 +59,18 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem bld_reg =gna_reg_read (gna_priv,GNA_MMIO_IBUFFS ); gna_priv->hw_info.in_buf_s = bld_reg &GENMASK (7 ,0 ); + ret =gna_mmu_alloc (gna_priv); +if (ret) { +dev_err (parent,"mmu allocation failed\n" ); +return ret; + + } +dev_dbg (parent,"maximum memory size %llu num pd %d\n" , + gna_priv->info.max_hw_mem, gna_priv->info.num_pagetables); +dev_dbg (parent,"desc rsvd size %d mmu vamax size %d\n" , + gna_priv->info.desc_info.rsvd_size, + gna_priv->info.desc_info.mmu_info.vamax_size); +mutex_init (&gna_priv->mmu_lock);idr_init (&gna_priv->memory_idr);
Signature · 1 line
2.28.0
PATCH v3 6/14 intel_gna: add hardware ids
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Add PCI ids of Intel(R) Gaussian & Neural Accelerator on supported platforms.
--- drivers/misc/intel/gna/hw.h | 34 +++++++++++++++++++ drivers/misc/intel/gna/pci.c | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+)
drivers/misc/intel/gna/hw.h +34 -0
@@ -10,6 +10,40 @@struct gna_compute_cfg ;struct gna_private ; +#define GNA_FEATURES \ + .max_hw_mem = 256 * 1024 * 1024, \ + .num_pagetables = 64, \ + .num_page_entries = PAGE_SIZE / sizeof(u32), \ + /* desc_info all in bytes */ \ + .desc_info = { \ + .rsvd_size = 256, \ + .cfg_size = 256, \ + .desc_size = 784, \ + .mmu_info = { \ + .vamax_size = 4, \ + .rsvd_size = 12, \ + .pd_size = 4 * 64, \ + }, \ + } + +#define GNA_GEN1_FEATURES \ + GNA_FEATURES, \ + .max_layer_count = 1024 + +#define GNA_GEN2_FEATURES \ + GNA_FEATURES, \ + .max_layer_count = 4096 + +#define GNA_DEV_HWID_CNL 0x5A11 +#define GNA_DEV_HWID_EHL 0x4511 +#define GNA_DEV_HWID_GLK 0x3190 +#define GNA_DEV_HWID_ICL 0x8A11 +#define GNA_DEV_HWID_JSL 0x4E11 +#define GNA_DEV_HWID_TGL 0x9A11 +#define GNA_DEV_HWID_RKL 0x4C11 +#define GNA_DEV_HWID_ADL 0x464F +#define GNA_DEV_HWID_RPL 0xA74F +/* GNA MMIO registers */ #define GNA_MMIO_STS 0x80#define GNA_MMIO_CTRL 0x84
drivers/misc/intel/gna/pci.c +65 -0
80 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v3 7/14 intel_gna: add request component
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
The scoring work submitted to the GNA driver is implemented as a list of requests that will be processed by the hardware.
--- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/device.c | 7 +- drivers/misc/intel/gna/device.h | 6 + drivers/misc/intel/gna/mem.c | 3 + drivers/misc/intel/gna/request.c | 350 +++++++++++++++++++++++++++++++ drivers/misc/intel/gna/request.h | 65 ++++++ include/uapi/misc/intel/gna.h | 37 ++++ 7 files changed, 468 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/intel/gna/request.c create mode 100644 drivers/misc/intel/gna/request.h
drivers/misc/intel/gna/Kbuild +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := device.o hw.o mem.o pci.o +intel_gna-y := device.o hw.o mem.o pci.o request.o obj-$(CONFIG_INTEL_GNA) += intel_gna.o
drivers/misc/intel/gna/device.c +6 -1
@@ -1,13 +1,13 @@// SPDX-License-Identifier: GPL-2.0-only // Copyright(c) 2017-2021 Intel Corporation -#include <linux/atomic.h> #include <linux/device.h> #include <linux/dma-mapping.h> #include <linux/module.h> #include "device.h" #include "hw.h" +#include "request.h" static int recovery_timeout =60 ;
@@ -82,6 +82,11 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemmutex_init (&gna_priv->memidr_lock); +atomic_set (&gna_priv->request_count,0 ); + +mutex_init (&gna_priv->reqlist_lock); +INIT_LIST_HEAD (&gna_priv->request_list); +return 0 ; }
drivers/misc/intel/gna/device.h +6 -0
@@ -4,6 +4,7 @@#ifndef __GNA_DEVICE_H__#define __GNA_DEVICE_H__ +#include <linux/atomic.h> #include <linux/idr.h> #include <linux/io.h> #include <linux/list.h>
@@ -44,6 +45,11 @@ struct gna_private {struct gna_mmu_object mmu;struct mutex mmu_lock; +struct list_head request_list; +/* protects request_list */ +struct mutex reqlist_lock; +atomic_t request_count; +/* memory objects' store */ struct idr memory_idr;/* lock protecting memory_idr */
drivers/misc/intel/gna/mem.c +3 -0
@@ -21,6 +21,7 @@#include "hw.h" #include "device.h" #include "mem.h" +#include "request.h" static void gna_mmu_init (struct gna_private *gna_priv) {
@@ -340,6 +341,8 @@ static void gna_memory_release(struct work_struct *work) mo = container_of(work, struct gna_memory_object, work); +gna_delete_memory_requests (mo->memory_id, mo->gna_priv); + mo->user_ptr =NULL ;wake_up_interruptible (&mo->waitq);
drivers/misc/intel/gna/request.c new file +350 -0
350 lines not on this page · raw message
drivers/misc/intel/gna/request.h new file +65 -0
65 lines not on this page · raw message
include/uapi/misc/intel/gna.h +37 -0
@@ -26,6 +26,43 @@ extern "C" { GNA_STS_PARAM_OOR |\ GNA_STS_VA_OOR) +/* +* Structure describes part of memory to be overwritten before starting GNA +*/ +struct gna_memory_patch { +/* offset from targeted memory */ +__u64 offset; + +__u64 size; +__u64 value; +}; + +struct gna_buffer { +__u64 memory_id; + +__u64 offset; +__u64 size; + +__u64 patch_count; +__u64 patches_ptr; +}; + +/* +* Driver performance timestamps in nanoseconds. +* Values regard system boot time, but do not count during suspend. +*/ +struct gna_drv_perf { +__u64 pre_processing;/* driver starts pre-processing */ +__u64 processing;/* hw starts processing */ +__u64 hw_completed;/* hw finishes processing */ +__u64 completion;/* driver finishes post-processing */ +}; + +struct gna_hw_perf { +__u64 total; +__u64 stall; +}; +struct gna_compute_cfg {__u32 layer_base;__u32 layer_count;
Signature · 1 line
2.28.0
PATCH v3 8/14 intel_gna: implement scoring
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Add a new component for scoring logic such as configuring and kicking off the hardware.
--- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/device.c | 3 + drivers/misc/intel/gna/device.h | 5 + drivers/misc/intel/gna/score.c | 291 ++++++++++++++++++++++++++++++++ drivers/misc/intel/gna/score.h | 17 ++ include/uapi/misc/intel/gna.h | 4 + 6 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/intel/gna/score.c create mode 100644 drivers/misc/intel/gna/score.h
drivers/misc/intel/gna/Kbuild +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := device.o hw.o mem.o pci.o request.o +intel_gna-y := device.o hw.o mem.o pci.o request.o score.o obj-$(CONFIG_INTEL_GNA) += intel_gna.o
drivers/misc/intel/gna/device.c +3 -0
@@ -82,6 +82,9 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemmutex_init (&gna_priv->memidr_lock); +mutex_init (&gna_priv->flist_lock); +INIT_LIST_HEAD (&gna_priv->file_list); +atomic_set (&gna_priv->request_count,0 );mutex_init (&gna_priv->reqlist_lock);
drivers/misc/intel/gna/device.h +5 -0
@@ -30,6 +30,11 @@ struct gna_file_private { };struct gna_private { +/* list of opened files */ +struct list_head file_list; +/* protects file_list */ +struct mutex flist_lock; +int index;int recovery_timeout_jiffies;
drivers/misc/intel/gna/score.c new file +291 -0
291 lines not on this page · raw message
drivers/misc/intel/gna/score.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef __GNA_SCORE_H__ +#define __GNA_SCORE_H__ + +struct gna_file_private ; +struct gna_compute_cfg ; +struct gna_private ; +struct gna_request ; + +int gna_validate_score_config (struct gna_compute_cfg *compute_cfg, +struct gna_file_private *file_priv); + +int gna_score (struct gna_request *score_request); + +#endif // __GNA_SCORE_H__
include/uapi/misc/intel/gna.h +4 -0
@@ -10,6 +10,10 @@ extern "C" {#include <linux/types.h> +/* Operation modes */ +#define GNA_MODE_GMM 0 +#define GNA_MODE_XNN 1 +#define GNA_STS_SCORE_COMPLETED _BITUL(0)#define GNA_STS_STATISTICS_VALID _BITUL(3)#define GNA_STS_PCI_MMU_ERR _BITUL(4)
Signature · 1 line
2.28.0
PATCH v3 9/14 intel_gna: add a work queue to process scoring requests
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
The new workqueue is responsible to process the list of requests
in a FIFO manner. It waits for the hardware to complete on every
request until it is woken up by an interrupt that will be addressed in following changes.
--- drivers/misc/intel/gna/device.c | 34 +++++++++ drivers/misc/intel/gna/device.h | 14 ++++ drivers/misc/intel/gna/request.c | 115 +++++++++++++++++++++++++++++++ drivers/misc/intel/gna/request.h | 2 + 4 files changed, 165 insertions(+)
drivers/misc/intel/gna/device.c +34 -0
@@ -23,6 +23,34 @@ static void gna_devm_idr_destroy(void *data)idr_destroy (idr); } +static void gna_devm_destroy_workqueue (void *data) +{ +struct workqueue_struct *request_wq = data; + +destroy_workqueue (request_wq); +} + +static int gna_devm_create_singlethread_workqueue (struct gna_private *gna_priv) +{ +struct device *dev =gna_parent (gna_priv); +const char *name =gna_name (gna_priv); +int ret; + + gna_priv->request_wq =create_singlethread_workqueue (name); +if (!gna_priv->request_wq) { +dev_err (dev,"could not create %s workqueue\n" , name); +return -EFAULT ; + } + + ret =devm_add_action (dev, gna_devm_destroy_workqueue, gna_priv->request_wq); +if (ret) { +dev_err (dev,"could not add devm action for %s workqueue\n" , name); +gna_devm_destroy_workqueue (gna_priv->request_wq); + } + +return ret; +} +int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase) {static atomic_t dev_last_idx =ATOMIC_INIT (-1 );
@@ -90,6 +118,12 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemmutex_init (&gna_priv->reqlist_lock);INIT_LIST_HEAD (&gna_priv->request_list); +init_waitqueue_head (&gna_priv->dev_busy_waitq); + + ret =gna_devm_create_singlethread_workqueue (gna_priv); +if (ret) +return ret; +return 0 ; }
drivers/misc/intel/gna/device.h +14 -0
@@ -16,6 +16,7 @@#define GNA_DV_NAME "intel_gna" +struct workqueue_struct ;struct device ;struct file ;
@@ -42,6 +43,9 @@ struct gna_private {const char *name;struct device *parent; +/* hardware status set by interrupt handler */ +u32 hw_status; +/* device related resources */ void __iomem *iobase;struct gna_dev_info info;
@@ -50,9 +54,14 @@ struct gna_private {struct gna_mmu_object mmu;struct mutex mmu_lock; +/* if true, then gna device is processing */ +bool dev_busy; +struct wait_queue_head dev_busy_waitq; +struct list_head request_list;/* protects request_list */ struct mutex reqlist_lock; +struct workqueue_struct *request_wq;atomic_t request_count;/* memory objects' store */
@@ -78,6 +87,11 @@ static inline struct device *gna_parent(struct gna_private *gna_priv)return gna_priv->parent; } +static inline const char *gna_name (struct gna_private *gna_priv) +{ +return gna_priv->name; +} +static inline struct device *gna_dev (struct gna_private *gna_priv) {return gna_priv->parent;
drivers/misc/intel/gna/request.c +115 -0
153 lines not on this page · raw message
drivers/misc/intel/gna/request.h +2 -0
@@ -8,6 +8,7 @@#include <linux/list.h> #include <linux/types.h> #include <linux/wait.h> +#include <linux/workqueue.h> #include <uapi/misc/intel/gna.h>
@@ -46,6 +47,7 @@ struct gna_request {struct gna_buffer *buffer_list;u64 buffer_count; +struct work_struct work;struct wait_queue_head waitq; };
Signature · 1 line
2.28.0
PATCH v3 10/14 intel_gna: add interrupt handler
In reply to Maciej KwapulinskiAn interrupt is generated by the hardware when a scoring job is done. The interrupt handler wakes up the work queue to resume the processing on the current request.
--- drivers/misc/intel/gna/device.c | 20 ++++++++++++++++++- drivers/misc/intel/gna/device.h | 2 +- drivers/misc/intel/gna/pci.c | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-)
drivers/misc/intel/gna/device.c +19 -1
@@ -3,6 +3,7 @@#include <linux/device.h> #include <linux/dma-mapping.h> +#include <linux/interrupt.h> #include <linux/module.h> #include "device.h"
@@ -23,6 +24,16 @@ static void gna_devm_idr_destroy(void *data)idr_destroy (idr); } +static irqreturn_t gna_interrupt (int irq,void *priv) +{ +struct gna_private *gna_priv; + + gna_priv = (struct gna_private *)priv; + gna_priv->dev_busy = false; +wake_up (&gna_priv->dev_busy_waitq); +return IRQ_HANDLED ; +} +static void gna_devm_destroy_workqueue (void *data) {struct workqueue_struct *request_wq = data;
@@ -51,7 +62,7 @@ static int gna_devm_create_singlethread_workqueue(struct gna_private *gna_priv)return ret; } -int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase) +int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase,int irq) {static atomic_t dev_last_idx =ATOMIC_INIT (-1 );struct gna_private *gna_priv;
@@ -124,6 +135,13 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemif (ret)return ret; + ret =devm_request_irq (parent, irq, gna_interrupt, +IRQF_SHARED , dev_misc_name, gna_priv); +if (ret) { +dev_err (parent,"could not register for interrupt\n" ); +return ret; + } +return 0 ; }
drivers/misc/intel/gna/device.h +1 -1
@@ -70,7 +70,7 @@ struct gna_private {struct mutex memidr_lock; }; -int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase); +int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase,int irq);static inline u32 gna_reg_read (struct gna_private *gna_priv,u32 reg) {
drivers/misc/intel/gna/pci.c +34 -1
@@ -69,10 +69,33 @@ static const struct pci_device_id gna_pci_ids[] = { { } }; +static void gna_pcim_free_irq_vectors (void *data) +{ +struct pci_dev *pcidev = data; + +pci_free_irq_vectors (pcidev); +} + +static int gna_pcim_alloc_irq_vectors (struct pci_dev *pcidev) +{ +int ret; + + ret =pci_alloc_irq_vectors (pcidev,1 ,1 ,PCI_IRQ_ALL_TYPES ); +if (ret <0 ) +return ret; + + ret =devm_add_action (&pcidev->dev, gna_pcim_free_irq_vectors, pcidev); +if (ret) +gna_pcim_free_irq_vectors (pcidev); + +return ret; +} +int gna_pci_probe (struct pci_dev *pcidev,const struct pci_device_id *pci_id) {struct gna_dev_info *dev_info;void __iomem *iobase; +int irq;int ret; ret =pcim_enable_device (pcidev);
@@ -91,9 +114,19 @@ int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)pci_set_master (pcidev); + ret =gna_pcim_alloc_irq_vectors (pcidev); +if (ret <0 ) +return ret; + + irq =pci_irq_vector (pcidev,0 ); +if (unlikely (irq <0 )) { +dev_err (&pcidev->dev,"could not get irq number\n" ); +return -EIO ; + } + dev_info = (struct gna_dev_info *)pci_id->driver_data; - ret =gna_probe (&pcidev->dev, dev_info, iobase); + ret =gna_probe (&pcidev->dev, dev_info, iobase, irq);if (ret) {dev_err (&pcidev->dev,"could not initialize device\n" );return ret;
Signature · 1 line
2.28.0
PATCH v3 11/14 intel_gna: add ioctl handler
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.
--- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/device.c | 47 ++++++ drivers/misc/intel/gna/device.h | 2 + drivers/misc/intel/gna/ioctl.c | 257 ++++++++++++++++++++++++++++++++ drivers/misc/intel/gna/ioctl.h | 11 ++ include/uapi/misc/intel/gna.h | 53 +++++++ 6 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/intel/gna/ioctl.c create mode 100644 drivers/misc/intel/gna/ioctl.h
drivers/misc/intel/gna/Kbuild +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := device.o hw.o mem.o pci.o request.o score.o +intel_gna-y := device.o hw.o ioctl.o mem.o pci.o request.o score.o obj-$(CONFIG_INTEL_GNA) += intel_gna.o
drivers/misc/intel/gna/device.c +47 -0
61 lines not on this page · raw message
drivers/misc/intel/gna/device.h +2 -0
@@ -17,6 +17,7 @@#define GNA_DV_NAME "intel_gna"struct workqueue_struct ; +union gna_parameter ;struct device ;struct file ;
@@ -71,6 +72,7 @@ struct gna_private { };int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase,int irq); +int gna_getparam (struct gna_private *gna_priv,union gna_parameter *param);static inline u32 gna_reg_read (struct gna_private *gna_priv,u32 reg) {
drivers/misc/intel/gna/ioctl.c new file +257 -0
257 lines not on this page · raw message
drivers/misc/intel/gna/ioctl.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef __GNA_IOCTL_H__ +#define __GNA_IOCTL_H__ + +struct file ; + +long gna_ioctl (struct file *f,unsigned int cmd,unsigned long arg); + +#endif // __GNA_IOCTL_H__
include/uapi/misc/intel/gna.h +53 -0
83 lines not on this page · raw message
Signature · 1 line
2.28.0
Greg Kroah-Hartman
maintainerRe: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 8 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.
Do you have a pointer to the userspace code that uses this ioctl? That's kind of required here, otherwise we have no idea how this all works.
Quoted 66 lines
Signed-off-by Tomasz Jankowski <[email protected]>Tested-by Savo Novakovic <[email protected]>Co-developed-by Jianxun Zhang <[email protected]>Signed-off-by Jianxun Zhang <[email protected]>Co-developed-by Maciej Kwapulinski <[email protected]>Signed-off-by Maciej Kwapulinski <[email protected]>--- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/device.c | 47 ++++++ drivers/misc/intel/gna/device.h | 2 + drivers/misc/intel/gna/ioctl.c | 257 ++++++++++++++++++++++++++++++++ drivers/misc/intel/gna/ioctl.h | 11 ++ include/uapi/misc/intel/gna.h | 53 +++++++ 6 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/intel/gna/ioctl.c create mode 100644 drivers/misc/intel/gna/ioctl.hdrivers/misc/intel/gna/Kbuild +1
-1@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := device.o hw.o mem.o pci.o request.o score.o +intel_gna-y := device.o hw.o ioctl.o mem.o pci.o request.o score.o obj-$(CONFIG_INTEL_GNA) += intel_gna.odrivers/misc/intel/gna/device.c +20
-0@@ -6,8 +6,11 @@#include <linux/interrupt.h> #include <linux/module.h> +#include <uapi/misc/intel/gna.h> +#include "device.h" #include "hw.h" +#include "ioctl.h" #include "request.h" static int recovery_timeout =60 ;@@ -145,6 +148,50 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemreturn 0 ; } +static u32 gna_device_type_by_hwid (u32 hwid) +{ +switch (hwid) { +case GNA_DEV_HWID_CNL : +return GNA_DEV_TYPE_0_9 ; +case GNA_DEV_HWID_GLK : +case GNA_DEV_HWID_EHL : +case GNA_DEV_HWID_ICL : +return GNA_DEV_TYPE_1_0 ; +case GNA_DEV_HWID_JSL : +case GNA_DEV_HWID_TGL : +case GNA_DEV_HWID_RKL : +return GNA_DEV_TYPE_2_0 ; +case GNA_DEV_HWID_ADL : +case GNA_DEV_HWID_RPL : +return GNA_DEV_TYPE_3_0 ; +default :
drivers/misc/intel/gna/device.c int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem · line 177
Quoted 10 lines
drivers/misc/intel/gna/device.c +10
-0+return 0 ; + } +} + +int gna_getparam (struct gna_private *gna_priv,union gna_parameter *param) +{ +switch (param->in.id) { +case GNA_PARAM_DEVICE_ID : + param->out.value = gna_priv->info.hwid; +break ;
Why do you need an ioctl to get the device id? What's wrong with sysfs?
drivers/misc/intel/gna/device.c int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem · line 185
Quoted 8 lines
drivers/misc/intel/gna/device.c +8
-0+case GNA_PARAM_RECOVERY_TIMEOUT : + param->out.value =jiffies_to_msecs (gna_priv->recovery_timeout_jiffies) /1000 ; +break ; +case GNA_PARAM_INPUT_BUFFER_S : + param->out.value = gna_priv->hw_info.in_buf_s; +break ; +case GNA_PARAM_DEVICE_TYPE : + param->out.value =gna_device_type_by_hwid (gna_priv->info.hwid);
Same here, why isn't this a sysfs file?
drivers/misc/intel/gna/device.c int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem · line 188
Quoted 3 lines
drivers/misc/intel/gna/device.c +3
-0+break ; +default : +dev_err (gna_dev (gna_priv),"unknown parameter id %llu\n" , param->in.id);
Userspace can cause syslog DoS? Not nice :(
Please just eat the error and move on.
drivers/misc/intel/gna/device.c int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem · line 189
Quoted 1 line
drivers/misc/intel/gna/device.c +1
-0+return -EINVAL ;
Wrong error value for invalid ioctl value.
Quoted 57 lines
drivers/misc/intel/gna/device.c +5
-0+ } + +return 0 ; +} +MODULE_AUTHOR ("Intel Corporation" );MODULE_DESCRIPTION ("Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA) Driver" );MODULE_LICENSE ("GPL" );drivers/misc/intel/gna/device.h +2
-0@@ -17,6 +17,7 @@#define GNA_DV_NAME "intel_gna"struct workqueue_struct ; +union gna_parameter ;struct device ;struct file ;@@ -71,6 +72,7 @@ struct gna_private { };int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase,int irq); +int gna_getparam (struct gna_private *gna_priv,union gna_parameter *param);static inline u32 gna_reg_read (struct gna_private *gna_priv,u32 reg) {drivers/misc/intel/gna/ioctl.c new file +23
-0@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright(c) 2017-2021 Intel Corporation + +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/idr.h> +#include <linux/jiffies.h> +#include <linux/kref.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/uaccess.h> +#include <linux/wait.h> +#include <linux/workqueue.h> + +#include <uapi/misc/intel/gna.h> + +#include "device.h" +#include "ioctl.h" +#include "mem.h" +#include "request.h" +#include "score.h" + +static int gna_ioctl_score (struct gna_file_private *file_priv,void __user *argptr)
drivers/misc/intel/gna/ioctl.c line 33
Quoted 10 lines
drivers/misc/intel/gna/ioctl.c new file +10
-0+{ +union gna_compute score_args; +struct gna_private *gna_priv; +u64 request_id; +int ret; + + gna_priv = file_priv->gna_priv; + +if (copy_from_user (&score_args, argptr,sizeof (score_args))) { +dev_err (gna_dev (gna_priv),"could not copy score ioctl config from user\n" );
No need for errors that userspace can cause, please drop, you already got a message if there needed to be one.
drivers/misc/intel/gna/ioctl.c line 37
Quoted 4 lines
drivers/misc/intel/gna/ioctl.c new file +4
-0+return -EFAULT ; + } + + ret =gna_validate_score_config (&score_args.in.config, file_priv);
This function is in a different patch? Now I have to dig through that to try to figure out if you really are validating the data properly? That's just mean to reviewers, would you want to review code like this? Please fix.
drivers/misc/intel/gna/ioctl.c line 39
Quoted 2 lines
drivers/misc/intel/gna/ioctl.c new file +2
-0+if (ret) { +dev_err (gna_dev (gna_priv),"request not valid\n" );
Same here, clean up all error reporting in your ioctl to be none at all please.
drivers/misc/intel/gna/ioctl.c line 43
Quoted 4 lines
drivers/misc/intel/gna/ioctl.c new file +4
-0+return ret; + } + + ret =gna_enqueue_request (&score_args.in.config, file_priv, &request_id);
Same here, where is this function to review?
Same for all your other ioctl handlers, please fix up, this is rough to review...
greg k-h
Re: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 10 lines · Greg Kroah-Hartman
Quoted 8 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.
Quoted 4 lines
Do you have a pointer to the userspace code that uses this ioctl? That's kind of required here, otherwise we have no idea how this all works.
yes, it's present under following link:
regards,
Maciej
Greg Kroah-Hartman
maintainerRe: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 13 lines · Maciej Kwapulinski
Quoted 10 lines · Greg Kroah-Hartman
Quoted 8 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.
Quoted 8 lines
Quoted 4 lines
Do you have a pointer to the userspace code that uses this ioctl? That's kind of required here, otherwise we have no idea how this all works.
yes, it's present under following link:
Then that needs to go here in this changelog text, right?
Re: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Maciej Kwapulinski
Quoted 14 lines · Greg Kroah-Hartman
Quoted 8 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.Do you have a pointer to the userspace code that uses this ioctl? That's kind of required here, otherwise we have no idea how this all works.
Quoted 5 lines
Quoted 3 lines
yes, it's present under following link:
Then that needs to go here in this changelog text, right?
link to library is already present in 00/14, I didn't want to have it in two places, that's why not present here.
Greg Kroah-Hartman
maintainerRe: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 22 lines · Maciej Kwapulinski
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Maciej Kwapulinski
Quoted 14 lines · Greg Kroah-Hartman
Quoted 8 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.Do you have a pointer to the userspace code that uses this ioctl? That's kind of required here, otherwise we have no idea how this all works.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
yes, it's present under following link:
Then that needs to go here in this changelog text, right?
link to library is already present in 00/14, I didn't want to have it in two places, that's why not present here.
Commit 00/XX never shows up in the changelog :(
Re: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 25 lines · Greg Kroah-Hartman
Quoted 24 lines · Maciej Kwapulinski
Quoted 21 lines · Greg Kroah-Hartman
Quoted 20 lines · Maciej Kwapulinski
Quoted 10 lines · Greg Kroah-Hartman
Quoted 8 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Add ioctl handler into GNA driver.
The ioctl interface provides the ability to do the following:
- Map and unmap memory buffers for GNA computation requests.
- Retrieve capabilities of the underlying GNA IP.
- Submit GNA computation requests.
- Request notification of scoring completion.Quoted 4 lines
Do you have a pointer to the userspace code that uses this ioctl? That's kind of required here, otherwise we have no idea how this all works.
yes, it's present under following link:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Then that needs to go here in this changelog text, right?
link to library is already present in 00/14, I didn't want to have it in two places, that's why not present here.
Commit 00/XX never shows up in the changelog :(
right
Re: [PATCH v3 11/14] intel_gna: add ioctl handler
In reply to Maciej KwapulinskiQuoted 1 line · Maciej Kwapulinski
+#include <
linux/idr.h>
Please don't use the IDR in new code. Use the XArray instead.
drivers/misc/intel/gna/ioctl.c line 162
Quoted 3 lines
drivers/misc/intel/gna/ioctl.c new file +3
-0+mutex_lock (&gna_priv->memidr_lock); + mo =idr_find (&gna_priv->memory_idr, memory_id); +mutex_unlock (&gna_priv->memidr_lock);
You don't need your own lock with the XArray.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v3 11/14] intel_gna: add ioctl handler
Quoted 1 line · Hillf Danton
On Thu, 13 May 2021 13:00:37 +0200 Tomasz Jankowski wrote:
Greg, Matthew, Hillf
thank You for Your comments.
Next week I'll start applying them to code
regards,
Maciej
PATCH v3 12/14 intel_gna: add a 'misc' device
In reply to Maciej KwapulinskiThe new 'misc' device is the node for applications in user space to interact with the driver.
--- drivers/misc/intel/gna/device.c | 52 +++++++++++++++++++++++++++++++-- drivers/misc/intel/gna/device.h | 11 +++---- 2 files changed, 55 insertions(+), 8 deletions(-)
drivers/misc/intel/gna/device.c +49 -3
@@ -20,6 +20,18 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif +struct file ; + +static int gna_open (struct inode *inode,struct file *f) +{ +return -EPERM ; +} + +static const struct file_operations gna_file_ops = { + .owner =THIS_MODULE , + .open = gna_open, +}; +static void gna_devm_idr_destroy (void *data) {struct idr *idr = data;
@@ -27,6 +39,36 @@ static void gna_devm_idr_destroy(void *data)idr_destroy (idr); } +static void gna_devm_deregister_misc_dev (void *data) +{ +struct miscdevice *misc = data; + +misc_deregister (misc); +} + +static int gna_devm_register_misc_dev (struct device *parent,struct miscdevice *misc) +{ +int ret; + + ret =misc_register (misc); +if (ret) { +dev_err (parent,"misc device %s registering failed. errcode: %d\n" , + misc->name, ret); +gna_devm_deregister_misc_dev (misc); + }else { +dev_dbg (parent,"device: %s registered\n" , + misc->name); + } + + ret =devm_add_action (parent, gna_devm_deregister_misc_dev, misc); +if (ret) { +dev_err (parent,"could not add devm action for %s misc deregister\n" , misc->name); +gna_devm_deregister_misc_dev (misc); + } + +return ret; +} +static irqreturn_t gna_interrupt (int irq,void *priv) {struct gna_private *gna_priv;
@@ -81,13 +123,13 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem gna_priv->recovery_timeout_jiffies =msecs_to_jiffies (recovery_timeout *1000 ); gna_priv->iobase = iobase; gna_priv->info = *dev_info; - gna_priv->parent = parent; + gna_priv->misc.parent = parent; dev_misc_name =devm_kasprintf (parent,GFP_KERNEL ,"%s%d" ,GNA_DV_NAME , gna_priv->index);if (!dev_misc_name)return -ENOMEM ; - gna_priv->name = dev_misc_name; + gna_priv->misc.name = dev_misc_name;if (!(sizeof (dma_addr_t) >4 ) ||dma_set_mask (parent,DMA_BIT_MASK (64 ))) {
@@ -145,7 +187,11 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomemreturn ret; } -return 0 ; + gna_priv->misc.minor =MISC_DYNAMIC_MINOR ; + gna_priv->misc.fops = &gna_file_ops; + gna_priv->misc.mode =0666 ; + +return gna_devm_register_misc_dev (parent, &gna_priv->misc); }static u32 gna_device_type_by_hwid (u32 hwid)
drivers/misc/intel/gna/device.h +6 -5
@@ -8,6 +8,7 @@#include <linux/idr.h> #include <linux/io.h> #include <linux/list.h> +#include <linux/miscdevice.h> #include <linux/mutex.h> #include <linux/types.h>
@@ -41,8 +42,8 @@ struct gna_private {int recovery_timeout_jiffies; -const char *name; -struct device *parent; +/* gna misc-device */ +struct miscdevice misc;/* hardware status set by interrupt handler */ u32 hw_status;
@@ -86,17 +87,17 @@ static inline void gna_reg_write(struct gna_private *gna_priv, u32 reg, u32 val)static inline struct device *gna_parent (struct gna_private *gna_priv) { -return gna_priv->parent; +return gna_priv->misc.parent; }static inline const char *gna_name (struct gna_private *gna_priv) { -return gna_priv->name; +return gna_priv->misc.name; }static inline struct device *gna_dev (struct gna_private *gna_priv) { -return gna_priv->parent; +return gna_priv->misc.this_device; }#endif /* __GNA_DEVICE_H__ */
Signature · 1 line
2.28.0
Greg Kroah-Hartman
maintainerRe: [PATCH v3 12/14] intel_gna: add a 'misc' device
Quoted 15 lines · Maciej Kwapulinski
The new 'misc' device is the node for applications in user space to interact with the driver.
Signed-off-by Maciej Kwapulinski <[email protected]>Tested-by Savo Novakovic <[email protected]>--- drivers/misc/intel/gna/device.c | 52 +++++++++++++++++++++++++++++++-- drivers/misc/intel/gna/device.h | 11 +++---- 2 files changed, 55 insertions(+), 8 deletions(-)drivers/misc/intel/gna/device.c +0
-0
drivers/misc/intel/gna/device.c module_param(recovery_timeout, int, 0644); · line 28
Quoted 9 lines
drivers/misc/intel/gna/device.c +6
-0@@ -20,6 +20,18 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif +struct file ; + +static int gna_open (struct inode *inode,struct file *f) +{ +return -EPERM ; +}
That sucks, why have an open that does nothing but fail?
Quoted 10 lines
drivers/misc/intel/gna/device.c +6
-0+ +static const struct file_operations gna_file_ops = { + .owner =THIS_MODULE , + .open = gna_open, +}; +static void gna_devm_idr_destroy (void *data) {struct idr *idr = data;
drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 42
Quoted 4 lines
drivers/misc/intel/gna/device.c +1
-0@@ -27,6 +39,36 @@ static void gna_devm_idr_destroy(void *data)idr_destroy (idr); } +static void gna_devm_deregister_misc_dev (void *data)
Why is this a void *?
This isn't windows, use real pointer types everywhere in the kernel please.
Quoted 8 lines
drivers/misc/intel/gna/device.c +8
-0+{ +struct miscdevice *misc = data; + +misc_deregister (misc); +} + +static int gna_devm_register_misc_dev (struct device *parent,struct miscdevice *misc) +{
drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 60
Quoted 10 lines
drivers/misc/intel/gna/device.c +10
-0+int ret; + + ret =misc_register (misc); +if (ret) { +dev_err (parent,"misc device %s registering failed. errcode: %d\n" , + misc->name, ret); +gna_devm_deregister_misc_dev (misc); + }else { +dev_dbg (parent,"device: %s registered\n" , + misc->name);
You have loads of debugging in this driver still, is it really needed?
drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 63
Quoted 3 lines
drivers/misc/intel/gna/device.c +3
-0+ } + + ret =devm_add_action (parent, gna_devm_deregister_misc_dev, misc);
Why do you need this?
thanks,
greg k-h
Re: [PATCH v3 12/14] intel_gna: add a 'misc' device
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Maciej Kwapulinski
The new 'misc' device is the node for applications in user space to interact with the driver.
Signed-off-by Maciej Kwapulinski <[email protected]>Tested-by Savo Novakovic <[email protected]>--- drivers/misc/intel/gna/device.c | 52 +++++++++++++++++++++++++++++++-- drivers/misc/intel/gna/device.h | 11 +++---- 2 files changed, 55 insertions(+), 8 deletions(-)drivers/misc/intel/gna/device.c +0
-0@@ -20,6 +20,18 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif
Quoted 8 lines
drivers/misc/intel/gna/device.c module_param(recovery_timeout, int, 0644); · line 28
Quoted 6 lines
drivers/misc/intel/gna/device.c +6
-0+struct file ; + +static int gna_open (struct inode *inode,struct file *f) +{ +return -EPERM ; +}That sucks, why have an open that does nothing but fail?
next patch provides complete implementation of gna_open(), here it's just a protection if someone would incidentally run gna in the middle of patch series
Quoted 14 lines
Quoted 14 lines
drivers/misc/intel/gna/device.c +6
-0+ +static const struct file_operations gna_file_ops = { + .owner =THIS_MODULE , + .open = gna_open, +}; +static void gna_devm_idr_destroy (void *data) {struct idr *idr = data;@@ -27,6 +39,36 @@ static void gna_devm_idr_destroy(void *data)idr_destroy (idr); }
Quoted 3 lines
drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 42
Quoted 1 line
drivers/misc/intel/gna/device.c +1
-0+static void gna_devm_deregister_misc_dev (void *data)Why is this a void *?
it goes to devm_add_action() api.
Quoted 25 lines
This isn't windows, use real pointer types everywhere in the kernel please.
Quoted 8 lines
drivers/misc/intel/gna/device.c +8
-0+{ +struct miscdevice *misc = data; + +misc_deregister (misc); +} + +static int gna_devm_register_misc_dev (struct device *parent,struct miscdevice *misc) +{drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 60
Quoted 10 lines
drivers/misc/intel/gna/device.c +10
-0+int ret; + + ret =misc_register (misc); +if (ret) { +dev_err (parent,"misc device %s registering failed. errcode: %d\n" , + misc->name, ret); +gna_devm_deregister_misc_dev (misc); + }else { +dev_dbg (parent,"device: %s registered\n" , + misc->name);You have loads of debugging in this driver still, is it really needed?
Quoted 5 lines
drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 63
Quoted 3 lines
drivers/misc/intel/gna/device.c +3
-0+ } + + ret =devm_add_action (parent, gna_devm_deregister_misc_dev, misc);Why do you need this?
I'd like to avoid having gna_probe's fail path at all.
Quoted 5 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH v3 12/14] intel_gna: add a 'misc' device
Quoted 31 lines · Maciej Kwapulinski
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Maciej Kwapulinski
The new 'misc' device is the node for applications in user space to interact with the driver.
Signed-off-by Maciej Kwapulinski <[email protected]>Tested-by Savo Novakovic <[email protected]>--- drivers/misc/intel/gna/device.c | 52 +++++++++++++++++++++++++++++++-- drivers/misc/intel/gna/device.h | 11 +++---- 2 files changed, 55 insertions(+), 8 deletions(-)drivers/misc/intel/gna/device.c +0
-0@@ -20,6 +20,18 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif Quoted 8 lines
drivers/misc/intel/gna/device.c module_param(recovery_timeout, int, 0644); · line 28
Quoted 6 lines
drivers/misc/intel/gna/device.c +6
-0+struct file ; + +static int gna_open (struct inode *inode,struct file *f) +{ +return -EPERM ; +}That sucks, why have an open that does nothing but fail?
Quoted 2 lines
next patch provides complete implementation of
gna_open(), here it's just a protection if someone would incidentally run gna in the middle of patch series
Then don't provide an open at all, and it will be fine :)
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/misc/intel/gna/device.c +6
-0+ +static const struct file_operations gna_file_ops = { + .owner =THIS_MODULE , + .open = gna_open, +}; +static void gna_devm_idr_destroy (void *data) {struct idr *idr = data;@@ -27,6 +39,36 @@ static void gna_devm_idr_destroy(void *data)idr_destroy (idr); }
Quoted 5 lines
Quoted 3 lines
drivers/misc/intel/gna/device.c static void gna_devm_idr_destroy(void *data) · line 42
Quoted 1 line
drivers/misc/intel/gna/device.c +1
-0+static void gna_devm_deregister_misc_dev (void *data)Why is this a void *?
it goes to
devm_add_action()api.
Ah. That's not obvious :(
PATCH v3 13/14 intel_gna: add file operations to a 'misc' device
In reply to Maciej KwapulinskiFrom: Tomasz Jankowski <[email protected]>
--- drivers/misc/intel/gna/device.c | 60 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-)
drivers/misc/intel/gna/device.c +57 -3
@@ -4,7 +4,9 @@#include <linux/device.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h> +#include <linux/fs.h> #include <linux/module.h> +#include <linux/slab.h> #include <uapi/misc/intel/gna.h>
@@ -20,16 +22,68 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif -struct file ; -static int gna_open (struct inode *inode,struct file *f) { -return -EPERM ; +struct gna_file_private *file_priv; +struct gna_private *gna_priv; + + gna_priv = container_of(f->private_data, struct gna_private, misc); + + file_priv =kzalloc (sizeof (*file_priv),GFP_KERNEL ); +if (!file_priv) +return -ENOMEM ; + + file_priv->fd = f; + file_priv->gna_priv = gna_priv; + +mutex_init (&file_priv->memlist_lock); +INIT_LIST_HEAD (&file_priv->memory_list); + +INIT_LIST_HEAD (&file_priv->flist); + +mutex_lock (&gna_priv->flist_lock); +list_add_tail (&file_priv->flist, &gna_priv->file_list); +mutex_unlock (&gna_priv->flist_lock); + + f->private_data = file_priv; + +return 0 ; +} + +static int gna_release (struct inode *inode,struct file *f) +{ +struct gna_memory_object *iter_mo, *temp_mo; +struct gna_file_private *file_priv; +struct gna_private *gna_priv; + +/* free all memory objects created by that file */ + file_priv = (struct gna_file_private *)f->private_data; + gna_priv = file_priv->gna_priv; + +mutex_lock (&file_priv->memlist_lock); +list_for_each_entry_safe (iter_mo, temp_mo, &file_priv->memory_list, file_mem_list) { +queue_work (gna_priv->request_wq, &iter_mo->work); +wait_event (iter_mo->waitq, true); +gna_memory_free (gna_priv, iter_mo); + } +mutex_unlock (&file_priv->memlist_lock); + +gna_delete_file_requests (f, gna_priv); + +mutex_lock (&gna_priv->flist_lock); +list_del_init (&file_priv->flist); +mutex_unlock (&gna_priv->flist_lock); +kfree (file_priv); + f->private_data =NULL ; + +return 0 ; }static const struct file_operations gna_file_ops = { .owner =THIS_MODULE , .open = gna_open, + .release = gna_release, + .unlocked_ioctl = gna_ioctl, };static void gna_devm_idr_destroy (void *data)
Signature · 1 line
2.28.0
Greg Kroah-Hartman
maintainerRe: [PATCH v3 13/14] intel_gna: add file operations to a 'misc' device
Quoted 85 lines · Maciej Kwapulinski
From: Tomasz Jankowski <[email protected]>
Signed-off-by Tomasz Jankowski <[email protected]>Tested-by Savo Novakovic <[email protected]>Co-developed-by Jianxun Zhang <[email protected]>Signed-off-by Jianxun Zhang <[email protected]>Co-developed-by Maciej Kwapulinski <[email protected]>Signed-off-by Maciej Kwapulinski <[email protected]>--- drivers/misc/intel/gna/device.c | 60 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-)drivers/misc/intel/gna/device.c +52
-3@@ -4,7 +4,9 @@#include <linux/device.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h> +#include <linux/fs.h> #include <linux/module.h> +#include <linux/slab.h> #include <uapi/misc/intel/gna.h> @@ -20,16 +22,68 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif -struct file ; -static int gna_open (struct inode *inode,struct file *f) { -return -EPERM ; +struct gna_file_private *file_priv; +struct gna_private *gna_priv; + + gna_priv = container_of(f->private_data, struct gna_private, misc); + + file_priv =kzalloc (sizeof (*file_priv),GFP_KERNEL ); +if (!file_priv) +return -ENOMEM ; + + file_priv->fd = f; + file_priv->gna_priv = gna_priv; + +mutex_init (&file_priv->memlist_lock); +INIT_LIST_HEAD (&file_priv->memory_list); + +INIT_LIST_HEAD (&file_priv->flist); + +mutex_lock (&gna_priv->flist_lock); +list_add_tail (&file_priv->flist, &gna_priv->file_list); +mutex_unlock (&gna_priv->flist_lock); + + f->private_data = file_priv; + +return 0 ; +} + +static int gna_release (struct inode *inode,struct file *f) +{ +struct gna_memory_object *iter_mo, *temp_mo; +struct gna_file_private *file_priv; +struct gna_private *gna_priv; + +/* free all memory objects created by that file */ + file_priv = (struct gna_file_private *)f->private_data; + gna_priv = file_priv->gna_priv; + +mutex_lock (&file_priv->memlist_lock); +list_for_each_entry_safe (iter_mo, temp_mo, &file_priv->memory_list, file_mem_list) { +queue_work (gna_priv->request_wq, &iter_mo->work); +wait_event (iter_mo->waitq, true); +gna_memory_free (gna_priv, iter_mo); + } +mutex_unlock (&file_priv->memlist_lock); + +gna_delete_file_requests (f, gna_priv); + +mutex_lock (&gna_priv->flist_lock); +list_del_init (&file_priv->flist); +mutex_unlock (&gna_priv->flist_lock); +kfree (file_priv);
drivers/misc/intel/gna/device.c module_param(recovery_timeout, int, 0644); · line 86
Quoted 10 lines
drivers/misc/intel/gna/device.c +5
-0+ f->private_data =NULL ; + +return 0 ; }static const struct file_operations gna_file_ops = { .owner =THIS_MODULE , .open = gna_open, + .release = gna_release, + .unlocked_ioctl = gna_ioctl,
Wait, where's the ioctl? You added it earlier in the series?
gotta go dig now...
greg k-h
PATCH v3 14/14 intel_gna: add power management
In reply to Maciej KwapulinskiImplement power management in intel_gna driver
--- drivers/misc/intel/gna/device.c | 55 +++++++++++++++++++++++++++++++- drivers/misc/intel/gna/device.h | 3 ++ drivers/misc/intel/gna/hw.h | 1 + drivers/misc/intel/gna/pci.c | 3 ++ drivers/misc/intel/gna/request.c | 15 +++++++++ 5 files changed, 76 insertions(+), 1 deletion(-)
drivers/misc/intel/gna/device.c +54 -1
@@ -22,6 +22,30 @@ module_param(recovery_timeout, int, 0644);MODULE_PARM_DESC (recovery_timeout,"Recovery timeout in seconds" );#endif +static int __maybe_unused gna_runtime_suspend (struct device *dev) +{ +struct gna_private *gna_priv =dev_get_drvdata (dev); +u32 val =gna_reg_read (gna_priv,GNA_MMIO_D0I3C ); + +dev_dbg (dev,"%s D0I3, reg %.8x\n" , __func__, val); + +return 0 ; +} + +static int __maybe_unused gna_runtime_resume (struct device *dev) +{ +struct gna_private *gna_priv =dev_get_drvdata (dev); +u32 val =gna_reg_read (gna_priv,GNA_MMIO_D0I3C ); + +dev_dbg (dev,"%s D0I3, reg %.8x\n" , __func__, val); + +return 0 ; +} + +const struct dev_pm_ops __maybe_unused gna_pm = { +SET_RUNTIME_PM_OPS (gna_runtime_suspend, gna_runtime_resume,NULL ) +}; +static int gna_open (struct inode *inode,struct file *f) {struct gna_file_private *file_priv;
@@ -123,6 +147,22 @@ static int gna_devm_register_misc_dev(struct device *parent, struct miscdevice *return ret; } +static void gna_pm_init (struct device *dev) +{ +pm_runtime_set_autosuspend_delay (dev,200 ); +pm_runtime_use_autosuspend (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_allow (dev); +pm_runtime_put_noidle (dev); +} + +static void gna_pm_remove (void *data) +{ +struct device *dev = data; + +pm_runtime_get_noresume (dev); +} +static irqreturn_t gna_interrupt (int irq,void *priv) {struct gna_private *gna_priv;
@@ -245,7 +285,20 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem gna_priv->misc.fops = &gna_file_ops; gna_priv->misc.mode =0666 ; -return gna_devm_register_misc_dev (parent, &gna_priv->misc); + ret =gna_devm_register_misc_dev (parent, &gna_priv->misc); +if (ret) +return ret; + +dev_set_drvdata (parent, gna_priv); + +gna_pm_init (parent); + ret =devm_add_action (parent, gna_pm_remove, parent); +if (ret) { +dev_err (parent,"could not add devm action for pm\n" ); +return ret; + } + +return 0 ; }static u32 gna_device_type_by_hwid (u32 hwid)
drivers/misc/intel/gna/device.h +3 -0
@@ -10,6 +10,7 @@#include <linux/list.h> #include <linux/miscdevice.h> #include <linux/mutex.h> +#include <linux/pm_runtime.h> #include <linux/types.h> #include "hw.h"
@@ -75,6 +76,8 @@ struct gna_private {int gna_probe (struct device *parent,struct gna_dev_info *dev_info,void __iomem *iobase,int irq);int gna_getparam (struct gna_private *gna_priv,union gna_parameter *param); +extern const struct dev_pm_ops __maybe_unused gna_pm; +static inline u32 gna_reg_read (struct gna_private *gna_priv,u32 reg) {return readl (gna_priv->iobase + reg);
drivers/misc/intel/gna/hw.h +1 -0
@@ -49,6 +49,7 @@ struct gna_private;#define GNA_MMIO_CTRL 0x84#define GNA_MMIO_PTC 0x8C#define GNA_MMIO_PSC 0x90 +#define GNA_MMIO_D0I3C 0xA8#define GNA_MMIO_DESBASE 0xB0#define GNA_MMIO_IBUFFS 0xB4
drivers/misc/intel/gna/pci.c +3 -0
@@ -139,6 +139,9 @@ static struct pci_driver gna_pci_driver = { .name = GNA_DV_NAME, .id_table = gna_pci_ids, .probe = gna_pci_probe, + .driver = { + .pm = &gna_pm, + }, };module_pci_driver (gna_pci_driver);
drivers/misc/intel/gna/request.c +15 -0
@@ -6,6 +6,7 @@#include <linux/idr.h> #include <linux/mm.h> #include <linux/mutex.h> +#include <linux/pm_runtime.h> #include <linux/uaccess.h> #include <linux/slab.h>
@@ -65,6 +66,14 @@ static void gna_request_process(struct work_struct *work) score_request->drv_perf.pre_processing =ktime_get_ns (); + ret =pm_runtime_get_sync (gna_parent (gna_priv)); +if (ret <0 && ret != -EACCES ) { +dev_warn (gna_dev (gna_priv),"pm_runtime_get_sync() failed: %d\n" , ret); + score_request->status = -ENODEV ; +pm_runtime_put_noidle (gna_parent (gna_priv)); + goto end; + } +/* Set busy flag before kicking off HW. The isr will clear it and wake up us. There is * no difference if isr is missed in a timeout situation of the last request. We just * always set it busy and let the wait_event_timeout check the reset.
@@ -75,6 +84,8 @@ static void gna_request_process(struct work_struct *work) ret =gna_score (score_request);if (ret) { +if (pm_runtime_put (gna_parent (gna_priv)) <0 ) +dev_warn (gna_dev (gna_priv),"pm_runtime_put() failed: %d\n" , ret); score_request->status = ret; goto end; }
@@ -94,6 +105,10 @@ static void gna_request_process(struct work_struct *work)gna_request_update_status (score_request);gna_abort_hw (gna_priv); + ret =pm_runtime_put (gna_parent (gna_priv)); +if (ret <0 ) +dev_warn (gna_dev (gna_priv),"pm_runtime_put() failed: %d\n" , ret); + buffer = score_request->buffer_list;for (i =0 ; i < score_request->buffer_count; i++, buffer++) {mutex_lock (&gna_priv->memidr_lock);
Signature · 1 line
2.28.0
Greg Kroah-Hartman
maintainerQuoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
thanks,
greg k-h
Arnd Bergmann
maintainerQuoted 11 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
Quoted 7 lines
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have support for Intel habanalabs hardware in drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including
- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm Ethos
plus many more that are somewhat less likely to gain fully open source driver stacks.
Arnd
Quoted 16 lines · Arnd Bergmann
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]
Quoted 8 lines
Quoted 4 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called drivers/gpu. Feel free to rename to drivers/xpu or think G as in General, not Graphisc.
Quoted 12 lines
We have support for Intel habanalabs hardware in
drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm Ethos
Quoted 2 lines
plus many more that are somewhat less likely to gain fully open source driver stacks.
We also had this entire discussion 2 years ago with habanalabs. The hang-up is that drivers/gpu folks require fully open source userspace, including compiler and anything else you need to actually use the chip. Greg doesn't, he's happy if all he has is the runtime library with some tests.
These two drivers here look a lot more like classic gpus than habanalabs did, at least from a quick look they operate with explicit buffer allocations/registration model. So even more reasons to just reuse all the stuff we have already. But also I don't expect these drivers here to come with open compilers, they never do, not initially at least before you started talking with the vendor. Hence I expect there'll be more drivers/totally-not-drm acceleration subsystem nonsense.
Anyway this horse has been throughroughly beaten to death and more, the agreement is that accel drivers in drivers/misc must not use any gpu stuff, so that drivers/gpu people dont end up in a prickly situation they never signed up for. E.g. I removed some code sharing from habanalabs. This means interop between gpu and nn/ai drivers will be no-go until this is resolved, but *shrug*.
Cheers, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Greg Kroah-Hartman
maintainerQuoted 41 lines · Daniel Vetter
Quoted 16 lines · Arnd Bergmann
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Quoted 8 lines
Quoted 4 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.Quoted 12 lines
We have support for Intel habanalabs hardware in
drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm Ethos
Quoted 8 lines
Quoted 2 lines
plus many more that are somewhat less likely to gain fully open source driver stacks.
We also had this entire discussion 2 years ago with habanalabs. The hang-up is that
drivers/gpufolks require fully open source userspace, including compiler and anything else you need to actually use the chip. Greg doesn't, he's happy if all he has is the runtime library with some tests.
All you need is a library, what you write on top of that is always application-specific, so how can I ask for "more"?
Quoted 7 lines
These two drivers here look a lot more like classic gpus than habanalabs did, at least from a quick look they operate with explicit buffer allocations/registration model. So even more reasons to just reuse all the stuff we have already. But also I don't expect these drivers here to come with open compilers, they never do, not initially at least before you started talking with the vendor. Hence I expect there'll be more
drivers/totally-not-drmacceleration subsystem nonsense.
As these are both from Intel, why aren't they using the same open compiler? Why aren't they using the same userspace api as well? What's preventing them from talking to each other about this and not forcing the community (i.e. outsiders) from being the one to force this to happen?
Quoted 6 lines
Anyway this horse has been throughroughly beaten to death and more, the agreement is that accel drivers in
drivers/miscmust not use any gpu stuff, so thatdrivers/gpupeople dont end up in a prickly situation they never signed up for. E.g. I removed some code sharing from habanalabs. This means interop between gpu and nn/ai drivers will be no-go until this is resolved, but *shrug*.
I'm all for making this unified, but these are not really devices doing graphics so putting it all into DRM always feels wrong to me. The fact that people abuse GPU devices for not graphic usages would indicate to me that that code should be moving _out_ of the drm subsystem :)
thanks,
greg k-h
Quoted 43 lines · Greg Kroah-Hartman
Quoted 41 lines · Daniel Vetter
Quoted 16 lines · Arnd Bergmann
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Quoted 8 lines
Quoted 4 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.Quoted 12 lines
We have support for Intel habanalabs hardware in
drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm Ethos
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
plus many more that are somewhat less likely to gain fully open source driver stacks.
We also had this entire discussion 2 years ago with habanalabs. The hang-up is that
drivers/gpufolks require fully open source userspace, including compiler and anything else you need to actually use the chip. Greg doesn't, he's happy if all he has is the runtime library with some tests.
I guess we're really going to beat this horse into pulp ... oh well.
Quoted 2 lines
All you need is a library, what you write on top of that is always application-specific, so how can I ask for "more"?
This is like accepting a new cpu port, where all you require is that the libc port is open source, but the cpu compiler is totally fine as a blob (doable with llvm now being supported). It makes no sense at all, at least to people who have worked with accelerators like this before.
We are not requiring that applications are open. We're only requiring that at least one of the compilers you need (no need to open the fully optimized one with all the magic sauce) to create any kind of applications is open, because without that you can't use the device, you can't analyze the stack, and you have no idea at all about what exactly it is you're merging. With these devices, the uapi visible in include/uapi is the smallest part of the interface exposed to userspace.
Quoted 8 lines
Quoted 7 lines
These two drivers here look a lot more like classic gpus than habanalabs did, at least from a quick look they operate with explicit buffer allocations/registration model. So even more reasons to just reuse all the stuff we have already. But also I don't expect these drivers here to come with open compilers, they never do, not initially at least before you started talking with the vendor. Hence I expect there'll be more
drivers/totally-not-drmacceleration subsystem nonsense.
Quoted 5 lines
As these are both from Intel, why aren't they using the same open compiler? Why aren't they using the same userspace api as well? What's preventing them from talking to each other about this and not forcing the community (i.e. outsiders) from being the one to force this to happen?
I'm unfortuantely not the CEO of this company. Also you're the one who keeps accepting drivers that the accel folks (aka dri-devel community) said shouldn't be merged, so my internal bargaining power is zero to force something reaonable here. So please don't blame me for this mess, this is yours entirely.
Quoted 11 lines
Quoted 6 lines
Anyway this horse has been throughroughly beaten to death and more, the agreement is that accel drivers in
drivers/miscmust not use any gpu stuff, so thatdrivers/gpupeople dont end up in a prickly situation they never signed up for. E.g. I removed some code sharing from habanalabs. This means interop between gpu and nn/ai drivers will be no-go until this is resolved, but *shrug*.I'm all for making this unified, but these are not really devices doing graphics so putting it all into DRM always feels wrong to me. The fact that people abuse GPU devices for not graphic usages would indicate to me that that code should be moving _out_ of the drm subsystem :)
Like I said, if the 'g' really annoys you that much, feel free to send in a patch to rename drivers/gpu to drivers/xpu.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Greg Kroah-Hartman
maintainerQuoted 65 lines · Daniel Vetter
Quoted 43 lines · Greg Kroah-Hartman
Quoted 41 lines · Daniel Vetter
Quoted 16 lines · Arnd Bergmann
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Quoted 8 lines
Quoted 4 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.Quoted 12 lines
We have support for Intel habanalabs hardware in
drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm EthosQuoted 8 lines
Quoted 8 lines
Quoted 2 lines
plus many more that are somewhat less likely to gain fully open source driver stacks.
We also had this entire discussion 2 years ago with habanalabs. The hang-up is that
drivers/gpufolks require fully open source userspace, including compiler and anything else you need to actually use the chip. Greg doesn't, he's happy if all he has is the runtime library with some tests.I guess we're really going to beat this horse into pulp ... oh well.
Quoted 2 lines
All you need is a library, what you write on top of that is always application-specific, so how can I ask for "more"?
This is like accepting a new cpu port, where all you require is that the libc port is open source, but the cpu compiler is totally fine as a blob (doable with llvm now being supported). It makes no sense at all, at least to people who have worked with accelerators like this before.
Quoted 8 lines
We are not requiring that applications are open. We're only requiring that at least one of the compilers you need (no need to open the fully optimized one with all the magic sauce) to create any kind of applications is open, because without that you can't use the device, you can't analyze the stack, and you have no idea at all about what exactly it is you're merging. With these devices, the uapi visible in
include/uapiis the smallest part of the interface exposed to userspace.
Ok, sorry, I was not aware that the habanalabs compiler was not available to all under an open source license. All I was trying to enforce was that the library to use the kernel api was open so that anyone could use it. Trying to enforce compiler requirements like this might feel to be a bit of a reach as the CPU on the hardware really doesn't fall under the license of the operating system running on this CPU over here :)
thanks,
greg k-h
Quoted 76 lines · Greg Kroah-Hartman
Quoted 65 lines · Daniel Vetter
Quoted 43 lines · Greg Kroah-Hartman
Quoted 41 lines · Daniel Vetter
Quoted 16 lines · Arnd Bergmann
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Quoted 8 lines
Quoted 4 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.Quoted 12 lines
We have support for Intel habanalabs hardware in
drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm EthosQuoted 8 lines
Quoted 8 lines
Quoted 2 lines
plus many more that are somewhat less likely to gain fully open source driver stacks.
We also had this entire discussion 2 years ago with habanalabs. The hang-up is that
drivers/gpufolks require fully open source userspace, including compiler and anything else you need to actually use the chip. Greg doesn't, he's happy if all he has is the runtime library with some tests.I guess we're really going to beat this horse into pulp ... oh well.
Quoted 2 lines
All you need is a library, what you write on top of that is always application-specific, so how can I ask for "more"?
This is like accepting a new cpu port, where all you require is that the libc port is open source, but the cpu compiler is totally fine as a blob (doable with llvm now being supported). It makes no sense at all, at least to people who have worked with accelerators like this before.
Quoted 8 lines
We are not requiring that applications are open. We're only requiring that at least one of the compilers you need (no need to open the fully optimized one with all the magic sauce) to create any kind of applications is open, because without that you can't use the device, you can't analyze the stack, and you have no idea at all about what exactly it is you're merging. With these devices, the uapi visible in
include/uapiis the smallest part of the interface exposed to userspace.
Quoted 7 lines
Ok, sorry, I was not aware that the habanalabs compiler was not available to all under an open source license. All I was trying to enforce was that the library to use the kernel api was open so that anyone could use it. Trying to enforce compiler requirements like this might feel to be a bit of a reach as the CPU on the hardware really doesn't fall under the license of the operating system running on this CPU over here :)
Experience says if you don't, forget about supporting your drivers/subsystem long-term. At best you're stuck with a per-device fragmented mess that vendors might or might not support. This has nothing to do with GPL licensing or not, but about making sure you can do proper engineering/support/review of the driver stack. At least in the GPU world we're already making it rather clear that running blobby userspace is fine with us (as long as it's using the exact same uapi as the truly open stack, no exceptions/hacks/abuse are supported).
Also yes vendors don't like it. But they also don't like that they have to open source their kernel drivers, or runtime library. Lots of background chats over years, and a very clear line in the sand helps to get there, and also makes sure that the vendors who got here don't return to the old closed source ways they love so much.
Anyway we've had all this discussions 2 years ago, nothing has changed (well on the gpu side we managed to get ARM officially on board with fully open stack paid by them meanwhile, other discussions still ongoing). I just wanted to re-iterate that if we'd really care about having a proper accel subsystem, there's people who've been doing this for decades.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 102 lines · Daniel Vetter
Quoted 76 lines · Greg Kroah-Hartman
Quoted 65 lines · Daniel Vetter
Quoted 43 lines · Greg Kroah-Hartman
Quoted 41 lines · Daniel Vetter
Quoted 16 lines · Arnd Bergmann
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Quoted 8 lines
Quoted 4 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.Quoted 12 lines
We have support for Intel habanalabs hardware in
drivers/misc, and there are countless hardware solutions out of tree that would hopefully go the same way with an upstream submission and open source user space, including- Intel/Mobileye EyeQ
- Intel/Movidius Keembay
- Nvidia NVDLA
- Gyrfalcon Lightspeeur
- Apple Neural Engine
- Google TPU
- Arm EthosQuoted 8 lines
Quoted 8 lines
Quoted 2 lines
plus many more that are somewhat less likely to gain fully open source driver stacks.
We also had this entire discussion 2 years ago with habanalabs. The hang-up is that
drivers/gpufolks require fully open source userspace, including compiler and anything else you need to actually use the chip. Greg doesn't, he's happy if all he has is the runtime library with some tests.I guess we're really going to beat this horse into pulp ... oh well.
Quoted 2 lines
All you need is a library, what you write on top of that is always application-specific, so how can I ask for "more"?
This is like accepting a new cpu port, where all you require is that the libc port is open source, but the cpu compiler is totally fine as a blob (doable with llvm now being supported). It makes no sense at all, at least to people who have worked with accelerators like this before.
Quoted 8 lines
We are not requiring that applications are open. We're only requiring that at least one of the compilers you need (no need to open the fully optimized one with all the magic sauce) to create any kind of applications is open, because without that you can't use the device, you can't analyze the stack, and you have no idea at all about what exactly it is you're merging. With these devices, the uapi visible in
include/uapiis the smallest part of the interface exposed to userspace.Quoted 7 lines
Ok, sorry, I was not aware that the habanalabs compiler was not available to all under an open source license. All I was trying to enforce was that the library to use the kernel api was open so that anyone could use it. Trying to enforce compiler requirements like this might feel to be a bit of a reach as the CPU on the hardware really doesn't fall under the license of the operating system running on this CPU over here :)
Experience says if you don't, forget about supporting your
drivers/subsystemlong-term. At best you're stuck with a per-device fragmented mess that vendors might or might not support. This has nothing to do with GPL licensing or not, but about making sure you can do proper engineering/support/review of the driver stack. At least in the GPU world we're already making it rather clear that running blobby userspace is fine with us (as long as it's using the exact same uapi as the truly open stack, no exceptions/hacks/abuse are supported).Also yes vendors don't like it. But they also don't like that they have to open source their kernel drivers, or runtime library. Lots of background chats over years, and a very clear line in the sand helps to get there, and also makes sure that the vendors who got here don't return to the old closed source ways they love so much.
Quoted 6 lines
Anyway we've had all this discussions 2 years ago, nothing has changed (well on the gpu side we managed to get ARM officially on board with fully open stack paid by them meanwhile, other discussions still ongoing). I just wanted to re-iterate that if we'd really care about having a proper accel subsystem, there's people who've been doing this for decades.
I think the other point worth reiterating is that most of these devices are unobtanium for your average kernel maintainer. It's hard to create a subsystem standard when you don't have access to a collection of devices + the complete picture of what the stack is doing and how it interoperates with the ecosystem at large, not just the kernel. Kernel maintainers need to help ensure there is a viable ecosystem beyond the kernel before merging stuff that is clearly a large kernel + user stack architecture. i.e. misc USB drivers, merge away, misc small layer drivers for larger vendor-specific ecosystems we need to tread more carefully as longterm we do nobody any favours.
Dave.
Quoted 6 lines
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Hi
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to
free
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Quoted 6 lines
Quoted 3 lines
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.
I hope this was a joke.
Just some thoughts:
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't. Treating both as the same, even if they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
And as Dave mentioned, these devices are hard to obtain. We don't really know what we sign up for.
Just my 2 cents.
Best regards
Thomas
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Quoted 38 lines · Thomas Zimmermann
Hi
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to
free
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Quoted 6 lines
Quoted 3 lines
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Just some thoughts:
Quoted 9 lines
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't. Treating both as the same, even if they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
The putting something on the screen is just a tiny part of what GPUs do these days. Many GPUs don't even have display hardware anymore. Even with drawing APIs, it's just some operation that you do with memory. The display may be another device entirely. GPUs also do video encode and decode, jpeg acceleration, etc. drivers/gpu seems like a logical place to me. Call it drivers/accelerators if you like. Other than modesetting most of the shared infrastructure in drivers/gpu is around memory management and synchronization which are all the hard parts. Better to try and share that than to reinvent that in some other subsystem.
Alex
Quoted 19 lines
And as Dave mentioned, these devices are hard to obtain. We don't really know what we sign up for.
Just my 2 cents.
Best regards
Thomas--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Quoted 50 lines · Alex Deucher
Quoted 38 lines · Thomas Zimmermann
Hi
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to
free
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Quoted 6 lines
Quoted 3 lines
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Just some thoughts:
Quoted 9 lines
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't. Treating both as the same, even if they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
Quoted 10 lines
The putting something on the screen is just a tiny part of what GPUs do these days. Many GPUs don't even have display hardware anymore. Even with drawing APIs, it's just some operation that you do with memory. The display may be another device entirely. GPUs also do video encode and decode, jpeg acceleration, etc.
drivers/gpuseems like a logical place to me. Call itdrivers/acceleratorsif you like. Other than modesetting most of the shared infrastructure indrivers/gpuis around memory management and synchronization which are all the hard parts. Better to try and share that than to reinvent that in some other subsystem.
Maybe to add: Most of our driver stack is in userspace (like for NN/AI chips too), both where high amounts of code sharing are the norm (like with mesa3d) and areas there the landscape is a lot more fragmented (like compute and media, where the userspace driver APIs are all different for each vendor, or at least highly specialized). That's another thing which I don't think any other kernel subsystem has, at least as much as we do.
So for both the big design questions on how the overall stack is organized down to the details like code sharing, drivers/g^Hxpu should be the best place. Aside from the pesky problem that we do actually look at the userspace side and have some expectations on that too, not just on the kernel code alone.
-Daniel
Quoted 22 lines
Alex
Quoted 19 lines
And as Dave mentioned, these devices are hard to obtain. We don't really know what we sign up for.
Just my 2 cents.
Best regards
Thomas--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Hi
Am 17.05.21 um 21:23 schrieb Alex Deucher:
Quoted 1 line
On Mon, May 17, 2021 at 3:12 PM Thomas Zimmermann <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines
Hi
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 1 line · Arnd Bergmann
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can
offload
Quoted 35 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
continuous inference workloads to an Intel(R) GNA device in order to
free
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Quoted 6 lines
Quoted 3 lines
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Just some thoughts:
Quoted 9 lines
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't. Treating both as the same, even if they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
Quoted 10 lines
The putting something on the screen is just a tiny part of what GPUs do these days. Many GPUs don't even have display hardware anymore. Even with drawing APIs, it's just some operation that you do with memory. The display may be another device entirely. GPUs also do video encode and decode, jpeg acceleration, etc.
drivers/gpuseems like a logical place to me. Call itdrivers/acceleratorsif you like. Other than modesetting most of the shared infrastructure indrivers/gpuis around memory management and synchronization which are all the hard parts. Better to try and share that than to reinvent that in some other subsystem.
I'm not sure whether we're on the same page or not.
I look at this from the UAPI perspective: the only interfaces that we really standardize among GPUs is modesetting, dumb buffers, GEM. The sophisticated rendering is done with per-driver interfaces. And modesetting is the thing that AI does not do.
Sharing common code among subsystems is not a problem. Many of our more-sophisticated helpers are located in DRM because no other subsystems have the requirements yet. Maybe AI now has and we can move the rsp shareable code to a common location. But AI is still no GPU. To give a bad analogy: GPUs transmit audio these days. Yet we don't treat them as sound cards.
Best regards
Thomas
Quoted 22 lines
Alex
Quoted 19 lines
And as Dave mentioned, these devices are hard to obtain. We don't really know what we sign up for.
Just my 2 cents.
Best regards
Thomas--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Quoted 66 lines · Thomas Zimmermann
Hi
Am 17.05.21 um 21:23 schrieb Alex Deucher:
Quoted 1 line
On Mon, May 17, 2021 at 3:12 PM Thomas Zimmermann <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines
Hi
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 1 line · Arnd Bergmann
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can
offload
Quoted 35 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
continuous inference workloads to an Intel(R) GNA device in order to
free
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
Quoted 6 lines
Quoted 3 lines
Agreed, but I think we should go further than this and work towards a subsystem across companies for machine learning and neural networks accelerators for both inferencing and training.
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Just some thoughts:
Quoted 9 lines
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't. Treating both as the same, even if they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
Quoted 10 lines
The putting something on the screen is just a tiny part of what GPUs do these days. Many GPUs don't even have display hardware anymore. Even with drawing APIs, it's just some operation that you do with memory. The display may be another device entirely. GPUs also do video encode and decode, jpeg acceleration, etc.
drivers/gpuseems like a logical place to me. Call itdrivers/acceleratorsif you like. Other than modesetting most of the shared infrastructure indrivers/gpuis around memory management and synchronization which are all the hard parts. Better to try and share that than to reinvent that in some other subsystem.
Quoted 6 lines
I'm not sure whether we're on the same page or not.
I look at this from the UAPI perspective: the only interfaces that we really standardize among GPUs is modesetting, dumb buffers, GEM. The sophisticated rendering is done with per-driver interfaces. And modesetting is the thing that AI does not do.
Yeah, but the peole who know what should be standardized and what should not be standardized for accel drivers are here. Because we've done both models in the past, and pretty much everything in between.
Also like Daniel said, we support hw (and know how to drive it) for anything from "kernel bashes register values" (gpus worked like that 20 years ago) to "mostly direct userspace submit (amdkfd and parts of nouveau work like this).
There isn't any other subsystem with that much knowledge about how to stand up the entire accelerator stack and not making it suck too badly. That is the real value of dri-devel and the community we have here, not the code sharing we occasionally tend to do.
Quoted 6 lines
Sharing common code among subsystems is not a problem. Many of our more-sophisticated helpers are located in DRM because no other subsystems have the requirements yet. Maybe AI now has and we can move the rsp shareable code to a common location. But AI is still no GPU. To give a bad analogy: GPUs transmit audio these days. Yet we don't treat them as sound cards.
We actually do, there are full blown sound drivers for them over in sound/ (ok I think they're all in sound/hda for pci gpus or in sound/soc actually). There's some glue to tie it together because it requires coordination between the gpu and sound side of things, but that's it.
Also I think it would be extremely silly to remove all the drm_ stuff just because it's originated from GPUs, and therefore absolutely cannot be used by other accelarators. I'm not seeing the point in that, but if someone has convincing technical argument for this we could do it. A tree wide s/drm_/xpu_ might make some sense perhaps if that makes people more comfortable with the idea of reusing code from gpu origins for accelerators in general.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Hi
Am 17.05.21 um 22:00 schrieb Daniel Vetter:
Quoted 7 lines
Quoted 6 lines
Sharing common code among subsystems is not a problem. Many of our more-sophisticated helpers are located in DRM because no other subsystems have the requirements yet. Maybe AI now has and we can move the rsp shareable code to a common location. But AI is still no GPU. To give a bad analogy: GPUs transmit audio these days. Yet we don't treat them as sound cards.
Quoted 5 lines
We actually do, there are full blown sound drivers for them over in
sound/(ok I think they're all insound/hdafor pci gpus or insound/socactually). There's some glue to tie it together because it requires coordination between the gpu and sound side of things, but that's it.
I know. But we don't merge both subsystems, just because the devices have some overlap in functionality.
Best regards
Thomas
Quoted 10 lines
Also I think it would be extremely silly to remove all the
drm_stuff just because it's originated from GPUs, and therefore absolutely cannot be used by other accelarators. I'm not seeing the point in that, but if someone has convincing technical argument for this we could do it. A tree wide s/drm_/xpu_ might make some sense perhaps if that makes people more comfortable with the idea of reusing code from gpu origins for accelerators in general.
-Daniel
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Hi,
Quoted 6 lines · Thomas Zimmermann
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 2 lines
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Quoted 8 lines
Just some thoughts:
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't.
But it isn't. A GPU is a device that has a kernel-arbitrated MMU hosting kernel-managed buffers, executes user-supplied compiled programs with reference to those buffers and other jobs, and informs the kernel about progress.
KMS lies under the same third-level directory, but even when GPU and display are on the same die, they're totally different IP blocks developed on different schedules which are just periodically glued together.
Quoted 4 lines
Treating both as the same, even if
they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
Why not? All we have in common in GPU land right now is MMU + buffer references + job scheduling + synchronisation. None of this has common top-level API, or even a common top-level model. It's not just ISA differences, but we have very old-school devices where the kernel needs to register fill on every job, living next to middle-age devices where the kernel and userspace co-operate to fill a ring buffer, living next to modern devices where userspace does some stuff and then the hardware makes it happen with the bare minimum of kernel awareness.
Honestly I think there's more difference between lima and amdgpu then there is between amdgpu and current NN/ML devices.
Cheers,
Daniel
Hi
Am 17.05.21 um 21:32 schrieb Daniel Stone:
Quoted 23 lines
Hi,
Quoted 6 lines · Thomas Zimmermann
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 2 lines
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Quoted 8 lines
Just some thoughts:
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't.
But it isn't. A GPU is a device that has a kernel-arbitrated MMU hosting kernel-managed buffers, executes user-supplied compiled programs with reference to those buffers and other jobs, and informs the kernel about progress.
Quoted 4 lines
KMS lies under the same third-level directory, but even when GPU and display are on the same die, they're totally different IP blocks developed on different schedules which are just periodically glued together.
I mentioned this elsewhere: it's not about the chip architecture, it's about the UAPI. In the end, the GPU is about displaying things on a screen. Even if the rendering and the scanout engines are on different IP blocks. (Or different devices.)
The fact that one can do general purpose computing on a GPU is a byproduct of the evolution of graphics hardware. It never was the goal.
Quoted 6 lines
Quoted 5 lines
Treating both as the same, even if
they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.
Quoted 9 lines
Why not? All we have in common in GPU land right now is MMU + buffer references + job scheduling + synchronisation. None of this has common top-level API, or even a common top-level model. It's not just ISA differences, but we have very old-school devices where the kernel needs to register fill on every job, living next to middle-age devices where the kernel and userspace co-operate to fill a ring buffer, living next to modern devices where userspace does some stuff and then the hardware makes it happen with the bare minimum of kernel awareness.
I see all this as an example why AI should not live under gpu/. There are already many generations of GPUs with different feature sets supported. Why lump more behind the same abstractions if AI can take a fresh start? Why should we care about AI and why should AI care about all our legacy.
We can still share all the internal code if AI needs any of it. Meanwhile AI drivers can provide their own UAPIs until a common framework emerges.
Again, just my 2 cents.
Best regards
Thomas
Quoted 7 lines
Honestly I think there's more difference between lima and amdgpu then there is between amdgpu and current NN/ML devices.
Cheers,
Daniel
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Quoted 32 lines · Thomas Zimmermann
Hi
Am 17.05.21 um 21:32 schrieb Daniel Stone:
Quoted 23 lines
Hi,
Quoted 6 lines · Thomas Zimmermann
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 2 lines
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Quoted 8 lines
Just some thoughts:
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't.
But it isn't. A GPU is a device that has a kernel-arbitrated MMU hosting kernel-managed buffers, executes user-supplied compiled programs with reference to those buffers and other jobs, and informs the kernel about progress.
Quoted 4 lines
KMS lies under the same third-level directory, but even when GPU and display are on the same die, they're totally different IP blocks developed on different schedules which are just periodically glued together.
Quoted 4 lines
I mentioned this elsewhere: it's not about the chip architecture, it's about the UAPI. In the end, the GPU is about displaying things on a screen. Even if the rendering and the scanout engines are on different IP blocks. (Or different devices.)
Sure, but that's ignoring the reality there there's enormous amounts of code needed to make this rendering possible. All of which keeps existing if you take away the display, use your gpu to do compute, throw out the the raster and texture fetch blocks and rebalance your compute units to be much faster at the bfloat16 and u8 math (or whatever it is the NN people love today) than fp32, where traditional render gpus are kind. At that point you have a NN/AI chip, and like Daniel Stone says, the difference here is often much smaller than the difference between drm/lima and drm/amdgpu. Which at least on the 3d side happen to share large chunks of our stack (more sharing in userspace than the kernel, but still quite some sharing overall in concepts and code).
There's overall substantially more code to make this work than the modeset drivers you think are the corner stone of a gpu driver.
Also if you want to do broad strokes refactoring like pulling the memory management/command submission stuff out of drm, then the right thing would be to pull the modeset stuff out and merge it with maybe v4l. modesetting was a 10 years later addition to drm, this entire thing started with memory/command submission management.
And a lot of people got rather mad that the drm folks reinvented their own modeset api and didn't use one of the existing ones. We eclipsed them by now with atomic support, so somewhat moot point now, but not when it landed 10 years ago.
Quoted 2 lines
The fact that one can do general purpose computing on a GPU is a byproduct of the evolution of graphics hardware. It never was the goal.
I think we've crossed now the point where 50% of gpu sales are displayless. It stopped being a byproduct long ago and became the main goal in many areas and markets.
But also the core of drivers/gpu _is_ the memory management stuff. That's what this subsystem has been doing for 20 years or so by now. The modeset stuff is a comparitively recent addition (but has grown a lot thanks to tons of new drivers that landed and fbdev essentially dying).
Quoted 15 lines
Quoted 5 lines
Quoted 4 lines
Treating both as the same, even if
they share similar chip architectures, seems like a stretch. They might evolve in different directions and fit less and less under the same umbrella.Quoted 9 lines
Why not? All we have in common in GPU land right now is MMU + buffer references + job scheduling + synchronisation. None of this has common top-level API, or even a common top-level model. It's not just ISA differences, but we have very old-school devices where the kernel needs to register fill on every job, living next to middle-age devices where the kernel and userspace co-operate to fill a ring buffer, living next to modern devices where userspace does some stuff and then the hardware makes it happen with the bare minimum of kernel awareness.
Quoted 5 lines
I see all this as an example why AI should not live under gpu/. There are already many generations of GPUs with different feature sets supported. Why lump more behind the same abstractions if AI can take a fresh start? Why should we care about AI and why should AI care about all our legacy.
Fresh start here means "ignore all the lessons learned from 20 years of accelerator driver hacking" I think.
Quoted 3 lines
We can still share all the internal code if AI needs any of it. Meanwhile AI drivers can provide their own UAPIs until a common framework emerges.
Again the no 1 lesson of writing accel drivers is that you need the fully open userspace stack, or it's game over long term. No amount of "we'll share code later on" will save you from that, because that's just not going to be an option. There's a few other lessons like you don't actually want to have a standardized uapi for the accelerator command submission and memory management, but there are some standardized approaches that make sense (we've probably tried them all).
This has nothing to do with how you organize the kernel subsystem, but all about how you set up the overall driver stack. Of which the userspace side is the important part.
And back to your point that display is the main reason why drivers/gpu
exists: None of this has anything to do with display, but is exactly what the render _accelerator_ part of dri-devel has been doing for a rather long time by now. Which is why other accelarators should probably do the same thing instead of going "nah we're different, there's no DP output connected to our accelator".
Cheers, Daniel
PS: Also there are NN chips with DP/HDMI ports thrown in for the lolz. Turns out that these NN things are pretty useful when building video processing pipelines.
Quoted 21 lines
Again, just my 2 cents.
Best regards
ThomasQuoted 7 lines
Honestly I think there's more difference between lima and amdgpu then there is between amdgpu and current NN/ML devices.
Cheers,
Daniel--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 32 lines · Thomas Zimmermann
Hi
Am 17.05.21 um 21:32 schrieb Daniel Stone:
Quoted 23 lines
Hi,
Quoted 6 lines · Thomas Zimmermann
Am 17.05.21 um 09:40 schrieb Daniel Vetter:
Quoted 2 lines
We have, it's called
drivers/gpu. Feel free to rename todrivers/xpuor think G as in General, not Graphisc.I hope this was a joke.
Quoted 8 lines
Just some thoughts:
AFAICT AI first came as an application of GPUs, but has now evolved/specialized into something of its own. I can imagine sharing some code among the various subsystems, say GEM/TTM internals for memory management. Besides that there's probably little that can be shared in the userspace interfaces. A GPU is device that puts an image onto the screen and an AI accelerator isn't.
But it isn't. A GPU is a device that has a kernel-arbitrated MMU hosting kernel-managed buffers, executes user-supplied compiled programs with reference to those buffers and other jobs, and informs the kernel about progress.
Quoted 4 lines
KMS lies under the same third-level directory, but even when GPU and display are on the same die, they're totally different IP blocks developed on different schedules which are just periodically glued together.
Quoted 7 lines
I mentioned this elsewhere: it's not about the chip architecture, it's about the UAPI. In the end, the GPU is about displaying things on a screen. Even if the rendering and the scanout engines are on different IP blocks. (Or different devices.)
The fact that one can do general purpose computing on a GPU is a byproduct of the evolution of graphics hardware. It never was the goal.
But then we would have a subsystem for AI accelerators excluding GPUs, do we then start to layer that subsystem onto drivers/gpu? at which point why bother.
The thing is UAPI and stack architecture are important, but what is more important than any of that is that there is a place where the people invested in the area can come together outside of company boundaries and discuss ideas and bounce designs around each other to come to an agreement without the overheads of company interactions. dri-devel + mesa have managed this for graphics but it's taken years and we are still fighting that battle within major companies who even when they know it produces good results can't drag themselves to give up control over anything unless given no other choice.
I expect the accel teams in these companies need to step outside their productization timelines and powerpoints and start discussing uAPI designs with the other companies in the area. Until that happens I expect upstreaming any of these should be a default no.
Dave.
Quoted 14 lines · Greg Kroah-Hartman
Quoted 9 lines · Maciej Kwapulinski
Dear kernel maintainers,
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.
How does this compare with the "nnpi" driver being proposed here:
https://lore.kernel.org/r/[email protected]
Quoted 8 lines
Please work with those developers to share code and userspace api and tools. Having the community review two totally different apis and drivers for the same type of functionality from the same company is totally wasteful of our time and energy.
thanks,
greg k-h
after consulting, we will try to share api and some kernel code between the two drivers.
Following is the reference for more information:
https://lore.kernel.org/lkml/[email protected]/
regards,
Maciej
Quoted 2 lines · Maciej Kwapulinski
after consulting, we will try to share api and some kernel code between the two drivers.
We prepared a prototype work based on Daniel Vetter’s invitation to evaluate DRM framework as prospective fit.
Early results look quite promising. Effective leverage of DRM framework for non GPU driver has been achieved. GNA driver source code turned out to have been simplified by offloading some areas (device management + memory regions management).
As a result, GNA driver source code size has been reduced by 15% (420 lines). DRM Framework complexity has not been an issue so far.
Plan for next step is to publish code to dri-devel ML. Please share your thoughts.
Regards,
Maciej
Greg KH
maintainerQuoted 1 line · On Mon, Jun 20, 2022 at 11:49:07AM +0200, [email protected]…
Please share your thoughts.
No code here to share thoughts about :(
Quoted 4 lines · Greg KH
Quoted 1 line · On Mon, Jun 20, 2022 at 11:49:07AM +0200, [email protected]…
Please share your thoughts.
No code here to share thoughts about :(
code will be published in comming weeks to dri-devel ML
Greg KH
maintainerQuoted 9 lines · Maciej Kwapulinski
Quoted 4 lines · Greg KH
Quoted 1 line · On Mon, Jun 20, 2022 at 11:49:07AM +0200, [email protected]…
Please share your thoughts.
No code here to share thoughts about :(
code will be published in comming weeks to dri-devel ML
Saying "we will send patches sometime in the future" is a bit odd when we have thousands of patches each week in our inbox to review now. Why not help us out with that workload? :)
thanks,
greg k-h
Quoted 7 lines · On Mon, 20 Jun 2022 at 11:51, <[email protected]> wrote:
Quoted 2 lines · Maciej Kwapulinski
after consulting, we will try to share api and some kernel code between the two drivers.
We prepared a prototype work based on Daniel Vetter’s invitation to evaluate DRM framework as prospective fit.
Quoted 7 lines
Early results look quite promising. Effective leverage of DRM framework for non GPU driver has been achieved. GNA driver source code turned out to have been simplified by offloading some areas (device management + memory regions management).
As a result, GNA driver source code size has been reduced by 15% (420 lines). DRM Framework complexity has not been an issue so far.
Nice.
Quoted 2 lines
Plan for next step is to publish code to dri-devel ML. Please share your thoughts.
Sounds like solid progress and looking forward for some patches!
Cheers, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 3 lines · Maciej Kwapulinski
This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms.
I replied to v2 and did not get any answer:
https://lore.kernel.org/lkml/CACRpkdaHMKueLr9Q5CAXQXN5A5FwZScfroE-DYfK+NaGXaqN1A@mail.gmail.com/
Now more kernel maintainers are saying more or less the same thing, please address and reply to serious architectural comments instead of sending new iterations of the same patch set.
Also include me and Olof Johansson when reposting, thanks.
Yours,
Linus Walleij