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