Vship icon indicating copy to clipboard operation
Vship copied to clipboard

`--gpu-id` flag is parsed but never used - GPU selection doesn't work

Open sleepy-af-dev opened this issue 11 months ago • 19 comments

Description

The --gpu-id command-line argument is parsed but never applied, causing FFVship to always use GPU 0 regardless of the specified value. This breaks multi-GPU systems where the default GPU 0 may be an unsupported integrated GPU.

Environment

  • FFVship v4.0.2 (AMD build)
  • Windows 11
  • ROCm HIP SDK 6.4

GPUs

  • GPU 0: AMD Radeon Graphics (integrated, gfx1036)
  • GPU 1: AMD Radeon RX 9070 XT (discrete, gfx1201)

Steps to Reproduce

  1. Have a system with both integrated and discrete AMD GPUs
  2. Run: FFVship --list-gpu (shows both GPUs correctly)
  3. Run: FFVship --source ref.mkv --encoded enc.mkv -m SSIMULACRA2 --gpu-id 1
  4. Observe error: VshipException: invalid device function at gpuhelper.hpp:50

Expected Behavior

--gpu-id 1 should run computations on GPU 1 (the discrete RX 9070 XT)

Actual Behavior

Kernels always execute on GPU 0 (integrated), causing "invalid device function" error because gfx1036 kernels aren't compiled in.

Workaround

Disable integrated GPU in BIOS so discrete GPU becomes GPU 0.

Root Cause

In src/ffvship_utility/ffmpegmain.hpp, the gpu_id is parsed:

parser.add_flag({"--gpu-id"}, &opts.gpu_id, "GPU index");

But Vship_SetDevice(opts.gpu_id) is never called before metric handler initialization.

Suggested Fix

Add this call before initializing metric handlers:

Vship_SetDevice(opts.gpu_id);

sleepy-af-dev avatar Dec 21 '25 13:12 sleepy-af-dev

you can retry now but in theory Vship_GPUFullCheck is already calling hipSetDevice so it shouldnt be needed, just in case I added Vship_SetDevice so you can try, I don't have a multi gpu config to test on

Line-fr avatar Dec 21 '25 15:12 Line-fr

can you compile vship or do I need to?

Line-fr avatar Dec 21 '25 15:12 Line-fr

I can compile here - I can get to this a little later on today. Thanks!

sleepy-af-dev avatar Dec 21 '25 15:12 sleepy-af-dev

Unfortunately it's still not working on my system.

In gpuFullCheck() (gpuhelper.hpp), hipGetDeviceCount() is called before hipSetDevice(gpuid):

