8000 Changes to make the wrapper compile with arrayfire 3.0 · wcork/arrayfire-java@c068c9f · GitHub
[go: up one dir, main page]

Skip to content

Commit c068c9f

Browse files
committed
Changes to make the wrapper compile with arrayfire 3.0
1 parent a66274f commit c068c9f

File tree

4 files changed

+30
-70
lines changed

4 files changed

+30
-70
lines changed

Makefile

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
AF_PATH ?= /opt/arrayfire
2-
CUDA_PATH ?= /usr/local/cuda/
3-
OCL_PATH ?= $(AF_PATH)
42

53
ifneq ($(shell uname), Linux)
64
$(error Only Linux supported for Java)
75
endif
86

9-
ifeq ($(shell uname -m), x86_64)
10-
LIB:=lib64
11-
else
12-
LIB:=lib
13-
endif
7+
LIB:=lib
148

159
AF_CFLAGS = -I$(AF_PATH)/include
1610
AF_CFLAGS += -I$(JAVA_HOME)/include
@@ -24,12 +18,10 @@ AF_JAVA_COM = $(shell ls com/arrayfire/*.java)
2418
AF_JAVA_CLASSES = $(patsubst %.java, %.class, $(AF_JAVA_COM))
2519

2620
ifeq ($(findstring opencl, $(MAKECMDGOALS)), opencl)
27-
AF_CFLAGS += -DAFCL -I$(OCL_PATH)/include
28-
AF=afcl
21+
AF=afopencl
2922
AF_JAVA_LIB_EXT=$(patsubst %.so, %_ocl.so, $(AF_JAVA_LIB))
3023
else
31-
AF_CFLAGS += -I$(CUDA_PATH)/include
32-
AF=afcu
24+
AF=afcuda
3325
AF_JAVA_LIB_EXT=$(patsubst %.so, %_cuda.so, $(AF_JAVA_LIB))
3426
endif
3527

@@ -51,13 +43,10 @@ $(AF_JAVA_JAR): $(AF_JAVA_LIB) $(AF_JAVA_CLASSES)
5143
$(AF_JAVA_LIB): $(AF_JAVA_LIB_EXT)
5244
cp $(AF_JAVA_LIB_EXT) $(AF_JAVA_LIB)
5345
cp $(AF_LIB_PATH)/lib$(AF).so $(AF_JAVA_PATH)/$(LIB)
54-
ifeq ($(findstring opencl, $(MAKECMDGOALS)), opencl)
55-
cp $(AF_LIB_PATH)/libcl* $(AF_JAVA_PATH)/$(LIB)
56-
endif
5746

5847
$(AF_JAVA_LIB_EXT): $(AF_JAVA_PATH)/src/java_wrapper.cpp
5948
gcc -shared -fPIC $< $(AF_CFLAGS) -L$(AF_LIB_PATH) -l$(AF) -o $@
6049

6150
clean:
62-
rm -f lib/*.so lib64/*.so $(AF_JAVA_JAR)
51+
rm -f lib/*.so $(AF_JAVA_JAR)
6352
rm -f $(AF_JAVA_CLASSES)

examples/Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
ifeq ($(shell uname -m), x86_64)
2-
LIB:=lib64
3-
else
4-
LIB:=lib
5-
endif
1+
LIB:=lib
62

73
AF_JAVA_PATH?=../
84
AF_JAVA_JAR?=$(AF_JAVA_PATH)/ArrayFire.jar
95
AF_JAVA_LIB_PATH?=$(AF_JAVA_PATH)/$(LIB)
106

117
CLASSES=$(patsubst %.java, %.class, $(shell ls *.java))
12-
BINS=$(patsubst %.class, %, $(CLASSES))
8+
BINS=$(patsubst %.class, %, $(CLASSES))
139

1410
all: $(CLASSES)
1511

1612
run: $(BINS)
1713

1814
%: %.class
19-
LD_LIBRARY_PATH=$(AF_JAVA_LIB_PATH) java -cp .:$(AF_JAVA_JAR) $@
15+
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(AF_JAVA_LIB_PATH) java -cp .:$(AF_JAVA_JAR) $@
2016

2117
%.class: %.java
2218
javac -cp $(AF_JAVA_PATH)/ArrayFire.jar $<

lib64/.gitignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/java_wrapper.cpp

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <vector>
22
#include <arrayfire.h>
3-
#include <af/utils.h>
3+
#include <af/util.h>
44
#include "java_wrapper.h"
55

66
#ifdef ANDROID
@@ -26,6 +26,9 @@ JNIEXPORT void JNICALL Java_com_arrayfire_Array_info(JNIEnv *env, jclass clazz)
2626
}
2727
}
2828

29+
using af::cfloat;
30+
using af::cdouble;
31+
2932
JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createRanduArray(JNIEnv *env, jclass clazz, jintArray dims, jint type)
3033
{
3134
jlong ret;
@@ -158,13 +161,8 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createArrayFromFloatComplex(JNI
158161
jfloat real = env->GetFloatField(obj, re);
159162
jfloat imag = env->GetFloatField(obj, im);
160163

161-
#ifdef AFCL
162-
tmp[i].s[0] = real;
163-
tmp[i].s[1] = imag;
164-
#else
165-
tmp[i].x = real;
166-
tmp[i].y = imag;
167-
#endif
164+
tmp[i].real = real;
165+
tmp[i].imag = imag;
168166
}
169167

170168
af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3],tmp);
@@ -207,13 +205,8 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createArrayFromDoubleComplex(JN
207205
jdouble real = env->GetDoubleField(obj, re);
208206
jdouble imag = env->GetDoubleField(obj, im);
209207

210-
#ifdef AFCL
211-
tmp[i].s[0] = real;
212-
tmp[i].s[1] = imag;
213-
#else
214-
tmp[i].x = real;
215-
tmp[i].y = imag;
216-
#endif
208+
tmp[i].real = real;
209+
tmp[i].imag = imag;
217210
}
218211

219212
af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3],tmp);
@@ -287,20 +280,14 @@ JNIEXPORT jobjectArray JNICALL Java_com_arrayfire_Array_getFloatComplexFromArray
287280
cfloat *tmp = (*A).host<cfloat>();
288281

289282
for (int i = 0; i < size; i++) {
290-
#ifdef AFCL
291-
float re = tmp[i].s[0];
292-
float im = tmp[i].s[1];
293-
#else
294-
float re = tmp[i].x;
295-
float im = tmp[i].y;
296-
#endif
283+
float re = tmp[i].real;
284+
float im = tmp[i].imag;
297285
jobject obj = env->NewObject(cls, id, re, im);
298286

299287
env->SetObjectArrayElement(result, i, obj);
300288
}
301289

302-
af::array::free(tmp);
303-
290+
delete[] tmp;
304291
} catch (af::exception& e) {
305292
result = NULL;
306293
} catch (std::exception& e) {
@@ -325,20 +312,14 @@ JNIEXPORT jobjectArray JNICALL Java_com_arrayfire_Array_getDoubleComplexFromArra
325312
cdouble *tmp = (*A).host<cdouble>();
326313

327314
for (int i = 0; i < size; i++) {
328-
#ifdef AFCL
329-
double re = tmp[i].s[0];
330-
double im = tmp[i].s[1];
331-
#else
332-
double re = tmp[i].x;
333-
double im = tmp[i].y;
334-
#endif
315+
double re = tmp[i].real;
316+
double im = tmp[i].imag;
335317
jobject obj = env->NewObject(cls, id, re, im);
336318

337319
env->SetObjectArrayElement(result, i, obj);
338320
}
339321

340-
af::array::free(tmp);
341-
322+
delete[] tmp;
342323
} catch (af::exception& e) {
343324
result = NULL;
344325
} catch (std::exception& e) {
@@ -445,13 +426,13 @@ UNARY_OP_DEF(sqrt)
445426
{ \
446427
try { \
447428
af::array *A = (af::array*)(a); \
448-
if (A->type() == af::f32) \
429+
if (A->type() == f32) \
449430
return af::func<float>( (*A) ); \
450-
if (A->type() == af::s32) \
431+
if (A->type() == s32) \
451432
return af::func<int>( (*A) ); \
452-
if (A->type() == af::f64) \
433+
if (A->type() == f64) \
453434
return af::func<double>( (*A) ); \
454-
if (A->type() == af::b8) \
435+
if (A->type() == b8) \
455436
return af::func<float>( (*A) ); \
456437
return af::NaN; \
457438
} catch(af::exception& e) { \
@@ -617,7 +598,7 @@ void blur_logic(unsigned char* bufIn, unsigned char* bufOut, int* info)
617598
convert_uchar2float(&inptr,bufIn,imgsz, chnls);
618599

619600
af::array img(width,height,chnls,inptr);
620-
af::array ker = af::gaussiankernel(5,5);
601+
af::array ker = af::gaussianKernel(5,5);
621602
af::array res = af::convolve(img, ker);
622603
res(af::span, af::span, 3) = 1;
623604
res.host(outptr);
@@ -701,7 +682,7 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Image_meanshift(JNIEnv *env, jclass c
701682
try {
702683
af::array *A = (af::array*)(a);
703684
af::array *res = new af::array();
704-
(*res) = af::meanshift( (*A) , space, color, iter );
685+
(*res) = af::meanShift( (*A) , space, color, iter );
705686
ret = (jlong)(res);
706687
} catch(af::exception& e) {
707688
ret = 0;
@@ -765,7 +746,7 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Image_resize1(JNIEnv *env, jclass cla
765746
try {
766747
af::array *A = (af::array*)(a);
767748
af::array *res = new af::array();
768-
(*res) = af::resize( scale, (*A) , method );
749+
(*res) = af::resize( scale, (*A));
769750
ret = (jlong)(res);
770751
} catch(af::exception& e) {
771752
ret = 0;
@@ -781,7 +762,7 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Image_resize2(JNIEnv *env, jclass cla
781762
try {
782763
af::array *A = (af::array*)(a);
783764
af::array *res = new af::array();
784-
(*res) = af::resize( scalex, scaley, (*A) , method );
765+
(*res) = af::resize( scalex, scaley, (*A));
785766
ret = (jlong)(res);
786767
} catch(af::exception& e) {
787768
ret = 0;
@@ -797,7 +778,7 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Image_resize3(JNIEnv *env, jclass cla
797778
try {
798779
af::array *A = (af::array*)(a);
799780
af::array *res = new af::array();
800-
(*res) = af::resize( (unsigned int)height, (unsigned int)width, (*A) , method );
781+
(*res) = af::resize( (unsigned int)height, (unsigned int)width, (*A));
801782
ret = (jlong)(res);
802783
} catch(af::exception& e) {
803784
ret = 0;

0 commit comments

Comments
 (0)
0