baracuda-cuda-sys 0.0.1-alpha.2

Raw FFI bindings and dynamic loader for the CUDA Driver and Runtime APIs (libcuda / libcudart).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
//! C function-pointer aliases for the CUDA Runtime API.
//!
//! Runtime symbols are resolved via plain `dlsym` (unlike the Driver API,
//! `libcudart` does not expose `cuGetProcAddress`). Most runtime functions
//! are stable and do not have `_v2` / `_v3` variants you need to pin to.

#![allow(non_camel_case_types)]

use core::ffi::{c_char, c_int, c_uint, c_void};

use super::status::cudaError_t;
use super::types::{cudaEvent_t, cudaKernel_t, cudaLibrary_t, cudaMemcpyKind, cudaStream_t, dim3};

// ---- version & error -------------------------------------------------------

pub type PFN_cudaRuntimeGetVersion = unsafe extern "C" fn(version: *mut c_int) -> cudaError_t;
pub type PFN_cudaDriverGetVersion = unsafe extern "C" fn(version: *mut c_int) -> cudaError_t;
pub type PFN_cudaGetLastError = unsafe extern "C" fn() -> cudaError_t;
pub type PFN_cudaPeekAtLastError = unsafe extern "C" fn() -> cudaError_t;
pub type PFN_cudaGetErrorName = unsafe extern "C" fn(error: cudaError_t) -> *const c_char;
pub type PFN_cudaGetErrorString = unsafe extern "C" fn(error: cudaError_t) -> *const c_char;

// ---- device management -----------------------------------------------------

pub type PFN_cudaGetDeviceCount = unsafe extern "C" fn(count: *mut c_int) -> cudaError_t;
pub type PFN_cudaSetDevice = unsafe extern "C" fn(device: c_int) -> cudaError_t;
pub type PFN_cudaGetDevice = unsafe extern "C" fn(device: *mut c_int) -> cudaError_t;
pub type PFN_cudaDeviceSynchronize = unsafe extern "C" fn() -> cudaError_t;
pub type PFN_cudaDeviceReset = unsafe extern "C" fn() -> cudaError_t;
pub type PFN_cudaDeviceGetAttribute =
    unsafe extern "C" fn(value: *mut c_int, attr: c_int, device: c_int) -> cudaError_t;
pub type PFN_cudaInitDevice =
    unsafe extern "C" fn(device: c_int, device_flags: c_uint, flags: c_uint) -> cudaError_t;

// ---- memory ---------------------------------------------------------------

pub type PFN_cudaMalloc =
    unsafe extern "C" fn(dev_ptr: *mut *mut c_void, size: usize) -> cudaError_t;
pub type PFN_cudaFree = unsafe extern "C" fn(dev_ptr: *mut c_void) -> cudaError_t;
pub type PFN_cudaMallocManaged =
    unsafe extern "C" fn(dev_ptr: *mut *mut c_void, size: usize, flags: c_uint) -> cudaError_t;