void gpuFullCheck(int gpuid = 0){
    int count = checkGpuCount();
    // ...
    GPU_CHECK(hipSetDevice(gpuid));
    if (!gpuKernelCheck()){

Device 0 on my system is the integrated AMD GPU (gfx1036) which isn't in the compiled architectures. Is it possible that when hipGetDeviceCount() initializes the HIP runtime on Windows, something gets cached with device 0's context that affects later kernel code selection - even after calling hipSetDevice(1)?

You could try calling hipSetDevice(gpuid) before hipGetDeviceCount():

void gpuFullCheck(int gpuid = 0){
    hipError_t err = hipSetDevice(gpuid);  // Initialize HIP with target device
    if (err != hipSuccess) {
        throw VshipError(BadDeviceArgument, __FILE__, __LINE__, hipGetErrorString(err));
    }
    int count = checkGpuCount();
    // ... rest of validation
}

This way the HIP runtime initializes with the correct device context.

sleepy-af-dev avatar Dec 21 '25 16:12 sleepy-af-dev

No, the first fix was wrong as I guessed it because the issue we are identifying is not what you seem to think it is the AI seem to have a poor understanding of the situation (as always lol). And clearly, this theory is wrong. (as you know how to compile with such details you could have tried it yourself also)

I will try to see if I can get people with multiple gpu to reproduce the issue on AMD ideally but also on Cuda

Line-fr avatar Dec 21 '25 18:12 Line-fr

Also, what is the exact error vship returns, you didnt say it

Line-fr avatar Dec 21 '25 18:12 Line-fr

Damn these AIs

Line-fr avatar Dec 21 '25 18:12 Line-fr

No, the first fix was wrong as I guessed it because the issue we are identifying is not what you seem to think it is the AI seem to have a poor understanding of the situation (as always lol). And clearly, this theory is wrong. (as you know how to compile with such details you could have tried it yourself also)

I will try to see if I can get people with multiple gpu to reproduce the issue on AMD ideally but also on Cuda

Alright, no problem! And yes, I don't hide that I use AI to support development - but do be reassured I'm a real person and I'm happy to help in any way I can! 🙂

The error given was as per my first post: error: VshipException: invalid device function at gpuhelper.hpp:50. The only working resolution so far is to disable my iGPU.

sleepy-af-dev avatar Dec 21 '25 18:12 sleepy-af-dev

Just for completeness, here's the full error:

VshipException
InternalError: A GPU Call failed inside Vship. This may be due to a bad environment but is likely due to a bug in Vship.
 - At line 50 of src\butter\../util/gpuhelper.hpp
Detail: invalid device function

sleepy-af-dev avatar Dec 21 '25 18:12 sleepy-af-dev

Thank you for the detailed input, I will try to see if I can find something, eventually send a patch to check on something

Line-fr avatar Dec 21 '25 18:12 Line-fr

I identified multiple issues related to --gpu-id that I plan on solving but it won't be trivial However, none of them should create the issue you are having so I am confused no one seems to have such a system, especially not me so I can't reproduce or test anything. (Not enough money allocated to the project ahah, enjoy open source)

Line-fr avatar Dec 21 '25 20:12 Line-fr

I identified multiple issues related to --gpu-id that I plan on solving but it won't be trivial However, none of them should create the issue you are having so I am confused no one seems to have such a system, especially not me so I can't reproduce or test anything. (Not enough money allocated to the project ahah, enjoy open source)

Ah ok, no problem. I'll have a play around here with different environments/configurations and see if there's anything helpful I find. My CPU is an AMD Ryzen 9 9950X3D, hence the iGPU.

sleepy-af-dev avatar Dec 21 '25 20:12 sleepy-af-dev

I did fix a lot of issues right now regarding gpu_id though I don't believe it will fix your specific issue since this one is really mysterious for me. I think it could still be worth it to try.

Line-fr avatar Dec 21 '25 21:12 Line-fr

did you try?

Line-fr avatar Dec 25 '25 12:12 Line-fr

did you try?

I haven't yet - but should have some time this weekend.

sleepy-af-dev avatar Dec 25 '25 23:12 sleepy-af-dev

did you try?

I'm pleased to report that the GPU selection issue is resolved! VShip didn't throw VshipException: invalid device function at gpuhelper.hpp:50 warnings.

However, I'm seeing that when running, my GPU driver times out and all frame scores are 100. Just doing some digging to see if that's an issue with my environment. In any case, it won't be related to this, so I think the changes you made are successful!

sleepy-af-dev avatar Dec 29 '25 17:12 sleepy-af-dev

Apparently there are still some known issues with RDNA4 cards and ROCm, and these are causing the other issues I'm seeing. The GPU selection is fixed though! 🙂

sleepy-af-dev avatar Dec 29 '25 19:12 sleepy-af-dev

I am glad it fixed the issue. Recent rocm versions seems quite unstable. Since 6.4 I saw a lot of things break. I hope it will resolve (and I also hope it's not an issue from vship under the hood)

Line-fr avatar Dec 29 '25 22:12 Line-fr

I am glad it fixed the issue. Recent rocm versions seems quite unstable. Since 6.4 I saw a lot of things break. I hope it will resolve (and I also hope it's not an issue from vship under the hood)

Supposedly in v7, but we'll see... thanks for your help with this issue! I'll close it off now.

sleepy-af-dev avatar Dec 29 '25 22:12 sleepy-af-dev