Can't locate cuda_runtime.h when compiling CUDA and C++ files

Hello!

I’ve recently switched devices (I was using a Jetson Nano and now I’m using a Laptop with Nvidia GeForce RTX 2060), and I’m having problems compiling/linking my C++ and CUDA code. To clarify, this code wasn’t run on the Jetson Nano, but I am slightly more used to writing and compiling CUDA for the Nano.

Right now I only have one CUDA .cu file, which has a

#include <cuda_runtime.h>

header.

I’m compiling my C++ and CUDA files in a makefile with the following structure:

all: test

test: cudacode.o
  g++ -std=c++11 -o test main.cpp -L/usr/local/cuda -lucdadevrt -lcudart cudacode.o

cudacode.o :
  nvcc -c -arch=sm_75 cuda_file.cu -o cudacode.o

When I make this, I get the following error triggered in my .cu file:

fatal error: cuda_runtime.h: No such file or directory

I feel like I’ve gone through every possible stack overflow and nvidia discussion post on this issue, and tried a few different variations of this makefile, but haven’t had any luck.

For additional context:

  1. My compute capability is 7.5.

  2. running “sudo find / -name cuda_runtime.h” returns /usr/local/cuda-11.5/targets/x86_64-linux/include/cuda_runtime.h

  3. running “sudo find / -name cuda” returns multiple things but the two important ones are /usr/local/cuda-11.5/targets/x86_64-linux/include/cuda and /usr/local/cuda
    (in addition to noting that I am using cuda-11.5, I also changed the link -L/usr/local/cuda in the makefile to -L/usr/local/cuda-11.5 with no luck).

Any help or guidance would be very much appreciated!

Edit

If I compile with the single line

nvcc -arch=sm_75 cuda_file.cu main.cpp 

It seems to find the #include<cuda_runtime.h> file okay, but it throws errors, not recognising cuda syntax like “<<<” or “blockIdx”

Hi Sophie,

You might need an:

#include <device_launch_parameters.h>

No luck unfortunately :(

Running the makefile returns

fatal error: device_launch_parameters.h: no such file or directory

And compiling with the single nvcc line in my edit returns half of the previous error (it looks like it can now find thredIdx, but it doesn’t know what <<< or >>> are.

I’ve semi-fixed the problem. I can get the nvcc compiler line (see edit) working, but I’m still having trouble with the makefile.

My problem was, I included the .cu file in the main .cpp file, and didn’t make a wrapper for the .cu file. I followed this discussion and got it working.

Still not sure why the makefile isn’t working though. Any thoughts?