X Tutup
Skip to content

Commit 092f2ee

Browse files
committed
JavaCL: ignore mismatching byte order for byte buffers, and replaced mentions to getKernelsDefaultByteOrder() by getByteOrder() (issue #336)
1 parent 8ead248 commit 092f2ee

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ private <T> CLBuffer<T> createBuffer(PointerIO<T> io, Pointer<T> data, long byte
683683
if (data != null) {
684684
ByteOrder contextOrder = getByteOrder();
685685
ByteOrder dataOrder = data.order();
686-
if (contextOrder != null && !dataOrder.equals(contextOrder))
687-
throw new IllegalArgumentException("Byte order of this context is " + contextOrder + ", but was given pointer to data with order " + dataOrder + ". Please create a pointer with correct byte order (Pointer.order(CLContext.getKernelsDefaultByteOrder())).");
686+
if (contextOrder != null && !dataOrder.equals(contextOrder) && data.getTargetSize() > 1)
687+
throw new IllegalArgumentException("Byte order of this context is " + contextOrder + ", but was given pointer to data with order " + dataOrder + ". Please create a pointer with correct byte order (Pointer.order(CLContext.getByteOrder())).");
688688
}
689689

690690
#declareReusablePtrsAndPErr()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Comparable extractValue(CLDevice device) {
166166
}
167167
},
168168
/**
169-
* Prefer devices with the same byte ordering as the hosting platform (see {@link CLDevice#getKernelsDefaultByteOrder() })
169+
* Prefer devices with the same byte ordering as the hosting platform (see {@link CLDevice#getByteOrder() })
170170
*/
171171
NativeEndianness {
172172
Comparable extractValue(CLDevice device) {

Core/src/test/java/com/nativelibs4java/opencl/BufferTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ public static List<Object[]> getDeviceParameters() {
3939
return AbstractCommon.getDeviceParameters();
4040
}
4141

42+
static ByteOrder otherOrder(ByteOrder o) {
43+
return o.equals(ByteOrder.BIG_ENDIAN) ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
44+
}
45+
46+
@Test(expected = IllegalArgumentException.class)
47+
public void testMismatchingOrder() {
48+
context.createBuffer(CLMem.Usage.InputOutput, allocateFloats(10).order(otherOrder(context.getByteOrder())));
49+
}
50+
@Test
51+
public void testMismatchingByteOrder() {
52+
context.createBuffer(CLMem.Usage.InputOutput, allocateBytes(10).order(otherOrder(context.getByteOrder())));
53+
}
54+
4255
@Test
4356
public void testReadWrite() {
4457
for (Class<?> bufferClass : bufferClasses)

0 commit comments

Comments
 (0)
X Tutup