compilling jni and cuda

hello,

I got a small problem, I recently came back to c/c++ (after 7 years of java) and started to write a simple application with cuda. The goal is basically to provide a jni interface to several chemical algorithms which are executed on a gt 8800.

Now the challenge it has to run on windows/linux/osx.

so my idea is, have a library which works on plain c -> done

have a library which works on c and cuda -> done

have a java api which works on c or cuda or falls back to a java implementation.

-> jni access not working

ok now the fun parts:

1. make file to build the jni lib

CUDA_INSTALL_PATH := "C:\Progra~1\NVIDIA~1\NVIDIA~1"

#

# simple make file for cuda on osx

# Add source files here

BASEDIR=../../../

TARGET_DIR=$(BASEDIR)target/

HEADER=$(TARGET_DIR)include

EXECUTABLE      := $(TARGET_DIR)classes/jacuda-jni.dll

CUFILES         := jni-similarity.cpp

# Includes

INCLUDES  += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I$(HEADER) -I$(TARGET_DIR)/classes -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32"

LIB       := -L$(CUDA_INSTALL_PATH)/common/lib -L$(TARGET_DIR)lib -L$(CUDA_INSTALL_PATH)/lib

DOLINK    := -lcuda -lcudart -ljacuda-c -ljacuda-cu

device:

	nvcc -lib -shared -o $(EXECUTABLE) $(CUFILES) $(INCLUDES) $(LIB) $(DOLINK)

emulate:

	nvcc -lib -shared -o $(EXECUTABLE) $(CUFILES) $(INCLUDES) $(LIB) $(DOLINK) -deviceemu

2. my jni class who calls the stuff (for now with an absolute path)

public class Similarity {

	/**

  * loads our library

  */

	static{

  System.load("F:\workspaces\c++\JaCuda\target\classes\jacuda-jni.dll");

	}

	

	/**

  * calculates the similarities between the unknown and the library spectra

  * @param lib

  * @param unk

  * @return

  */

	public static native float[] calculateSimilarity(String[] lib, String[] unk);

	

	

}

and finally i get an error message like:

“is not a win32 application”

anybody got some pointers for me how my make files have to look to make this thing work?

env:

visual c++ express

cygwin

java 1.5

maven 2.0.9

ant 1.6,*

thanks for your help!

Ok after spending some more hours over the problem and rewriting some code I wrote a makefile which works.

Basically my main error was that I wanted to link to many libraries together and sometimes the simplest approach with one library instead of 3 works best.

Anyway attached a makefile which generates a dll under windowsXp/cygwin/visual studio 8 and is able to be accessed using jni.

The complete project can be found under

https://sourceforge.net/projects/jacuda/

#

# simple make file for cuda on osx

# Add source files here

BASEDIR=../../

TARGET_DIR=$(BASEDIR)target/

HEADER=$(TARGET_DIR)include/

EXECUTABLE      := $(BASEDIR)Jacuda.dll

CUFILES         := ./c++/similarity.cpp ./c++/spectra.cpp ./c++/sfunction.cpp ./cuda/similarityCuda.cu ./jni/jni-similarity.cpp ./jni/jni-cuda-similarity.cpp

############################################################

####################

# Rules and targets

# Includes

INCLUDES  += -I. -I"$(CUDA_INC_PATH)" -I$(HEADER) -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/win32"  -I$(TARGET_DIR)classes 

#INCLUDES  += -I. -I"$(JAVA_HOME)/include" -I$(TARGET_DIR)classes 

# Libs

LIB       := -L$(CUDA_LIB_PATH)

#LIB :=

#DOLINK :=

DOLINK    := -lcuda -lcudart

device:

	cp cuda/*.h $(HEADER)

	cp c++/*.h $(HEADER)

	nvcc -O3 -shared -o $(EXECUTABLE)  $(CUFILES) $(INCLUDES) $(LIB) $(DOLINK)

emulate:

	cp cuda/*.h $(HEADER)

	cp c++/*.h $(HEADER)

	nvcc -O3 -shared -o $(EXECUTABLE)  $(CUFILES) $(INCLUDES) $(LIB) $(DOLINK) -deviceemu

clean:

	rm -f $(CCOFILES) $(EXECUTABLE)

moreclean: clean

	rm -f *.cu.c

the makefile for osx would be

#

# simple make file for cuda on osx

# Add source files here

BASEDIR=../../

TARGET_DIR=$(BASEDIR)target/

HEADER=$(TARGET_DIR)include/

EXECUTABLE      := $(BASEDIR)libJacuda.jnilib

CUFILES         := ./c++/similarity.cpp ./c++/spectra.cpp ./c++/sfunction.cpp ./cuda/similarityCuda.cu ./jni/jni-similarity.cpp ./jni/jni-cuda-similarity.cpp

############################################################

####################

# Rules and targets

CUDA_INSTALL_PATH := /usr/local/cuda

# Includes

INCLUDES  += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I$(HEADER) -I/System/Library/Frameworks/JavaVM.framework/Headers -I$(TARGET_DIR)classes 

#INCLUDES  += -I. -I/System/Library/Frameworks/JavaVM.framework/Headers -I$(TARGET_DIR)classes 

# Libs

LIB       := -L$(CUDA_INSTALL_PATH)/common/lib

#LIB :=

#DOLINK :=

DOLINK    := -lcuda -lcudart

device:

	mkdir $(HEADER)

	cp cuda/*.h $(HEADER)

	cp c++/*.h $(HEADER)

	nvcc -O3 -shared -o $(EXECUTABLE)  $(CUFILES) $(INCLUDES) $(LIB) $(DOLINK)

emulate:

	mkdir $(HEADER)

	cp cuda/*.h $(HEADER)

	cp c++/*.h $(HEADER)

	nvcc -O3 -shared -o $(EXECUTABLE)  $(CUFILES) $(INCLUDES) $(LIB) $(DOLINK) -deviceemu

clean:

	rm -f $(CCOFILES) $(EXECUTABLE)

moreclean: clean

	rm -f *.cu.c