pub type PFN_cudaMemcpy = unsafe extern "C" fn(
    dst: *mut c_void,
    src: *const c_void,
    count: usize,
    kind: cudaMemcpyKind,
) -> cudaError_t;
pub type PFN_cudaMemcpyAsync = unsafe extern "C" fn(
    dst: *mut c_void,
    src: *const c_void,
    count: usize,
    kind: cudaMemcpyKind,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaMemset =
    unsafe extern "C" fn(dst: *mut c_void, value: c_int, count: usize) -> cudaError_t;
pub type PFN_cudaMemsetAsync = unsafe extern "C" fn(
    dst: *mut c_void,
    value: c_int,
    count: usize,
    stream: cudaStream_t,
) -> cudaError_t;

// ---- stream ---------------------------------------------------------------

pub type PFN_cudaStreamCreate = unsafe extern "C" fn(stream: *mut cudaStream_t) -> cudaError_t;
pub type PFN_cudaStreamCreateWithFlags =
    unsafe extern "C" fn(stream: *mut cudaStream_t, flags: c_uint) -> cudaError_t;
pub type PFN_cudaStreamDestroy = unsafe extern "C" fn(stream: cudaStream_t) -> cudaError_t;
pub type PFN_cudaStreamSynchronize = unsafe extern "C" fn(stream: cudaStream_t) -> cudaError_t;
pub type PFN_cudaStreamQuery = unsafe extern "C" fn(stream: cudaStream_t) -> cudaError_t;
pub type PFN_cudaStreamWaitEvent =
    unsafe extern "C" fn(stream: cudaStream_t, event: cudaEvent_t, flags: c_uint) -> cudaError_t;

// ---- event ----------------------------------------------------------------

pub type PFN_cudaEventCreate = unsafe extern "C" fn(event: *mut cudaEvent_t) -> cudaError_t;
pub type PFN_cudaEventCreateWithFlags =
    unsafe extern "C" fn(event: *mut cudaEvent_t, flags: c_uint) -> cudaError_t;
pub type PFN_cudaEventDestroy = unsafe extern "C" fn(event: cudaEvent_t) -> cudaError_t;
pub type PFN_cudaEventRecord =
    unsafe extern "C" fn(event: cudaEvent_t, stream: cudaStream_t) -> cudaError_t;
pub type PFN_cudaEventSynchronize = unsafe extern "C" fn(event: cudaEvent_t) -> cudaError_t;
pub type PFN_cudaEventQuery = unsafe extern "C" fn(event: cudaEvent_t) -> cudaError_t;
pub type PFN_cudaEventElapsedTime =
    unsafe extern "C" fn(ms: *mut f32, start: cudaEvent_t, end: cudaEvent_t) -> cudaError_t;

// ---- kernel launch --------------------------------------------------------

pub type PFN_cudaLaunchKernel = unsafe extern "C" fn(
    func: *const c_void,
    grid_dim: dim3,
    block_dim: dim3,
    args: *mut *mut c_void,
    shared_mem: usize,
    stream: cudaStream_t,
) -> cudaError_t;

// ---- library management (CUDA 12.0+) --------------------------------------

pub type PFN_cudaLibraryLoadData = unsafe extern "C" fn(
    library: *mut cudaLibrary_t,
    code: *const c_void,
    jit_options: *mut c_int,
    jit_option_values: *mut *mut c_void,
    num_jit_options: c_uint,
    library_options: *mut c_int,
    library_option_values: *mut *mut c_void,
    num_library_options: c_uint,
) -> cudaError_t;
pub type PFN_cudaLibraryUnload = unsafe extern "C" fn(library: cudaLibrary_t) -> cudaError_t;
pub type PFN_cudaLibraryGetKernel = unsafe extern "C" fn(
    kernel: *mut cudaKernel_t,
    library: cudaLibrary_t,
    name: *const c_char,
) -> cudaError_t;

// ---- Stream extras --------------------------------------------------------

pub type PFN_cudaStreamCreateWithPriority =
    unsafe extern "C" fn(stream: *mut cudaStream_t, flags: c_uint, priority: c_int) -> cudaError_t;

pub type PFN_cudaStreamGetPriority =
    unsafe extern "C" fn(stream: cudaStream_t, priority: *mut c_int) -> cudaError_t;

pub type PFN_cudaStreamGetFlags =
    unsafe extern "C" fn(stream: cudaStream_t, flags: *mut c_uint) -> cudaError_t;

pub type PFN_cudaDeviceGetStreamPriorityRange =
    unsafe extern "C" fn(least_priority: *mut c_int, greatest_priority: *mut c_int) -> cudaError_t;

// ---- Peer access ----------------------------------------------------------

pub type PFN_cudaDeviceCanAccessPeer =
    unsafe extern "C" fn(can_access: *mut c_int, device: c_int, peer_device: c_int) -> cudaError_t;

pub type PFN_cudaDeviceEnablePeerAccess =
    unsafe extern "C" fn(peer_device: c_int, flags: c_uint) -> cudaError_t;

pub type PFN_cudaDeviceDisablePeerAccess = unsafe extern "C" fn(peer_device: c_int) -> cudaError_t;

// ---- Mem prefetch / advise -----------------------------------------------

pub type PFN_cudaMemPrefetchAsync = unsafe extern "C" fn(
    dev_ptr: *const c_void,
    count: usize,
    dst_device: c_int,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaMemAdvise = unsafe extern "C" fn(
    dev_ptr: *const c_void,
    count: usize,
    advice: c_int,
    device: c_int,
) -> cudaError_t;

pub type PFN_cudaMemGetInfo =
    unsafe extern "C" fn(free: *mut usize, total: *mut usize) -> cudaError_t;

// ---- Managed + pinned memory ---------------------------------------------

pub type PFN_cudaMallocHost =
    unsafe extern "C" fn(pp: *mut *mut c_void, size: usize) -> cudaError_t;

pub type PFN_cudaFreeHost = unsafe extern "C" fn(ptr: *mut c_void) -> cudaError_t;

pub type PFN_cudaHostAlloc =
    unsafe extern "C" fn(pp: *mut *mut c_void, size: usize, flags: c_uint) -> cudaError_t;

pub type PFN_cudaHostRegister =
    unsafe extern "C" fn(ptr: *mut c_void, size: usize, flags: c_uint) -> cudaError_t;

pub type PFN_cudaHostUnregister = unsafe extern "C" fn(ptr: *mut c_void) -> cudaError_t;

pub type PFN_cudaHostGetDevicePointer = unsafe extern "C" fn(
    dev_ptr: *mut *mut c_void,
    host_ptr: *mut c_void,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaHostGetFlags =
    unsafe extern "C" fn(flags: *mut c_uint, host_ptr: *mut c_void) -> cudaError_t;

// ---- Async alloc / free (CUDA 11.2+) --------------------------------------

pub type PFN_cudaMallocAsync = unsafe extern "C" fn(
    dev_ptr: *mut *mut c_void,
    size: usize,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaFreeAsync =
    unsafe extern "C" fn(dev_ptr: *mut c_void, stream: cudaStream_t) -> cudaError_t;

// ---- Graphs + stream capture ---------------------------------------------

use super::types::{cudaGraphExec_t, cudaGraphNode_t, cudaGraph_t};

pub type PFN_cudaGraphCreate =
    unsafe extern "C" fn(graph: *mut cudaGraph_t, flags: c_uint) -> cudaError_t;

pub type PFN_cudaGraphDestroy = unsafe extern "C" fn(graph: cudaGraph_t) -> cudaError_t;

pub type PFN_cudaGraphInstantiate = unsafe extern "C" fn(
    graph_exec: *mut cudaGraphExec_t,
    graph: cudaGraph_t,
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaGraphLaunch =
    unsafe extern "C" fn(graph_exec: cudaGraphExec_t, stream: cudaStream_t) -> cudaError_t;

pub type PFN_cudaGraphExecDestroy =
    unsafe extern "C" fn(graph_exec: cudaGraphExec_t) -> cudaError_t;

pub type PFN_cudaGraphGetNodes = unsafe extern "C" fn(
    graph: cudaGraph_t,
    nodes: *mut cudaGraphNode_t,
    num_nodes: *mut usize,
) -> cudaError_t;

pub type PFN_cudaStreamBeginCapture =
    unsafe extern "C" fn(stream: cudaStream_t, mode: c_int) -> cudaError_t;

pub type PFN_cudaStreamEndCapture =
    unsafe extern "C" fn(stream: cudaStream_t, graph: *mut cudaGraph_t) -> cudaError_t;

pub type PFN_cudaStreamIsCapturing =
    unsafe extern "C" fn(stream: cudaStream_t, status: *mut c_int) -> cudaError_t;

// ---- Function-symbol lookup + func attrs + occupancy ----------------------

pub type PFN_cudaGetFuncBySymbol =
    unsafe extern "C" fn(func: *mut *mut c_void, symbol: *const c_void) -> cudaError_t;

pub type PFN_cudaFuncGetAttributes =
    unsafe extern "C" fn(attr: *mut c_void, func: *const c_void) -> cudaError_t;

pub type PFN_cudaFuncSetAttribute =
    unsafe extern "C" fn(func: *const c_void, attr: c_int, value: c_int) -> cudaError_t;

pub type PFN_cudaOccupancyMaxActiveBlocksPerMultiprocessor = unsafe extern "C" fn(
    num_blocks: *mut c_int,
    func: *const c_void,
    block_size: c_int,
    dynamic_smem_bytes: usize,
) -> cudaError_t;

pub type PFN_cudaOccupancyMaxPotentialBlockSize = unsafe extern "C" fn(
    min_grid_size: *mut c_int,
    block_size: *mut c_int,
    func: *const c_void,
    dyn_smem_fn: *mut c_void,
    dyn_smem_bytes: usize,
    block_size_limit: c_int,
) -> cudaError_t;

// ---- Pointer attributes ---------------------------------------------------

pub type PFN_cudaPointerGetAttributes =
    unsafe extern "C" fn(attrs: *mut c_void, ptr: *const c_void) -> cudaError_t;

// ---- 2-D memcpy + memset variants + async memset -------------------------

pub type PFN_cudaMemcpy2D = unsafe extern "C" fn(
    dst: *mut c_void,
    dst_pitch: usize,
    src: *const c_void,
    src_pitch: usize,
    width: usize,
    height: usize,
    kind: cudaMemcpyKind,
) -> cudaError_t;

pub type PFN_cudaMemcpy2DAsync = unsafe extern "C" fn(
    dst: *mut c_void,
    dst_pitch: usize,
    src: *const c_void,
    src_pitch: usize,
    width: usize,
    height: usize,
    kind: cudaMemcpyKind,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaMallocPitch = unsafe extern "C" fn(
    dev_ptr: *mut *mut c_void,
    pitch: *mut usize,
    width: usize,
    height: usize,
) -> cudaError_t;

pub type PFN_cudaMemset2D = unsafe extern "C" fn(
    dev_ptr: *mut c_void,
    pitch: usize,
    value: c_int,
    width: usize,
    height: usize,
) -> cudaError_t;

pub type PFN_cudaMemset2DAsync = unsafe extern "C" fn(
    dev_ptr: *mut c_void,
    pitch: usize,
    value: c_int,
    width: usize,
    height: usize,
    stream: cudaStream_t,
) -> cudaError_t;

// ---- Peer memcpy ---------------------------------------------------------

pub type PFN_cudaMemcpyPeer = unsafe extern "C" fn(
    dst: *mut c_void,
    dst_device: c_int,
    src: *const c_void,
    src_device: c_int,
    count: usize,
) -> cudaError_t;

pub type PFN_cudaMemcpyPeerAsync = unsafe extern "C" fn(
    dst: *mut c_void,
    dst_device: c_int,
    src: *const c_void,
    src_device: c_int,
    count: usize,
    stream: cudaStream_t,
) -> cudaError_t;

// ---- Device properties (big struct) --------------------------------------

/// `cudaGetDeviceProperties_v2` — the full 1KB+ device-properties struct.
/// We expose it as an opaque byte buffer; callers can cast to
/// `cudaDeviceProp` from a bindgen-generated header if they need typed
/// access to the individual fields.
pub type PFN_cudaGetDeviceProperties =
    unsafe extern "C" fn(prop: *mut c_void, device: c_int) -> cudaError_t;

// ---- External memory + semaphore interop ---------------------------------
//
// `cudaExternalMemoryHandleDesc` / `cudaExternalMemoryBufferDesc` /
// `cudaExternalSemaphoreHandleDesc` / `cudaExternalSemaphore*Params` are
// binary-compatible with their Driver-API counterparts in
// [`crate::types`]. We reuse those struct definitions here rather than
// duplicating them.

use super::types::{cudaExternalMemory_t, cudaExternalSemaphore_t};

pub type PFN_cudaImportExternalMemory = unsafe extern "C" fn(
    mem_out: *mut cudaExternalMemory_t,
    mem_handle_desc: *const crate::types::CUDA_EXTERNAL_MEMORY_HANDLE_DESC,
) -> cudaError_t;

pub type PFN_cudaDestroyExternalMemory =
    unsafe extern "C" fn(mem: cudaExternalMemory_t) -> cudaError_t;

pub type PFN_cudaExternalMemoryGetMappedBuffer = unsafe extern "C" fn(
    dev_ptr: *mut *mut c_void,
    mem: cudaExternalMemory_t,
    buf_desc: *const crate::types::CUDA_EXTERNAL_MEMORY_BUFFER_DESC,
) -> cudaError_t;

pub type PFN_cudaExternalMemoryGetMappedMipmappedArray = unsafe extern "C" fn(
    mipmap: *mut c_void,
    mem: cudaExternalMemory_t,
    mipmap_desc: *const c_void,
) -> cudaError_t;

pub type PFN_cudaImportExternalSemaphore = unsafe extern "C" fn(
    sem_out: *mut cudaExternalSemaphore_t,
    sem_handle_desc: *const crate::types::CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC,
) -> cudaError_t;

pub type PFN_cudaDestroyExternalSemaphore =
    unsafe extern "C" fn(sem: cudaExternalSemaphore_t) -> cudaError_t;

pub type PFN_cudaSignalExternalSemaphoresAsync = unsafe extern "C" fn(
    ext_sem_array: *const cudaExternalSemaphore_t,
    params_array: *const crate::types::CUDA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS,
    num_ext_sems: c_uint,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaWaitExternalSemaphoresAsync = unsafe extern "C" fn(
    ext_sem_array: *const cudaExternalSemaphore_t,
    params_array: *const crate::types::CUDA_EXTERNAL_SEMAPHORE_WAIT_PARAMS,
    num_ext_sems: c_uint,
    stream: cudaStream_t,
) -> cudaError_t;

// ---- Runtime Wave 1: host-fn launch + stream write/wait value -----------

use super::types::{
    cudaHostFn_t, cudaHostNodeParams, cudaKernelNodeParams, cudaMemAccessDesc,
    cudaMemAllocNodeParams, cudaMemLocation, cudaMemPoolProps, cudaMemPoolPtrExportData,
    cudaMemPool_t, cudaMemsetParams,
};

pub type PFN_cudaLaunchHostFunc = unsafe extern "C" fn(
    stream: cudaStream_t,
    fn_ptr: cudaHostFn_t,
    user_data: *mut c_void,
) -> cudaError_t;

pub type PFN_cudaStreamWriteValue32 = unsafe extern "C" fn(
    stream: cudaStream_t,
    addr: *mut c_void,
    value: u32,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaStreamWriteValue64 = unsafe extern "C" fn(
    stream: cudaStream_t,
    addr: *mut c_void,
    value: u64,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaStreamWaitValue32 = unsafe extern "C" fn(
    stream: cudaStream_t,
    addr: *mut c_void,
    value: u32,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaStreamWaitValue64 = unsafe extern "C" fn(
    stream: cudaStream_t,
    addr: *mut c_void,
    value: u64,
    flags: c_uint,
) -> cudaError_t;

// ---- Memory pools --------------------------------------------------------

pub type PFN_cudaMemPoolCreate =
    unsafe extern "C" fn(pool: *mut cudaMemPool_t, props: *const cudaMemPoolProps) -> cudaError_t;

pub type PFN_cudaMemPoolDestroy = unsafe extern "C" fn(pool: cudaMemPool_t) -> cudaError_t;

pub type PFN_cudaMemPoolSetAttribute =
    unsafe extern "C" fn(pool: cudaMemPool_t, attr: c_int, value: *mut c_void) -> cudaError_t;

pub type PFN_cudaMemPoolGetAttribute =
    unsafe extern "C" fn(pool: cudaMemPool_t, attr: c_int, value: *mut c_void) -> cudaError_t;

pub type PFN_cudaMemPoolTrimTo =
    unsafe extern "C" fn(pool: cudaMemPool_t, min_bytes_to_keep: usize) -> cudaError_t;

pub type PFN_cudaMemPoolSetAccess = unsafe extern "C" fn(
    pool: cudaMemPool_t,
    desc_list: *const cudaMemAccessDesc,
    count: usize,
) -> cudaError_t;

pub type PFN_cudaMemPoolGetAccess = unsafe extern "C" fn(
    flags: *mut c_int,
    pool: cudaMemPool_t,
    location: *mut cudaMemLocation,
) -> cudaError_t;

pub type PFN_cudaMallocFromPoolAsync = unsafe extern "C" fn(
    dev_ptr: *mut *mut c_void,
    size: usize,
    pool: cudaMemPool_t,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaDeviceGetDefaultMemPool =
    unsafe extern "C" fn(pool: *mut cudaMemPool_t, device: c_int) -> cudaError_t;

pub type PFN_cudaDeviceGetMemPool =
    unsafe extern "C" fn(pool: *mut cudaMemPool_t, device: c_int) -> cudaError_t;

pub type PFN_cudaDeviceSetMemPool =
    unsafe extern "C" fn(device: c_int, pool: cudaMemPool_t) -> cudaError_t;

pub type PFN_cudaMemPoolExportToShareableHandle = unsafe extern "C" fn(
    shareable: *mut c_void,
    pool: cudaMemPool_t,
    handle_type: c_int,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaMemPoolImportFromShareableHandle = unsafe extern "C" fn(
    pool: *mut cudaMemPool_t,
    shareable: *mut c_void,
    handle_type: c_int,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaMemPoolExportPointer = unsafe extern "C" fn(
    export_data: *mut cudaMemPoolPtrExportData,
    ptr: *mut c_void,
) -> cudaError_t;

pub type PFN_cudaMemPoolImportPointer = unsafe extern "C" fn(
    ptr: *mut *mut c_void,
    pool: cudaMemPool_t,
    export_data: *mut cudaMemPoolPtrExportData,
) -> cudaError_t;

// ---- Explicit graph node builders ----------------------------------------

pub type PFN_cudaGraphAddKernelNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    node_params: *const cudaKernelNodeParams,
) -> cudaError_t;

pub type PFN_cudaGraphAddMemsetNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    node_params: *const cudaMemsetParams,
) -> cudaError_t;

pub type PFN_cudaGraphAddMemcpyNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    node_params: *const c_void, // cudaMemcpy3DParms — opaque here
) -> cudaError_t;

pub type PFN_cudaGraphAddHostNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    node_params: *const cudaHostNodeParams,
) -> cudaError_t;

pub type PFN_cudaGraphAddEmptyNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
) -> cudaError_t;

pub type PFN_cudaGraphAddChildGraphNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    child_graph: cudaGraph_t,
) -> cudaError_t;

pub type PFN_cudaGraphAddEventRecordNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    event: cudaEvent_t,
) -> cudaError_t;

pub type PFN_cudaGraphAddEventWaitNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    event: cudaEvent_t,
) -> cudaError_t;

pub type PFN_cudaGraphAddMemAllocNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    node_params: *mut cudaMemAllocNodeParams,
) -> cudaError_t;

pub type PFN_cudaGraphAddMemFreeNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    dptr: *mut c_void,
) -> cudaError_t;

// ---- Graph exec update + dependency helpers -----------------------------

pub type PFN_cudaGraphExecUpdate = unsafe extern "C" fn(
    graph_exec: cudaGraphExec_t,
    graph: cudaGraph_t,
    error_node: *mut cudaGraphNode_t,
    result: *mut c_int,
) -> cudaError_t;

pub type PFN_cudaGraphAddDependencies = unsafe extern "C" fn(
    graph: cudaGraph_t,
    from: *const cudaGraphNode_t,
    to: *const cudaGraphNode_t,
    num_dependencies: usize,
) -> cudaError_t;

pub type PFN_cudaGraphMemFreeNodeGetParams =
    unsafe extern "C" fn(node: cudaGraphNode_t, dptr_out: *mut *mut c_void) -> cudaError_t;

pub type PFN_cudaGraphNodeGetType =
    unsafe extern "C" fn(node: cudaGraphNode_t, type_out: *mut c_int) -> cudaError_t;

// ---- Runtime Wave 2: arrays + tex/surf + user objects + coop + IPC ------

use super::types::{cudaArray_t, cudaUserObject_t};

pub type PFN_cudaMallocArray = unsafe extern "C" fn(
    array: *mut cudaArray_t,
    desc: *const c_void, // cudaChannelFormatDesc — 20 bytes
    width: usize,
    height: usize,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaFreeArray = unsafe extern "C" fn(array: cudaArray_t) -> cudaError_t;

pub type PFN_cudaMemcpy2DToArray = unsafe extern "C" fn(
    dst: cudaArray_t,
    w_offset: usize,
    h_offset: usize,
    src: *const c_void,
    spitch: usize,
    width: usize,
    height: usize,
    kind: cudaMemcpyKind,
) -> cudaError_t;

pub type PFN_cudaMemcpy2DFromArray = unsafe extern "C" fn(
    dst: *mut c_void,
    dpitch: usize,
    src: cudaArray_t,
    w_offset: usize,
    h_offset: usize,
    width: usize,
    height: usize,
    kind: cudaMemcpyKind,
) -> cudaError_t;

pub type PFN_cudaCreateTextureObject = unsafe extern "C" fn(
    tex_out: *mut u64,
    resource_desc: *const c_void,
    tex_desc: *const c_void,
    resource_view_desc: *const c_void,
) -> cudaError_t;

pub type PFN_cudaDestroyTextureObject = unsafe extern "C" fn(tex: u64) -> cudaError_t;

pub type PFN_cudaCreateSurfaceObject =
    unsafe extern "C" fn(surf_out: *mut u64, resource_desc: *const c_void) -> cudaError_t;

pub type PFN_cudaDestroySurfaceObject = unsafe extern "C" fn(surf: u64) -> cudaError_t;

// User objects for graphs
pub type PFN_cudaUserObjectCreate = unsafe extern "C" fn(
    object_out: *mut cudaUserObject_t,
    ptr: *mut c_void,
    destroy: cudaHostFn_t,
    initial_refcount: c_uint,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaUserObjectRetain =
    unsafe extern "C" fn(object: cudaUserObject_t, count: c_uint) -> cudaError_t;

pub type PFN_cudaUserObjectRelease =
    unsafe extern "C" fn(object: cudaUserObject_t, count: c_uint) -> cudaError_t;

pub type PFN_cudaGraphRetainUserObject = unsafe extern "C" fn(
    graph: cudaGraph_t,
    object: cudaUserObject_t,
    count: c_uint,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphReleaseUserObject = unsafe extern "C" fn(
    graph: cudaGraph_t,
    object: cudaUserObject_t,
    count: c_uint,
) -> cudaError_t;

// Cooperative launch
pub type PFN_cudaLaunchCooperativeKernel = unsafe extern "C" fn(
    func: *const c_void,
    grid_dim: super::types::dim3,
    block_dim: super::types::dim3,
    args: *mut *mut c_void,
    shared_mem: usize,
    stream: cudaStream_t,
) -> cudaError_t;

// Stream attach
pub type PFN_cudaStreamAttachMemAsync = unsafe extern "C" fn(
    stream: cudaStream_t,
    dev_ptr: *mut c_void,
    length: usize,
    flags: c_uint,
) -> cudaError_t;

// Stream attrs
pub type PFN_cudaStreamGetAttribute =
    unsafe extern "C" fn(stream: cudaStream_t, attr: c_int, value_out: *mut c_void) -> cudaError_t;

pub type PFN_cudaStreamSetAttribute =
    unsafe extern "C" fn(stream: cudaStream_t, attr: c_int, value: *const c_void) -> cudaError_t;

pub type PFN_cudaStreamCopyAttributes =
    unsafe extern "C" fn(dst: cudaStream_t, src: cudaStream_t) -> cudaError_t;

// IPC
pub type PFN_cudaIpcGetEventHandle = unsafe extern "C" fn(
    handle_out: *mut crate::types::CUipcEventHandle,
    event: cudaEvent_t,
) -> cudaError_t;

pub type PFN_cudaIpcOpenEventHandle = unsafe extern "C" fn(
    event_out: *mut cudaEvent_t,
    handle: crate::types::CUipcEventHandle,
) -> cudaError_t;

pub type PFN_cudaIpcGetMemHandle = unsafe extern "C" fn(
    handle_out: *mut crate::types::CUipcMemHandle,
    dev_ptr: *mut c_void,
) -> cudaError_t;

pub type PFN_cudaIpcOpenMemHandle = unsafe extern "C" fn(
    dev_ptr_out: *mut *mut c_void,
    handle: crate::types::CUipcMemHandle,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaIpcCloseMemHandle = unsafe extern "C" fn(dev_ptr: *mut c_void) -> cudaError_t;

// Device flags
pub type PFN_cudaSetDeviceFlags = unsafe extern "C" fn(flags: c_uint) -> cudaError_t;
pub type PFN_cudaGetDeviceFlags = unsafe extern "C" fn(flags_out: *mut c_uint) -> cudaError_t;

// ---- Runtime Wave 3: batch mem ops + conditional nodes + driver bridge + occupancy ----

pub type PFN_cudaStreamBatchMemOp = unsafe extern "C" fn(
    stream: cudaStream_t,
    count: c_uint,
    param_array: *mut crate::types::CUstreamBatchMemOpParams,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphAddNode = unsafe extern "C" fn(
    graph_node: *mut cudaGraphNode_t,
    graph: cudaGraph_t,
    dependencies: *const cudaGraphNode_t,
    num_dependencies: usize,
    node_params: *mut c_void,
) -> cudaError_t;

pub type PFN_cudaGraphConditionalHandleCreate = unsafe extern "C" fn(
    handle_out: *mut u64,
    graph: cudaGraph_t,
    default_launch_value: c_uint,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGetDriverEntryPoint = unsafe extern "C" fn(
    symbol: *const c_char,
    fn_ptr_out: *mut *mut c_void,
    flags: u64,
    driver_status: *mut c_int,
) -> cudaError_t;

pub type PFN_cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags =
    unsafe extern "C" fn(
        num_blocks: *mut c_int,
        func: *const c_void,
        block_size: c_int,
        dynamic_smem_bytes: usize,
        flags: c_uint,
    ) -> cudaError_t;

pub type PFN_cudaOccupancyAvailableDynamicSMemPerBlock = unsafe extern "C" fn(
    dynamic_smem_size: *mut usize,
    func: *const c_void,
    num_blocks: c_int,
    block_size: c_int,
) -> cudaError_t;

// ---- Runtime Wave 4: graphics interop (core + GL + D3D + VDPAU + EGL + NvSci) ----

// `cudaGraphicsResource_t` is an opaque pointer — typedef-compatible with
// the Driver API's `CUgraphicsResource`. We reuse the Driver alias so
// both loaders speak the same ABI.
use crate::CUgraphicsResource as cudaGraphicsResource_t;

// -- Core graphics (shared across GL / D3D / VDPAU / EGL) --

pub type PFN_cudaGraphicsUnregisterResource =
    unsafe extern "C" fn(resource: cudaGraphicsResource_t) -> cudaError_t;

pub type PFN_cudaGraphicsMapResources = unsafe extern "C" fn(
    count: c_int,
    resources: *mut cudaGraphicsResource_t,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaGraphicsUnmapResources = unsafe extern "C" fn(
    count: c_int,
    resources: *mut cudaGraphicsResource_t,
    stream: cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaGraphicsResourceGetMappedPointer = unsafe extern "C" fn(
    dev_ptr_out: *mut *mut c_void,
    size_out: *mut usize,
    resource: cudaGraphicsResource_t,
) -> cudaError_t;

pub type PFN_cudaGraphicsSubResourceGetMappedArray = unsafe extern "C" fn(
    array_out: *mut *mut c_void, // cudaArray_t
    resource: cudaGraphicsResource_t,
    array_index: c_uint,
    mip_level: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsResourceGetMappedMipmappedArray = unsafe extern "C" fn(
    mipmap_out: *mut *mut c_void, // cudaMipmappedArray_t
    resource: cudaGraphicsResource_t,
) -> cudaError_t;

pub type PFN_cudaGraphicsResourceSetMapFlags =
    unsafe extern "C" fn(resource: cudaGraphicsResource_t, flags: c_uint) -> cudaError_t;

// -- OpenGL --

pub type PFN_cudaGraphicsGLRegisterBuffer = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    buffer: c_uint, // GLuint
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsGLRegisterImage = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    image: c_uint,  // GLuint
    target: c_uint, // GLenum
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGLGetDevices = unsafe extern "C" fn(
    cuda_device_count_out: *mut c_uint,
    cuda_devices: *mut c_int,
    cuda_device_count_in: c_uint,
    device_list: c_uint, // cudaGLDeviceList
) -> cudaError_t;

// -- D3D9 / D3D10 / D3D11 --

pub type PFN_cudaD3D9GetDevice =
    unsafe extern "C" fn(device_out: *mut c_int, adapter_name: *const c_char) -> cudaError_t;

pub type PFN_cudaD3D9GetDevices = unsafe extern "C" fn(
    cuda_device_count_out: *mut c_uint,
    cuda_devices: *mut c_int,
    cuda_device_count_in: c_uint,
    d3d_device: *mut c_void,
    device_list: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsD3D9RegisterResource = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    d3d_resource: *mut c_void,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaD3D10GetDevice =
    unsafe extern "C" fn(device_out: *mut c_int, adapter: *mut c_void) -> cudaError_t;

pub type PFN_cudaD3D10GetDevices = unsafe extern "C" fn(
    cuda_device_count_out: *mut c_uint,
    cuda_devices: *mut c_int,
    cuda_device_count_in: c_uint,
    d3d_device: *mut c_void,
    device_list: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsD3D10RegisterResource = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    d3d_resource: *mut c_void,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaD3D11GetDevice =
    unsafe extern "C" fn(device_out: *mut c_int, adapter: *mut c_void) -> cudaError_t;

pub type PFN_cudaD3D11GetDevices = unsafe extern "C" fn(
    cuda_device_count_out: *mut c_uint,
    cuda_devices: *mut c_int,
    cuda_device_count_in: c_uint,
    d3d_device: *mut c_void,
    device_list: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsD3D11RegisterResource = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    d3d_resource: *mut c_void,
    flags: c_uint,
) -> cudaError_t;

// -- VDPAU --

pub type PFN_cudaVDPAUGetDevice = unsafe extern "C" fn(
    device_out: *mut c_int,
    vdp_device: *mut c_void,
    vdp_get_proc_address: *mut c_void,
) -> cudaError_t;

pub type PFN_cudaGraphicsVDPAURegisterVideoSurface = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    vdp_surface: *mut c_void,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsVDPAURegisterOutputSurface = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    vdp_surface: *mut c_void,
    flags: c_uint,
) -> cudaError_t;

// -- EGL --

pub type PFN_cudaGraphicsEGLRegisterImage = unsafe extern "C" fn(
    resource_out: *mut cudaGraphicsResource_t,
    image: *mut c_void, // EGLImageKHR
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGraphicsResourceGetMappedEglFrame = unsafe extern "C" fn(
    egl_frame_out: *mut c_void, // cudaEglFrame
    resource: cudaGraphicsResource_t,
    index: c_uint,
    mip_level: c_uint,
) -> cudaError_t;

pub type PFN_cudaEventCreateFromEGLSync = unsafe extern "C" fn(
    event_out: *mut cudaEvent_t,
    egl_sync: *mut c_void, // EGLSyncKHR
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaEGLStreamConsumerConnect = unsafe extern "C" fn(
    connection: *mut c_void, // cudaEglStreamConnection*
    egl_stream: *mut c_void, // EGLStreamKHR
) -> cudaError_t;

pub type PFN_cudaEGLStreamConsumerDisconnect =
    unsafe extern "C" fn(connection: *mut c_void) -> cudaError_t;

pub type PFN_cudaEGLStreamConsumerAcquireFrame = unsafe extern "C" fn(
    connection: *mut c_void,
    resource_out: *mut cudaGraphicsResource_t,
    stream_out: *mut cudaStream_t,
    timeout: c_uint,
) -> cudaError_t;

pub type PFN_cudaEGLStreamConsumerReleaseFrame = unsafe extern "C" fn(
    connection: *mut c_void,
    resource: cudaGraphicsResource_t,
    stream_inout: *mut cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaEGLStreamProducerConnect = unsafe extern "C" fn(
    connection: *mut c_void,
    egl_stream: *mut c_void,
    width: c_int,
    height: c_int,
) -> cudaError_t;

pub type PFN_cudaEGLStreamProducerDisconnect =
    unsafe extern "C" fn(connection: *mut c_void) -> cudaError_t;

pub type PFN_cudaEGLStreamProducerPresentFrame = unsafe extern "C" fn(
    connection: *mut c_void,
    egl_frame: *mut c_void,
    stream_inout: *mut cudaStream_t,
) -> cudaError_t;

pub type PFN_cudaEGLStreamProducerReturnFrame = unsafe extern "C" fn(
    connection: *mut c_void,
    egl_frame_out: *mut c_void,
    stream_inout: *mut cudaStream_t,
) -> cudaError_t;

// -- NvSci --

pub type PFN_cudaDeviceGetNvSciSyncAttributes = unsafe extern "C" fn(
    attr_list: *mut c_void, // NvSciSyncAttrList
    device: c_int,
    direction: c_int,
) -> cudaError_t;

// ---- Runtime Wave 5: arrays/tex/surf + 3D + launch-ex + profiler + VMM + multicast + green ctx + tensor maps ----

use super::types::{
    cudaGreenCtx_t, cudaLaunchConfig_t, cudaMemGenericAllocationHandle_t, cudaMipmappedArray_t,
    cudaSurfaceObject_t, cudaTextureObject_t,
};

// -- Arrays (extra) + tex/surf object descriptors --

pub type PFN_cudaMallocMipmappedArray = unsafe extern "C" fn(
    mipmap: *mut cudaMipmappedArray_t,
    desc: *const c_void,   // cudaChannelFormatDesc
    extent: *const c_void, // cudaExtent
    num_levels: c_uint,
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaFreeMipmappedArray =
    unsafe extern "C" fn(mipmap: cudaMipmappedArray_t) -> cudaError_t;

pub type PFN_cudaArrayGetInfo = unsafe extern "C" fn(
    desc_out: *mut c_void,   // cudaChannelFormatDesc
    extent_out: *mut c_void, // cudaExtent
    flags_out: *mut c_uint,
    array: cudaArray_t,
) -> cudaError_t;

pub type PFN_cudaGetMipmappedArrayLevel = unsafe extern "C" fn(
    level_out: *mut cudaArray_t,
    mipmap: cudaMipmappedArray_t,
    level: c_uint,
) -> cudaError_t;

pub type PFN_cudaGetTextureObjectResourceDesc = unsafe extern "C" fn(
    desc_out: *mut c_void, // cudaResourceDesc
    tex_object: cudaTextureObject_t,
) -> cudaError_t;

pub type PFN_cudaGetTextureObjectTextureDesc = unsafe extern "C" fn(
    desc_out: *mut c_void, // cudaTextureDesc
    tex_object: cudaTextureObject_t,
) -> cudaError_t;

pub type PFN_cudaGetTextureObjectResourceViewDesc = unsafe extern "C" fn(
    desc_out: *mut c_void, // cudaResourceViewDesc
    tex_object: cudaTextureObject_t,
) -> cudaError_t;

pub type PFN_cudaGetSurfaceObjectResourceDesc = unsafe extern "C" fn(
    desc_out: *mut c_void, // cudaResourceDesc
    surf_object: cudaSurfaceObject_t,
) -> cudaError_t;

// Signature note: the *existing* `PFN_cudaCreateTextureObject` already
// uses `*const c_void` for the descriptors, so no change there.

// -- 3D memcpy --

pub type PFN_cudaMemcpy3D = unsafe extern "C" fn(params: *const c_void) -> cudaError_t;
pub type PFN_cudaMemcpy3DAsync =
    unsafe extern "C" fn(params: *const c_void, stream: cudaStream_t) -> cudaError_t;
pub type PFN_cudaMemcpy3DPeer = unsafe extern "C" fn(params: *const c_void) -> cudaError_t;
pub type PFN_cudaMemcpy3DPeerAsync =
    unsafe extern "C" fn(params: *const c_void, stream: cudaStream_t) -> cudaError_t;

pub type PFN_cudaMemset3D = unsafe extern "C" fn(
    pitched_dev_ptr: *mut c_void, // cudaPitchedPtr (passed by value in C, but CUDA runtime's C ABI
    // copies via pointer on some platforms — we just pass the 32-byte
    // struct through as *mut for portability).
    value: c_int,
    extent: *const c_void, // cudaExtent
) -> cudaError_t;

pub type PFN_cudaMalloc3D = unsafe extern "C" fn(
    pitched_dev_ptr: *mut c_void, // out
    extent: *const c_void,        // cudaExtent
) -> cudaError_t;

pub type PFN_cudaMalloc3DArray = unsafe extern "C" fn(
    array: *mut cudaArray_t,
    desc: *const c_void,
    extent: *const c_void, // cudaExtent
    flags: c_uint,
) -> cudaError_t;

// -- Launch-ex / cluster --

pub type PFN_cudaLaunchKernelEx = unsafe extern "C" fn(
    config: *const cudaLaunchConfig_t,
    func: *const c_void,
    args: *mut *mut c_void,
) -> cudaError_t;

// -- Profiler --

pub type PFN_cudaProfilerStart = unsafe extern "C" fn() -> cudaError_t;
pub type PFN_cudaProfilerStop = unsafe extern "C" fn() -> cudaError_t;

// -- Tensor maps (Hopper, driver-hosted; runtime doesn't expose dedicated PFNs) --
// No runtime PFNs exist for tensor map encoding — the Hopper tensor-map
// API (`cuTensorMapEncodeTiled`, etc.) is Driver-API only. The Runtime
// accepts an already-built `CUtensorMap` via regular pointer-struct
// kernel-argument marshaling. So we skip the runtime tensor-map PFNs.

// -- VMM --

pub type PFN_cudaMemAddressReserve = unsafe extern "C" fn(
    dev_ptr_out: *mut *mut c_void,
    size: usize,
    alignment: usize,
    addr: *mut c_void,
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaMemAddressFree =
    unsafe extern "C" fn(dev_ptr: *mut c_void, size: usize) -> cudaError_t;

pub type PFN_cudaMemCreate = unsafe extern "C" fn(
    handle_out: *mut cudaMemGenericAllocationHandle_t,
    size: usize,
    prop: *const c_void, // cudaMemAllocationProp
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaMemRelease =
    unsafe extern "C" fn(handle: cudaMemGenericAllocationHandle_t) -> cudaError_t;

pub type PFN_cudaMemMap = unsafe extern "C" fn(
    ptr: *mut c_void,
    size: usize,
    offset: usize,
    handle: cudaMemGenericAllocationHandle_t,
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaMemUnmap = unsafe extern "C" fn(ptr: *mut c_void, size: usize) -> cudaError_t;

pub type PFN_cudaMemSetAccess = unsafe extern "C" fn(
    ptr: *mut c_void,
    size: usize,
    desc: *const c_void, // cudaMemAccessDesc
    count: usize,
) -> cudaError_t;

pub type PFN_cudaMemGetAccess = unsafe extern "C" fn(
    flags_out: *mut u64,
    location: *const c_void, // cudaMemLocation
    ptr: *mut c_void,
) -> cudaError_t;

pub type PFN_cudaMemGetAllocationGranularity = unsafe extern "C" fn(
    granularity_out: *mut usize,
    prop: *const c_void, // cudaMemAllocationProp
    option: c_int,
) -> cudaError_t;

pub type PFN_cudaMemGetAllocationPropertiesFromHandle = unsafe extern "C" fn(
    prop_out: *mut c_void, // cudaMemAllocationProp
    handle: cudaMemGenericAllocationHandle_t,
) -> cudaError_t;

pub type PFN_cudaMemExportToShareableHandle = unsafe extern "C" fn(
    shareable_handle_out: *mut c_void,
    handle: cudaMemGenericAllocationHandle_t,
    handle_type: c_int,
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaMemImportFromShareableHandle = unsafe extern "C" fn(
    handle_out: *mut cudaMemGenericAllocationHandle_t,
    os_handle: *mut c_void,
    shareable_handle_type: c_int,
) -> cudaError_t;

pub type PFN_cudaMemRetainAllocationHandle = unsafe extern "C" fn(
    handle_out: *mut cudaMemGenericAllocationHandle_t,
    addr: *mut c_void,
) -> cudaError_t;

// -- Multicast (12.0+) --

pub type PFN_cudaMulticastCreate = unsafe extern "C" fn(
    mc_handle_out: *mut cudaMemGenericAllocationHandle_t,
    prop: *const c_void, // cudaMulticastObjectProp
) -> cudaError_t;

pub type PFN_cudaMulticastAddDevice =
    unsafe extern "C" fn(mc_handle: cudaMemGenericAllocationHandle_t, device: c_int) -> cudaError_t;

pub type PFN_cudaMulticastBindMem = unsafe extern "C" fn(
    mc_handle: cudaMemGenericAllocationHandle_t,
    mc_offset: usize,
    mem_handle: cudaMemGenericAllocationHandle_t,
    mem_offset: usize,
    size: usize,
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaMulticastBindAddr = unsafe extern "C" fn(
    mc_handle: cudaMemGenericAllocationHandle_t,
    mc_offset: usize,
    mem_ptr: *mut c_void,
    size: usize,
    flags: u64,
) -> cudaError_t;

pub type PFN_cudaMulticastUnbind = unsafe extern "C" fn(
    mc_handle: cudaMemGenericAllocationHandle_t,
    device: c_int,
    mc_offset: usize,
    size: usize,
) -> cudaError_t;

pub type PFN_cudaMulticastGetGranularity = unsafe extern "C" fn(
    granularity_out: *mut usize,
    prop: *const c_void, // cudaMulticastObjectProp
    option: c_int,
) -> cudaError_t;

// -- Green contexts (Runtime, 13.1+) --

pub type PFN_cudaDeviceCreateGreenCtx = unsafe extern "C" fn(
    green_ctx_out: *mut cudaGreenCtx_t,
    desc: *const c_void, // cudaDevResourceDesc
    flags: c_uint,
) -> cudaError_t;

pub type PFN_cudaGreenCtxDestroy = unsafe extern "C" fn(green_ctx: cudaGreenCtx_t) -> cudaError_t;

pub type PFN_cudaGreenCtxRecordEvent =
    unsafe extern "C" fn(green_ctx: cudaGreenCtx_t, event: cudaEvent_t) -> cudaError_t;

pub type PFN_cudaGreenCtxWaitEvent =
    unsafe extern "C" fn(green_ctx: cudaGreenCtx_t, event: cudaEvent_t) -> cudaError_t;

pub type PFN_cudaGreenCtxStreamCreate = unsafe extern "C" fn(
    stream_out: *mut cudaStream_t,
    green_ctx: cudaGreenCtx_t,
    flags: c_uint,
    priority: c_int,
) -> cudaError_t;