m-ab-s / media-autobuild_suite

This Windows Batchscript helps setup a Mingw-w64 compiler environment for building ffmpeg and other media tools under Windows.
GNU General Public License v3.0
1.5k stars 257 forks source link

Request: [Support for libvmaf_cuda] #2526

Open nico-lab opened 9 months ago

nico-lab commented 9 months ago

Wish to support libvmaf_cuda recently added to FFmpeg. https://github.com/FFmpeg/FFmpeg/commit/7f685d0f493bbfa44cf1b3b65f9347291e23872b

https://github.com/m-ab-s/media-autobuild_suite/blob/05957e23da42fcb910baf12581d97e7c982e88e4/build/media-suite_compile.sh#L1082 adding -Denable_cuda=true

Likely error (tail of the failed operation logfile): Program nasm found: YES (H:\mas\msys64\mingw64\bin/nasm.EXE) Configuring config.asm using configuration Program xxd found: YES (H:\mas\msys64\usr\bin/xxd.EXE) Run-time dependency CUDA (modules: cudart) found: YES 12.2 (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2) ../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.

../src/meson.build:166:4: ERROR: Compiler ccache nvcc can not compile programs.

A full log can be found at H:/mas/build/vmaf-git/libvmaf/build-64bit/meson-logs/meson-log.txt meson failed. Check H:/mas/build/vmaf-git/libvmaf/build-64bit/ab-suite.meson.log This is required for other packages, so this script will exit.

H:/mas/build/vmaf-git/libvmaf/build-64bit/ab-suite.meson.log Sanity testing Cuda compiler: ccache nvcc Is cross compiler: False. Sanity check compiler command line: ccache nvcc -w -cudart static H:/mas/build/vmaf-git/libvmaf/build-64bit/meson-private/sanitycheckcuda.cu -o H:/mas/build/vmaf-git/libvmaf/build-64bit/meson-private/sanitycheckcuda.exe Sanity check compile stdout: nvcc fatal : Failed to preprocess host compiler properties.


Sanity check compile stderr: Microsoft(R) C/C++ Optimizing Compiler Version 19.25.28612 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

tmpxft_00000f7c_00000000-2.cpp cl : コマンド ライン error D8027 : 'c1xx' を実行できません


../src/meson.build:166:4: ERROR: Compiler ccache nvcc can not compile programs.

waldonnis commented 9 months ago

I poked at this a little since it's something that's potentially useful to me, but it's not a priority and I have no idea if/when I'll get around to working on it myself. Here are some thoughts, though, in case anyone else has some interest in working on it....

nvcc is really just a compiler driver rather than a compiler itself, and on Windows, it (unfortunately) depends on MS' C++ compiler (cl.exe). This may add to the current CUDA requirements if nvcc is a hard requirement for libvmaf_cuda support. I have Visual Studio and the CUDA Toolkit installed anyway for other projects, so I don't know if not having it breaks anything currently. Probably the best alternative I can think of is trying to use clang/llvm to build the CUDA kernels, but I haven't tried it yet. There's a discussion about it in vmaf's github issues list that I haven't looked at too deeply at that may yield some ideas as far as that goes.

Suite-wise, it looks like do_changeFFmpegConfig() and verify_cuda_deps() handle checking and adding CUDA-related paths to the environment, but that's not called until just before compiling ffmpeg itself (and it's not as simple as just calling those functions earlier). It seems like splitting out the CUDA-related bits into their own, not-ffmpeg-centric function(s) would be ideal. Doing so is not super easy, though, since a lot of what is currently being done in both functions is specific to ffmpeg anyway. IMO, that whole aspect needs to be redesigned to possibly be more generic/abstracted from the current ffmpeg focus or at least written so that it can be performed earlier with no unwanted side effects to the non-ffmpeg parts of the building process.

nico-lab commented 9 months ago

Probably the best alternative I can think of is trying to use clang/llvm to build the CUDA kernels,

Thanks. I'll give it a try.

nico-lab commented 9 months ago

https://github.com/m-ab-s/media-autobuild_suite/blob/05957e23da42fcb910baf12581d97e7c982e88e4/build/media-suite_compile.sh#L1081 delete -mstackrealign $CFLAGS and set at CC=1 in media-autobuild_suite.ini but nvcc fatal : Cannot find compiler 'cl.exe' in PATH meson-log.txt

HunterAP23 commented 9 months ago

That's because, as waldonnis said, the checks used for adding in CUDA paths comes much later than when libvmaf gets compiled. Without checking and adding the CUDA paths to the environment variables, libvmaf will not compile with CUDA support.

nvcc is really just a compiler driver rather than a compiler itself, and on Windows, it (unfortunately) depends on MS' C++ compiler (cl.exe). This may add to the current CUDA requirements if nvcc is a hard requirement for libvmaf_cuda support. I have Visual Studio and the CUDA Toolkit installed anyway for other projects, so I don't know if not having it breaks anything currently. Probably the best alternative I can think of is trying to use clang/llvm to build the CUDA kernels, but I haven't tried it yet. There's a discussion about it in vmaf's github issues list that I haven't looked at too deeply at that may yield some ideas as far as that goes.

I opened that ticket in the hopes that I could statically compile libvmaf with CUDA support on Windows, rather than through WSL, and then use them in this tool rather than building libvmaf from source due to the exact issues you described. It'll take quite a bit of work that I'm not personally able to do, so the best I can do is wait until a later date. I can offer to do testing and small additions if need be though