@@ -773,28 +773,6 @@ ur_result_t AsanInterceptor::prepareLaunch(
773
773
LaunchInfo.Data .Host .DeviceTy = DeviceInfo->Type ;
774
774
LaunchInfo.Data .Host .Debug = getOptions ().Debug ? 1 : 0 ;
775
775
776
- auto EnqueueAllocateShadowMemory = [Context = ContextInfo->Handle ,
777
- Device = DeviceInfo->Handle ,
778
- Queue](size_t Size, uptr &Ptr) {
779
- void *Allocated = nullptr ;
780
- auto URes = getContext ()->urDdiTable .USM .pfnDeviceAlloc (
781
- Context, Device, nullptr , nullptr , Size, &Allocated);
782
- if (URes != UR_RESULT_SUCCESS) {
783
- return URes;
784
- }
785
- // Initialize shadow memory
786
- URes = EnqueueUSMBlockingSet (Queue, Allocated, 0 , Size);
787
- if (URes != UR_RESULT_SUCCESS) {
788
- [[maybe_unused]] auto URes =
789
- getContext ()->urDdiTable .USM .pfnFree (Context, Allocated);
790
- assert (URes == UR_RESULT_SUCCESS &&
791
- " urUSMFree failed at allocating shadow memory" );
792
- Allocated = nullptr ;
793
- }
794
- Ptr = (uptr)Allocated;
795
- return URes;
796
- };
797
-
798
776
auto LocalMemoryUsage =
799
777
GetKernelLocalMemorySize (Kernel, DeviceInfo->Handle );
800
778
auto PrivateMemoryUsage =
@@ -806,86 +784,45 @@ ur_result_t AsanInterceptor::prepareLaunch(
806
784
807
785
// Write shadow memory offset for local memory
808
786
if (getOptions ().DetectLocals ) {
809
- // CPU needn't this
810
- if (DeviceInfo->Type == DeviceType::GPU_PVC ||
811
- DeviceInfo->Type == DeviceType::GPU_DG2) {
812
- const size_t LocalMemorySize =
813
- GetDeviceLocalMemorySize (DeviceInfo->Handle );
814
- const size_t LocalShadowMemorySize =
815
- (NumWG * LocalMemorySize) >> ASAN_SHADOW_SCALE;
816
-
817
- getContext ()->logger .debug (
818
- " LocalMemory(WorkGroup={}, LocalMemorySize={}, "
819
- " LocalShadowMemorySize={})" ,
820
- NumWG, LocalMemorySize, LocalShadowMemorySize);
821
-
822
- if (EnqueueAllocateShadowMemory (
823
- LocalShadowMemorySize,
824
- LaunchInfo.Data .Host .LocalShadowOffset ) !=
825
- UR_RESULT_SUCCESS) {
826
- getContext ()->logger .warning (
827
- " Failed to allocate shadow memory for local "
828
- " memory, maybe the number of workgroup ({}) is too "
829
- " large" ,
830
- NumWG);
831
- getContext ()->logger .warning (
832
- " Skip checking local memory of kernel <{}>" ,
833
- GetKernelName (Kernel));
834
- } else {
835
- LaunchInfo.Data .Host .LocalShadowOffsetEnd =
836
- LaunchInfo.Data .Host .LocalShadowOffset +
837
- LocalShadowMemorySize - 1 ;
838
-
839
- ContextInfo->Stats .UpdateShadowMalloced (
840
- LocalShadowMemorySize);
841
-
842
- getContext ()->logger .info (
843
- " ShadowMemory(Local, {} - {})" ,
844
- (void *)LaunchInfo.Data .Host .LocalShadowOffset ,
845
- (void *)LaunchInfo.Data .Host .LocalShadowOffsetEnd );
846
- }
787
+ if (DeviceInfo->Shadow ->AllocLocalShadow (
788
+ Queue, NumWG, LaunchInfo.Data .Host .LocalShadowOffset ,
789
+ LaunchInfo.Data .Host .LocalShadowOffsetEnd ) !=
790
+ UR_RESULT_SUCCESS) {
791
+ getContext ()->logger .warning (
792
+ " Failed to allocate shadow memory for local "
793
+ " memory, maybe the number of workgroup ({}) is too "
794
+ " large" ,
795
+ NumWG);
796
+ getContext ()->logger .warning (
797
+ " Skip checking local memory of kernel <{}>" ,
798
+ GetKernelName (Kernel));
799
+ } else {
800
+ getContext ()->logger .info (
801
+ " ShadowMemory(Local, WorkGroup{}, {} - {})" , NumWG,
802
+ (void *)LaunchInfo.Data .Host .LocalShadowOffset ,
803
+ (void *)LaunchInfo.Data .Host .LocalShadowOffsetEnd );
847
804
}
848
805
}
849
806
850
807
// Write shadow memory offset for private memory
851
808
if (getOptions ().DetectPrivates ) {
852
- if (DeviceInfo->Type == DeviceType::CPU) {
853
- LaunchInfo.Data .Host .PrivateShadowOffset =
854
- DeviceInfo->Shadow ->ShadowBegin ;
855
- } else if (DeviceInfo->Type == DeviceType::GPU_PVC ||
856
- DeviceInfo->Type == DeviceType::GPU_DG2) {
857
- const size_t PrivateShadowMemorySize =
858
- (NumWG * ASAN_PRIVATE_SIZE) >> ASAN_SHADOW_SCALE;
859
-
860
- getContext ()->logger .debug (" PrivateMemory(WorkGroup={}, "
861
- " PrivateShadowMemorySize={})" ,
862
- NumWG, PrivateShadowMemorySize);
863
-
864
- if (EnqueueAllocateShadowMemory (
865
- PrivateShadowMemorySize,
866
- LaunchInfo.Data .Host .PrivateShadowOffset ) !=
867
- UR_RESULT_SUCCESS) {
868
- getContext ()->logger .warning (
869
- " Failed to allocate shadow memory for private "
870
- " memory, maybe the number of workgroup ({}) is too "
871
- " large" ,
872
- NumWG);
873
- getContext ()->logger .warning (
874
- " Skip checking private memory of kernel <{}>" ,
875
- GetKernelName (Kernel));
876
- } else {
877
- LaunchInfo.Data .Host .PrivateShadowOffsetEnd =
878
- LaunchInfo.Data .Host .PrivateShadowOffset +
879
- PrivateShadowMemorySize - 1 ;
880
-
881
- ContextInfo->Stats .UpdateShadowMalloced (
882
- PrivateShadowMemorySize);
883
-
884
- getContext ()->logger .info (
885
- " ShadowMemory(Private, {} - {})" ,
886
- (void *)LaunchInfo.Data .Host .PrivateShadowOffset ,
887
- (void *)LaunchInfo.Data .Host .PrivateShadowOffsetEnd );
888
- }
809
+ if (DeviceInfo->Shadow ->AllocPrivateShadow (
810
+ Queue, NumWG, LaunchInfo.Data .Host .PrivateShadowOffset ,
811
+ LaunchInfo.Data .Host .PrivateShadowOffsetEnd ) !=
812
+ UR_RESULT_SUCCESS) {
813
+ getContext ()->logger .warning (
814
+ " Failed to allocate shadow memory for private "
815
+ " memory, maybe the number of workgroup ({}) is too "
816
+ " large" ,
817
+ NumWG);
818
+ getContext ()->logger .warning (
819
+ " Skip checking private memory of kernel <{}>" ,
820
+ GetKernelName (Kernel));
821
+ } else {
822
+ getContext ()->logger .info (
823
+ " ShadowMemory(Private, WorkGroup{}, {} - {})" , NumWG,
824
+ (void *)LaunchInfo.Data .Host .PrivateShadowOffset ,
825
+ (void *)LaunchInfo.Data .Host .PrivateShadowOffsetEnd );
889
826
}
890
827
}
891
828
@@ -970,24 +907,6 @@ ContextInfo::~ContextInfo() {
970
907
971
908
AsanRuntimeDataWrapper::~AsanRuntimeDataWrapper () {
972
909
[[maybe_unused]] ur_result_t Result;
973
- auto Type = GetDeviceType (Context, Device);
974
- auto ContextInfo = getAsanInterceptor ()->getContextInfo (Context);
975
- if (Type == DeviceType::GPU_PVC || Type == DeviceType::GPU_DG2) {
976
- if (Host.PrivateShadowOffset ) {
977
- ContextInfo->Stats .UpdateShadowFreed (Host.PrivateShadowOffsetEnd -
978
- Host.PrivateShadowOffset + 1 );
979
- Result = getContext ()->urDdiTable .USM .pfnFree (
980
- Context, (void *)Host.PrivateShadowOffset );
981
- assert (Result == UR_RESULT_SUCCESS);
982
- }
983
- if (Host.LocalShadowOffset ) {
984
- ContextInfo->Stats .UpdateShadowFreed (Host.LocalShadowOffsetEnd -
985
- Host.LocalShadowOffset + 1 );
986
- Result = getContext ()->urDdiTable .USM .pfnFree (
987
- Context, (void *)Host.LocalShadowOffset );
988
- assert (Result == UR_RESULT_SUCCESS);
989
- }
990
- }
991
910
if (Host.LocalArgs ) {
992
911
Result = getContext ()->urDdiTable .USM .pfnFree (Context,
993
912
(void *)Host.LocalArgs );
0 commit comments