@@ -19,29 +19,6 @@ use crate::memory::UnifiedPointer;
1919use crate :: memory:: malloc:: { cuda_free_unified, cuda_malloc_unified} ;
2020use crate :: prelude:: Stream ;
2121
22- #[ cfg( any( cuMemPrefetchAsync_v2, cuMemAdvise_v2) ) ]
23- unsafe fn cu_mem_location (
24- type_ : driver_sys:: CUmemLocationType ,
25- id : std:: os:: raw:: c_int ,
26- ) -> driver_sys:: CUmemLocation {
27- let mut location = std:: mem:: MaybeUninit :: < driver_sys:: CUmemLocation > :: zeroed ( ) ;
28- let location_ptr = location. as_mut_ptr ( ) ;
29-
30- // Support both older bindgen output (`{ type_, id }`) and the newer
31- // anonymous-union layout emitted from CUDA 13.2 headers.
32- unsafe {
33- ( * location_ptr) . type_ = type_;
34- std:: ptr:: write (
35- ( location_ptr. cast :: < u8 > ( ) )
36- . add ( std:: mem:: size_of :: < driver_sys:: CUmemLocationType > ( ) )
37- . cast :: < std:: os:: raw:: c_int > ( ) ,
38- id,
39- ) ;
40-
41- location. assume_init ( )
42- }
43- }
44-
4522/// A pointer type for heap-allocation in CUDA unified memory.
4623///
4724/// See the [`module-level documentation`](../memory/index.html) for more information on unified
@@ -663,13 +640,20 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
663640 let mem_size = std:: mem:: size_of_val ( slice) ;
664641
665642 unsafe {
643+ let id = -1 ; // -1 is CU_DEVICE_CPU
666644 driver_sys:: cuMemPrefetchAsync (
667645 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
668646 mem_size,
669647 #[ cfg( cuMemPrefetchAsync_v2) ]
670- cu_mem_location ( driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_HOST , 0 ) ,
648+ driver_sys:: CUmemLocation {
649+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
650+ #[ cfg( cuMemLocation_anon_id) ]
651+ __bindgen_anon_1 : driver_sys:: CUmemLocation_st__bindgen_ty_1 { id } ,
652+ #[ cfg( not( cuMemLocation_anon_id) ) ]
653+ id,
654+ } ,
671655 #[ cfg( not( cuMemPrefetchAsync_v2) ) ]
672- - 1 , // -1 is CU_DEVICE_CPU
656+ id ,
673657 #[ cfg( cuMemPrefetchAsync_v2) ]
674658 0 , // flags for future use, must be 0 as of CUDA 13.0
675659 stream. as_inner ( ) ,
@@ -710,7 +694,13 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
710694 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
711695 mem_size,
712696 #[ cfg( cuMemPrefetchAsync_v2) ]
713- cu_mem_location ( driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE , id) ,
697+ driver_sys:: CUmemLocation {
698+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
699+ #[ cfg( cuMemLocation_anon_id) ]
700+ __bindgen_anon_1 : driver_sys:: CUmemLocation_st__bindgen_ty_1 { id } ,
701+ #[ cfg( not( cuMemLocation_anon_id) ) ]
702+ id,
703+ } ,
714704 #[ cfg( not( cuMemPrefetchAsync_v2) ) ]
715705 id,
716706 #[ cfg( cuMemPrefetchAsync_v2) ]
@@ -743,14 +733,21 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
743733 } ;
744734
745735 unsafe {
736+ let id = 0 ;
746737 driver_sys:: cuMemAdvise (
747738 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
748739 mem_size,
749740 advice,
750741 #[ cfg( cuMemAdvise_v2) ]
751- cu_mem_location ( driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_HOST , 0 ) ,
742+ driver_sys:: CUmemLocation {
743+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
744+ #[ cfg( cuMemLocation_anon_id) ]
745+ __bindgen_anon_1 : driver_sys:: CUmemLocation_st__bindgen_ty_1 { id } ,
746+ #[ cfg( not( cuMemLocation_anon_id) ) ]
747+ id,
748+ } ,
752749 #[ cfg( not( cuMemAdvise_v2) ) ]
753- 0 ,
750+ id ,
754751 )
755752 . to_result ( ) ?;
756753 }
@@ -787,11 +784,12 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
787784 mem_size,
788785 driver_sys:: CUmem_advise :: CU_MEM_ADVISE_SET_PREFERRED_LOCATION ,
789786 #[ cfg( cuMemAdvise_v2) ]
790- match preferred_location {
791- Some ( _) => {
792- cu_mem_location ( driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE , id)
793- }
794- None => cu_mem_location ( driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_HOST , 0 ) ,
787+ driver_sys:: CUmemLocation {
788+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
789+ #[ cfg( cuMemLocation_anon_id) ]
790+ __bindgen_anon_1 : driver_sys:: CUmemLocation_st__bindgen_ty_1 { id } ,
791+ #[ cfg( not( cuMemLocation_anon_id) ) ]
792+ id,
795793 } ,
796794 #[ cfg( not( cuMemAdvise_v2) ) ]
797795 id,
@@ -807,14 +805,21 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
807805 let mem_size = std:: mem:: size_of_val ( slice) ;
808806
809807 unsafe {
808+ let id = 0 ;
810809 driver_sys:: cuMemAdvise (
811810 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
812811 mem_size,
813812 driver_sys:: CUmem_advise :: CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION ,
814813 #[ cfg( cuMemAdvise_v2) ]
815- cu_mem_location ( driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_HOST , 0 ) ,
814+ driver_sys:: CUmemLocation {
815+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
816+ #[ cfg( cuMemLocation_anon_id) ]
817+ __bindgen_anon_1 : driver_sys:: CUmemLocation_st__bindgen_ty_1 { id } ,
818+ #[ cfg( not( cuMemLocation_anon_id) ) ]
819+ id,
820+ } ,
816821 #[ cfg( not( cuMemAdvise_v2) ) ]
817- 0 ,
822+ id ,
818823 )
819824 . to_result ( ) ?;
820825 }
0 commit comments