Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request]: Add CUDA support #3301

Open
obreo opened this issue Mar 3, 2024 · 9 comments
Open

[Request]: Add CUDA support #3301

obreo opened this issue Mar 3, 2024 · 9 comments

Comments

@obreo
Copy link

obreo commented Mar 3, 2024

Tell us the problem or your need

I'm trying to install Davinci resolve using bottles' Caffe 9.2 runner, The software is running and recognizing the Nvidia driver, however, it is recognizing OpenCL but showing 'failed to initialize OpenCL' error in the logs. I'm trying to add Cuda to the option so davinci would pick it up instead of openCL (the davinci settings show only the OpenCL available).

Based on my search, it seems Winehq supports CUDA for wine-staging only. But it looks like they removed the nvcuda.dll and cuda library in the recent winehq builds, as I cant find it in the library
https://wiki.winehq.org/Wine-Staging_CUDA

So I'm trying to add that to wine installed on Bottles runner, but with no luck as I'm unable to locate the configuration path exactly.

Here is the cuda library supported for wine:
https://github.com/SveSop/nvidia-libs

I hope you add this library as a feature so it can be either chosen from the dependencies or the winecfg.

Based on my debugging experience with davinci resolve, the only runner was able to make it work with nvidia is Cafe 9.2 version. I believe if Davinci was able to pick the CUDA support from wine then it will work - as the software is functioning but playback is not. Running Davinci resolve on wine can help users use h.264 and h.265 support on linux, this is why i am working on this fix. It looks promising.

I'd love to collaborate.
Thanks

Describe the solution you'd like

CUDA support is missing, it is a library that can be added to wine-staging.

Other solutions?

No response

Additional context and references

https://wiki.winehq.org/Wine-Staging_CUDA

Here is the cuda library supported for wine:
https://github.com/SveSop/nvidia-libs

@orowith2os
Copy link
Contributor

I recommend you to get some definitely working steps to reproduce a working CUDA environment in Wine first, and then create something akin to how dxvk and latencyflex and vkd3d ship their DLLs that Bottles can pull from in order to set things up appropriately.

Alternatively, or also, get OpenCL working by way of rusticl, that way Davinci would work on AMD and Intel, plus NVK, as well.

@obreo
Copy link
Author

obreo commented Mar 4, 2024

Ok I got CUDA running on Bottles.

Method:
Runner: Cafe 9.2
OS: PopOs 22.02
Architecture: 64bit (davinci does not run over 32bit)
Settings: discrete gpu and other gpu settings ON.
Dependecies: DirectX11/10 libraries & visualc++ redistributable libraries.

Workaround for Resolve:
I needed to download directml.dll manually and insert it in System32 directory to let davinci run.

Installing CUDA:
What I did was installing the dlls from the source I mentioned in the post, then copied them to the directory where the Cafe runner is installed. I then added the dll library for nvcuda.dll in the winecfg.

I had to install the CUDA-toolkit from nvidia and verify that cuda is installed on my PopOs machine.

I needed to install ffshow dependency for windows codecs.

Then it was detected by Davinci Resolve.

Result:

  • Davinci was able to run.
  • The playback was running but cutting a lot of frames and showing Media Offline for those frames. The playback sound was running fine.
  • I checked the davinci logs and it gives error says: Failed to decode.
  • I get ole error in the terminal while runnig davinci, although the ole libraries were installed in winecfg.
  • Generating media and proxy files didnt work and i think that is related to the previous error.

Thoughts:

  • I think there is GPU driver/library incompatibility/missing libraries that is causing the mentioned error and the skipping of frames.

Note:
I use davinci resolve on my Windows machine using CUDA and it works smoothly.

When I choose openCL the playback in PopOs, it does not work. I am not sure if this is related to my GPU as I have never tried running davinci over OpenCL in my Windows machine. So it could be running out of the box and maybe missing.

@kurageart
Copy link

Hi, I also need this.. I can confirm that the cuda library from github it works fine for most of what I need (on a standard wine installation), but I haven't try to run davinci on wine ..
By the way, in bottles I downloaded the wine-ge runner , stating on his page that is adding"
Nvidia CUDA support for phsyx and nvapi" .
But even opening cudaZ I get the "Cuda not found! Please update your Nvidia driver and try again". Having this working on bottles would save the hassle to enable multiarch ,installing wine at all, and keep everything in flatpaks

