I’ve created a glue kernel routine in C that is callable from my gfortran module.
How do I link my gfortran objects w/ nvcc objects? Do I just compile them w/ gfortran (-c) and
then use
nvcc mykernel.c f1.o f2.o -o my_executable
I imagine there are library issues.
Anybody do this?
Vince Schuster
Essentially you are doing it backwards.
Fist just compile your cuda code, “nvcc -c mykernel”
Also compile your fortran code with “gfortran -c myfortrancode”
Link all the object files together with gfortran, be sure to include a library path and include path to libcuda, and libcudart
Here is a Makefile that I have used to do this:
[codebox]
NVCC := /usr/local/cuda/bin/nvcc
LD_LIBRARY_PATH := /usr/local/cuda/lib64
LD_INCLUDE_PATH := /usr/local/cuda/include,/usr/local/pgplot
CUDAFORTRAN_FLAGS := -L $(LD_LIBRARY_PATH) -I $(LD_INCLUDE_PATH) -lcudart -lcuda
PGPLOT_FLAGS := -L/usr/local/pgplot -lcpgplot -lpgplot -lX11 -lgcc -lm
PGPLOT_DIR = /usr/local/pgplot/
NVCCFLAGS := -gencode arch=compute_20,code=sm_20 -I $(LD_INCLUDE_PATH)
all: cuda plottest run
cuda: pspline.cu
$(NVCC) -c pspline.cu $(NVCCFLAGS) $(PGPLOT_FLAGS)
plottest:
gfortran -o pspline pspline.o $(PGPLOT_FLAGS) $(CUDAFORTRAN_FLAGS)
run:
./pspline
[/codebox]
You can do this with any fortran compiler, I’ve personally done it with both gfortran and ifort.
There is a very good guide here:
http://www.computationalmathematics.org/to…om_fortran.html