You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request: CUDA feature extraction for Windows #1154
Referencing #1152 which added the ability to use Nvidia CUDA acceleration for calculating VMAF and related scores, the existing pipeline does not seem possible to be able to compile a version of libvmaf with CUDA enabled for Windows.
Based on the Windows build pipeline used here, it uses MING64 with MYSYS2, which does not have a way to install the necessary CUDA dependencies (MYSYS2 uses the pacman package manager tool, which Nvidia does not have official instructions on installing CUDA for, and the MYSYS2 package repositories do not include CUDA).
Would it also be possible to include builds with CUDA enabled in the existing pipelines? I don't believe there should be any issues in terms of licensing, but someone more knowledgeable than me on that topic can confirm if this is correct.
I should've mentioned that I've also tried WSL2 with the correct WSL2 Ubuntu CUDA toolkit installation. These are the steps I've followed until I encounter an error:
git clone https://github.com/Netflix/vmaf
cd vmaf/libvmaf
# instructions from the libvmaf README
python3 -m pip install virtualenv
python3 -m virtualenv .venv
source .venv/bin/activate
pip install meson
sudo apt install nasm ninja-build doxygen xxd
# Install the CUDA toolkit, including NVCC
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt install cuda nvidia-cuda-toolkit nvcc
# Edited the libvmaf/meson_options.txt file to have "enable_cuda" set to "true"# Go through with build instructions as per libvmaf README
meson build --buildtype release
ninja -vC build
After that last step, I get an error saying:
FAILED: src/libcuda_common_vmaf_lib.a.p/cuda_integer_adm_adm_cm.cu.o
nvcc -Isrc/libcuda_common_vmaf_lib.a.p -Xcompiler=-Wall,-Winvalid-pch,-Wextra -O3 -Xcompiler=-fPIC -Isrc -I/usr/local/cuda/include -I/usr/local/cuda/include -I../src/cuda -I../src/feature -I../src/cuda -I../src/feature/common -I../src -Isrc -I../src/feature/common -I../src/feature -I../src -Isrc -I../include -Iinclude -I../src -Isrc -lineinfo -I../src -Isrc -Isrc/libcuda_common_vmaf_lib.a.p -o src/libcuda_common_vmaf_lib.a.p/cuda_integer_adm_adm_cm.cu.o -c ../src/cuda/integer_adm/adm_cm.cu
../src/cuda/integer_adm/adm_cm.cu(52): warning #68-D: integer conversion resulted in a change of sign
../src/cuda/integer_adm/adm_cm.cu(196): warning #186-D: pointless comparison of unsigned integer with zero
../src/cuda/integer_adm/adm_cm.cu(52): warning #68-D: integer conversion resulted in a change of sign
../src/cuda/integer_adm/adm_cm.cu(196): warning #186-D: pointless comparison of unsigned integer with zero
/usr/include/c++/11/bits/std_function.h:435:145: error: parameter packs not expanded with ‘...’:
435 | function(_Functor&& __f)
| ^
/usr/include/c++/11/bits/std_function.h:435:145: note: ‘_ArgTypes’
/usr/include/c++/11/bits/std_function.h:530:146: error: parameter packs not expanded with ‘...’:
530 | operator=(_Functor&& __f)
Trying to find any other error messages but this is the only one I could find
For me compilation with WSL worked apart from a library issue that was solved by creating a symlink as explained here - haven't had that before with WSL not sure what is going on there.
Nonetheless i would recommend only doing sudo apt install cuda specifying nvcc seems excessive. After installing CUDA you might want to add /usr/local/cuda/bin to your PATH.
So I added /usr/local/cuda/bin to my PATH and restarted WSL, as well as creating the symlink sudo ln -s /usr/lib/wsl/lib/libcuda.so.1 /usr/local/cuda/lib64/libcuda.so, but the same error appeared.
I then uninstalled nvidia-cuda-toolkit with sudo apt remove nvidia-cuda-toolkit and did a meson setup --wipe build just to clean up anything from prior build attempts.
The build worked! But afterwards when I went to run ninja -vC build test it fails for gpumask features:
That just seems to be an issue with the test file vmaf\libvmaf\tools\testtest_vmaf_cuda_gpumask.sh:
#!/bin/sh -xset -e
# no gpumask: use cuda
./tools/vmaf \
--reference /dev/zero \
--distorted /dev/zero \
--width 1920 --height 1080 --pixel_format 420 --bitdepth 8 \
--frame_cnt 2 \
--gpumask 0
# gpumask: use cpu
./tools/vmaf \
--reference /dev/zero \
--distorted /dev/zero \
--width 1920 --height 1080 --pixel_format 420 --bitdepth 8 \
--frame_cnt 2 \
--gpumask -1
# no gpumask: use cuda for vmaf features, cpu for psnr
./tools/vmaf \
--reference /dev/zero \
--distorted /dev/zero \
--width 1920 --height 1080 --pixel_format 420 --bitdepth 8 \
--frame_cnt 2 \
--gpumask 0 \
--feature psnr \
--output /dev/stdout
# gpumask: use cpu for vmaf features and psnr
./tools/vmaf \
--reference /dev/zero \
--distorted /dev/zero \
--width 1920 --height 1080 --pixel_format 420 --bitdepth 8 \
--frame_cnt 2 \
--gpumask -1 \
--feature psnr
Although I'm not sure if the error is from #!/bin/sh -x or set -e or some other line, as the error message just says it's from line 0 so I assume it's the #!/bin/sh -x?
Regardless of the test script, the actual commands used for testing do work properly, and they do work with some test video files I have (getting >200fps on some y4m files) but now I'm not sure how to make this build for Windows, as the built vmaf binary is for Linux.
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" # probably $env:CUDA_PATH/bin is already in your path if you have restarted
$env:CC="ccache gcc"; $env:CXX="ccache g++"
meson -Denable_cuda=true build .\libvmaf\
Arrive at
Run-time dependency CUDA (modules: cudart) found: YES 12.0 (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0)
libvmaf/src/meson.build:166: WARNING: add_languages is missing native:, assuming languages are wanted for both host and build.
Compiler for language cuda for the build machine not found.
libvmaf/src/meson.build:166:4: ERROR: Compiler nvcc can not compile programs.
...
Sanity testing Cuda compiler: nvcc
Is cross compiler: False.
Sanity check compiler command line: nvcc -w -cudart static C:/Users/cddeg/vmaf/bui/meson-private/sanitycheckcuda.cu -o C:/Users/cddeg/vmaf/bui/meson-private/sanitycheckcuda.exe
Sanity check compile stdout:
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\vcruntime.h(197): error: invalid redeclaration of type name "size_t"
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\vcruntime_new.h(48): error: first parameter of allocation functionmust be of type"size_t"
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\vcruntime_new.h(53): error: first parameter of allocation functionmust be of type"size_t"
...
and give up after finding out that cuda sdk's nvcc doesn't understand gcc/g++ on Windows at all.
I already tried seeing if I could get meson to use clang as the cuda compiler (since ffmpeg was able to), but couldn't find out how.
I've been thinking about this, it may make sense to eventually migrate to using nv-codec-headers. This gives us runtime dynamic linking, and should also simplify multi-platform building. This is what is used by FFmpeg.
I second the notion of migrating to the nv-codec-headers.
And speaking of FFmpeg, I'm reminded of this other project called media-autobuild_suite that allows Windows users to cross compile FFmpeg in a MINGW64 MYSYS2 environment, and the interesting part is that they are able to do so with CUDA support. I'll investigate into their build scripts and see if it's possible to translate what they do to get CUDA working into VMAF directly.
And speaking of FFmpeg, I'm reminded of this other project called media-autobuild_suite that allows Windows users to cross compile FFmpeg in a MINGW64 MYSYS2 environment, and the interesting part is that they are able to do so with CUDA support. I'll investigate into their build scripts and see if it's possible to translate what they do to get CUDA working into VMAF directly.
So it seems that the media-autobuild_suite project gets CUDA and NVCC working like so:
User has to download the Windows CUDA SDK. They outline what's necessary in this part of their README
They utilize a program within MING64 MSYS2 called cygpath to get a Linux path to the CUDA_PATH environment variable (that should be set in Windows after installing the Windows CUDA SDK). This part of their script utilizes this command to get the CUDA_PATH env var that contains all the dependencies.
It's been quite a while since I provided an update.
I changed the steps used in trying to compile VMAF for use in Windows by moving to using the ffmpeg-windows-build-helpers app to cross-compile FFmpeg with libvmaf support.
The issue comes down to getting CUDA to register correctly (at least on Ubuntu-WSL). These are the steps I've been following:
# Download CUDA 11.8 since CUDA 12 does not seem to work
# Instructions come from https://developer.nvidia.com/cuda-11-8-0-download-archive
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
sudo apt install -y nvidia-cuda-toolkit
# Clone the builder app
git clone https://github.com/rdp/ffmpeg-windows-build-helpers
# install dependencies for this app
sudo apt-get install subversion ragel curl texinfo g++ ed bison flex cvs yasm automake libtool autoconf gcc cmake git make pkg-config zlib1g-dev unzip pax nasm gperf autogen bzip2 autoconf-archive p7zip-full meson clang python3-distutils python-is-python3 -y
# apply a fix for Ubuntu 20.04 for WSL: https://github.com/rdp/ffmpeg-windows-build-helpers/issues/452
sudo dpkg -r --force-depends "libgc1c2"
git clone https://github.com/ivmai/bdwgc
cd bdwgc
./autogen.sh
./configure --prefix=/usr && make -j
sudo make install
# Make a copy of the cross_compile_ffmpeg.sh file for modification
cd ffmpeg-windows-build-helpers
cp cross_compile_ffmpeg.sh cross_compile_ffmpeg_libvmaf_cuda.sh
Next I do some hacky edits to the cross_compile_ffmpeg_libvmaf_cuda.sh file. Here is a git diff between the old and modified versions:
Pull the latest version of the vmaf's master branch rather than a specific release
Use the -Denable_cuda=true flag for building libvmaf
Added in --enable-nonfree --enable-ffnvcodec to the FFmpeg configure command
Then just run the modified cross compiler script: cross_compile_ffmpeg_libvmaf_cuda.sh and when prompted enter 3 for a Win64 build
The script typically fails with VMAF due to meson not finding the cudart_static package. I'm not sure what environment variable or otherwise may be missing that would cause this, but doing the meson setup command like so fixes the issue:
This works, but trying the compiler script again or just using the regular command of ninja -C build install (which the compiler script also does with some extra environment variables) still fails. This time it's due to errors in the attached log file: build.log
This was with CUDA 11.8 so it could be that this version is either too new or too old to work with VMAF, I'll try with other CUDA versions and report back.
It's been quite a while since I provided an update. I changed the steps used in trying to compile VMAF for use in Windows by moving to using the ffmpeg-windows-build-helpers app to cross-compile FFmpeg with libvmaf support.
The issue comes down to getting CUDA to register correctly (at least on Ubuntu-WSL). These are the steps I've been following:
# Download CUDA 11.8 since CUDA 12 does not seem to work
# Instructions come from https://developer.nvidia.com/cuda-11-8-0-download-archive
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
sudo apt install -y nvidia-cuda-toolkit
# Clone the builder app
git clone https://github.com/rdp/ffmpeg-windows-build-helpers
# install dependencies for this app
sudo apt-get install subversion ragel curl texinfo g++ ed bison flex cvs yasm automake libtool autoconf gcc cmake git make pkg-config zlib1g-dev unzip pax nasm gperf autogen bzip2 autoconf-archive p7zip-full meson clang python3-distutils python-is-python3 -y
# apply a fix for Ubuntu 20.04 for WSL: https://github.com/rdp/ffmpeg-windows-build-helpers/issues/452
sudo dpkg -r --force-depends "libgc1c2"
git clone https://github.com/ivmai/bdwgc
cd bdwgc
./autogen.sh
./configure --prefix=/usr && make -j
sudo make install
# Make a copy of the cross_compile_ffmpeg.sh file for modification
cd ffmpeg-windows-build-helpers
cp cross_compile_ffmpeg.sh cross_compile_ffmpeg_libvmaf_cuda.sh
Next I do some hacky edits to the cross_compile_ffmpeg_libvmaf_cuda.sh file. Here is a git diff between the old and modified versions:
Pull the latest version of the vmaf's master branch rather than a specific release
Use the -Denable_cuda=true flag for building libvmaf
Added in --enable-nonfree --enable-ffnvcodec to the FFmpeg configure command
Then just run the modified cross compiler script: cross_compile_ffmpeg_libvmaf_cuda.sh and when prompted enter 3 for a Win64 build
The script typically fails with VMAF due to meson not finding the cudart_static package. I'm not sure what environment variable or otherwise may be missing that would cause this, but doing the meson setup command like so fixes the issue:
This works, but trying the compiler script again or just using the regular command of ninja -C build install (which the compiler script also does with some extra environment variables) still fails. This time it's due to errors in the attached log file: build.log
This was with CUDA 11.8 so it could be that this version is either too new or too old to work with VMAF, I'll try with other CUDA versions and report back.
have you ever solved the issues and finish built vmaf-cuda windows version?
@HunterAP23 Any luck? I just started this journey and any help would be appreciated. I am about to just dual boot Ubuntu because I have been banging my head against this off and on now for a few weeks.
@peterlus@sew3521 I unfortunately have not spent any time looking into this further. Once I hit the above roadblock I wasn't able to progress and further and haven't tried again in a while
If you're looking for GPU VMAF, I recently wrote a GUI program just for that called VideoMetricsLab. It makes GPU VMAF and a bunch of other metrics much easier to do. Check it out below.
There's also my own fork of libvmaf called libvmaf-fast that has the CUDA/Vulkan support for VMAF v0.6.1 and partial Vulkan support for VMAF v1, as well as various general speedups for the PSNR/SSIM/XPSNR section.
Activity
gedoensmax commentedon Jan 12, 2023
I can tell you from NV side we did not test under windows and did not really targeted it. Have you considered using WSL with CUDA support ? https://docs.nvidia.com/cuda/wsl-user-guide/index.html
HunterAP23 commentedon Jan 12, 2023
I should've mentioned that I've also tried WSL2 with the correct WSL2 Ubuntu CUDA toolkit installation. These are the steps I've followed until I encounter an error:
After that last step, I get an error saying:
Trying to find any other error messages but this is the only one I could find
gedoensmax commentedon Jan 12, 2023
For me compilation with WSL worked apart from a library issue that was solved by creating a symlink as explained here - haven't had that before with WSL not sure what is going on there.
Nonetheless i would recommend only doing
sudo apt install cudaspecifying nvcc seems excessive. After installing CUDA you might want to add/usr/local/cuda/binto yourPATH.HunterAP23 commentedon Jan 12, 2023
So I added
/usr/local/cuda/binto myPATHand restarted WSL, as well as creating the symlinksudo ln -s /usr/lib/wsl/lib/libcuda.so.1 /usr/local/cuda/lib64/libcuda.so, but the same error appeared.I then uninstalled
nvidia-cuda-toolkitwithsudo apt remove nvidia-cuda-toolkitand did ameson setup --wipe buildjust to clean up anything from prior build attempts.The build worked! But afterwards when I went to run
ninja -vC build testit fails forgpumaskfeatures:That just seems to be an issue with the test file
vmaf\libvmaf\tools\testtest_vmaf_cuda_gpumask.sh:Although I'm not sure if the error is from
#!/bin/sh -xorset -eor some other line, as the error message just says it's from line 0 so I assume it's the#!/bin/sh -x?Regardless of the test script, the actual commands used for testing do work properly, and they do work with some test video files I have (getting >200fps on some y4m files) but now I'm not sure how to make this build for Windows, as the built
vmafbinary is for Linux.1480c1 commentedon Jan 12, 2023
steps I've tried so far
Invoke-RestMethod -Uri https://aka.ms/vs/17/release/vs_buildtools.exe -OutFile vs_buildtools.exe.\vs_buildtools.exe$env:CC="ccache gcc"; $env:CXX="ccache g++"and give up after finding out that cuda sdk's nvcc doesn't understand gcc/g++ on Windows at all.
I already tried seeing if I could get meson to use clang as the cuda compiler (since ffmpeg was able to), but couldn't find out how.
kylophone commentedon Jan 13, 2023
I've been thinking about this, it may make sense to eventually migrate to using nv-codec-headers. This gives us runtime dynamic linking, and should also simplify multi-platform building. This is what is used by FFmpeg.
HunterAP23 commentedon Jan 13, 2023
I second the notion of migrating to the nv-codec-headers.
And speaking of FFmpeg, I'm reminded of this other project called media-autobuild_suite that allows Windows users to cross compile FFmpeg in a MINGW64 MYSYS2 environment, and the interesting part is that they are able to do so with CUDA support. I'll investigate into their build scripts and see if it's possible to translate what they do to get CUDA working into VMAF directly.
kylophone commentedon Jan 13, 2023
That would be great, thank you.
HunterAP23 commentedon Jan 14, 2023
So it seems that the media-autobuild_suite project gets CUDA and NVCC working like so:
cygpathto get a Linux path to theCUDA_PATHenvironment variable (that should be set in Windows after installing the Windows CUDA SDK). This part of their script utilizes this command to get theCUDA_PATHenv var that contains all the dependencies.nvcc.exeHunterAP23 commentedon Oct 25, 2023
It's been quite a while since I provided an update.
I changed the steps used in trying to compile VMAF for use in Windows by moving to using the ffmpeg-windows-build-helpers app to cross-compile FFmpeg with libvmaf support.
The issue comes down to getting CUDA to register correctly (at least on Ubuntu-WSL). These are the steps I've been following:
Next I do some hacky edits to the
cross_compile_ffmpeg_libvmaf_cuda.shfile. Here is agit diffbetween the old and modified versions:Essentially I'm telling the script to:
-Denable_cuda=trueflag for buildinglibvmaf--enable-nonfree --enable-ffnvcodecto the FFmpeg configure commandThen just run the modified cross compiler script:
cross_compile_ffmpeg_libvmaf_cuda.shand when prompted enter3for a Win64 buildThe script typically fails with VMAF due to
mesonnot finding thecudart_staticpackage. I'm not sure what environment variable or otherwise may be missing that would cause this, but doing themeson setupcommand like so fixes the issue:This works, but trying the compiler script again or just using the regular command of
ninja -C build install(which the compiler script also does with some extra environment variables) still fails. This time it's due to errors in the attached log file: build.logThis was with CUDA 11.8 so it could be that this version is either too new or too old to work with VMAF, I'll try with other CUDA versions and report back.
peterlus commentedon Jun 13, 2024
have you ever solved the issues and finish built vmaf-cuda windows version?
sew3521 commentedon Nov 29, 2024
@HunterAP23 Any luck? I just started this journey and any help would be appreciated. I am about to just dual boot Ubuntu because I have been banging my head against this off and on now for a few weeks.
XuShiSheng commentedon Nov 29, 2024
HunterAP23 commentedon Nov 29, 2024
@peterlus @sew3521 I unfortunately have not spent any time looking into this further. Once I hit the above roadblock I wasn't able to progress and further and haven't tried again in a while
4KVCD commentedon Oct 5, 2026
If you're looking for GPU VMAF, I recently wrote a GUI program just for that called VideoMetricsLab. It makes GPU VMAF and a bunch of other metrics much easier to do. Check it out below.
https://github.com/4KVCD/VideoMetricsLab
There's also my own fork of libvmaf called libvmaf-fast that has the CUDA/Vulkan support for VMAF v0.6.1 and partial Vulkan support for VMAF v1, as well as various general speedups for the PSNR/SSIM/XPSNR section.
https://github.com/4KVCD/libvmaf-fast