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 OrtKernelImpl {
 18  *     uint32_t ort_version_supported;
 19  *     uint32_t flags;
 20  *     OrtStatusPtr (*Compute)(OrtKernelImpl *, OrtKernelContext *);
 21  *     void (*Release)(OrtKernelImpl *);
 22  *     OrtStatusPtr (*PrePackWeight)(OrtKernelImpl *, const OrtValue *, int, OrtAllocator *, OrtSharedPrePackedWeightCache *, bool *);
 23  *     OrtStatusPtr (*SetSharedPrePackedWeight)(OrtKernelImpl *, const void *const *, const size_t *, size_t, int);
 24  * }
 25  * }
 26  */
 27 public class OrtKernelImpl {
 28 
 29     OrtKernelImpl() {
 30         // Should not be called directly
 31     }
 32 
 33     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
 34         onnxruntime_c_api_h.C_INT.withName("ort_version_supported"),
 35         onnxruntime_c_api_h.C_INT.withName("flags"),
 36         onnxruntime_c_api_h.C_POINTER.withName("Compute"),
 37         onnxruntime_c_api_h.C_POINTER.withName("Release"),
 38         onnxruntime_c_api_h.C_POINTER.withName("PrePackWeight"),
 39         onnxruntime_c_api_h.C_POINTER.withName("SetSharedPrePackedWeight")
 40     ).withName("OrtKernelImpl");
 41 
 42     /**
 43      * The layout of this struct
 44      */
 45     public static final GroupLayout layout() {
 46         return $LAYOUT;
 47     }
 48 
 49     private static final OfInt ort_version_supported$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ort_version_supported"));
 50 
 51     /**
 52      * Layout for field:
 53      * {@snippet lang=c :
 54      * uint32_t ort_version_supported
 55      * }
 56      */
 57     public static final OfInt ort_version_supported$layout() {
 58         return ort_version_supported$LAYOUT;
 59     }
 60 
 61     private static final long ort_version_supported$OFFSET = $LAYOUT.byteOffset(groupElement("ort_version_supported"));
 62 
 63     /**
 64      * Offset for field:
 65      * {@snippet lang=c :
 66      * uint32_t ort_version_supported
 67      * }
 68      */
 69     public static final long ort_version_supported$offset() {
 70         return ort_version_supported$OFFSET;
 71     }
 72 
 73     /**
 74      * Getter for field:
 75      * {@snippet lang=c :
 76      * uint32_t ort_version_supported
 77      * }
 78      */
 79     public static int ort_version_supported(MemorySegment struct) {
 80         return struct.get(ort_version_supported$LAYOUT, ort_version_supported$OFFSET);
 81     }
 82 
 83     /**
 84      * Setter for field:
 85      * {@snippet lang=c :
 86      * uint32_t ort_version_supported
 87      * }
 88      */
 89     public static void ort_version_supported(MemorySegment struct, int fieldValue) {
 90         struct.set(ort_version_supported$LAYOUT, ort_version_supported$OFFSET, fieldValue);
 91     }
 92 
 93     private static final OfInt flags$LAYOUT = (OfInt)$LAYOUT.select(groupElement("flags"));
 94 
 95     /**
 96      * Layout for field:
 97      * {@snippet lang=c :
 98      * uint32_t flags
 99      * }
100      */
101     public static final OfInt flags$layout() {
102         return flags$LAYOUT;
103     }
104 
105     private static final long flags$OFFSET = $LAYOUT.byteOffset(groupElement("flags"));
106 
107     /**
108      * Offset for field:
109      * {@snippet lang=c :
110      * uint32_t flags
111      * }
112      */
113     public static final long flags$offset() {
114         return flags$OFFSET;
115     }
116 
117     /**
118      * Getter for field:
119      * {@snippet lang=c :
120      * uint32_t flags
121      * }
122      */
123     public static int flags(MemorySegment struct) {
124         return struct.get(flags$LAYOUT, flags$OFFSET);
125     }
126 
127     /**
128      * Setter for field:
129      * {@snippet lang=c :
130      * uint32_t flags
131      * }
132      */
133     public static void flags(MemorySegment struct, int fieldValue) {
134         struct.set(flags$LAYOUT, flags$OFFSET, fieldValue);
135     }
136 
137     /**
138      * {@snippet lang=c :
139      * OrtStatusPtr (*Compute)(OrtKernelImpl *, OrtKernelContext *)
140      * }
141      */
142     public final static class Compute {
143 
144         private Compute() {
145             // Should not be called directly
146         }
147 
148         /**
149          * The function pointer signature, expressed as a functional interface
150          */
151         public interface Function {
152             MemorySegment apply(MemorySegment _x0, MemorySegment _x1);
153         }
154 
155         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
156             onnxruntime_c_api_h.C_POINTER,
157             onnxruntime_c_api_h.C_POINTER,
158             onnxruntime_c_api_h.C_POINTER
159         );
160 
161         /**
162          * The descriptor of this function pointer
163          */
164         public static FunctionDescriptor descriptor() {
165             return $DESC;
166         }
167 
168         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(Compute.Function.class, "apply", $DESC);
169 
170         /**
171          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
172          * The lifetime of the returned segment is managed by {@code arena}
173          */
174         public static MemorySegment allocate(Compute.Function fi, Arena arena) {
175             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
176         }
177 
178         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
179 
180         /**
181          * Invoke the upcall stub {@code funcPtr}, with given parameters
182          */
183         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) {
184             try {
185                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
186             } catch (Error | RuntimeException ex) {
187                 throw ex;
188             } catch (Throwable ex$) {
189                 throw new AssertionError("should not reach here", ex$);
190             }
191         }
192     }
193 
194     private static final AddressLayout Compute$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Compute"));
195 
196     /**
197      * Layout for field:
198      * {@snippet lang=c :
199      * OrtStatusPtr (*Compute)(OrtKernelImpl *, OrtKernelContext *)
200      * }
201      */
202     public static final AddressLayout Compute$layout() {
203         return Compute$LAYOUT;
204     }
205 
206     private static final long Compute$OFFSET = $LAYOUT.byteOffset(groupElement("Compute"));
207 
208     /**
209      * Offset for field:
210      * {@snippet lang=c :
211      * OrtStatusPtr (*Compute)(OrtKernelImpl *, OrtKernelContext *)
212      * }
213      */
214     public static final long Compute$offset() {
215         return Compute$OFFSET;
216     }
217 
218     /**
219      * Getter for field:
220      * {@snippet lang=c :
221      * OrtStatusPtr (*Compute)(OrtKernelImpl *, OrtKernelContext *)
222      * }
223      */
224     public static MemorySegment Compute(MemorySegment struct) {
225         return struct.get(Compute$LAYOUT, Compute$OFFSET);
226     }
227 
228     /**
229      * Setter for field:
230      * {@snippet lang=c :
231      * OrtStatusPtr (*Compute)(OrtKernelImpl *, OrtKernelContext *)
232      * }
233      */
234     public static void Compute(MemorySegment struct, MemorySegment fieldValue) {
235         struct.set(Compute$LAYOUT, Compute$OFFSET, fieldValue);
236     }
237 
238     /**
239      * {@snippet lang=c :
240      * void (*Release)(OrtKernelImpl *)
241      * }
242      */
243     public final static class Release {
244 
245         private Release() {
246             // Should not be called directly
247         }
248 
249         /**
250          * The function pointer signature, expressed as a functional interface
251          */
252         public interface Function {
253             void apply(MemorySegment _x0);
254         }
255 
256         private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
257             onnxruntime_c_api_h.C_POINTER
258         );
259 
260         /**
261          * The descriptor of this function pointer
262          */
263         public static FunctionDescriptor descriptor() {
264             return $DESC;
265         }
266 
267         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(Release.Function.class, "apply", $DESC);
268 
269         /**
270          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
271          * The lifetime of the returned segment is managed by {@code arena}
272          */
273         public static MemorySegment allocate(Release.Function fi, Arena arena) {
274             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
275         }
276 
277         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
278 
279         /**
280          * Invoke the upcall stub {@code funcPtr}, with given parameters
281          */
282         public static void invoke(MemorySegment funcPtr, MemorySegment _x0) {
283             try {
284                  DOWN$MH.invokeExact(funcPtr, _x0);
285             } catch (Error | RuntimeException ex) {
286                 throw ex;
287             } catch (Throwable ex$) {
288                 throw new AssertionError("should not reach here", ex$);
289             }
290         }
291     }
292 
293     private static final AddressLayout Release$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Release"));
294 
295     /**
296      * Layout for field:
297      * {@snippet lang=c :
298      * void (*Release)(OrtKernelImpl *)
299      * }
300      */
301     public static final AddressLayout Release$layout() {
302         return Release$LAYOUT;
303     }
304 
305     private static final long Release$OFFSET = $LAYOUT.byteOffset(groupElement("Release"));
306 
307     /**
308      * Offset for field:
309      * {@snippet lang=c :
310      * void (*Release)(OrtKernelImpl *)
311      * }
312      */
313     public static final long Release$offset() {
314         return Release$OFFSET;
315     }
316 
317     /**
318      * Getter for field:
319      * {@snippet lang=c :
320      * void (*Release)(OrtKernelImpl *)
321      * }
322      */
323     public static MemorySegment Release(MemorySegment struct) {
324         return struct.get(Release$LAYOUT, Release$OFFSET);
325     }
326 
327     /**
328      * Setter for field:
329      * {@snippet lang=c :
330      * void (*Release)(OrtKernelImpl *)
331      * }
332      */
333     public static void Release(MemorySegment struct, MemorySegment fieldValue) {
334         struct.set(Release$LAYOUT, Release$OFFSET, fieldValue);
335     }
336 
337     /**
338      * {@snippet lang=c :
339      * OrtStatusPtr (*PrePackWeight)(OrtKernelImpl *, const OrtValue *, int, OrtAllocator *, OrtSharedPrePackedWeightCache *, bool *)
340      * }
341      */
342     public final static class PrePackWeight {
343 
344         private PrePackWeight() {
345             // Should not be called directly
346         }
347 
348         /**
349          * The function pointer signature, expressed as a functional interface
350          */
351         public interface Function {
352             MemorySegment apply(MemorySegment _x0, MemorySegment _x1, int _x2, MemorySegment _x3, MemorySegment _x4, MemorySegment _x5);
353         }
354 
355         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
356             onnxruntime_c_api_h.C_POINTER,
357             onnxruntime_c_api_h.C_POINTER,
358             onnxruntime_c_api_h.C_POINTER,
359             onnxruntime_c_api_h.C_INT,
360             onnxruntime_c_api_h.C_POINTER,
361             onnxruntime_c_api_h.C_POINTER,
362             onnxruntime_c_api_h.C_POINTER
363         );
364 
365         /**
366          * The descriptor of this function pointer
367          */
368         public static FunctionDescriptor descriptor() {
369             return $DESC;
370         }
371 
372         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(PrePackWeight.Function.class, "apply", $DESC);
373 
374         /**
375          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
376          * The lifetime of the returned segment is managed by {@code arena}
377          */
378         public static MemorySegment allocate(PrePackWeight.Function fi, Arena arena) {
379             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
380         }
381 
382         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
383 
384         /**
385          * Invoke the upcall stub {@code funcPtr}, with given parameters
386          */
387         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1, int _x2, MemorySegment _x3, MemorySegment _x4, MemorySegment _x5) {
388             try {
389                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5);
390             } catch (Error | RuntimeException ex) {
391                 throw ex;
392             } catch (Throwable ex$) {
393                 throw new AssertionError("should not reach here", ex$);
394             }
395         }
396     }
397 
398     private static final AddressLayout PrePackWeight$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("PrePackWeight"));
399 
400     /**
401      * Layout for field:
402      * {@snippet lang=c :
403      * OrtStatusPtr (*PrePackWeight)(OrtKernelImpl *, const OrtValue *, int, OrtAllocator *, OrtSharedPrePackedWeightCache *, bool *)
404      * }
405      */
406     public static final AddressLayout PrePackWeight$layout() {
407         return PrePackWeight$LAYOUT;
408     }
409 
410     private static final long PrePackWeight$OFFSET = $LAYOUT.byteOffset(groupElement("PrePackWeight"));
411 
412     /**
413      * Offset for field:
414      * {@snippet lang=c :
415      * OrtStatusPtr (*PrePackWeight)(OrtKernelImpl *, const OrtValue *, int, OrtAllocator *, OrtSharedPrePackedWeightCache *, bool *)
416      * }
417      */
418     public static final long PrePackWeight$offset() {
419         return PrePackWeight$OFFSET;
420     }
421 
422     /**
423      * Getter for field:
424      * {@snippet lang=c :
425      * OrtStatusPtr (*PrePackWeight)(OrtKernelImpl *, const OrtValue *, int, OrtAllocator *, OrtSharedPrePackedWeightCache *, bool *)
426      * }
427      */
428     public static MemorySegment PrePackWeight(MemorySegment struct) {
429         return struct.get(PrePackWeight$LAYOUT, PrePackWeight$OFFSET);
430     }
431 
432     /**
433      * Setter for field:
434      * {@snippet lang=c :
435      * OrtStatusPtr (*PrePackWeight)(OrtKernelImpl *, const OrtValue *, int, OrtAllocator *, OrtSharedPrePackedWeightCache *, bool *)
436      * }
437      */
438     public static void PrePackWeight(MemorySegment struct, MemorySegment fieldValue) {
439         struct.set(PrePackWeight$LAYOUT, PrePackWeight$OFFSET, fieldValue);
440     }
441 
442     /**
443      * {@snippet lang=c :
444      * OrtStatusPtr (*SetSharedPrePackedWeight)(OrtKernelImpl *, const void *const *, const size_t *, size_t, int)
445      * }
446      */
447     public final static class SetSharedPrePackedWeight {
448 
449         private SetSharedPrePackedWeight() {
450             // Should not be called directly
451         }
452 
453         /**
454          * The function pointer signature, expressed as a functional interface
455          */
456         public interface Function {
457             MemorySegment apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2, long _x3, int _x4);
458         }
459 
460         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
461             onnxruntime_c_api_h.C_POINTER,
462             onnxruntime_c_api_h.C_POINTER,
463             onnxruntime_c_api_h.C_POINTER,
464             onnxruntime_c_api_h.C_POINTER,
465             onnxruntime_c_api_h.C_LONG,
466             onnxruntime_c_api_h.C_INT
467         );
468 
469         /**
470          * The descriptor of this function pointer
471          */
472         public static FunctionDescriptor descriptor() {
473             return $DESC;
474         }
475 
476         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(SetSharedPrePackedWeight.Function.class, "apply", $DESC);
477 
478         /**
479          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
480          * The lifetime of the returned segment is managed by {@code arena}
481          */
482         public static MemorySegment allocate(SetSharedPrePackedWeight.Function fi, Arena arena) {
483             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
484         }
485 
486         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
487 
488         /**
489          * Invoke the upcall stub {@code funcPtr}, with given parameters
490          */
491         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1, MemorySegment _x2, long _x3, int _x4) {
492             try {
493                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4);
494             } catch (Error | RuntimeException ex) {
495                 throw ex;
496             } catch (Throwable ex$) {
497                 throw new AssertionError("should not reach here", ex$);
498             }
499         }
500     }
501 
502     private static final AddressLayout SetSharedPrePackedWeight$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("SetSharedPrePackedWeight"));
503 
504     /**
505      * Layout for field:
506      * {@snippet lang=c :
507      * OrtStatusPtr (*SetSharedPrePackedWeight)(OrtKernelImpl *, const void *const *, const size_t *, size_t, int)
508      * }
509      */
510     public static final AddressLayout SetSharedPrePackedWeight$layout() {
511         return SetSharedPrePackedWeight$LAYOUT;
512     }
513 
514     private static final long SetSharedPrePackedWeight$OFFSET = $LAYOUT.byteOffset(groupElement("SetSharedPrePackedWeight"));
515 
516     /**
517      * Offset for field:
518      * {@snippet lang=c :
519      * OrtStatusPtr (*SetSharedPrePackedWeight)(OrtKernelImpl *, const void *const *, const size_t *, size_t, int)
520      * }
521      */
522     public static final long SetSharedPrePackedWeight$offset() {
523         return SetSharedPrePackedWeight$OFFSET;
524     }
525 
526     /**
527      * Getter for field:
528      * {@snippet lang=c :
529      * OrtStatusPtr (*SetSharedPrePackedWeight)(OrtKernelImpl *, const void *const *, const size_t *, size_t, int)
530      * }
531      */
532     public static MemorySegment SetSharedPrePackedWeight(MemorySegment struct) {
533         return struct.get(SetSharedPrePackedWeight$LAYOUT, SetSharedPrePackedWeight$OFFSET);
534     }
535 
536     /**
537      * Setter for field:
538      * {@snippet lang=c :
539      * OrtStatusPtr (*SetSharedPrePackedWeight)(OrtKernelImpl *, const void *const *, const size_t *, size_t, int)
540      * }
541      */
542     public static void SetSharedPrePackedWeight(MemorySegment struct, MemorySegment fieldValue) {
543         struct.set(SetSharedPrePackedWeight$LAYOUT, SetSharedPrePackedWeight$OFFSET, fieldValue);
544     }
545 
546     /**
547      * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
548      * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
549      */
550     public static MemorySegment asSlice(MemorySegment array, long index) {
551         return array.asSlice(layout().byteSize() * index);
552     }
553 
554     /**
555      * The size (in bytes) of this struct
556      */
557     public static long sizeof() { return layout().byteSize(); }
558 
559     /**
560      * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
561      */
562     public static MemorySegment allocate(SegmentAllocator allocator) {
563         return allocator.allocate(layout());
564     }
565 
566     /**
567      * Allocate an array of size {@code elementCount} using {@code allocator}.
568      * The returned segment has size {@code elementCount * layout().byteSize()}.
569      */
570     public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
571         return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
572     }
573 
574     /**
575      * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
576      * The returned segment has size {@code layout().byteSize()}
577      */
578     public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
579         return reinterpret(addr, 1, arena, cleanup);
580     }
581 
582     /**
583      * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
584      * The returned segment has size {@code elementCount * layout().byteSize()}
585      */
586     public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
587         return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
588     }
589 }
590