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

DirectML use device_id to select GPU #410

Closed
hpx502766238 opened this issue Jul 5, 2023 · 22 comments
Closed

DirectML use device_id to select GPU #410

hpx502766238 opened this issue Jul 5, 2023 · 22 comments
Labels
enhancement New feature or request

Comments

@hpx502766238
Copy link

Issue Type

Feature Request

vc client version number

MMVCServerSIO_win_onnxdirectML-cuda_v.1.5.3.8a.zip

OS

Windows11

GPU

Radeon Vega8,RTX3060 6G

Clear setting

yes

Sample model

yes

Input chunk num

yes

Wait for a while

The GUI successfully launched.

read tutorial

yes

Voice Changer type

RVC

Model type

ONNX f0

Situation

print(onnxruntime.get_available_providers())
model_path = "model.onnx"
session = onnxruntime.InferenceSession("model.onnx",providers=['DmlExecutionProvider'])
session.set_providers(['DmlExecutionProvider'], [ {'device_id': 0}])

we can change "device_id" to choose a GPU
can you add a feature to switch GPUs?

@w-okada
Copy link
Owner

w-okada commented Jul 6, 2023

Did you confirm that it works when I tried it with DmlExecutionProvider?
I know it can be done with Nvidia, and it has been implemented.

@hpx502766238
Copy link
Author

Yes this option is effective, and I confirmed it by monitoring the GPU utilization.

@w-okada
Copy link
Owner

w-okada commented Jul 9, 2023

How do I know which ID corresponds to which GPU?

@hpx502766238
Copy link
Author

How do I know which ID corresponds to which GPU?

windows taskmanager,GPU0 device_id 0,GPU1 device_id 1

@w-okada
Copy link
Owner

w-okada commented Jul 9, 2023

I apologize. I was not clear enough.

How do I know which ID corresponds to which GPU "in python script"?

@hpx502766238
Copy link
Author

hpx502766238 commented Jul 10, 2023

I apologize. I was not clear enough.

How do I know which ID corresponds to which GPU "in python script"?

I only find a C++ method at present.
https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html
Creates a DirectML Execution Provider which executes on the hardware adapter with the given , also known as the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by IDXGIFactory::EnumAdapters. A of 0 always corresponds to the default adapter, which is typically the primary display GPU installed on the system. Beware that in systems with multiple GPU’s, the primary display (GPU 0) is often not the most performant one, particularly on laptops with dual adapters where battery lifetime is preferred over performance.
IDXGIFactory::EnumAdapter
https://learn.microsoft.com/zh-cn/windows/win32/api/dxgi/nf-dxgi-idxgifactory-enumadapters

here is the c++ example:
#include
#include
#include
#include <dxgi1_6.h>

std::vector<IDXGIAdapter*> EnumerateAdapters()
{
IDXGIAdapter* pAdapter;
std::vector<IDXGIAdapter*> vAdapters;
IDXGIFactory1* pFactory = nullptr;

if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&pFactory))))
{
    return vAdapters;
}

for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i)
{
    vAdapters.push_back(pAdapter);
}

if (pFactory)
{
    pFactory->Release();
}

return vAdapters;

}

int main()
{
std::vector<IDXGIAdapter*> adapters = EnumerateAdapters();

std::cout << "numbers of adapter: " << adapters.size() << std::endl;
for (UINT i = 0; i < adapters.size(); ++i)
{
    DXGI_ADAPTER_DESC adapterDesc;
    adapters[i]->GetDesc(&adapterDesc);

    std::wstring adapterName = adapterDesc.Description;
    UINT adapterIndex = i;

    std::wcout <<  "index of adapter: "  << adapterIndex << std::endl;
    std::wcout <<"name of adapter: "<< adapterName << std::endl;

    adapters[i]->Release();
}

return 0;

}

@hpx502766238
Copy link
Author

I have submitted a feature request to the official ONNX Runtime.
microsoft/onnxruntime#16644

@hpx502766238
Copy link
Author

hpx502766238 commented Jul 10, 2023

I apologize. I was not clear enough.

How do I know which ID corresponds to which GPU "in python script"?

ok,I have find a python solution now.We can use torch-directml.I have tested that its running result is the same as the official C++code. Here is the python test script:
import torch_directml