@kurageart
Copy link

What I did was installing the dlls from the source I mentioned in the post, then copied them to the directory where the Cafe runner is installed. I then added the dll library for nvcuda.dll in the winecfg.

Hi obreo , can You please tell witch file You copied and exactly where? I'm trying to use the "release" version of https://github.com/SveSop/nvidia-libs , since on Debian and Clearlinux it won't compile . Installing it using the regular setup_nvlibs.sh on the real wineprefix works fine, but I would be happy to stay away from multiarch etc and simply having it work on bottles ... The script itself requires a real wine installation to work, but all is doing from my modest understanding is symlinking the dll to the wine/c/windows/system32 directory ..

@obreo
Copy link
Author

obreo commented Mar 17, 2024

What I did was installing the dlls from the source I mentioned in the post, then copied them to the directory where the Cafe runner is installed. I then added the dll library for nvcuda.dll in the winecfg.

Hi obreo , can You please tell witch file You copied and exactly where? I'm trying to use the "release" version of https://github.com/SveSop/nvidia-libs , since on Debian and Clearlinux it won't compile . Installing it using the regular setup_nvlibs.sh on the real wineprefix works fine, but I would be happy to stay away from multiarch etc and simply having it work on bottles ... The script itself requires a real wine installation to work, but all is doing from my modest understanding is symlinking the dll to the wine/c/windows/system32 directory ..

Hi, I downloaded the file in https://github.com/SveSop/nvidia-lib from release, but choose the
nvidia-libs-0.7.14.tar.xz , extract it, and you'll have two folders, one of them is nvida-libs-release, inside it, there are two folders, lib and lib64, copy the .dll and .so files inside each of these folders based on their architecture to the relative folders inside the cafe runner directory. Cafe runner itself is wine and located -sorry i dont remember the exact path as I'm working on Windows currently but something similar to this - in /home/USER/.var/bottles/data/bottle/runners/cafe (The one you installed by bottles)/

Inside that directory you will add the dll files inside the lib and lib64 to the relative folders in the cafe runner path, similarly for the .so . Make sure that you put the right files in the right architecture folder for x86_64 and i386 architectures.

After that, open winecfg from the bottle you created in bottles, from library tab, you should find the nvcuda.dll file, add it along with the rest of dll files you are copied above.

Finally, add the nvcuda.dll file inside the System32 directory in the c/windows/system32/ path

@kurageart
Copy link

Thank You! unfortunately it still don't wanna work..I followed what you said step by step. Could it be cause I'm using an amd apu as display card, and a discrete 3060 not connected to any monitor? or because i'm using a flatpak version of bottles?

@SveSop
Copy link

SveSop commented Mar 24, 2024

Just a quick chime in to this, as i tested it using bottles and creating a bottle and running some cuda samples.

The "tricky" part is that for wine-9 and late wine-8 versions of wine, it is no longer possible to use the "fake" .dll's that is produced from the nvidia-libs archive. This is mainly due to how newer versions of wine load libraries that "talk to" native linux libs, and tbh i have not started that work yet.

However, using the dll.so file AS a .dll (basically renaming nvcuda.dll.so -> nvcuda.dll still works and loads.. for now).

Not really familiar with using bottles and creating scripts that could be used for the GUI in a similar manner as DXVK and so on, but it might be just as good an idea as any if that would be interesting. I actually have nvcuda as a separate repo where i do the development and then just import this to nvidia-libs. So if some sort of "NVCUDA" toggle thing would be of use for the bottles GUI, i could provide "release" type of binaries on the nvcuda repo for you to download?

https://github.com/SveSop/nvcuda/tree/devel
(The master branch is where wine-staging left off a couple of years ago)

EDIT:
I made a change to how nvcuda is built standalone here: https://github.com/SveSop/nvcuda/tree/buildscript
This would build nvcuda as nvcuda.dll and not .dll.so (even if it is an ELF library), and put it in lib32 and lib64 folder. If this could be more useful and easier to implement as a addon "NVCUDA" thing to bottles, let me know and i could provide some sort of "release" binaries for you to use if that is interesting (Suppose there are some sort of manual intervention to update available versions whenever there is a release of libs like DXVK or whatnot?)

