Enable correctness checks in runtime for map clauses under unified_shared_memory mode.
Add OPENMP_DISABLE_MAPS environment variable input to disable this behavior.
As an example, before this patch is applied, this example would not fail:
#pragma omp requires unified_shared_memory
void foo() {
int a[10]; #pragma omp target enter data map(to:a[0:5]) #pragma omp target enter data map(to:a[0:10]) // extending already mapped memory, illegal!
}
This is illegal in OpenMP, and presumably also under unified_shared_memory mode, but the current implementation bails out on map checks under this mode.
By specifications, under unified_shared_memory mode, the user is allowed not to use maps and can expect the program to work on an system that supports the mode. However, for portability to systems that do not support unified_shared_memory, map clauses should always be correct. Not applying checks in the runtime should be a conscious request by the user.
We will have a problem here after D107925, D107927 and D107928 land. These patches assume that USM mappings do not have an entry in HostDataToTargetMap. That's how they figure out whether we have an allocation in shared memory or in GPU memory, i.e. the value of IsHostPtr is determined by the presence or absence of an entry in the map. If we want to move on with this change here, we'll need to introduce an extra member in struct HostDataToTargetTy, e.g. bool IsUSMAlloc = false;, and this emplacement here will have to be extended with ..., HstPtrName, /*IsUSMAlloc*/ true). In general, I think that implementing desired support involves much more work than this patch. Basically, we need to treat USM data the exact same way as device-side mappings, i.e. remove all specialized code paths for USM allocations and only check whether we have USM data when we are about to alloc memory / perform data transfers.