[OpenMP] Fix two usm tests for amdgpus. (#78824)

Some are missing setting of HSA_XNACK=1 environment variable, used to
enable unified memory support on amdgpu's when it's not been set at
kernel boot time. Some others needed to be marked as supporting
unified_shared_memory in the lit test harness.

Extend lit test harness to enable unified_shared_memory requirement for
AMD GPUs.

Reland: #77851
GitOrigin-RevId: 3440466536c97ced20e366301a60f12f4fd01e30
diff --git a/libomptarget/test/lit.cfg b/libomptarget/test/lit.cfg
index 9078561..a0df731 100644
--- a/libomptarget/test/lit.cfg
+++ b/libomptarget/test/lit.cfg
@@ -116,8 +116,13 @@
   except ValueError:
     # If the architecture is invalid, assume it is supported.
     supports_unified_shared_memory = True
-if config.libomptarget_current_target.startswith('amdgcn'):
-    supports_unified_shared_memory = False
+elif config.libomptarget_current_target.startswith('amdgcn'):
+    # amdgpu_test_arch contains a list of AMD GPUs in the system
+    # only check the first one assuming that we will run the test on it.
+    if not (config.amdgpu_test_arch.startswith("gfx90a") or
+            config.amdgpu_test_arch.startswith("gfx940") or
+            config.amdgpu_test_arch.startswith("gfx942")):
+       supports_unified_shared_memory = False
 if supports_unified_shared_memory:
    config.available_features.add('unified_shared_memory')
 
diff --git a/libomptarget/test/lit.site.cfg.in b/libomptarget/test/lit.site.cfg.in
index 2d63811..7c75aaa 100644
--- a/libomptarget/test/lit.site.cfg.in
+++ b/libomptarget/test/lit.site.cfg.in
@@ -10,6 +10,7 @@
 config.cuda_path = "@CUDA_TOOLKIT_ROOT_DIR@"
 config.cuda_libdir = "@CUDA_LIBDIR@"
 config.cuda_test_arch = "@LIBOMPTARGET_DEP_CUDA_ARCH@"
+config.amdgpu_test_arch = "@LIBOMPTARGET_AMDGPU_DETECTED_ARCH_LIST@"
 config.libomptarget_obj_root = "@CMAKE_CURRENT_BINARY_DIR@/@CURRENT_TARGET@"
 config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
 config.llvm_library_dir = "@LIBOMPTARGET_LLVM_LIBRARY_DIR@"
diff --git a/libomptarget/test/unified_shared_memory/api.c b/libomptarget/test/unified_shared_memory/api.c
index 4f0f93b..c7ab055 100644
--- a/libomptarget/test/unified_shared_memory/api.c
+++ b/libomptarget/test/unified_shared_memory/api.c
@@ -1,9 +1,10 @@
-// RUN: %libomptarget-compile-run-and-check-generic
+// RUN: %libomptarget-compile-generic
+// RUN: env HSA_XNACK=1 \
+// RUN: %libomptarget-run-generic | %fcheck-generic
 // XFAIL: nvptx64-nvidia-cuda
 // XFAIL: nvptx64-nvidia-cuda-LTO
 
-// Fails on amdgpu with error: GPU Memory Error
-// UNSUPPORTED: amdgcn-amd-amdhsa
+// REQUIRES: unified_shared_memory
 
 #include <omp.h>
 #include <stdio.h>
diff --git a/libomptarget/test/unified_shared_memory/close_enter_exit.c b/libomptarget/test/unified_shared_memory/close_enter_exit.c
index 71be4c9..b116c65 100644
--- a/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ b/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -1,11 +1,11 @@
-// RUN: %libomptarget-compile-run-and-check-generic
+// RUN: %libomptarget-compile-generic
+// RUN: env HSA_XNACK=1 \
+// RUN: %libomptarget-run-generic | %fcheck-generic
 
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// Fails on amdgpu with error: GPU Memory Error
 // Fails on nvptx with error: an illegal memory access was encountered
-// XFAIL: amdgcn-amd-amdhsa
 // XFAIL: nvptx64-nvidia-cuda
 // XFAIL: nvptx64-nvidia-cuda-LTO