web-llm icon indicating copy to clipboard operation
web-llm copied to clipboard

Initialize GPU device: WebGPU - Intel(R) UHD Graphics 630

Open ZhouXiaolin opened this issue 2 years ago • 5 comments

I have successfully run on my macOS, but the GPU is using Intel, which is too slow. My macOS is equipped with an 8G AMD graphics card, how can I switch to this graphics card?

截屏2023-04-17 11 12 00

ZhouXiaolin avatar Apr 17 '23 03:04 ZhouXiaolin

Hello @ZhouXiaolin

I think I find how to choose the right card but I cannot try it locally because when I'm using https://github.com/mlc-ai/web-llm/issues/19#issuecomment-1510426287 it refuses to initialize properly my GPU but it works on the demo webpage.

Based on the TVMJS method

/**
 * DetectGPU device in the environment.
 */
export async function detectGPUDevice(): Promise<GPUDevice | undefined | null> {
  if (typeof navigator !== "undefined" && navigator.gpu !== undefined) {
    const adapter = await navigator.gpu.requestAdapter();
    return await adapter?.requestDevice();
  } else {
    return undefined;
  }
}

It will return the first GPU but if you define high-performance parameter it changes.

a = await navigator.gpu.requestAdapter()
GPUAdapter?{features: GPUSupportedFeatures, limits: GPUSupportedLimits, isFallbackAdapter: false}
await a.requestAdapterInfo()
GPUAdapterInfo?{vendor: 'intel', architecture: 'gen-7', device: '0x0152', description: 'Intel(R) HD Graphics 2500 (IVB GT1)', driver: 'Intel open-source Mesa driver: Mesa 22.2.5'}

a = await navigator.gpu.requestAdapter({"powerPreference":"high-performance"})
GPUAdapter?{features: GPUSupportedFeatures, limits: GPUSupportedLimits, isFallbackAdapter: false}
await a.requestAdapterInfo()
GPUAdapterInfo?{vendor: 'nvidia', architecture: 'pascal', device: '0x1c03', description: 'NVIDIA GeForce GTX 1060 6GB', driver: 'NVIDIA: 525.105.17 525.105.17.0'}

kadogo avatar Apr 17 '23 13:04 kadogo

@kadogo thank you for great discovery, do you mind send a PR to the tvm unity branch https://github.com/apache/tvm/tree/unity adding {"powerPreference":"high-performance"}.

tqchen avatar Apr 17 '23 13:04 tqchen

Thanks @kadogo you are my savior, such a good finding !

tdockx avatar Apr 17 '23 13:04 tdockx

Hello @tqchen

I got it working so I will do the PR a bit later in the evening. I will add more info in #19 how it is working now for me.

kadogo avatar Apr 17 '23 16:04 kadogo

Hello @tqchen

Little double post because I'm uncertain if you will notice if I edit my previous answer. The MR is done at https://github.com/apache/tvm/pull/14650 (I did it the wrong way first sorry)

I hope it's correctly done.

Cheers

kadogo avatar Apr 17 '23 17:04 kadogo

Thank you!

tqchen avatar Apr 18 '23 01:04 tqchen