Cannot access GPU with WSL

Dear all,

I am trying to compile LAMMPS, the 23Jun2022 version on Windows 10 using WSL, with the GPU package enabled, which in principle was successful using the default settings, like below.

cmake -D PKG_GPU=on -C …/cmake/presets/most.cmake …/cmake

Running the lmp-executable works, but with the commandline option “-pk gpu x” with x beeing 0, 1, or any other integer I get the error:

ERROR: Invalid OpenCL platform ID. (src/GPU/gpu_extra.h:77)

Running ocl_get_devices shows the problem:

“Found 0 platform(s).”

as well as lmp -h shows:

"…
Accelerator configuration:

GPU package API: OpenCL
GPU package precision: mixed
OPENMP package API: OpenMP
OPENMP package precision: double

Compatible GPU present: no
…"

Trying to compile using CUDA instead of OpenCL (following this advice to get the neccessary CUDA-software: CUDA on WSL 2 User Guide) gives:
“CMake Error at Modules/Packages/GPU.cmake:44 (message):
Could not find bin2c, use -DBIN2C=/path/to/bin2c to help cmake finding it.” failing to compile in the first place.

Could someone maybe point me in the right direction to get this to work?
From my understanding, the issue is not with LAMMPS itself, but with the WSL not accessing the GPU, right?
My experience with these issues is very limited so any help is greatly appreciated!

Kind regards!
Jakob

Are you sure you have WSL2?
Might be, you need Windows 11 for that?

Also, have you tried the precompiled binaries for running natively on Windows. They include the GPU package with OpenCL support.

In addition, you can compile with the native compilers after installing the visual studio community edition.

If you compile from source we generally recommend using the latest feature release (8 Feb 2023) or check out the release branch from git.

Thanks for the advice!

I got the latest feature release and tested both compilations (CUDA and OpenCL) on WSL and WSL2 with the same results, namely OpenCL not finding a GPU and Cuda not being found while compilation.

I will try out the other recommendations.

Problem solved:
It finally works under Windows 10, WSL2, with CUDA on a Nvidia GeForce GTX 1660 Ti.

One issue was to get the right cuda-software, which I got from here: Enabling GPU acceleration on Ubuntu on WSL2 with the NVIDIA CUDA Platform | Ubuntu

The other problem was cmake not finding the bin2c file in the cuda-folders, so this had to be specified in the command line like:

cmake -D PKG_GPU=on -DGPU_API=cuda -DBIN2C=/usr/local/cuda/bin/bin2c …/cmake

Now it works and the speedup is immediately noticable!
Hope this helps anyone who might also encounter this issue.

1 Like