Skip to content

Commit

Permalink
Use GPU enum
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <[email protected]>
  • Loading branch information
docjyJ committed Dec 17, 2024
1 parent 66f9cf2 commit 415e006
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 61 deletions.
5 changes: 1 addition & 4 deletions community-containers/jellyfin/jellyfin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
"writeable": false
}
],
"devices": [
"/dev/dri"
],
"nvidia": true,
"enable_gpu": true,
"backup_volumes": [
"nextcloud_aio_jellyfin"
]
Expand Down
5 changes: 1 addition & 4 deletions community-containers/memories/memories.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
"writeable": false
}
],
"devices": [
"/dev/dri"
],
"nvidia": true,
"enable_gpu": true,
"nextcloud_exec_commands": [
"php /var/www/html/occ app:install memories",
"php /var/www/html/occ app:enable memories",
Expand Down
5 changes: 1 addition & 4 deletions community-containers/plex/plex.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
"writeable": false
}
],
"devices": [
"/dev/dri"
],
"nvidia": true,
"enable_gpu": true,
"backup_volumes": [
"nextcloud_aio_plex"
]
Expand Down
2 changes: 1 addition & 1 deletion php/containers-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"pattern": "^/dev/[a-z]+$"
}
},
"nvidia": {
"enable_gpu": {
"type": "boolean"
},
"apparmor_unconfined": {
Expand Down
5 changes: 1 addition & 4 deletions php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@
],
"stop_grace_period": 600,
"restart": "unless-stopped",
"devices": [
"/dev/dri"
],
"nvidia": true,
"enable_gpu": true,
"backup_volumes": [
"nextcloud_aio_nextcloud"
],
Expand Down
6 changes: 3 additions & 3 deletions php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
private array $secrets,
/** @var string[] */
private array $devices,
private bool $nvidia,
private bool $enable_gpu,
/** @var string[] */
private array $capAdd,
private int $shmSize,
Expand Down Expand Up @@ -93,8 +93,8 @@ public function GetDevices() : array {
return $this->devices;
}

public function CanUseNvidia() : bool {
return $this->nvidia;
public function GetGpuMode() : bool {
return $this->enable_gpu;
}

public function GetCapAdds() : array {
Expand Down
4 changes: 2 additions & 2 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private function GetDefinition(): array
$devices = $entry['devices'];
}

$nvidia = $entry['nvidia'] === true;
$enable_gpu = $entry['enable_gpu'] === true;

$capAdd = [];
if (isset($entry['cap_add'])) {
Expand Down Expand Up @@ -314,7 +314,7 @@ private function GetDefinition(): array
$dependsOn,
$secrets,
$devices,
$nvidia,
$enable_gpu,
$capAdd,
$shmSize,
$apparmorUnconfined,
Expand Down
23 changes: 7 additions & 16 deletions php/src/Data/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,33 +968,24 @@ public function GetEnabledCommunityContainers() : array {
return explode(' ', $this->GetCommunityContainers());
}

private function GetEnabledDriDevice() : string {
$envVariableName = 'NEXTCLOUD_ENABLE_DRI_DEVICE';
$configName = 'nextcloud_enable_dri_device';

private function GetEnabledGPUMode() : string {
$envVariableName = 'NEXTCLOUD_GPU_MODE';
$configName = 'nextcloud_gpu_mode';
$defaultValue = '';
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
}

public function isDriDeviceEnabled() : bool {
if ($this->GetEnabledDriDevice() === 'true') {
return true;
} else {
return false;
}
}
private function GetEnabledNvidiaGPUMode() : string {
$envVariableName = 'NEXTCLOUD_NVIDIA_GPU_MODE';
$configName = 'nextcloud_nvidia_gpu_mode';
$defaultValue = '';
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
return $this->GetEnabledGPUMode() === 'dri';
}

public function isNvidiaRuntimeEnabled() : bool {
return $this->GetEnabledNvidiaGPUMode() === 'runtime';
return $this->GetEnabledGPUMode() === 'nvidia-runtime';
}

public function isNvidiaDeployEnabled() : bool {
return $this->GetEnabledNvidiaGPUMode() === 'deploy';
return $this->GetEnabledGPUMode() === 'nvidia-deploy';
}

private function GetKeepDisabledApps() : string {
Expand Down
15 changes: 7 additions & 8 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,13 @@ public function CreateContainer(Container $container) : void {

$devices = [];
foreach($container->GetDevices() as $device) {
if ($device === '/dev/dri' && ! $this->configurationManager->isDriDeviceEnabled()) {
continue;
}
$devices[] = ["PathOnHost" => $device, "PathInContainer" => $device, "CgroupPermissions" => "rwm"];
}

if (count($devices) > 0) {
$requestBody['HostConfig']['Devices'] = $devices;
}

if ($container->canUseNvidia()) {
if ($this->configurationManager->isNvidiaRuntimeEnabled()) {
if($this->configurationManager->isDriDeviceEnabled()) {
$devices[] = ["PathOnHost" => '/dev/dri', "PathInContainer" => '/dev/dri', "CgroupPermissions" => "rwm"];
} elseif ($this->configurationManager->isNvidiaRuntimeEnabled()) {
$requestBody['HostConfig']['Runtime'] = 'nvidia';
} elseif ($this->configurationManager->isNvidiaDeployEnabled()) {
$requestBody['HostConfig']['DeviceRequests'] = [
Expand All @@ -505,6 +500,10 @@ public function CreateContainer(Container $container) : void {
}
}

if (count($devices) > 0) {
$requestBody['HostConfig']['Devices'] = $devices;
}

$shmSize = $container->GetShmSize();
if ($shmSize > 0) {
$requestBody['HostConfig']['ShmSize'] = $shmSize;
Expand Down
18 changes: 6 additions & 12 deletions php/templates/includes/aio-config.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@

<p>
{% if is_dri_device_enabled == true %}
The /dev/dri device which is needed for hardware transcoding is getting attached to the Nextcloud container.
{% else %}
The /dev/dri device which is needed for hardware transcoding is not attached to the Nextcloud container.
{% endif %}
See the <a href="https://github.com/nextcloud/all-in-one#how-to-enable-hardware-transcoding-for-nextcloud">NEXTCLOUD_ENABLE_DRI_DEVICE documentation</a> on how to change this.</p>

<p>
{% if is_nvidia_runtime_enabled == true %}
Nvidia runtime is enabled.
The /dev/dri device is getting attached to the Nextcloud container.
{% elseif is_nvidia_runtime_enabled == true %}
The Nvida runtime is used for the Nextcloud container.
{% elseif is_nvidia_gpu_deploy_enabled == true %}
Nvidia GPU access is enabled.
The Nvidia device is getting attached to the Nextcloud container.
{% else %}
Nvidia GPU access is disabled.
No GPU acceleration is enabled. It's recommended to enable hardware transcoding for better performance.
{% endif %}
</p>
See the <a href="https://github.com/nextcloud/all-in-one#how-to-enable-gpu-acceleration-for-nextcloud">NEXTCLOUD_GPU_MODE documentation</a> on how to change this.</p>

<p>For further documentation on AIO, refer to <strong><a href="https://github.com/nextcloud/all-in-one#nextcloud-all-in-one">this page</a></strong>. You can use the browser search [CTRL]+[F] to search through the documentation. Additional documentation can be found <strong><a href="https://github.com/nextcloud/all-in-one/discussions/categories/wiki">here</a></strong>.</p>
</details>
28 changes: 25 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,33 @@ You can do so by adding `--env NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS="imagick exte
### What about the pdlib PHP extension for the facerecognition app?
The [facerecognition app](https://apps.nextcloud.com/apps/facerecognition) requires the pdlib PHP extension to be installed. Unfortunately, it is not available on PECL nor via PHP core, so there is no way to add this into AIO currently. However you can use [this community container](https://github.com/nextcloud/all-in-one/tree/main/community-containers/facerecognition) in order to run facerecognition.
### How to enable hardware-transcoding for Nextcloud?
### How to enable GPU acceleration for Nextcloud?
Some container can use GPU acceleration to increase performance like [memories app](https://apps.nextcloud.com/apps/memories) allows to enable hardware transcoding for videos.
To enable it you need to add `--env NEXTCLOUD_GPU_MODE=<gpu_driver>` to the docker run command of the mastercontainer (but before the last line `nextcloud/all-in-one:latest`! If it was started already, you will need to stop the mastercontainer, remove it (no data will be lost) and recreate it using the docker run command that you initially used).
#### With open source drivers MESA for AMD, Intel and **new** drivers `Nouveau` for Nvidia
> [!WARNING]
> This only works if the `/dev/dri` device is present on the host! If it does not exists on your host, don't proceed as otherwise the Nextcloud container will fail to start! If you are unsure about this, better do not proceed with the instructions below.
> This only works if the `/dev/dri` device is present on the host! If it does not exists on your host, don't proceed as otherwise the Nextcloud container will fail to start! If you are unsure about this, better do not proceed with the instructions below. Make sure that your driver is correctly configured on the host.
A list of supported device can be fond in [MESA 3D documentation](https://docs.mesa3d.org/systems.html).
This methode use the [Direct Rendering Infrastructure](https://dri.freedesktop.org/wiki/) with the access to the `/dev/dri` device.
To enable it, use `--env NEXTCLOUD_GPU_MODE=dri` as driver mode.
#### With proprietary drivers for Nvidia :warning: BETA
> [!WARNING]
> This feature is in beta. Since the proprietary, we haven't a lot of user using proprietary drivers, we can't guarantee the stability of this feature.
> Your feedback is welcome.
This methode use the [Nvidia Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/index.html) with the nvidia runtime.
To enable it, use `--env NEXTCLOUD_GPU_MODE=nvidia-runtime` as driver mode.
The [memories app](https://apps.nextcloud.com/apps/memories) allows to enable hardware transcoding for videos. In order to use that, you need to add `--env NEXTCLOUD_ENABLE_DRI_DEVICE=true` to the docker run command of the mastercontainer (but before the last line `nextcloud/all-in-one:latest`! If it was started already, you will need to stop the mastercontainer, remove it (no data will be lost) and recreate it using the docker run command that you initially used) which will mount the `/dev/dri` device into the container. There is now a community container which allows to easily add the transcoding container of Memories to AIO: https://github.com/nextcloud/all-in-one/tree/main/community-containers/memories
You can use docker resource allocation with `--env NEXTCLOUD_GPU_MODE=nvidia-deploy` as driver mode.
### How to keep disabled apps?
In certain situations you might want to keep Nextcloud apps that are disabled in the AIO interface and not uninstall them if they should be installed in Nextcloud. You can do so by adding `--env NEXTCLOUD_KEEP_DISABLED_APPS=true` to the docker run command of the mastercontainer (but before the last line `nextcloud/all-in-one:latest`! If it was started already, you will need to stop the mastercontainer, remove it (no data will be lost) and recreate it using the docker run command that you initially used).
Expand Down
2 changes: 2 additions & 0 deletions tests/QA/060-environmental-variables.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Environmental variables

[//]: # (TODO NEXTCLOUD_GPU_MODE)

- [ ] When starting the mastercontainer with `--env APACHE_PORT=11000` on a clean instance, the domaincheck container should be started with that same port published. That makes sure that also the Apache container will use that port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. However `@INTERNAL` is also an allowed value which skips publishing the port on the host for internal usage inside a bridged network for example.
- [ ] When starting the mastercontainer with `--env APACHE_IP_BINDING=127.0.0.1` on a clean instance, the domaincheck container's apache port should only listen on localhost on the host. Using a value here that is not a number or dot will not allow the mastercontainer to start correctly.
- [ ] When starting the mastercontainer with `--env APACHE_ADDITIONAL_NETWORK=frontend_net` on a clean instance, the domaincheck and subsequently the apache containers should be connected to the specified `frontend_net` docker network, in addition to the default `nextcloud-aio` network. Specifying the network that doesn't already exist will not allow the mastercontainer to start correctly.
Expand Down

0 comments on commit 415e006

Please sign in to comment.