Call CUDA from FORTRAN How to call CUDA from FORTRAN

Hello everyone

I am trying to call CUDA from FORTRAN. I have tried to call CUDA the same way as we call CUDA from “C”, but it did not work out. I have read a number of articles online which said we can call C from FORTRAN and make C call CUDA. Could anyone help me. I have got my programs written but it does not work, it gives me errors when I try to make the .exe file. Here are the simple programs I am trying to generate the .exe for

The Header file b.h

#ifndef _B_H
#define _B_H

The FORTRAN fcode.F

  program fcode
  integer a1(4,4)
  integer a2(4,4)
  integer  r(4,4)
  integer i,j
  call ccode()
  do i=1,4
  do j=1,4
  end do
  end do
  write(UNIT=*,FMT=*) 'This is the Fortarn Code'
  do i=1,4
  do j=1,4
  r(i,j) = a1(i,j) + a2(i,j)
  end do
  end do

The C code ccode.c

#include “b.h”
extern void kernel_wrapper();
printf(“This is the C code”);

The CUDA code

#include “b.h”

extern “C” void kernel_wrapper();

global void kernel()

void kernel_wrapper()
dim3 dimBlock(4,4);
dim3 dimGrid(1,1);

kernel <<<dimGrid, dimBlock >>> ();
printf(“This is the CUDA code”);


The make file Makefile

run: fcode.o ccode.o cucode.o
gcc -L/usr/local/cuda/lib -lcudart -o run fcode.o ccode.o cucode.o

fcode.o: fcode.o
gfortran -c -o fcode.o

ccode.o: ccode.o
gcc -I/usr/local/cuda/lib -c -o ccode.o ccode.c

nvcc -c -o cucode.o

Take a look at…ortran_Cuda.tgz

or at the toolkit presentation in one of the CUDA tutorial (SC07,SC08,ISC09)