@@ -640,10 +640,19 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
640640 let mem_size = std:: mem:: size_of_val ( slice) ;
641641
642642 unsafe {
643+ let id = -1 ; // -1 is CU_DEVICE_CPU
643644 driver_sys:: cuMemPrefetchAsync (
644645 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
645646 mem_size,
646- -1 , // CU_DEVICE_CPU #define
647+ #[ cfg( cuMemPrefetchAsync_v2) ]
648+ driver_sys:: CUmemLocation {
649+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
650+ id,
651+ } ,
652+ #[ cfg( not( cuMemPrefetchAsync_v2) ) ]
653+ id,
654+ #[ cfg( cuMemPrefetchAsync_v2) ]
655+ 0 , // flags for future use, must be 0 as of CUDA 13.0
647656 stream. as_inner ( ) ,
648657 )
649658 . to_result ( ) ?;
@@ -677,10 +686,19 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
677686 let mem_size = std:: mem:: size_of_val ( slice) ;
678687
679688 unsafe {
689+ let id = device. as_raw ( ) ;
680690 driver_sys:: cuMemPrefetchAsync (
681691 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
682692 mem_size,
683- device. as_raw ( ) ,
693+ #[ cfg( cuMemPrefetchAsync_v2) ]
694+ driver_sys:: CUmemLocation {
695+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
696+ id,
697+ } ,
698+ #[ cfg( not( cuMemPrefetchAsync_v2) ) ]
699+ id,
700+ #[ cfg( cuMemPrefetchAsync_v2) ]
701+ 0 , // flags for future use, must be 0 as of CUDA 13.0
684702 stream. as_inner ( ) ,
685703 )
686704 . to_result ( ) ?;
@@ -709,11 +727,18 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
709727 } ;
710728
711729 unsafe {
730+ let id = 0 ;
712731 driver_sys:: cuMemAdvise (
713732 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
714733 mem_size,
715734 advice,
716- 0 ,
735+ #[ cfg( cuMemAdvise_v2) ]
736+ driver_sys:: CUmemLocation {
737+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
738+ id,
739+ } ,
740+ #[ cfg( not( cuMemAdvise_v2) ) ]
741+ id,
717742 )
718743 . to_result ( ) ?;
719744 }
@@ -744,11 +769,18 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
744769 let mem_size = std:: mem:: size_of_val ( slice) ;
745770
746771 unsafe {
772+ let id = preferred_location. map ( |d| d. as_raw ( ) ) . unwrap_or ( -1 ) ; // -1 is CU_DEVICE_CPU
747773 driver_sys:: cuMemAdvise (
748774 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
749775 mem_size,
750776 driver_sys:: CUmem_advise :: CU_MEM_ADVISE_SET_PREFERRED_LOCATION ,
751- preferred_location. map ( |d| d. as_raw ( ) ) . unwrap_or ( -1 ) ,
777+ #[ cfg( cuMemAdvise_v2) ]
778+ driver_sys:: CUmemLocation {
779+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
780+ id,
781+ } ,
782+ #[ cfg( not( cuMemAdvise_v2) ) ]
783+ id,
752784 )
753785 . to_result ( ) ?;
754786 }
@@ -761,11 +793,18 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed {
761793 let mem_size = std:: mem:: size_of_val ( slice) ;
762794
763795 unsafe {
796+ let id = 0 ;
764797 driver_sys:: cuMemAdvise (
765798 slice. as_ptr ( ) as driver_sys:: CUdeviceptr ,
766799 mem_size,
767800 driver_sys:: CUmem_advise :: CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION ,
768- 0 ,
801+ #[ cfg( cuMemAdvise_v2) ]
802+ driver_sys:: CUmemLocation {
803+ type_ : driver_sys:: CUmemLocationType :: CU_MEM_LOCATION_TYPE_DEVICE ,
804+ id,
805+ } ,
806+ #[ cfg( not( cuMemAdvise_v2) ) ]
807+ id,
769808 )
770809 . to_result ( ) ?;
771810 }
0 commit comments