Skip to content

Commit 0c99e14

Browse files
committed
JavaCL: some minor pointer tweaks
1 parent 2c01c57 commit 0c99e14

6 files changed

Lines changed: 30 additions & 24 deletions

File tree

Core/src/main/java/com/nativelibs4java/opencl/CLInfoGetter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public String getString(T entity, int infoName) {
5252
return "";
5353
}
5454
Pointer<?> buffer = allocateBytes(len + 1);
55-
error(getInfo(entity, infoName, pLen.get().intValue(), buffer, null));
55+
error(getInfo(entity, infoName, len, buffer, null));
5656

5757
return buffer.getCString();
5858
}
@@ -71,7 +71,7 @@ public Pointer<?> getMemory(T entity, int infoName) {
7171
Pointer<SizeT> pLen = allocate(SizeT.class);
7272
error(getInfo(entity, infoName, 0, null, pLen));
7373

74-
int len = pLen.get().intValue();
74+
int len = (int)pLen.getSizeT();
7575
Pointer<?> buffer = allocateBytes(len);
7676
error(getInfo(entity, infoName, len, buffer, null));
7777

@@ -84,8 +84,9 @@ public long[] getNativeSizes(T entity, int infoName, int n) {
8484
Pointer<SizeT> mem = allocateSizeTs(n);
8585
error(getInfo(entity, infoName, nBytes, mem, pLen));
8686

87-
if (pLen.get().longValue() != nBytes) {
88-
throw new RuntimeException("Not a Size[" + n + "] : len = " + pLen.get());
87+
int actualLen = (int)pLen.getSizeT();
88+
if (actualLen != nBytes) {
89+
throw new RuntimeException("Not a Size[" + n + "] : len = " + actualLen);
8990
}
9091
return mem.getSizeTs(n);
9192
}
@@ -132,7 +133,7 @@ public long getIntOrLong(T entity, int infoName) {
132133
Pointer<Long> mem = allocateLong();
133134
error(getInfo(entity, infoName, 8, mem, pLen));
134135

135-
switch (pLen.get().intValue()) {
136+
switch ((int)pLen.getSizeT()) {
136137
case 4:
137138
return mem.getInt();
138139
case 8:

Core/src/main/java/com/nativelibs4java/opencl/CLMem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public GLObjectInfo getGLObjectInfo() {
240240
Pointer<Integer> typeRef = allocateInt();
241241
Pointer<Integer> nameRef = allocateInt();
242242
CL.clGetGLObjectInfo(getEntity(), typeRef, nameRef);
243-
return new GLObjectInfo(GLObjectType.getEnum(typeRef.get()), nameRef.get());
243+
return new GLObjectInfo(GLObjectType.getEnum(typeRef.getInt()), nameRef.getInt());
244244
}
245245
public enum MapFlags implements com.nativelibs4java.util.ValuedEnum {
246246
Read(CL_MAP_READ),

Core/src/main/java/com/nativelibs4java/opencl/CLPlatform.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,15 @@ public CLContext createContext(Map<ContextProperties, Object> contextProperties,
381381
ids.set(i, devices[i].getEntity());
382382
}
383383

384-
Pointer<Integer> errRef = allocateInt();
384+
ReusablePointers ptrs = ReusablePointers.get();
385+
Pointer<Integer> pErr = ptrs.pErr;
385386

386387
long[] props = getContextProps(contextProperties);
387388
Pointer<SizeT> propsRef = props == null ? null : pointerToSizeTs(props);
388389
//Pointer<clCreateContext_arg1_callback> errCb = null;//pointerTo(errorCallback);
389390
//System.out.println("ERROR CALLBACK " + Long.toHexString(errCb.getPeer()));
390-
cl_context context = CL.clCreateContext((Pointer)propsRef, nDevs, ids, null, null, errRef);
391-
error(errRef.get());
391+
cl_context context = CL.clCreateContext((Pointer)propsRef, nDevs, ids, null, null, pErr);
392+
error(pErr.get());
392393
return new CLContext(this, ids, context);
393394
}
394395
/*
@@ -409,7 +410,7 @@ public CLDevice[] listDevices(CLDevice.Type type, boolean onlyAvailable) {
409410
Pointer<Integer> pCount = allocateInt();
410411
error(CL.clGetDeviceIDs(getEntity(), type.value(), 0, null, pCount));
411412

412-
int nDevs = pCount.get();
413+
int nDevs = pCount.getInt();
413414
if (nDevs <= 0) {
414415
return new CLDevice[0];
415416
}

Core/src/main/java/com/nativelibs4java/opencl/CLProgram.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ protected void setBinaries(Map<CLDevice, byte[]> binaries) {
172172
if (nDevices == 0)
173173
return;
174174

175-
Pointer<Integer> errBuff = allocateInt();
175+
ReusablePointers ptrs = ReusablePointers.get();
176+
Pointer<Integer> pErr = ptrs.pErr;
176177
int previousAttempts = 0;
177178
Pointer<Integer> statuses = allocateInts(nDevices);
178179
do {
179-
setEntity(CL.clCreateProgramWithBinary(context.getEntity(), nDevices, deviceIds, lengths, binariesArray, statuses, errBuff));
180-
} while (failedForLackOfMemory(errBuff.get(), previousAttempts++));
180+
setEntity(CL.clCreateProgramWithBinary(context.getEntity(), nDevices, deviceIds, lengths, binariesArray, statuses, pErr));
181+
} while (failedForLackOfMemory(pErr.getInt(), previousAttempts++));
181182
}
182183

183184
/**
@@ -302,12 +303,14 @@ public synchronized void allocate() {
302303
for (int i = 0; i < sources.length; i++) {
303304
lengths[i] = sources[i].length();
304305
}
305-
Pointer<Integer> errBuff = allocateInt();
306+
307+
ReusablePointers ptrs = ReusablePointers.get();
308+
Pointer<Integer> pErr = ptrs.pErr;
306309
cl_program program;
307310
int previousAttempts = 0;
308311
do {
309-
program = CL.clCreateProgramWithSource(context.getEntity(), sources.length, pointerToCStrings(sources), pointerToSizeTs(lengths), errBuff);
310-
} while (failedForLackOfMemory(errBuff.get(0), previousAttempts++));
312+
program = CL.clCreateProgramWithSource(context.getEntity(), sources.length, pointerToCStrings(sources), pointerToSizeTs(lengths), pErr);
313+
} while (failedForLackOfMemory(pErr.getInt(), previousAttempts++));
311314
setEntity(program);
312315
}
313316

@@ -834,7 +837,7 @@ public CLKernel[] createKernels() throws CLBuildException {
834837
int previousAttempts = 0;
835838
while (failedForLackOfMemory(CL.clCreateKernelsInProgram(getEntity(), 0, null, pCount), previousAttempts++)) {}
836839

837-
int count = pCount.get();
840+
int count = pCount.getInt();
838841
Pointer<cl_kernel> kerns = allocateTypedPointers(cl_kernel.class, count);
839842
previousAttempts = 0;
840843
while (failedForLackOfMemory(CL.clCreateKernelsInProgram(getEntity(), count, kerns, pCount), previousAttempts++)) {}
@@ -854,12 +857,13 @@ public CLKernel createKernel(String name, Object... args) throws CLBuildExceptio
854857
if (!built)
855858
build();
856859
}
857-
Pointer<Integer> errBuff = allocateInt();
860+
ReusablePointers ptrs = ReusablePointers.get();
861+
Pointer<Integer> pErr = ptrs.pErr;
858862
cl_kernel kernel;
859863
int previousAttempts = 0;
860864
do {
861-
kernel = CL.clCreateKernel(getEntity(), pointerToCString(name), errBuff);
862-
} while (failedForLackOfMemory(errBuff.get(0), previousAttempts++));
865+
kernel = CL.clCreateKernel(getEntity(), pointerToCString(name), pErr);
866+
} while (failedForLackOfMemory(pErr.getInt(), previousAttempts++));
863867

864868
CLKernel kn = new CLKernel(this, name, kernel);
865869
if (args.length != 0)

Core/src/main/java/com/nativelibs4java/opencl/JavaCL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static Pointer<cl_platform_id> getPlatformIDs() {
119119
Pointer<Integer> pCount = allocateInt();
120120
error(getPlatformIDs(0, null, pCount));
121121

122-
int nPlats = pCount.get();
122+
int nPlats = pCount.getInt();
123123
if (nPlats == 0)
124124
return null;
125125

@@ -234,7 +234,7 @@ public static CLPlatform[] listPlatforms() {
234234
Pointer<Integer> pCount = allocateInt();
235235
error(getPlatformIDs(0, null, pCount));
236236

237-
int nPlats = pCount.get();
237+
int nPlats = pCount.getInt();
238238
if (nPlats == 0)
239239
return new CLPlatform[0];
240240

Core/src/main/velocity/com/nativelibs4java/opencl/CLContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public CLImageFormat[] getSupportedImageFormats(CLBuffer.Flags flags, CLBuffer.O
257257
CL.clGetSupportedImageFormats(getEntity(), memFlags, imTyp, 0, null, pCount);
258258
//cl_image_format ft = new cl_image_format();
259259
//int sz = ft.size();
260-
int n = pCount.get();
260+
int n = pCount.getInt();
261261
if (n == 0) {
262262
n = 30; // There HAS to be at least one format. the spec even says even more, but in fact on Mac OS X / CPU there's only one...
263263
}
@@ -356,7 +356,7 @@ public CLDevice guessCurrentGLDevice() {
356356
else
357357
error(CL.clGetGLContextInfoKHR((Pointer)propsRef, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, Pointer.SIZE, mem, pCount));
358358

359-
if (pCount.get().intValue() != Pointer.SIZE)
359+
if (pCount.getSizeT() != Pointer.SIZE)
360360
throw new RuntimeException("Not a device : len = " + pCount.get().intValue());
361361

362362
Pointer p = mem.getPointer();

0 commit comments

Comments
 (0)