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

Simplifying InvokePtr example #166

Closed
Closed
Changes from all commits
Commits
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
@@ -29,6 +29,7 @@

import hat.Schema;
import hat.buffer.Buffer;
import hat.buffer.MappableIface;

import java.lang.constant.ClassDesc;
import java.lang.foreign.*;
@@ -169,8 +170,7 @@ static CoreOp.FuncOp transformInvokesToPtrs(MethodHandles.Lookup l,

static boolean isBufferOrBufferChild(Class<?> maybeIface) {
return maybeIface.isInterface() && (
Buffer.class.isAssignableFrom(maybeIface)
|| Buffer.Child.class.isAssignableFrom(maybeIface)
MappableIface.class.isAssignableFrom(maybeIface)
);

}
51 changes: 18 additions & 33 deletions hat/examples/experiments/src/main/java/experiments/PointyHat.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package experiments;



import hat.Accelerator;
import hat.ComputeContext;
import hat.KernelContext;
import hat.Schema;
import hat.buffer.Buffer;
import hat.buffer.BufferAllocator;
import hat.buffer.CompleteBuffer;
@@ -15,23 +17,9 @@
import java.lang.runtime.CodeReflection;

public class PointyHat {

/*
struct ColoredWeightedPoint{
struct WeightedPoint{
int x;
int y;
float weight;
}
struct WeightedPoint weightedPoint;
int color;
}
*/
@PtrDebugBackend.Struct
public interface ColoredWeightedPoint extends CompleteBuffer {

@PtrDebugBackend.Struct
interface WeightedPoint extends Buffer.StructChild {
interface WeightedPoint extends Buffer.StructChild {
int x();

void x(int x);
@@ -44,35 +32,32 @@ interface WeightedPoint extends Buffer.StructChild {

void weight(float weight);

static MemoryLayout layout() {
return LAYOUT;
}

MemoryLayout LAYOUT = MemoryLayout.structLayout(
ValueLayout.JAVA_FLOAT.withName("weight"),
ValueLayout.JAVA_INT.withName("x"),
ValueLayout.JAVA_INT.withName("y")
).withName(WeightedPoint.class.getName());
ValueLayout.JAVA_FLOAT.withName("weight"),
ValueLayout.JAVA_INT.withName("x"),
ValueLayout.JAVA_INT.withName("y")
).withName(ColoredWeightedPoint.WeightedPoint.class.getName());
}

WeightedPoint weightedPoint();
ColoredWeightedPoint.WeightedPoint weightedPoint();

int color();

void color(int color);

static MemoryLayout layout() {
return LAYOUT;
}
void color(int v);

MemoryLayout LAYOUT = MemoryLayout.structLayout(
WeightedPoint.layout(),
ValueLayout.JAVA_INT.withName("color")
).withName(ColoredWeightedPoint.class.getName());
ColoredWeightedPoint.WeightedPoint.LAYOUT.withName(ColoredWeightedPoint.WeightedPoint.class.getName() + "::weightedPoint"),
ValueLayout.JAVA_INT.withName("color")
).withName(ColoredWeightedPoint.class.getName());

static ColoredWeightedPoint create(BufferAllocator bufferAllocator) {
return bufferAllocator.allocate(SegmentMapper.of(MethodHandles.lookup(), ColoredWeightedPoint.class, layout()));
return bufferAllocator.allocate(SegmentMapper.of(MethodHandles.lookup(), ColoredWeightedPoint.class, LAYOUT));
}

Schema<ColoredWeightedPoint> schema = Schema.of(ColoredWeightedPoint.class, (cwp)-> cwp
.field("weightedPoint", (wp)-> wp.fields("weight","x","y"))
.field("color")
);
}

static class Compute {
Loading