Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement and benchmark ArrowOperationPlus node #10150

Merged
merged 43 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a56aa05
Test for +[Int8] behavior
JaroslavTulach May 31, 2024
a9e07f1
Generalizing parser to support +
JaroslavTulach May 31, 2024
f6d7e84
Trivial implementation of ArrowOperationPlus
JaroslavTulach Jun 3, 2024
2f78ea9
Merge remote-tracking branch 'origin/develop' into wip/jtulach/PocArr…
JaroslavTulach Jun 3, 2024
a044cb0
Benchmark Arrow + implementation against Table one
JaroslavTulach Jun 3, 2024
9c70d17
Invoke foreign function with arguments
JaroslavTulach Jun 3, 2024
a008b3d
Allow Int64 value to be null
JaroslavTulach Jun 3, 2024
a6248a1
Support isNull arguments
JaroslavTulach Jun 3, 2024
2f16308
Measure just arrow_plus performance
JaroslavTulach Jun 3, 2024
2bfba6e
Speeding up by using different interop library for different element
JaroslavTulach Jun 3, 2024
760a106
Tests for Int64 buffer
JaroslavTulach Jun 3, 2024
f9a802e
For some reasons there are nulls in the array
JaroslavTulach Jun 3, 2024
68d9306
Fix byte mask used for index calculation
hubertp Jun 3, 2024
1dbbae1
Tell the compiler static values are final constants
JaroslavTulach Jun 4, 2024
ea36864
Prefer final fields and hope they will be constant
JaroslavTulach Jun 4, 2024
82ca3e7
Use null bitmapBuffer when there are no null values
JaroslavTulach Jun 4, 2024
c36d22e
Make sure unit tests work
JaroslavTulach Jun 4, 2024
33f8694
Measure arrow x + u (and not y)
JaroslavTulach Jun 4, 2024
ac3eda6
Inline ByteBuffer.getLong and putLong methods
JaroslavTulach Jun 4, 2024
869fd76
Using Specialized Libraries
JaroslavTulach Jun 4, 2024
87ff552
Brute force speedup
JaroslavTulach Jun 4, 2024
d78e305
Eliminating write overhead
JaroslavTulach Jun 4, 2024
13e244b
Let's abstract direct buffer access with a Truffle Iterator
JaroslavTulach Jun 5, 2024
62cf4fb
Merge remote-tracking branch 'origin/develop' into wip/jtulach/PocArr…
JaroslavTulach Jun 5, 2024
1b126a8
Benchmarking overflowing plus
JaroslavTulach Jun 7, 2024
fa140c0
Introducing AppendNode
JaroslavTulach Jun 7, 2024
f8eefc3
Using (unoptimized) builder.append again
JaroslavTulach Jun 7, 2024
801184a
Cache logical layout in the plus operation
JaroslavTulach Jun 7, 2024
5dc5d77
Value to number conversion node
JaroslavTulach Jun 7, 2024
46f28d0
AppendNode via ValueToNumberNode
JaroslavTulach Jun 7, 2024
fc42f06
Removing unused crap
JaroslavTulach Jun 7, 2024
c993a91
Runtime.assert that the Column results are the same as Arrow results
JaroslavTulach Jun 7, 2024
f10bd06
PutNode to optimize AppendNode
JaroslavTulach Jun 7, 2024
a661aca
Merging with develop
JaroslavTulach Jun 7, 2024
72c89a1
Proper, but slow, support for nulls in the arrow vectors
JaroslavTulach Jun 7, 2024
5e54a10
Manipulate bitmapBuffer from nodes
JaroslavTulach Jun 8, 2024
5fcba2d
Introducing NullIterator that reads bitmapBuffer
JaroslavTulach Jun 8, 2024
d03e484
Introducing executeOp and eliminating overhead of ArithmeticException
JaroslavTulach Jun 8, 2024
3f49737
Making the graph smaller by eliminating handling of exceptional state
JaroslavTulach Jun 8, 2024
55ee7cc
Math.addExact is intrinsified. Use it! But only until first Arithmeti…
JaroslavTulach Jun 8, 2024
2bb6ebc
Benchmark work with an array with occational Nothing values
JaroslavTulach Jun 8, 2024
bce1892
Merge branch 'develop' into wip/jtulach/PocArrowPlus10056
mergify[bot] Jun 10, 2024
807fd6d
create_arrow_columns function
JaroslavTulach Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,41 @@ public record Result(PhysicalLayout physicalLayout, LogicalLayout logicalLayout,

public static Result parse(Source source) {
String src = source.getCharacters().toString();
Matcher m = NEW_ARRAY_CONSTR.matcher(src);
Matcher m = PATTERN.matcher(src);
if (m.find()) {
try {
var layout = LogicalLayout.valueOf(m.group(1));
return new Result(PhysicalLayout.Primitive, layout, Mode.Allocate);
var layout = LogicalLayout.valueOf(m.group(2));
var mode = Mode.parse(m.group(1));
if (layout != null && mode != null) {
return new Result(PhysicalLayout.Primitive, layout, mode);
}
} catch (IllegalArgumentException iae) {
// propagate warning
return null;
}
}

m = CAST_PATTERN.matcher(src);
if (m.find()) {
try {
var layout = LogicalLayout.valueOf(m.group(1));
return new Result(PhysicalLayout.Primitive, layout, Mode.Cast);
} catch (IllegalArgumentException iae) {
// propagate warning
return null;
}
}
return null;
}

private static final Pattern NEW_ARRAY_CONSTR = Pattern.compile("^new\\[(.+)\\]$");
private static final Pattern CAST_PATTERN = Pattern.compile("^cast\\[(.+)\\]$");
private static final Pattern PATTERN = Pattern.compile("^([a-z\\+]+)\\[(.+)\\]$");

public enum Mode {
Allocate,
Cast
Allocate("new"),
Cast("cast"),
Plus("+");

private final String op;

private Mode(String text) {
this.op = text;
}

static Mode parse(String operation) {
for (var m : values()) {
if (m.op.equals(operation)) {
return m;
}
}
return null;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import com.oracle.truffle.api.nodes.RootNode;
import org.enso.interpreter.arrow.ArrowLanguage;
import org.enso.interpreter.arrow.ArrowParser;
import org.enso.interpreter.arrow.runtime.ArrowCastToFixedSizeArrayFactory;
import org.enso.interpreter.arrow.runtime.ArrowFixedSizeArrayFactory;
import org.enso.interpreter.arrow.runtime.ArrowOperationPlus;

public class ArrowEvalNode extends RootNode {
private final ArrowParser.Result code;

@Child private ArrowFixedSizeNode fixedPhysicalLayout = ArrowFixedSizeNode.create();
@Child private ArrowCastFixedSizeNode castToFixedPhysicalLayout = ArrowCastFixedSizeNode.create();

public static ArrowEvalNode create(ArrowLanguage language, ArrowParser.Result code) {
return new ArrowEvalNode(language, code);
}
Expand All @@ -25,8 +25,13 @@ private ArrowEvalNode(ArrowLanguage language, ArrowParser.Result code) {
public Object execute(VirtualFrame frame) {
return switch (code.physicalLayout()) {
case Primitive -> switch (code.mode()) {
case Allocate -> fixedPhysicalLayout.execute(code.logicalLayout());
case Cast -> castToFixedPhysicalLayout.execute(code.logicalLayout());
case Allocate -> new ArrowFixedSizeArrayFactory(code.logicalLayout());
case Cast -> new ArrowCastToFixedSizeArrayFactory(code.logicalLayout());
case Plus -> {
var factory = new ArrowFixedSizeArrayFactory(code.logicalLayout());
yield new ArrowOperationPlus(factory);
}
default -> throw CompilerDirectives.shouldNotReachHere("unsupported mode");
};
default -> throw CompilerDirectives.shouldNotReachHere("unsupported physical layout");
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.enso.interpreter.arrow.LogicalLayout;

@ExportLibrary(InteropLibrary.class)
public class ArrowFixedSizeArrayFactory implements TruffleObject {
public final class ArrowFixedSizeArrayFactory implements TruffleObject {

private final LogicalLayout logicalLayout;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.enso.interpreter.arrow.runtime;

import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;

@ExportLibrary(InteropLibrary.class)
public final class ArrowOperationPlus implements TruffleObject {
private final ArrowFixedSizeArrayFactory factory;

public ArrowOperationPlus(ArrowFixedSizeArrayFactory factory) {
this.factory = factory;
}

@ExportMessage
boolean isExecutable() {
return true;
}

@ExportMessage
Object execute(Object[] args, @CachedLibrary(limit = "3") InteropLibrary iop)
throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
if (args.length != 2) {
throw ArityException.create(2, 2, args.length);
}
var arr0 = args[0];
var arr1 = args[1];
if (!iop.hasArrayElements(arr0) || !iop.hasArrayElements(arr1)) {
throw UnsupportedTypeException.create(args);
}
var len = iop.getArraySize(arr0);
if (len != iop.getArraySize(arr1)) {
throw UnsupportedTypeException.create(args, "Arrays must have the same length");
}
var builder = iop.instantiate(factory, len);
try {
for (long i = 0; i < len; i++) {
var elem0 = iop.readArrayElement(arr0, i);
var elem1 = iop.readArrayElement(arr1, i);
var l0 = iop.asLong(elem0);
var l1 = iop.asLong(elem1);
iop.invokeMember(builder, "append", l0 + l1);
}
return iop.invokeMember(builder, "build");
} catch (InvalidArrayIndexException | UnknownIdentifierException ex) {
throw raise(RuntimeException.class, ex);
}
}

@SuppressWarnings("unchecked")
private static <E extends Throwable> E raise(Class<E> type, Throwable t) throws E {
throw (E) t;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.enso.interpreter.arrow;

import static org.junit.Assert.*;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.io.IOAccess;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class AddArrowTest {
private static Context ctx;

@BeforeClass
public static void initEnsoContext() {
ctx =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ContextUtils and declare dependency runtime-language-arrow/Test --> test-utils. Being able to use context and project utils from test-utils was the main motivation to move test-utils into separate project in #10112

Context.newBuilder()
.allowExperimentalOptions(true)
.allowIO(IOAccess.ALL)
.out(System.out)
.err(System.err)
.allowAllAccess(true)
.build();
}

@AfterClass
public static void closeEnsoContext() throws Exception {
if (ctx != null) {
ctx.close();
}
}

@Test
public void addTwoInt8ArrowArrays() {
var arrow = ctx.getEngine().getLanguages().get("arrow");
assertNotNull("Arrow is available", arrow);
var int8Constr = ctx.eval("arrow", "new[Int8]");
assertNotNull(int8Constr);

var arrLength = 10;
var builder1 = int8Constr.newInstance(arrLength);
var builder2 = int8Constr.newInstance(arrLength);

for (var i = 0; i < arrLength; i++) {
var ni = arrLength - i - 1;
var v = i * i;
builder1.invokeMember("append", i, (byte) v);
builder2.invokeMember("append", ni, (byte) v);
}

var arr1 = builder1.invokeMember("build");
assertEquals("Right size of arr1", arrLength, arr1.getArraySize());
var arr2 = builder2.invokeMember("build");
assertEquals("Right size of arr2", arrLength, arr2.getArraySize());

var int8Plus = ctx.eval("arrow", "+[Int8]");
var resultArr = int8Plus.execute(arr1, arr2);

assertTrue("Result is an array", resultArr.hasArrayElements());
assertEquals("Right size", arrLength, resultArr.getArraySize());

for (var i = 0; i < arrLength; i++) {
var ni = arrLength - i - 1;
var v1 = resultArr.getArrayElement(i).asInt();
var v2 = resultArr.getArrayElement(ni).asInt();

assertEquals("Values at " + i + " and " + ni + " are the same", v1, v2);
assertTrue("Values are always bigger than zero: " + v1, v1 > 0);
}
}
}
Loading