Skip to content

Commit

Permalink
feat: add support for nvidia gpu access
Browse files Browse the repository at this point in the history
  • Loading branch information
MondoGao committed Aug 16, 2024
1 parent c63440f commit b774837
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
# NEXTCLOUD_ADDITIONAL_APKS: imagemagick # This allows to add additional packages to the Nextcloud container permanently. Default is imagemagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-os-packages-permanently-to-the-nextcloud-container
# NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS: imagick # This allows to add additional php extensions to the Nextcloud container permanently. Default is imagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-php-extensions-permanently-to-the-nextcloud-container
# NEXTCLOUD_ENABLE_DRI_DEVICE: true # This allows to enable the /dev/dri device in the Nextcloud container. ⚠️⚠️⚠️ Warning: this only works if the '/dev/dri' device is present on the host! If it should not exist on your host, don't set this to true as otherwise the Nextcloud container will fail to start! See https://github.com/nextcloud/all-in-one#how-to-enable-hardware-transcoding-for-nextcloud
# NEXTCLOUD_NVIDIA_GPU_MODE: 'runtime' # 'runtime' or 'deploy': This allows to enable the [NVIDIA runtime](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) or [GPU access](https://docs.docker.com/compose/gpu-support/) in the Nextcloud container. Make sure you follow the instructions before setting this value. If you're using WSL2 and want to use the NVIDIA runtime, please follow the instructions to [install the NVIDIA Container Toolkit meta-version in WSL](https://docs.nvidia.com/cuda/wsl-user-guide/index.html#cuda-support-for-wsl-2).
# NEXTCLOUD_KEEP_DISABLED_APPS: false # Setting this to true will keep Nextcloud apps that are disabled in the AIO interface and not uninstall them if they should be installed. See https://github.com/nextcloud/all-in-one#how-to-keep-disabled-apps
# TALK_PORT: 3478 # This allows to adjust the port that the talk container is using. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-talk-port
# WATCHTOWER_DOCKER_SOCKET_PATH: /var/run/docker.sock # Needs to be specified if the docker socket on the host is not located in the default '/var/run/docker.sock'. Otherwise mastercontainer updates will fail. For macos it needs to be '/var/run/docker.sock'
Expand Down
2 changes: 2 additions & 0 deletions php/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
'nextcloud_max_time' => $configurationManager->GetNextcloudMaxTime(),
'nextcloud_memory_limit' => $configurationManager->GetNextcloudMemoryLimit(),
'is_dri_device_enabled' => $configurationManager->isDriDeviceEnabled(),
'is_nvidia_runtime_enabled' => $configurationManager->isNvidiaRuntimeEnabled(),
'is_nvidia_gpu_deploy_enabled' => $configurationManager->isNvidiaDeployEnabled(),
'is_talk_recording_enabled' => $configurationManager->isTalkRecordingEnabled(),
'is_docker_socket_proxy_enabled' => $configurationManager->isDockerSocketProxyEnabled(),
]);
Expand Down
22 changes: 22 additions & 0 deletions php/src/Data/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,28 @@ public function isDriDeviceEnabled() : bool {
return false;
}
}
private function GetEnabledNvidiaGPUMode() : string {
$envVariableName = 'NEXTCLOUD_NVIDIA_GPU_MODE';
$configName = 'nextcloud_nvidia_gpu_mode';
$defaultValue = '';
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
}

public function isNvidiaRuntimeEnabled() : bool {
if ($this->GetEnabledNvidiaGPUMode() === 'runtime') {
return true;
} else {
return false;
}
}

public function isNvidiaDeployEnabled() : bool {
if ($this->GetEnabledNvidiaGPUMode() === 'deploy') {
return true;
} else {
return false;
}
}

private function GetKeepDisabledApps() : string {
$envVariableName = 'NEXTCLOUD_KEEP_DISABLED_APPS';
Expand Down
12 changes: 12 additions & 0 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,18 @@ public function CreateContainer(Container $container) : void {
$requestBody['HostConfig']['Devices'] = $devices;
}

if ($this->configurationManager->isNvidiaRuntimeEnabled()) {
$requestBody['HostConfig']['Runtime'] = 'nvidia';
} elseif ($this->configurationManager->isNvidiaDeployEnabled()) {
$requestBody['HostConfig']['DeviceRequests'] = [
[
"Driver" => "nvidia",
"Count" => 1,
"Capabilities" => [["gpu"]],
]
];
}

$shmSize = $container->GetShmSize();
if ($shmSize > 0) {
$requestBody['HostConfig']['ShmSize'] = $shmSize;
Expand Down
10 changes: 10 additions & 0 deletions php/templates/includes/aio-config.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,15 @@
{% 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.
{% elseif is_nvidia_gpu_deploy_enabled = true %}
Nvidia GPU access is enabled.
{% else %}
Nvidia GPU access is disabled.
{% endif %}
</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>

0 comments on commit b774837

Please sign in to comment.