I have two versions of a function in an application, one implemented in CUDA and the other in standard C. They're in separate files, let's say cudafunc.h and func.h (the implementations are in cudafunc.cu and func.c). I'd like to offer two options when compiling the application. If the person has nvcc installed, it'll compile the cudafunc.h. Otherwise, it'll compile func.h.
Is there anyway to check if a machine has nvcc installed in the makefile and thus adjust the compiler accordingly?
Thanks a bunch,
This should work, included in your Makefile:
For GNU make, the recipe line(s) (after
test:
) actually start with tab characters.With the above preamble, you can use conditionals based on the
CC
variable to control the remainder of your Makefile.You would change the
test:
target to whatever target you want to be built conditionally.As a test, just run the above with
make
. You should get output ofnvcc
org++
based on whatever was detected.You could try a conditional, like
And then in the code that will call this function, it can test
#if USE_CUDA_FUNC
to decide which header to include and which interface to call.