cocoa-xu / evision

Evision: An OpenCV-Erlang/Elixir binding
https://evision.app
Apache License 2.0
323 stars 22 forks source link

CUDA support on Windows #170

Closed cocoa-xu closed 1 year ago

cocoa-xu commented 1 year ago

Let's try to bring CUDA support to Windows. This should address a previous issue #164.

cocoa-xu commented 1 year ago

So now I can install CUDA 11.1.0, 11.4.3 and 11.8.0 with cocoa-xu/cuda-toolkit, forked from Jimver/cuda-toolkit.

- uses: cocoa-xu/cuda-toolkit@v0.2.9
  id: cuda-toolkit
  with:
    cuda: '11.8.0'

For dev versions, set these env vars in cmd

set EVISION_PREFER_PRECOMPILED="false"
set EVISION_ENABLE_CUDA="true"

And the compilation process is fine, but we need to either

cocoa-xu commented 1 year ago

It works either way, Windows no more complains about missing DLLs.

Capture

Since the CUDA support will be explicitly specified by the users, it seems to be okay to copy these DLLs to priv/lib (for users who use precompiled binaries).

For users who prefer compiling from source, maybe they can configure the path in config.exs, something like

config :evision, copy_cuda_runtime: false
config :evision, cuda_runtime_dir: "C:/CUDA"

and if they are okay with copying all the runtime DLLs to priv/lib, then

config :evision, copy_cuda_runtime: true
cocoa-xu commented 1 year ago

Impossible to download cudnn libraries on Windows runner.

cocoa-xu commented 1 year ago

Actually, I just came up with an idea to address the cudnn thing. More changes will be made in cocoa-xu/cuda-toolkit, and hopefully, the precompiled version for Windows can use cudnn.

edwardzhou commented 1 year ago

Actually, I just came up with an idea to address the cudnn thing. More changes will be made in cocoa-xu/cuda-toolkit, and hopefully, the precompiled version for Windows can use cudnn.

precompiled for windows is huge helpful. much painful to setup compilation environment on windows than on Linux/Mac.

cocoa-xu commented 1 year ago

v0.1.26 is shipped!

edwardzhou commented 1 year ago

@cocoa-xu update to 0.1.28 with GPU config

set EVISION_CUDA_VERSION=118
set EVISION_ENABLE_CUDA=true
set EVISION_ENABLE_CONTRIB=true

mix deps.get
mix compile

iex -S mix

iex(1)> Evision.CUDA.DeviceInfo.deviceInfo

15:54:33.532 [warning] Failed to load nif: {:load_failed, [70, 97, 105, 108, 101, 100, 32, 116, 111, 32, 108, 111, 97, 100, 32, 78, 73, 70, 32, 108, 105, 98, 114, 97, 114, 121, 32, 100, 58, 47, 101, 108, 105, 120, 105, 114, 95, 119, 111, 114, 107, 47, 101, 118, 105, 115, 105, 111, ...]}, d:/elixir_work/evision_demo/_build/dev/lib/evision/priv/evision ** (ErlangError) Erlang error: "cv::cuda::DeviceInfo::cuda_DeviceInfo not loaded" :erlang.nif_error("cv::cuda::DeviceInfo::cuda_DeviceInfo not loaded") (evision 0.1.28) lib/generated/evision_nif.ex:1741: :evision_nif.cuda_cuda_DeviceInfo_DeviceInfo/1 (evision 0.1.28) lib/generated/evision_cuda_deviceinfo.ex:77: Evision.CUDA.DeviceInfo.deviceInfo/0 iex:1: (file) iex(1)>

cocoa-xu commented 1 year ago

Hi, please set EVISION_CUDA_RUNTIME_DIR to the directory that contains CUDA + cudnn runtime DLL files. These files are not redistributed to reduce the size of the precompiled archive.

Related link: https://github.com/cocoa-xu/evision#important-note-for-windows-users