if torch_directml.is_available(): #显示是否有dml设备
print('default device_id:',torch_directml.default_device()) # 显示缺省DML设备id
for i in range(torch_directml.device_count()):
print(f'device_id:{i},device_name:{torch_directml.device_name(i)}') # 显示第i个DML设备名称

else:
print('directml is not available')

@w-okada
Copy link
Owner

w-okada commented Jul 10, 2023

Thank you for your cooperation and for providing information.

I think you'll probably need to set up a development environment on Windows to do that. I need to think a bit because I can't risk breaking my current development environment. By the way, as stated in the readme, I don't even have an AMD GPU, so I can't test it. In order to proceed, it's quite risky.

Well, for now, I can't get started on it right away, so please wait a bit.

@w-okada w-okada added the enhancement New feature or request label Jul 10, 2023
@hpx502766238
Copy link
Author

hpx502766238 commented Jul 16, 2023

"There is also a particularly important point: To use torch-directml, we must install torch=2.0.0 torchvision in the CPUVersion; otherwise, the pip may auto-install other packages that depend on Nvidia. So, I suggest splitting the software into two versions: 'directml' and 'cuda'. Both of them support onnx and pth."

@w-okada
Copy link
Owner

w-okada commented Jul 18, 2023

select id will be in next release (not device name), only for experimental

@vitpekarek
Copy link

I tested many different settings. You closed #485 , so I just wanted to update you that I have issue only with crepe. It's increasing res ms even if I set highest chunk. Crepe tiny and full is working for me perfectly. I only had to set a chunk to 128 and it seems good.

@w-okada
Copy link
Owner

w-okada commented Jul 21, 2023

use latest version v.1.5.3.10

@flipknight001
Copy link

Tested with RX 5700 AMD GPU, I was having issues unless settings is "Crepe tiny", other seem to cause high res ms.

@w-okada
Copy link
Owner

w-okada commented Jul 22, 2023

amd is used with onnx. crepe is not onnx. crepe tiny is onnx. so, It's operating as expected.

@w-okada w-okada closed this as completed Jul 22, 2023
This was referenced Jul 24, 2023
@zerrmarch248
Copy link

@vitpekarek ****

@binplatin
Copy link

binplatin commented Jan 1, 2025

Hello, im sorry but i didnt really understand something up there. So my Problem is i got a Rx 7800x GPU and i cant select her. Could you please say what i exactly have to type and where.

@Kuuko-fokkusugaru
Copy link

Hello, im sorry but i didnt really understand something up there. So my Problem is i got a Rx 7800x GPU and i cant select her. Could you please say what i exactly have to type and where.

You haven't to type anything anywhere. Just click on the buttons that may say GPU0, GPU1, etc. One of them should be your 7800x

@binplatin
Copy link

Hello, im sorry but i didnt really understand something up there. So my Problem is i got a Rx 7800x GPU and i cant select her. Could you please say what i exactly have to type and where.

You haven't to type anything anywhere. Just click on the buttons that may say GPU0, GPU1, etc. One of them should be your 7800x

It doesnt matter which one i choose my cpu is always on 90%, so it is normal?

@Kuuko-fokkusugaru
Copy link

Hello, im sorry but i didnt really understand something up there. So my Problem is i got a Rx 7800x GPU and i cant select her. Could you please say what i exactly have to type and where.

You haven't to type anything anywhere. Just click on the buttons that may say GPU0, GPU1, etc. One of them should be your 7800x

It doesnt matter which one i choose my cpu is always on 90%, so it is normal?

No, it should use the GPU. Make sure that you check the GPU usage regardless of the cpu usage. It should raise whenever you speak. You could also try the v2 of the software instead of the v1.

@binplatin
Copy link

Hello, im sorry but i didnt really understand something up there. So my Problem is i got a Rx 7800x GPU and i cant select her. Could you please say what i exactly have to type and where.

You haven't to type anything anywhere. Just click on the buttons that may say GPU0, GPU1, etc. One of them should be your 7800x

It doesnt matter which one i choose my cpu is always on 90%, so it is normal?

No, it should use the GPU. Make sure that you check the GPU usage regardless of the cpu usage. It should raise whenever you speak. You could also try the v2 of the software instead of the v1.

how can i download the other software?

@Kuuko-fokkusugaru
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants