Skip to content

Commit 95281fb

Browse files
committed
Fix BufferTest expectation that buffer is nulled out (not true with AMD driver)
1 parent f5b9963 commit 95281fb

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,11 @@ public CLEvent copyBytesTo(CLQueue queue, CLBuffer destination, long sourceByteO
569569
#documentEventsToWaitForAndReturn()
570570
*/
571571
public CLEvent copyElementsTo(CLQueue queue, CLBuffer destination, long sourceElementOffset, long destinationElementOffset, long elementCount, CLEvent... eventsToWaitFor) {
572+
long elementSize = getElementSize();
572573
return copyBytesTo(queue, destination,
573-
sourceElementOffset * getElementSize(),
574-
destinationElementOffset * getElementSize(),
575-
elementCount * getElementSize(),
574+
sourceElementOffset * elementSize,
575+
destinationElementOffset * elementSize,
576+
elementCount * elementSize,
576577
eventsToWaitFor);
577578
}
578579

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,19 @@ public void testFill() {
166166
} catch (Throwable th) {}
167167
}
168168
@Test
169-
public void testCopyTo() {
170-
CLBuffer<Integer> b = context.createIntBuffer(CLMem.Usage.InputOutput, pointerToInts(1, 2, 3, 4));
171-
CLBuffer<Integer> out = context.createIntBuffer(CLMem.Usage.InputOutput, 4);
172-
CLEvent e = b.copyElementsTo(queue, out, 2, 1, 2);
173-
assertArrayEquals(new int[] { 0, 3, 4, 0 }, out.read(queue, e).getInts());
174-
175-
e = b.copyTo(queue, out);
176-
assertArrayEquals(new int[] { 1, 2, 3, 4 }, out.read(queue, e).getInts());
169+
public void testCopyTo_full() {
170+
CLBuffer<Integer> b = context.createIntBuffer(CLMem.Usage.InputOutput, pointerToInts(1, 2, 3, 4, 5, 6));
171+
CLBuffer<Integer> out = context.createIntBuffer(CLMem.Usage.InputOutput, 6);
172+
173+
CLEvent e = b.copyTo(queue, out);
174+
assertArrayEquals(new int[] { 1, 2, 3, 4, 5, 6 }, out.read(queue, e).getInts());
177175
}
176+
@Test
177+
public void testCopyTo_partial() {
178+
CLBuffer<Integer> b = context.createIntBuffer(CLMem.Usage.InputOutput, pointerToInts(1, 2, 3, 4, 5, 6));
179+
CLBuffer<Integer> out = context.createIntBuffer(CLMem.Usage.InputOutput, 6);
178180

181+
CLEvent e = b.copyElementsTo(queue, out, 2, 1, 2);
182+
assertArrayEquals(new int[] { 3, 4 }, out.read(queue, e).next().validElements(2).getInts());
183+
}
179184
}

0 commit comments

Comments
 (0)