1

I will preface this by saying: I don't have a lot of experience in a Linux environment.

I am trying to install ROCm on WSL2 running Ubuntu. I will be using PyTorch for a class and I want to use my GPU for compute. ROCm installed fine, however, I kept getting the error ROCk module is NOT loaded, possibly no GPU devices.

I found this post which indicated that the problem could be that WSL doesn't allow you to install modules. That linked to a comment found here which showed how to install a new kernel. I followed the instructions, but I have run across an error when running make.

The error is: No rule to make target '/home/<USER>/lkm_example.o', needed by '/home/<USER>/lkm_example.mod'. Stop.

(<USER> is my username, I just didn't want it out here)

Through Google, I found several posts saying that I need to install linux-headers. I tried running sudo apt-get install kernel-headers, but that resulted in an error: E: Unable to locate package kernel-headers

How do I proceed?

1 Answer 1

0

I found this post which indicated that the problem could be that WSL doesn't allow you to install modules.

Hey, that's my answer! Keep in mind:

  • I prefaced it with:

    "While I don't have any AMD GPU systems with which to try this out (nor do I know for sure if ROCm works on WSL2) ...".

  • And it has no upvotes, is not accepted, nor does it have any comments letting us know one way or the other whether it helped.

So ... don't trust it as being anywhere near reliable! Feel free to downvote it even! It's tough to say that about my own answer, but in retrospect it probably wasn't accurate. I'll add a link from it to this answer, however, so that it redirects to the latest info. Whether the info below is now correct or not, I'll need you to help me with!

I will be using PyTorch for a class and I want to use my GPU for compute.

Okay, that's the question I'm going to address, rather than how to build the kernel with ROCm support (since I no longer think that will help).

At this point, I still don't have an AMD GPU to be able to test this out on directly, but I have done some GPU compute work on my nVideo 2070 under WSL2 now, at least.

So here's my latest thinking, looking at that past question, your question, and some other information:

  • ROCm likely isn't needed under WSL2. WSL2 makes the GPU available to Linux through a passthrough system using the Windows (not Linux) driver. If you look under /usr/lib/wsl, you'll find two directories which are mounted into your WSL2 instance -- ../drivers and ../lib. They are added to the library cache by the (also injected in), /etc/ld.so.conf/ld.wsl.conf.

    It's these libraries and drivers which give you access to the GPU.

  • When I looked at the other question last year, I didn't realize that ROCm was the Linux equivalent library for GPU compute. And if it does install as a module, then it's not likely to be useful under WSL2 anyway, as it won't have the direct access to the GPU that it needs. In retrospect, I should have been able to figure that out with what I knew then.

So what do you need to use Pytorch under WSL2 on your AMD GPU? Again, taking a guess here, but ...

  • This doc seems to indicate that you need Windows 11. While I thought that most of the GPU compute support was available in Windows 10, this may be one area that requires Windows 11. You don't mention your Windows version, so I'm not sure if this will be possible for you or not.

  • The latest AMD drivers for Windows. Most anything in the last year or so should be sufficient.

  • An appropriate Python environment. Microsoft recommends Conda. I ended up using Docker myself for TensorFlow, at least.

  • Dependencies are libblas3 libomp5 liblapack3

  • And then pip install pytorch-directml

Honestly, that should be about it. According to this doc, AMD is supported for PyTorch with DirectML.

When running TensorFlow on my nVidia under WSL2, I didn't require any additional native drivers/modules. I did have to provide the /usr/lib/wsl/lib directory to Docker, but that's only because I needed to run a specific older Python version for TensorFlow, and the easiest way to do that was via Docker.

6
  • Thank you for the response! I'm on Windows 10 21H2. I will try installing directml and see if that works. Out of curiosity, what is the reason for running in a virtual env like with conda, instead of just the general python environment?
    – Excelsior
    Sep 2 at 15:08
  • It looks like DirectML on Windows works in Win10, while the WSL version is only on Win11.
    – Excelsior
    Sep 2 at 15:12
  • @Excelsior That's a good point - Even if you can't run it in WSL2, you can still run the Windows version on Win10. Sep 2 at 15:26
  • I followed the instructions on the PyTorch with DirectML page and installed it. However, it still doesn't recognize my GPU. As such, it defaults to the CPU and runs MUCH slower than using the CPU through WSL. I tested multiplying 2 tensors together on the cpu; WSL: 10 sec; DirectML: 6 min 26 sec.
    – Excelsior
    Sep 2 at 16:27
  • 1
    I just tested pure PyTorch on Windows and it actually performed a little better than on WSL. I think the earlier issue may have been with either conda or the DirectML backend/framework
    – Excelsior
    Sep 9 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.