Skip to content

Commit

Permalink
Merge pull request #131 from gigiblender/dev/misc/florin
Browse files Browse the repository at this point in the history
[fix][refactor] Deprecate OCLWriteNode and PTXWriteNode and fix stores
  • Loading branch information
gigiblender authored Jul 20, 2021
2 parents 30d9795 + df3150b commit eb2e828
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
import uk.ac.manchester.tornado.drivers.opencl.graal.lir.OCLKind;
import uk.ac.manchester.tornado.drivers.opencl.graal.lir.OCLWriteAtomicNode;
import uk.ac.manchester.tornado.drivers.opencl.graal.lir.OCLWriteAtomicNode.ATOMIC_OPERATION;
import uk.ac.manchester.tornado.drivers.opencl.graal.lir.OCLWriteNode;
import uk.ac.manchester.tornado.drivers.opencl.graal.nodes.AtomicAddNode;
import uk.ac.manchester.tornado.drivers.opencl.graal.nodes.CastNode;
import uk.ac.manchester.tornado.drivers.opencl.graal.nodes.FixedArrayNode;
Expand Down Expand Up @@ -362,10 +361,6 @@ private void lowerAtomicStoreIndexedNode(StoreAtomicIndexedNode storeIndexed) {
graph.replaceFixedWithFixed(storeIndexed, memoryWrite);
}

private boolean isSimpleCharOrShort(JavaKind elementKind, ValueNode value) {
return (elementKind == JavaKind.Char && value.getStackKind() != JavaKind.Object) || (elementKind == JavaKind.Short && value.getStackKind() != JavaKind.Object);
}

@Override
public void lowerStoreIndexedNode(StoreIndexedNode storeIndexed, LoweringTool tool) {
StructuredGraph graph = storeIndexed.graph();
Expand Down Expand Up @@ -597,17 +592,15 @@ private AddressNode createArrayAccess(StructuredGraph graph, LoadIndexedNode loa

private AbstractWriteNode createMemWriteNode(JavaKind elementKind, ValueNode value, ValueNode array, AddressNode address, StructuredGraph graph, StoreIndexedNode storeIndexed) {
AbstractWriteNode memoryWrite;
if (isSimpleCharOrShort(elementKind, value)) {
// XXX: This call is due to an error in Graal when storing a variable of type
// char or short. In future integrations with JVMCI and Graal, this issue is
// completely solved.
memoryWrite = graph.add(new OCLWriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), value, OnHeapMemoryAccess.BarrierType.NONE, elementKind));
} else if (isLocalIDNode(storeIndexed) || isPrivateIDNode(storeIndexed)) {
if (isLocalIDNode(storeIndexed) || isPrivateIDNode(storeIndexed)) {
address = createArrayLocalAddress(graph, array, storeIndexed.index());
memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), value, OnHeapMemoryAccess.BarrierType.NONE));
} else {
memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), value, OnHeapMemoryAccess.BarrierType.NONE));
}
ValueNode storeConvertValue = value;
Stamp valueStamp = value.stamp(NodeView.DEFAULT);
if (!(valueStamp instanceof OCLStamp) || !((OCLStamp) valueStamp).getOCLKind().isVector()) {
storeConvertValue = implicitStoreConvert(graph, elementKind, value);
}
memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), storeConvertValue, OnHeapMemoryAccess.BarrierType.NONE));
return memoryWrite;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaType;
import uk.ac.manchester.tornado.drivers.ptx.graal.lir.PTXKind;
import uk.ac.manchester.tornado.drivers.ptx.graal.lir.PTXWriteNode;
import uk.ac.manchester.tornado.drivers.ptx.graal.nodes.CastNode;
import uk.ac.manchester.tornado.drivers.ptx.graal.nodes.FixedArrayNode;
import uk.ac.manchester.tornado.drivers.ptx.graal.nodes.GlobalThreadIdNode;
Expand Down Expand Up @@ -501,21 +500,15 @@ private boolean isPrivateIDNode(LoadIndexedNode loadIndexedNode) {

private AbstractWriteNode createMemWriteNode(JavaKind elementKind, ValueNode value, ValueNode array, AddressNode address, StructuredGraph graph, StoreIndexedNode storeIndexed) {
AbstractWriteNode memoryWrite;
if (isSimpleCharOrShort(elementKind, value)) {
// XXX: This call is due to an error in Graal when storing a variable of type
// char or short. In future integrations with JVMCI and Graal, this issue is
// completely solved.
memoryWrite = graph.add(new PTXWriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), value, OnHeapMemoryAccess.BarrierType.NONE, elementKind));
} else if (isLocalIDNode(storeIndexed) || isPrivateIDNode(storeIndexed)) {
if (isLocalIDNode(storeIndexed) || isPrivateIDNode(storeIndexed)) {
address = createArrayLocalAddress(graph, array, storeIndexed.index());
memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), value, OnHeapMemoryAccess.BarrierType.NONE));
} else {
memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), value, OnHeapMemoryAccess.BarrierType.NONE));
}
ValueNode storeConvertValue = value;
Stamp valueStamp = value.stamp(NodeView.DEFAULT);
if (!(valueStamp instanceof PTXStamp) || !((PTXStamp) valueStamp).getPTXKind().isVector()) {
storeConvertValue = implicitStoreConvert(graph, elementKind, value);
}
memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), storeConvertValue, OnHeapMemoryAccess.BarrierType.NONE));
return memoryWrite;
}

private boolean isSimpleCharOrShort(JavaKind elementKind, ValueNode value) {
return (elementKind == JavaKind.Char && value.getStackKind() != JavaKind.Object) || (elementKind == JavaKind.Short && value.getStackKind() != JavaKind.Object);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,24 @@ public static void vectorChars(char[] a, char[] b, char[] c) {
}
}

public static void vectorAddByte(byte[] a, byte[] b, byte[] c) {
for (@Parallel int i = 0; i < c.length; i++) {
c[i] = (byte) (a[i] + b[i]);
}
}

public static void addChars(char[] a, int[] b) {
for (@Parallel int i = 0; i < a.length; i++) {
a[i] += b[i];
}
}

public static void initializeSequentialByte(byte[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = 21;
}
}

public static void initializeSequential(int[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = 1;
Expand Down Expand Up @@ -120,6 +132,23 @@ public void testWarmUp() {
}
}

@Test
public void testInitByteArray() {
final int N = 128;
byte[] data = new byte[N];

TaskSchedule s0 = new TaskSchedule("s0");
assertNotNull(s0);

s0.task("t0", TestArrays::initializeSequentialByte, data);
s0.streamOut(data).warmup();
s0.execute();

for (int i = 0; i < N; i++) {
assertEquals(21, data[i]);
}
}

@Test
public void testInitNotParallel() {
final int N = 128;
Expand Down Expand Up @@ -329,6 +358,31 @@ public void testVectorChars() {
}
}

@Test
public void testVectorBytes() {
final int numElements = 4096;
byte[] a = new byte[numElements];
byte[] b = new byte[numElements];
byte[] c = new byte[numElements];

IntStream.range(0, numElements).parallel().forEach(idx -> {
a[idx] = 10;
b[idx] = 11;
});

//@formatter:off
new TaskSchedule("s0")
.streamIn(a, b)
.task("t0", TestArrays::vectorAddByte, a, b, c)
.streamOut(c)
.execute();
//@formatter:on

for (byte value : c) {
assertEquals(21, value);
}
}

/**
* Inspired by the CUDA Hello World from Computer Graphics:
*
Expand Down

0 comments on commit eb2e828

Please sign in to comment.