CTranslate2
CTranslate2 copied to clipboard
How to compile from source on windows 11?
I got the error of RuntimeError: Library cublas64_11.dll is not found or cannot be loaded. I searched and saw that I need to compile it from source to make it support 12.1 CUDA.
How do I do it on windows? In the documentation it only works for linux.
You can check the windows compilation scripts under python/tools in the ctranslate2 source directory. https://github.com/OpenNMT/CTranslate2/blob/master/python/tools/prepare_build_environment_windows.sh It should use a linux-like shell environment for windows, like msys2. When I compiled it, I used the cmd terminal directly. Here is a brief description, the main content is similar to the above script.
-
install visual studio2022
-
install Intel MKL and Nvidia CudaToolkit and Cudnn from the official website.
Important Notes!When installing cudnn, you can refer to the pdf to merge the bin,include,lib directory of cudnn and cuda, otherwise you can't find the cudnn library in the cmake stage. https://docs.nvidia.com/deeplearning/cudnn/archives/cudnn-804/pdf/cuDNN-Installation-Guide.pdf
-
install oneDNN (you can refer to prepare_build_environment_windows.sh script to compile using cmake)
-
git clone source code to d-disk
git clone https://github.com/OpenNMT/CTranslate2.git
-
Open the build environment provided by Intel mkl "Intel oneAPI command prompt for Intel 64 for Visual Studio 2022".
-
cmake configuration
set CTRANSLATE2_ROOT=d:\ctranslate2\
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%CTRANSLATE2_ROOT% -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/Intel/oneAPI/ compiler/latest/windows/compiler/lib/intel64_win;C:/Program Files (x86)/oneDNN" -DBUILD_CLI=OFF -DWITH_DNNL=ON -DWITH_CUDA=ON -DWITH_CUDNN=ON -DCCMAKE_PREFIX_PATH="C:/Program Files (x86)/Intel/oneAPI/ CUDNN=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_ROOT% -DCUDA_DYNAMIC_LOADING=ON -DCUDA_NVCC_FLAGS="-Xfatbin=-compress-all" -DCUDA_ARCH_LIST=" Common" ...
cmake --build . --config Release --target install --parallel 6 --verbose
HI @seclog, @panosk, Based on the above instructions I've modified my cmake command to use only DNNL and not CUDA which looks like this cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%CTRANSLATE2_ROOT% -DWITH_DNNL=ON ..
.
Post the build, I followed the instructions in prepare_build_environment_windows.sh
I've copied the DLLs to python/ctranslate2/
folder.
Later after pip install is completed, I observe that the dlls are present as a part of the site-packages directory of the ctranslate2 package,
Yet when I try to import the ctranslate2 package in my code, I get the DLL not found error as in the image below.
The list of DLLs I've copied are
- ctranslate2.dll
- libiomp5md.dll
- cudnn64_8.dll
- dnnl.dll
Can you please suggest how do I fix this issue, inoder to get the import running? Also, I've uninstalled the CUDA from my machine as my priority was using DNNL and have retained only the dll.
Thanks in advance.
I was able to fix the above issue by copying all the .dlls from the oneapi/compiler
directory to the site-packages/ctranslate2/
directory. This helped and the above import error is not observed.
Appreciate any other alternative suggestions, as I feel what I did was more of a crude method/workaround.