From: Not Zed Date: Mon, 27 Jan 2020 10:34:45 +0000 (+1030) Subject: Use jextract for the bindings. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=9455cfeb8c9097987819ada835b05d98a04abc07;p=zcl Use jextract for the bindings. --- diff --git a/config.make.in b/config.make.in index 64bf34f..f05b38a 100644 --- a/config.make.in +++ b/config.make.in @@ -12,6 +12,8 @@ JAVAC ?= $(JAVA_HOME)/bin/javac JAR ?= $(JAVA_HOME)/bin/jar JMOD ?= $(JAVA_HOME)/bin/jmod +JEXTRACT = /opt/panama-jextract/bin/jextract + # Linux options linux-amd64_CPPFLAGS = \ -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java b/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java index 063b480..9906e20 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java @@ -1606,7 +1606,7 @@ public class CLCommandQueue extends CLExtendable { } Callback call = Native.resolve( - Call_pv_v.stub((MemoryAddress memargs) -> { + cl_h.clEnqueueNativeKernel$x0$make((MemoryAddress memargs) -> { int xmem = 0; for (int i=0;i call(CLContextNotify notify) { if (notify != null) { return Native.resolve( - Call_pBpvJpv_v.stub((cwhat, cinfo, cinfolen, dummy) -> { + cl_h.clCreateContext$x0$make((cwhat, cinfo, cinfolen, dummy) -> { MemorySegment seg = Memory.ofNative(cinfo, cinfolen); notify.notify(Native.toString(cwhat), seg.asByteBuffer()); }), diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java index 95331d1..d17615e 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java @@ -37,7 +37,7 @@ public interface CLEventNotify { static Callback call(CLEventNotify notify) { if (notify != null) { return Native.resolve( - Call_pLIpv_v.stub((cevent, status, dummy) -> notify.notify(Native.resolve(cevent, CLEvent::new), status)), + cl_h.clSetEventCallback$x0$make(((cevent, status, dummy) -> notify.notify(Native.resolve(cevent, CLEvent::new), status))), (p) -> new Callback<>(p, notify)); } else { return Callback.NULL; diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLLib.java b/src/notzed.zcl/classes/au/notzed/zcl/CLLib.java new file mode 100644 index 0000000..2e176fc --- /dev/null +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLLib.java @@ -0,0 +1,10 @@ + +/* + * This just imports the jextract types to the same library so i don't have to + * change the imports. + */ +package au.notzed.zcl; + +public class CLLib extends cl_h { + +} diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java index ceb6f8d..462ba76 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java @@ -33,8 +33,10 @@ public interface CLNotify { @SuppressWarnings("unchecked") static Callback> call(CLNotify notify, Function create) { if (notify != null) { + // jextract note: this 2-parameter callback is used in a few places, but as it's untyped it + // doesn't matter which one is used. return Native.resolve( - Call_pLpv_v.stub((co, dummy) -> notify.notify(Native.resolve(co, create))), + cl_h.clBuildProgram$x0$make((co, dummy) -> notify.notify(Native.resolve(co, create))), (p) -> new Callback<>(p, notify)); } else { return Callback.NULL; diff --git a/src/notzed.zcl/gen/gen.make b/src/notzed.zcl/gen/gen.make index 2be9c5f..a7a4ceb 100644 --- a/src/notzed.zcl/gen/gen.make +++ b/src/notzed.zcl/gen/gen.make @@ -1,42 +1,24 @@ -export_defines=src/notzed.zcl/gen/export-defines -generate_api=src/notzed.zcl/gen/generate-api -opencl_pm=src/notzed.zcl/gen/opencl.pm - -# this is in src/notzed.zcl/classes already -notzed.zcl_defines = \ - au/notzed/zcl/CL.java - notzed.zcl_generated = \ - au/notzed/zcl/CLLib.java \ - au/notzed/zcl/Call_pBpvJpv_v.java \ - au/notzed/zcl/Call_pLIppvpv_v.java \ - au/notzed/zcl/Call_pLIpv_v.java \ - au/notzed/zcl/Call_pLpv_v.java \ - au/notzed/zcl/Call_pv_v.java + au/notzed/zcl/cl_h.java \ + au/notzed/zcl/RuntimeHelper.java notzed.zcl_JAVA_GENERATED = \ $(notzed.zcl_generated) -$(notzed.zcl_genjavadir)/au/notzed/zcl/CL.java: src/notzed.zcl/include/CL/cl.h $(export_defines) - @install -d $(@D) - perl $(export_defines) $< > $@ || rm -f $@ - -$(addprefix $(notzed.zcl_genjavadir)/,$(notzed.zcl_generated)): $(generate_api) $(opencl_pm) - perl $(generate_api) \ - -d $(notzed.zcl_genjavadir) \ - -t au.notzed.zcl \ - -r _cl_platform_id=CLPlatform \ - -r _cl_device_id=CLDevice \ - -r _cl_context=CLContext \ - -r _cl_command_queue=CLCommandQueue \ - -r _cl_program=CLProgram \ - -r _cl_kernel=CLKernel \ - -r _cl_event=CLEvent \ - -r _cl_mem=CLMemory \ - -r _cl_sampler=CLSampler \ - -r _cl_image_desc=CLImageDesc \ - -r _cl_image_format=CLImageFormat \ - --raw-calls \ - -c CLLib -lOpenCL --func-file src/notzed.zcl/gen/opencl.txt \ - ./$(opencl_pm) +# This edits the jextract output a little bit +# - make class non-final +# - remove the constants +# - enqueueSVMFree uses a void *[], which jextract turns into an unknown-length sequence, don't do that. +$(addprefix $(notzed.zcl_genjavadir)/,$(notzed.zcl_generated)): src/notzed.zcl/include/CL/cl.h src/notzed.zcl/gen/gen.make + $(JEXTRACT) --output $(notzed.zcl_genjavadir) \ + -t au.notzed.zcl \ + -lOpenCL \ + --filter cl.h \ + -I /usr/lib64/clang/9.0.1/include \ + -I src/notzed.zcl/include \ + $< || ( rm $< ; exit 1) + ( echo '1,30 s/^public final class/public class/' ; \ + echo 'g/public static final int CL_/d' ; \ + echo '1,$$ s/MemoryLayout.ofSequence(MemoryLayouts.SysV.C_POINTER)/MemoryLayouts.SysV.C_POINTER/' ; \ + echo 'w' ) | ed $(notzed.zcl_genjavadir)/au/notzed/zcl/cl_h.java