@@ -8077,7 +8077,6 @@ static pi_result USMSharedAllocImpl(void **ResultPtr, pi_context Context,
8077
8077
pi_device Device,
8078
8078
pi_usm_mem_properties *Properties,
8079
8079
size_t Size, pi_uint32 Alignment) {
8080
- (void )Properties;
8081
8080
PI_ASSERT (Context, PI_ERROR_INVALID_CONTEXT);
8082
8081
PI_ASSERT (Device, PI_ERROR_INVALID_DEVICE);
8083
8082
@@ -8102,6 +8101,31 @@ static pi_result USMSharedAllocImpl(void **ResultPtr, pi_context Context,
8102
8101
reinterpret_cast <std::uintptr_t >(*ResultPtr) % Alignment == 0 ,
8103
8102
PI_ERROR_INVALID_VALUE);
8104
8103
8104
+ // See if the memory is going to be read-only on the device.
8105
+ bool DeviceReadOnly = false ;
8106
+ // Check that incorrect bits are not set in the properties.
8107
+ if (Properties && *Properties != 0 ) {
8108
+ PI_ASSERT (*(Properties) == PI_MEM_ALLOC_FLAGS && *(Properties + 2 ) == 0 ,
8109
+ PI_ERROR_INVALID_VALUE);
8110
+ DeviceReadOnly = *(Properties + 1 ) & PI_MEM_ALLOC_DEVICE_READ_ONLY;
8111
+ }
8112
+ if (!DeviceReadOnly)
8113
+ return PI_SUCCESS;
8114
+
8115
+ // For read-only memory, let L0 know about that by using advises.
8116
+
8117
+ // zeCommandListAppendMemAdvise must not be called from simultaneous threads
8118
+ // with the same command list handle.
8119
+ std::scoped_lock<pi_mutex> Lock (Context->ImmediateCommandListMutex );
8120
+
8121
+ ZE_CALL (zeCommandListAppendMemAdvise,
8122
+ (Context->ZeCommandListInit , Device->ZeDevice , *ResultPtr, Size,
8123
+ ZE_MEMORY_ADVICE_SET_READ_MOSTLY));
8124
+
8125
+ ZE_CALL (zeCommandListAppendMemAdvise,
8126
+ (Context->ZeCommandListInit , Device->ZeDevice , *ResultPtr, Size,
8127
+ ZE_MEMORY_ADVICE_SET_PREFERRED_LOCATION));
8128
+
8105
8129
return PI_SUCCESS;
8106
8130
}
8107
8131
@@ -8153,7 +8177,9 @@ pi_result USMSharedMemoryAlloc::allocateImpl(void **ResultPtr, size_t Size,
8153
8177
pi_result USMSharedReadOnlyMemoryAlloc::allocateImpl (void **ResultPtr,
8154
8178
size_t Size,
8155
8179
pi_uint32 Alignment) {
8156
- return USMSharedAllocImpl (ResultPtr, Context, Device, nullptr , Size,
8180
+ pi_usm_mem_properties Props[] = {PI_MEM_ALLOC_FLAGS,
8181
+ PI_MEM_ALLOC_DEVICE_READ_ONLY, 0 };
8182
+ return USMSharedAllocImpl (ResultPtr, Context, Device, Props, Size,
8157
8183
Alignment);
8158
8184
}
8159
8185
0 commit comments