1 // Generated by jextract
  2 
  3 package oracle.code.onnx.foreign;
  4 
  5 import java.lang.invoke.*;
  6 import java.lang.foreign.*;
  7 import java.nio.ByteOrder;
  8 import java.util.*;
  9 import java.util.function.*;
 10 import java.util.stream.*;
 11 
 12 import static java.lang.foreign.ValueLayout.*;
 13 import static java.lang.foreign.MemoryLayout.PathElement.*;
 14 
 15 /**
 16  * {@snippet lang=c :
 17  * struct OrtNodeComputeInfo {
 18  *     uint32_t ort_version_supported;
 19  *     OrtStatus *(*CreateState)(OrtNodeComputeInfo *, OrtNodeComputeContext *, void **);
 20  *     OrtStatus *(*Compute)(OrtNodeComputeInfo *, void *, OrtKernelContext *);
 21  *     void (*ReleaseState)(OrtNodeComputeInfo *, void *);
 22  * }
 23  * }
 24  */
 25 public class OrtNodeComputeInfo {
 26 
 27     OrtNodeComputeInfo() {
 28         // Should not be called directly
 29     }
 30 
 31     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
 32         onnxruntime_c_api_h.C_INT.withName("ort_version_supported"),
 33         MemoryLayout.paddingLayout(4),
 34         onnxruntime_c_api_h.C_POINTER.withName("CreateState"),
 35         onnxruntime_c_api_h.C_POINTER.withName("Compute"),
 36         onnxruntime_c_api_h.C_POINTER.withName("ReleaseState")
 37     ).withName("OrtNodeComputeInfo");
 38 
 39     /**
 40      * The layout of this struct
 41      */
 42     public static final GroupLayout layout() {
 43         return $LAYOUT;
 44     }
 45 
 46     private static final OfInt ort_version_supported$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ort_version_supported"));
 47 
 48     /**
 49      * Layout for field:
 50      * {@snippet lang=c :
 51      * uint32_t ort_version_supported
 52      * }
 53      */
 54     public static final OfInt ort_version_supported$layout() {
 55         return ort_version_supported$LAYOUT;
 56     }
 57 
 58     private static final long ort_version_supported$OFFSET = $LAYOUT.byteOffset(groupElement("ort_version_supported"));
 59 
 60     /**
 61      * Offset for field:
 62      * {@snippet lang=c :
 63      * uint32_t ort_version_supported
 64      * }
 65      */
 66     public static final long ort_version_supported$offset() {
 67         return ort_version_supported$OFFSET;
 68     }
 69 
 70     /**
 71      * Getter for field:
 72      * {@snippet lang=c :
 73      * uint32_t ort_version_supported
 74      * }
 75      */
 76     public static int ort_version_supported(MemorySegment struct) {
 77         return struct.get(ort_version_supported$LAYOUT, ort_version_supported$OFFSET);
 78     }
 79 
 80     /**
 81      * Setter for field:
 82      * {@snippet lang=c :
 83      * uint32_t ort_version_supported
 84      * }
 85      */
 86     public static void ort_version_supported(MemorySegment struct, int fieldValue) {
 87         struct.set(ort_version_supported$LAYOUT, ort_version_supported$OFFSET, fieldValue);
 88     }
 89 
 90     /**
 91      * {@snippet lang=c :
 92      * OrtStatus *(*CreateState)(OrtNodeComputeInfo *, OrtNodeComputeContext *, void **)
 93      * }
 94      */
 95     public final static class CreateState {
 96 
 97         private CreateState() {
 98             // Should not be called directly
 99         }
100 
101         /**
102          * The function pointer signature, expressed as a functional interface
103          */
104         public interface Function {
105             MemorySegment apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2);
106         }
107 
108         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
109             onnxruntime_c_api_h.C_POINTER,
110             onnxruntime_c_api_h.C_POINTER,
111             onnxruntime_c_api_h.C_POINTER,
112             onnxruntime_c_api_h.C_POINTER
113         );
114 
115         /**
116          * The descriptor of this function pointer
117          */
118         public static FunctionDescriptor descriptor() {
119             return $DESC;
120         }
121 
122         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(CreateState.Function.class, "apply", $DESC);
123 
124         /**
125          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
126          * The lifetime of the returned segment is managed by {@code arena}
127          */
128         public static MemorySegment allocate(CreateState.Function fi, Arena arena) {
129             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
130         }
131 
132         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
133 
134         /**
135          * Invoke the upcall stub {@code funcPtr}, with given parameters
136          */
137         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) {
138             try {
139                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2);
140             } catch (Error | RuntimeException ex) {
141                 throw ex;
142             } catch (Throwable ex$) {
143                 throw new AssertionError("should not reach here", ex$);
144             }
145         }
146     }
147 
148     private static final AddressLayout CreateState$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("CreateState"));
149 
150     /**
151      * Layout for field:
152      * {@snippet lang=c :
153      * OrtStatus *(*CreateState)(OrtNodeComputeInfo *, OrtNodeComputeContext *, void **)
154      * }
155      */
156     public static final AddressLayout CreateState$layout() {
157         return CreateState$LAYOUT;
158     }
159 
160     private static final long CreateState$OFFSET = $LAYOUT.byteOffset(groupElement("CreateState"));
161 
162     /**
163      * Offset for field:
164      * {@snippet lang=c :
165      * OrtStatus *(*CreateState)(OrtNodeComputeInfo *, OrtNodeComputeContext *, void **)
166      * }
167      */
168     public static final long CreateState$offset() {
169         return CreateState$OFFSET;
170     }
171 
172     /**
173      * Getter for field:
174      * {@snippet lang=c :
175      * OrtStatus *(*CreateState)(OrtNodeComputeInfo *, OrtNodeComputeContext *, void **)
176      * }
177      */
178     public static MemorySegment CreateState(MemorySegment struct) {
179         return struct.get(CreateState$LAYOUT, CreateState$OFFSET);
180     }
181 
182     /**
183      * Setter for field:
184      * {@snippet lang=c :
185      * OrtStatus *(*CreateState)(OrtNodeComputeInfo *, OrtNodeComputeContext *, void **)
186      * }
187      */
188     public static void CreateState(MemorySegment struct, MemorySegment fieldValue) {
189         struct.set(CreateState$LAYOUT, CreateState$OFFSET, fieldValue);
190     }
191 
192     /**
193      * {@snippet lang=c :
194      * OrtStatus *(*Compute)(OrtNodeComputeInfo *, void *, OrtKernelContext *)
195      * }
196      */
197     public final static class Compute {
198 
199         private Compute() {
200             // Should not be called directly
201         }
202 
203         /**
204          * The function pointer signature, expressed as a functional interface
205          */
206         public interface Function {
207             MemorySegment apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2);
208         }
209 
210         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
211             onnxruntime_c_api_h.C_POINTER,
212             onnxruntime_c_api_h.C_POINTER,
213             onnxruntime_c_api_h.C_POINTER,
214             onnxruntime_c_api_h.C_POINTER
215         );
216 
217         /**
218          * The descriptor of this function pointer
219          */
220         public static FunctionDescriptor descriptor() {
221             return $DESC;
222         }
223 
224         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(Compute.Function.class, "apply", $DESC);
225 
226         /**
227          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
228          * The lifetime of the returned segment is managed by {@code arena}
229          */
230         public static MemorySegment allocate(Compute.Function fi, Arena arena) {
231             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
232         }
233 
234         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
235 
236         /**
237          * Invoke the upcall stub {@code funcPtr}, with given parameters
238          */
239         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) {
240             try {
241                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2);
242             } catch (Error | RuntimeException ex) {
243                 throw ex;
244             } catch (Throwable ex$) {
245                 throw new AssertionError("should not reach here", ex$);
246             }
247         }
248     }
249 
250     private static final AddressLayout Compute$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Compute"));
251 
252     /**
253      * Layout for field:
254      * {@snippet lang=c :
255      * OrtStatus *(*Compute)(OrtNodeComputeInfo *, void *, OrtKernelContext *)
256      * }
257      */
258     public static final AddressLayout Compute$layout() {
259         return Compute$LAYOUT;
260     }
261 
262     private static final long Compute$OFFSET = $LAYOUT.byteOffset(groupElement("Compute"));
263 
264     /**
265      * Offset for field:
266      * {@snippet lang=c :
267      * OrtStatus *(*Compute)(OrtNodeComputeInfo *, void *, OrtKernelContext *)
268      * }
269      */
270     public static final long Compute$offset() {
271         return Compute$OFFSET;
272     }
273 
274     /**
275      * Getter for field:
276      * {@snippet lang=c :
277      * OrtStatus *(*Compute)(OrtNodeComputeInfo *, void *, OrtKernelContext *)
278      * }
279      */
280     public static MemorySegment Compute(MemorySegment struct) {
281         return struct.get(Compute$LAYOUT, Compute$OFFSET);
282     }
283 
284     /**
285      * Setter for field:
286      * {@snippet lang=c :
287      * OrtStatus *(*Compute)(OrtNodeComputeInfo *, void *, OrtKernelContext *)
288      * }
289      */
290     public static void Compute(MemorySegment struct, MemorySegment fieldValue) {
291         struct.set(Compute$LAYOUT, Compute$OFFSET, fieldValue);
292     }
293 
294     /**
295      * {@snippet lang=c :
296      * void (*ReleaseState)(OrtNodeComputeInfo *, void *)
297      * }
298      */
299     public final static class ReleaseState {
300 
301         private ReleaseState() {
302             // Should not be called directly
303         }
304 
305         /**
306          * The function pointer signature, expressed as a functional interface
307          */
308         public interface Function {
309             void apply(MemorySegment _x0, MemorySegment _x1);
310         }
311 
312         private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
313             onnxruntime_c_api_h.C_POINTER,
314             onnxruntime_c_api_h.C_POINTER
315         );
316 
317         /**
318          * The descriptor of this function pointer
319          */
320         public static FunctionDescriptor descriptor() {
321             return $DESC;
322         }
323 
324         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(ReleaseState.Function.class, "apply", $DESC);
325 
326         /**
327          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
328          * The lifetime of the returned segment is managed by {@code arena}
329          */
330         public static MemorySegment allocate(ReleaseState.Function fi, Arena arena) {
331             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
332         }
333 
334         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
335 
336         /**
337          * Invoke the upcall stub {@code funcPtr}, with given parameters
338          */
339         public static void invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) {
340             try {
341                  DOWN$MH.invokeExact(funcPtr, _x0, _x1);
342             } catch (Error | RuntimeException ex) {
343                 throw ex;
344             } catch (Throwable ex$) {
345                 throw new AssertionError("should not reach here", ex$);
346             }
347         }
348     }
349 
350     private static final AddressLayout ReleaseState$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ReleaseState"));
351 
352     /**
353      * Layout for field:
354      * {@snippet lang=c :
355      * void (*ReleaseState)(OrtNodeComputeInfo *, void *)
356      * }
357      */
358     public static final AddressLayout ReleaseState$layout() {
359         return ReleaseState$LAYOUT;
360     }
361 
362     private static final long ReleaseState$OFFSET = $LAYOUT.byteOffset(groupElement("ReleaseState"));
363 
364     /**
365      * Offset for field:
366      * {@snippet lang=c :
367      * void (*ReleaseState)(OrtNodeComputeInfo *, void *)
368      * }
369      */
370     public static final long ReleaseState$offset() {
371         return ReleaseState$OFFSET;
372     }
373 
374     /**
375      * Getter for field:
376      * {@snippet lang=c :
377      * void (*ReleaseState)(OrtNodeComputeInfo *, void *)
378      * }
379      */
380     public static MemorySegment ReleaseState(MemorySegment struct) {
381         return struct.get(ReleaseState$LAYOUT, ReleaseState$OFFSET);
382     }
383 
384     /**
385      * Setter for field:
386      * {@snippet lang=c :
387      * void (*ReleaseState)(OrtNodeComputeInfo *, void *)
388      * }
389      */
390     public static void ReleaseState(MemorySegment struct, MemorySegment fieldValue) {
391         struct.set(ReleaseState$LAYOUT, ReleaseState$OFFSET, fieldValue);
392     }
393 
394     /**
395      * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
396      * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
397      */
398     public static MemorySegment asSlice(MemorySegment array, long index) {
399         return array.asSlice(layout().byteSize() * index);
400     }
401 
402     /**
403      * The size (in bytes) of this struct
404      */
405     public static long sizeof() { return layout().byteSize(); }
406 
407     /**
408      * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
409      */
410     public static MemorySegment allocate(SegmentAllocator allocator) {
411         return allocator.allocate(layout());
412     }
413 
414     /**
415      * Allocate an array of size {@code elementCount} using {@code allocator}.
416      * The returned segment has size {@code elementCount * layout().byteSize()}.
417      */
418     public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
419         return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
420     }
421 
422     /**
423      * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
424      * The returned segment has size {@code layout().byteSize()}
425      */
426     public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
427         return reinterpret(addr, 1, arena, cleanup);
428     }
429 
430     /**
431      * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
432      * The returned segment has size {@code elementCount * layout().byteSize()}
433      */
434     public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
435         return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
436     }
437 }
438