Skip to content

Commit 8af602f

Browse files
committed
Added CLDevice.getPartitionMaxSubDevices(), fixed (?) getPartitionProperties(), skip tests that can't succeed
1 parent afa7dd1 commit 8af602f

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,15 +727,27 @@ public static long getValue(EnumSet<PartitionType> set) {
727727
return EnumValues.getValue(set);
728728
}
729729
730-
public static EnumSet<PartitionType> getEnumSet(long v) {
731-
return EnumValues.getEnumSet(v, PartitionType.class);
730+
public static PartitionType getEnum(long v) {
731+
return EnumValues.getEnum(v, PartitionType.class);
732732
}
733733
}
734734
735-
/** TODO */
736735
@InfoName("CL_DEVICE_PARTITION_PROPERTIES")
737736
public EnumSet<PartitionType> getPartitionProperties() {
738-
return PartitionType.getEnumSet(infos.getIntOrLong(getEntity(), CL_DEVICE_PARTITION_PROPERTIES));
737+
EnumSet<PartitionType> ret = EnumSet.noneOf(PartitionType.class);
738+
Pointer<?> ptr = infos.getPointer(getEntity(), CL_DEVICE_PARTITION_PROPERTIES);;
739+
if (ptr != null) {
740+
Pointer<SizeT> props = ptr.as(SizeT.class);
741+
for (long i = 0, n = props.getValidElements(); i < n; i++) {
742+
ret.add(PartitionType.getEnum(props.getSizeTAtIndex(i)));
743+
}
744+
}
745+
return ret;
746+
}
747+
748+
@InfoName("CL_DEVICE_PARTITION_MAX_SUB_DEVICES")
749+
public int getPartitionMaxSubDevices() {
750+
return infos.getInt(getEntity(), CL_DEVICE_PARTITION_MAX_SUB_DEVICES);
739751
}
740752
741753
/** TODO */

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,61 @@
1414

1515
import org.junit.*;
1616

17-
import com.nativelibs4java.test.MiscTestUtils;
1817
import com.nativelibs4java.util.NIOUtils;
1918
import org.bridj.*;
2019
import java.nio.ByteOrder;
2120
import static org.bridj.Pointer.*;
2221
import java.nio.ByteOrder;
23-
import java.util.List;
22+
import java.util.*;
23+
import org.junit.runner.RunWith;
2424
import org.junit.runners.Parameterized;
2525

2626
/**
2727
*
2828
* @author ochafik
2929
*/
30-
public class DeviceTest extends AbstractCommon {
30+
@RunWith(Parameterized.class)
31+
public class DeviceTest {
32+
private final CLDevice device;
33+
3134
public DeviceTest(CLDevice device) {
32-
super(device);
35+
this.device = device;
36+
37+
System.out.println(device);
38+
System.out.println("\tmax sub-devices: " + device.getPartitionMaxSubDevices());
39+
System.out.println("\tpartition properties: " + device.getPartitionProperties());
3340
}
3441

3542
@Parameterized.Parameters
3643
public static List<Object[]> getDeviceParameters() {
37-
return AbstractCommon.getDeviceParameters();
44+
List<Object[]> ret = new ArrayList<Object[]>();
45+
for (CLPlatform platform : JavaCL.listPlatforms()) {
46+
for (CLDevice device : platform.listAllDevices(true)) {
47+
ret.add(new Object[] { device });
48+
}
49+
}
50+
return ret;
3851
}
39-
@Ignore
52+
4053
@Test
4154
public void testSplitEqually() {
55+
if (!device.getPartitionProperties().contains(CLDevice.PartitionType.Equally)) return;
56+
4257
int computeUnits = device.getMaxComputeUnits();
4358
System.out.println("computeUnits = " + computeUnits);
44-
int subComputeUnits = 1;//computeUnits / 2;
59+
int subComputeUnits = computeUnits / 2;
4560

4661
CLDevice[] subDevices = device.createSubDevicesEqually(subComputeUnits);
4762
for (CLDevice subDevice : subDevices) {
4863
assertEquals(subComputeUnits, subDevice.getMaxComputeUnits());
4964
checkParent(device, subDevice);
5065
}
5166
}
52-
@Ignore
67+
5368
@Test
5469
public void testSplitByCounts() {
70+
if (!device.getPartitionProperties().contains(CLDevice.PartitionType.ByCounts)) return;
71+
5572
long[] counts = new long[] { 2, 4, 8 };
5673
CLDevice[] subDevices = device.createSubDevicesByCounts(counts);
5774
assertEquals(counts.length, subDevices.length);
@@ -63,9 +80,11 @@ public void testSplitByCounts() {
6380
i++;
6481
}
6582
}
66-
@Ignore
83+
6784
@Test
6885
public void testSplitByAffinity() {
86+
if (!device.getPartitionProperties().contains(CLDevice.PartitionType.ByAffinityDomain)) return;
87+
6988
CLDevice[] subDevices = device.createSubDevicesByAffinity(CLDevice.AffinityDomain.NextPartitionable);
7089
assertTrue(subDevices.length > 1);
7190
for (CLDevice subDevice : subDevices) {
@@ -76,7 +95,7 @@ public void testSplitByAffinity() {
7695
private void checkParent(CLDevice parent, CLDevice child) {
7796
assertSame(device, child.getParent());
7897
// Force a get info CL_DEVICE_PARENT_DEVICE.
79-
assertSame(device, new CLDevice(platform, null, child.getEntity(), false).getParent());
98+
assertSame(device, new CLDevice(device.getPlatform(), null, child.getEntity(), false).getParent());
8099
}
81100

82101
}

0 commit comments

Comments
 (0)