andreinechaev / nvcc4jupyter

A plugin for Jupyter Notebook to run CUDA C/C++ code
MIT License
200 stars 87 forks source link

cuda_runtime.h error on kaggle #29

Closed mmmovania closed 7 months ago

mmmovania commented 8 months ago

I am trying to run a basic CUDA code on kaggle.

%%cuda
#include <stdio.h>
​
__global__ void HelloKernel() {
    printf("\tHello from GPU (device)\n");
}
​
int main() {
  printf("Hello from CPU (host) before kernel execution\n");
  HelloKernel<<<1,32>>>();
  cudaDeviceSynchronize();
  printf("Hello from CPU (host) after kernel execution\n");
  return 0;
}

The same code works fine on Colab but on Kaggle it gives this error.

cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.

Any idea on what might be causing this?

cosminc98 commented 8 months ago

Hello @mmmovania,

According to this post from the nvidia forum, it looks like a broken CUDA install. I will test it as soon as I have time to see if there is a solution for it.

cosminc98 commented 8 months ago

The problem seems to be that the "nvidia-cuda-toolkit" package is not installed. After this, it seems that another error appears that is related to a wrong version of gcc. You can fix it by adding a new directory to the PATH environment variable (at the beginning so it is prioritized) where you put a symbolic link to the correct gcc version that is already installed in kaggle.

Cell 1:

!apt install -y nvidia-cuda-toolkit; mkdir /usr/bin/priority; ln -s /usr/bin/gcc-8 /usr/bin/priority/gcc

Cell 2:

import os
os.environ["PATH"] = "/usr/bin/priority:" + os.environ["PATH"]

If this does not solve your problem feel free to reopen the issue.

mmmovania commented 8 months ago

Yep that was it. It works :)

cosminc98 commented 7 months ago

The extension now runs these steps for you when it is loaded.