Does CUDA/NVCC support precompiled headers?

I understand that nvcc passes arguments to the C++ compiler (so on Linux its gcc by default). Since I can’t find it explicitly in the documentation or after searching on Google for a little bit, does nvcc support precompiled headers? I figure it would, but I am having trouble doing it in cuda. I got the c++ version working, though.

Command that works for pure STL:
g++ -std=c++11 pch/headers.h

Command that fails for pure STL:
nvcc -std=c++11 pch/headers.h

I get the error:

nvcc fatal   : Don't know what to do with 'pch/headers.h'
make: *** [makefile:14: pch/headers.h.gch] Error 1

Thanks in advance for any help.

pch/headers.h

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <complex>
#include <vector>

/* #include <cufft.h> */
/* #include <cufftXt.h> */

makefile

CXX = g++
# CXX = nvcc
CXXFLAGS = -std=c++17
OBJ = cuda_tet.o 

PCH_SRC = pch/headers.h
PCH_OUT = pch/headers.h.gch

main: $(OBJ) 
	$(CXX) $(CXXFLAGS) -o $@ $^

# Compiles your PCH
$(PCH_OUT): $(PCH_SRC) 
	$(CXX) $(CXXFLAGS) -o $@ $<

# the -include flag instructs the compiler to act as if lib.hpp
# were the first header in every source file
%.o: %.cpp $(PCH_OUT)
	$(CXX) $(CXXFLAGS) -include $(PCH_SRC) -c -o $@ $<

cuda_tet.cpp

#include "pch/headers.h"

#define PROJECT_NAME "cuda_tet"

int main(int argc, char **argv) {
	/* thrust::device_vector<float> temp; */
    if(argc != 1) {
        std::cout << argv[0] <<  "takes no arguments.\n";
        std::cout << argv[0] <<  "takes no arguments.\n";
        return 1;
    }
    std::cout << "This is project " << PROJECT_NAME << ".\n";
    return 0;
}

playing around with includes, I got it to compile with CUDA headers doing
g++ pch/headers.h -I/usr/local/cuda/include

Given this is an indirect method, nvcc seems to eschew using pre-compiled headers. Can someone explain why it would do this? Is there some negative performance with precompiled headers that someone new to CUDA would have no knowledge of.

I think its just a compiler “feature” that is not supported currently. If you would like to see a change in CUDA, you can file a bug.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.