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