@TiZ-HugLife
Copy link

Hi there. I've actually been using nvidia-libs in Bottles for a long time, because Bottles is how I run Daz Studio. The Iray renderer is pretty much a requirement for Daz Studio, and Iray requires CUDA. It currently takes a little bit of manual finagling due to the fact that the installer script wants to create a symlink to the library's actual location, so I'll outline the steps I take.

First, I create a folder: $XDG_DATA_HOME/bottles/nvidia-libs to keep all the versions in. I unpack the release archive into its own folder here. The last release was 0.7.14, so I extract the folder inside the archive as $XDG_DATA_HOME/bottles/nvidia-libs/0.7.14.

Now, if you want to use the installer script, it's tricky because you have to make the right set of components intersect:

  • A shell for the specific Flatpak environment for Bottles
  • The correct Wine prefix
  • The correct Wine runner bins
  • The correct paths for all of those, as seen by the Flatpak environment

So here's the commands I run and the terminal output:

❯ flatpak run --command=bash com.usebottles.bottles
[📦 com.usebottles.bottles ~]$ cd $XDG_DATA_HOME/bottles/nvidia-libs/0.7.14
[📦 com.usebottles.bottles 0.7.14]$ export WINEPREFIX=$(realpath ../../bottles/DAZ)
[📦 com.usebottles.bottles 0.7.14]$ export PATH=$(realpath ../../runners/caffe-8.21/bin):$PATH
[📦 com.usebottles.bottles 0.7.14]$ ./setup_nvlibs.sh install
[1/2] nvcuda :
    Creating DLL override... 
    Creating symlink to nvcuda.dll.so... 
[2/2] nvapi :
    Creating DLL override... 
    Creating symlink to nvapi.dll... 
[1/3] 64 bit nvcuda :
    Creating DLL override... 
    Creating symlink to nvcuda.dll.so... 
[2/3] 64 bit nvoptix :
    Creating DLL override... 
    Creating symlink to nvoptix.dll.so... 
[3/3] 64 bit nvapi64 :
    Creating DLL override... 
    Creating symlink to nvapi64.dll... 
Symlinks created in /home/tiz/.var/app/com.usebottles.bottles/data/bottles/bottles/DAZ. Do NOT remove this source folder!
OBS! NVML is NOT enabled. See Readme_nvml.txt for info
You need to REMOVE old overrides if older version of nvml have been used in /home/tiz/.var/app/com.usebottles.bottles/data/bottles/bottles/DAZ

I don't go through the process of enabling NVML because Iray doesn't need it. But after that's done, I can start Daz Studio and use GPU-accelerated Iray. It's just as fast as native Linux Iray Server. CUDA-Z works too, for a much more accessible way to test the setup.

Contrary to what @SveSop says--and I'm not sure why, because they would certainly know better than me--the distribution as-is works just fine with all Caffe versions from 7.2 through 9.2. But Caffe might be special in some crucial ways I'm not aware of. I actually can't run Daz Studio with any other branch, come to think of it, because it complains that it's being run as administrator.

It would definitely be better to have nvidia-libs integrated into Bottles itself if possible, because running the installer script is very clunky. But it's probably not actually necessary exactly as I'm doing it. It doesn't seem like the installer script does anything particularly magical; it makes the DLL files available in the prefix, and then sets up DLL overrides in the registry for each one. I don't really care about the DLL files being symlinks, because I don't want them to update without me explicitly doing so anyways. So I could probably just copy them and set up the DLL overrides manually.

@SveSop
Copy link

SveSop commented Apr 17, 2024

I am not horribly well at explaining myself..

Atm nvlibs is built with "fake" dll's in the nvidia-libs-release/lib64/wine/x86_64-windows folder, and it is kind of easy to think THAT is what you should symlink/copy into the wineprefix (its a .dll file after all). This does not work...
Prior to wine-8.x it was actually possible to use this fake .dll along with the dll.so in a way so you did not need to use dll-override and such, but this no longer works.

It just MAY seem "not correct" for some to think they need to symlink a linux .so library like that, and that was kind of what i was hinting at. It works just fine like it is, it just could possibly be a bit misleading, especially when comparing it to DXVK/VKD3D that is built as native PE libs.

I understand it sounded somewhat more serious than i intended 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants