canonical / nvidia-assemble

2 stars 2 forks source link

Should Core 20 still work? #8

Open mpena2099 opened 4 months ago

mpena2099 commented 4 months ago

Related to issue #7, I had to leave core22 aside because my application uses ROS1 Noetic, which is linked to Ubuntu 20 (it is not compatible with 22).

Doing a test now on Ubuntu Core 20, I am not able to follow the instructions in nvidia-assemble linked to Core 20 (branch main and not branch main-core22).

$ sudo snap refresh pc-kernel --channel 20/edge
error: cannot refresh "pc-kernel": snap "pc-kernel" is not installed 
$ sudo snap install pc-kernel --channel 20/edge
error: cannot perform the following tasks: 
- Mount snap "pc-kernel" (1940) (cannot replace kernel snap with a different one) 
$ sudo snap install --devmode nvidia-assemble --channel 20/edge
error: snap "nvidia-assemble" is not available on 20/edge but is available to install on the following tracks: 

latest/candidate snap install --candidate nvidia-assemble 
latest/beta snap install --beta nvidia-assemble 
latest/edge snap install --edge nvidia-assemble 
22/stable snap install --channel=22 nvidia-assemble
22/candidate snap install --channel=22/candidate nvidia-assemble
22/beta snap install --channel=22/beta nvidia-assemble
22/edge snap install --channel=22/edge nvidia-assemble

Please be mindful that different tracks may include different features. Get more information
with 'snap info nvidia-assemble'.

When I look at "https://snapcraft.io/nvidia-assemble", all releases are related to core22. Is there nothing else for core20?

Thanks!

jocado commented 4 months ago

I'm not an authority on this at all, but it looks to me like the nvidia-core20 snap is not being actively maintained.

$ snap info nvidia-core20
~~~ 8< ~~~
channels:
  latest/stable:    515.86.01 2023-01-30 (11) 332MB -
  latest/candidate: 515.86.01 2022-12-15 (11) 332MB -
  latest/beta:      515.86.01 2022-12-15 (11) 332MB -
  latest/edge:      515.86.01 2022-12-15 (11) 332MB -
jocado commented 4 months ago

But, are you sure you need to use Ubuntu Core 20 ?

If you are creating a snap which has a base of core20, you can still install and run that on a Ubuntu Core 22 system. The additional core20 base snap would also need to be installed, and should work fine.

Or, is the problem not specifically relating bases ?

mpena2099 commented 4 months ago

Yes, I can use a snap based on core20 and install it on a system with Ubuntu Core 22, but I can't configure it to use nvidia-core22.

I tried to configure it using nvidia-core20, and then I got to these reported problems...

jocado commented 4 months ago

but I can't configure it to use nvidia-core22

What's actually stopping you ? Perhaps there's a way round it.

jocado commented 4 months ago

BTW, I'm not suggesting you should try and mix bases, but many use cases wound't require it. Just interested to know the details, then I might be able to offer up a suggestion.

mpena2099 commented 4 months ago

OK, I'll share my test code. Based on https://mir-server.io/docs/the-graphics-core22-snap-interface I created the following snapcraft.yaml:

name: gpu-info
base: core22
version: '0.1'
summary: GPU test
description: |
  ...
grade: devel
confinement: strict

plugs:
  graphics-core22:
    interface: content
    target: $SNAP/graphics
    default-provider: mesa-core22
layout:
  /usr/share/libdrm:
    bind: $SNAP/graphics/libdrm
  /usr/share/drirc.d:
    symlink: $SNAP/graphics/drirc.d

parts:
  python-packages:
    plugin: python
    source: .
    python-requirements: [requirements.txt]
  gpu:
    plugin: dump
    source: bin
  graphics-core22:
    after: [gpu]
    source: https://github.com/MirServer/graphics-core.git
    plugin: dump
    override-prime: |
      craftctl default
      ${CRAFT_PART_SRC}/bin/graphics-core22-cleanup mesa-core22 nvidia-core22
    prime:
    - bin/graphics-core22-wrapper

