seasonjs / stable-diffusion

pure go for stable-diffusion and support cross-platform.
https://pkg.go.dev/github.com/seasonjs/stable-diffusion
MIT License
36 stars 5 forks source link

Error while using GPU #2

Closed Mars160 closed 8 months ago

Mars160 commented 8 months ago

I have a NVIDIA 4090 and an Intel GPU on my machine. I want to load model to my 4090. However, it only checked my intel gpu and said it's now support.

How to use my NVIDIA GPU not the Intel One?

Thank you.

Mars160 commented 8 months ago

I try to load the library manually, but it said The specified module could not be found. (sd-abi_cuda12.dll)

When I try to load sd-abi_avx2.dll, It works.

Cyberhan123 commented 8 months ago

@Mars160 Can you run the following command in powershell

Get-WmiObject Win32_VideoController | Format-List Name,AdapterCompatibility,AdapterRAM
Mars160 commented 8 months ago

@Cyberhan123

Thanks for your reply.

And here is the output

Name                 : Virtual Desktop Monitor
AdapterCompatibility : Virtual Desktop, Inc.
AdapterRAM           :

Name                 : NVIDIA GeForce RTX 4090
AdapterCompatibility : NVIDIA
AdapterRAM           : 4293918720

Name                 : Virtual Display
AdapterCompatibility : Xiaomi
AdapterRAM           :

Name                 : Intel(R) UHD Graphics 770
AdapterCompatibility : Intel Corporation
AdapterRAM           : 1073741824
Cyberhan123 commented 8 months ago

@Mars160 I'm not sure if this powershell script of mine is working properly, it goes like this:

  $graphicsCards = Get-WmiObject Win32_VideoController
  $graphicsArray = @()
  $graphicsEmpty = @{
      'Name'                 = ''
      'AdapterCompatibility' = ''
      'AdapterRAM'           = 0
  }
 $graphicsArray += $graphicsEmpty
  foreach ($card in $graphicsCards) {
      $graphicsInfo = @{
          'Name'                 = $card.Caption
          'AdapterCompatibility' = $card.VideoProcessor
          'AdapterRAM'           = $card.AdapterRAM
      }
      $graphicsArray += $graphicsInfo
  }
 $graphicsArray | ConvertTo-Json

Of course it would be better if you could switch to fix-gpu-windows git branch for testing

Mars160 commented 8 months ago

Thanks for your hard work! The GPU selection issue was fixed!

However, there is another issue. I can load 'sd-abi_cuda12.dll'

2024/01/10 13:55:31 get gpu info: NVIDIA GeForce RTX 4090
2024/01/10 13:55:31 Use GPU CUDA instead.
2024/01/10 13:55:31 If you want to try offload your model to the GPU. Please confirm the size of your GPU memory to prevent memory overflow.
The specified module could not be found.

And I found we should blame it on golang's package. I tried

package main

import "syscall"

func main() {
    lib, err := syscall.LoadLibrary("sd-abi_cuda12.dll")
    if err != nil {
        panic(err)
    }
    defer syscall.FreeLibrary(lib)
}

I got

panic: The specified module could not be found.

goroutine 1 [running]:
main.main()
        C:/other/AI/sd-go/test.go:8 +0x79
exit status 2

When I change the library from sd-abi_cuda12.dll to sd-abi_avx2.dll, It loaded it successfully.

I'm not so familiar with stable diffusion library. Is there a way to fix this?

Thank you!

Cyberhan123 commented 8 months ago

@Mars160 Have you installed cuda?

Mars160 commented 8 months ago

Thank you! You solved my problem perfectly!