Confusion of linking two cuda files

I originally wrote everything in one cuda file named, which is too big. Then I decide to split it and position the kernel part in a separate cuda file, say, and make it included in the

When editing the make file for them, it seems I even don’t need to mention the file at all and the make can find the file automatically via the include part. Is this correct?

Yes, with a caveat. The makefile doesn’t need to be changed for the compiler to find the included file. However, there now is a new dependency: You want be recompiled whenever changes, so that these changes are picked up for the generated binary. Unless your makefile has the necessary machinery for automatic dependency generation, you need to edit the makefile to reflect that dependency.

If e.g. the rule for in your makefile previously looked like this

main.o : someheader.h

        nvcc -arch compute_13 -c -o  main.o

you want to change that to

main.o : someheader.h

        nvcc -arch compute_13 -c -o  main.o

Some people would prefer to name as kernel.cuh to indicate it is not a separate compilation unit, but gets included into This is a matter of personal taste though.

Thanks for the reply!

What if I use prefix rule in Makefile?

$(CU_OBJ)= $(CU_SRC).o

Why this doesn’t work?

.SUFFIXES: .cu .cuh .h %cuh %h
nvcc -arch compute_20 -c -o main.o

$(CU_OBJ): $(CU_SRC) $(CU_H) $(C_H)

What happens if you try your above makefile? I don’t immediately see anything wrong with it apart from the obvious missing dots: %.cuh %.h