apps:
  gpu-info:
    command-chain:
      - bin/graphics-core22-wrapper
    command: gpu.py
    plugs:
      - opengl
      - hardware-observe
      - system-observe

The gpu.py file just lists the existing GPUs:

#!/usr/bin/env python3
import GPUtil

gpus = GPUtil.getGPUs()

print("GPUS:")
print(gpus)

This all works on Ubuntu Core 22. But when I change the base, in snapcraft.yaml, from core22 to core20, it reports several errors when I try to run snapcraft:

$ snapcraft
(...)

+ snapcraftctl stage
Priming gpu 
+ snapcraftctl prime
Priming graphics-core22 
+ craftctl default
error: 
Traceback (most recent call last):
  File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 68, in _client
    call_fifo = os.environ["PARTS_CALL_FIFO"]
  File "/snap/snapcraft/current/bin/../usr/lib/python3.10/os.py", line 680, in __getitem__
    raise KeyError(key) from None
KeyError: 'PARTS_CALL_FIFO'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 111, in main
    ret = CraftCtl.run(cmd, args)
  File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 45, in run
    _client(cmd, args)
  File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 71, in _client
    raise RuntimeError(
RuntimeError: 'PARTS_CALL_FIFO' environment variable must be defined.
Note that this utility is designed for use only in part scriptlets.
Failed to run 'override-prime': Exit code was 1.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

I managed to solve this indicated error but what follows are countless others, endless.

snapcraft.yaml core20 version:

name: gpu-info
# base: core22
base: core20
version: '0.1'
summary: GPU test
description: |
  ...
grade: devel
confinement: strict

plugs:
  graphics-core22:
    interface: content
    target: $SNAP/graphics
    default-provider: mesa-core22
layout:
  /usr/share/libdrm:
    bind: $SNAP/graphics/libdrm
  /usr/share/drirc.d:
    symlink: $SNAP/graphics/drirc.d

parts:
  # python-packages:
  #   plugin: python
  #   source: .
  #   python-requirements: [requirements.txt]
  requirements:
    plugin: python
    source: .
    requirements:
      - requirements.txt
  gpu:
    plugin: dump
    source: bin
  graphics-core22:
    after: [gpu]
    source: https://github.com/MirServer/graphics-core.git
    plugin: dump
    override-prime: |
      craftctl default
      ${CRAFT_PART_SRC}/bin/graphics-core22-cleanup mesa-core22 nvidia-core22
    prime:
    - bin/graphics-core22-wrapper

apps:
  gpu-info:
    command-chain:
      - bin/graphics-core22-wrapper
    command: gpu.py
    plugs:
      - opengl
      - hardware-observe
      - system-observe

I'm also using graphics-core20 as a reference: https://mir-server.io/docs/the-graphics-core20-snap-interface

jocado commented 4 months ago

Ahh, are you sure it's not just related tot he differences between core20 and core22 snapcraft configuration ?

Things such as craftctl util and CRAFT_* vars were introduced for core22, and I'm don't think they should be used the other way round. Although I'm surprised snapcraft doesn't warn you about that.

You want to basically reverse this guide: https://snapcraft.io/docs/migrate-core22

mpena2099 commented 4 months ago

OK @jocado, the guide you indicated helped a lot.

I made a few changes to override-prime and now the build works:

override-prime: |
export CRAFT_TARGET_ARCH=$(dpkg --print-architecture)
export CRAFT_PRIME=$SNAPCRAFT_PRIME
snapcraftctl prime
${SNAPCRAFT_PART_SRC}/bin/graphics-core22-cleanup mesa-core22 nvidia-core22

I will still need to reinstall Ubuntu Core 22 on the PC where I am testing my project, but I believe that now the chances of everything working are high.

Thanks again.

jocado commented 4 months ago

No worries :+1: