From 762b3cab06525c4414dba6e18353c4ca56accd08 Mon Sep 17 00:00:00 2001 From: yangbinfa Date: Fri, 24 Jan 2025 17:21:32 +0800 Subject: [PATCH] enable-openmp Signed-off-by: yangbinfa --- llvm-build/build.py | 21 ++++++++++----- llvm/utils/lit/lit/TestRunner.py | 21 +++++++++++++-- llvm/utils/lit/lit/TestingConfig.py | 4 +++ openmp/runtime/src/kmp_config.h.cmake | 4 +-- openmp/runtime/test/affinity/format/nested.c | 2 +- openmp/runtime/test/affinity/format/nested2.c | 2 +- .../test/affinity/format/nested_mixed.c | 2 +- .../test/affinity/format/nested_serial.c | 2 +- openmp/runtime/test/lit.cfg | 27 +++++++++++++++++-- openmp/tools/multiplex/tests/lit.cfg | 23 +++++++++++++++- 10 files changed, 91 insertions(+), 17 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index 90c454453b99..104cedd3a36a 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -624,6 +624,8 @@ class BuildUtils(object): defines['COMPILER_RT_BUILD_XRAY'] = 'OFF' defines['LIBUNWIND_USE_FRAME_HEADER_CACHE'] = 'ON' + defines['OPENMP_ENABLE_LIBOMPTARGET'] = 'OFF' + defines['LIBOMP_INSTALL_ALIASES'] = 'False' return defines def get_python_dir(self): @@ -1548,6 +1550,7 @@ class LlvmLibs(BuildUtils): self.open_ohos_triple('aarch64'), self.open_ohos_triple('riscv64'), self.open_ohos_triple('mipsel'), self.open_ohos_triple('x86_64'), self.open_ohos_triple('loongarch64')] + omp_list = [self.open_ohos_triple("aarch64"), self.open_ohos_triple("arm"), self.open_ohos_triple('x86_64')] libcxx_ndk_install = self.merge_out_path('libcxx-ndk') self.check_create_dir(libcxx_ndk_install) @@ -1569,9 +1572,11 @@ class LlvmLibs(BuildUtils): self.build_lldb_tools(llvm_install, llvm_path, arch, llvm_triple, cflags, ldflags, defines) seen_arch_list.append(llvm_triple) + if llvm_triple in omp_list: + self.build_libomp(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, 'TRUE') + self.build_libomp(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, 'FALSE') continue - self.build_libomp(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines) self.build_libz(arch, llvm_triple, cflags, ldflags, defines) if self.build_config.need_lldb_tools and has_lldb_tools and llvm_triple not in seen_arch_list: self.build_lldb_tools(llvm_install, llvm_path, arch, llvm_triple, cflags, ldflags, defines) @@ -1769,8 +1774,8 @@ class LlvmLibs(BuildUtils): cflags, ldflags, multilib_suffix, - defines): - + defines, + enable_shared): self.logger().info('Building libomp for %s', arch) libomp_path = self.merge_out_path('lib', 'libomp-%s' % llvm_triple) @@ -1791,7 +1796,7 @@ class LlvmLibs(BuildUtils): libomp_defines['OPENMP_ENABLE_LIBOMPTARGET'] = 'FALSE' libomp_defines['OPENMP_LIBDIR_SUFFIX'] = os.path.join(os.sep, llvm_triple, multilib_suffix) - libomp_defines['LIBOMP_ENABLE_SHARED'] = 'FALSE' + libomp_defines['LIBOMP_ENABLE_SHARED'] = enable_shared libomp_defines['CMAKE_POLICY_DEFAULT_CMP0056'] = 'NEW' libomp_defines['CMAKE_INSTALL_PREFIX'] = llvm_install libomp_defines['COMPILER_RT_USE_BUILTINS_LIBRARY'] = 'ON' @@ -1801,13 +1806,17 @@ class LlvmLibs(BuildUtils): libomp_defines['CMAKE_TRY_COMPILE_TARGET_TYPE'] = 'STATIC_LIBRARY' libomp_cmake_path = os.path.join(self.build_config.LLVM_PROJECT_DIR, 'openmp') - self.rm_cmake_cache(libomp_path) + + if enable_shared == "TRUE": + libomp_path = os.path.join(libomp_path, "shared") + else: + libomp_path = os.path.join(libomp_path, "static") + self.rm_cmake_cache(libomp_path) self.invoke_cmake(libomp_cmake_path, libomp_path, libomp_defines, env=dict(self.build_config.ORIG_ENV)) - self.invoke_ninja(out_path=libomp_path, env=dict(self.build_config.ORIG_ENV), target=None, diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 0242e0b75af3..4eceea37a05d 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -1734,7 +1734,11 @@ def executeShTest(test, litConfig, useExternalSh, if litConfig.noExecute: return lit.Test.Result(Test.PASS) - + # OHOS_LOCAL begin + # Setting environment variables on a remote device, this command is used only for OpenMP test. + if (test.config.name == 'libomp' or test.config.name == 'OMPT multiplex') and test.config.operating_system == 'OHOS': + script = replaceEnvrunForScript(script) + # OHOS_LOCAL end tmpDir, tmpBase = getTempPaths(test) substitutions = list(extra_substitutions) substitutions += getDefaultSubstitutions(test, tmpDir, tmpBase, @@ -1742,5 +1746,18 @@ def executeShTest(test, litConfig, useExternalSh, conditions = { feature: True for feature in test.config.available_features } script = applySubstitutions(script, substitutions, conditions, recursion_limit=test.config.recursiveExpansionLimit) - return _runShTest(test, litConfig, useExternalSh, script, tmpBase) + +def replaceEnvrunForScript(script): + """ + Replace `env xxxx %libomp-run` in the script with `%libomp-env-run env xxxx %root-path%t`. + """ + newScript = [] + pattern = re.compile(r"(env\s+.*?)(\s+%libomp-run)") + replacement = r'%libomp-env-run \1 %root-path%t' + for ln in script: + if pattern.search(ln): + newScript.append(pattern.sub(replacement, ln)) + else: + newScript.append(ln) + return newScript \ No newline at end of file diff --git a/llvm/utils/lit/lit/TestingConfig.py b/llvm/utils/lit/lit/TestingConfig.py index 55e2a764d8fa..e5d752f017aa 100644 --- a/llvm/utils/lit/lit/TestingConfig.py +++ b/llvm/utils/lit/lit/TestingConfig.py @@ -43,6 +43,10 @@ class TestingConfig(object): 'ADB', 'ANDROID_SERIAL', 'SSH_AUTH_SOCK', + 'HDC', + 'HDC_SERVER', + 'HDC_TARGET_SERIAL', + 'LIB_PATH_ON_TARGET', 'SANITIZER_IGNORE_CVE_2016_2143', 'TMPDIR', 'TMP', diff --git a/openmp/runtime/src/kmp_config.h.cmake b/openmp/runtime/src/kmp_config.h.cmake index 40d20115c9ec..7e8dad4ca6c9 100644 --- a/openmp/runtime/src/kmp_config.h.cmake +++ b/openmp/runtime/src/kmp_config.h.cmake @@ -134,9 +134,9 @@ # define KMP_GOMP_COMPAT #endif -// use shared memory with dynamic library (except Android, where shm_* +// use shared memory with dynamic library (except Android and OHOS, where shm_* // functions don't exist). -#if KMP_OS_UNIX && KMP_DYNAMIC_LIB && !__ANDROID__ +#if KMP_OS_UNIX && KMP_DYNAMIC_LIB && !__ANDROID__ && !__OHOS__ #define KMP_USE_SHM #endif #endif // KMP_CONFIG_H diff --git a/openmp/runtime/test/affinity/format/nested.c b/openmp/runtime/test/affinity/format/nested.c index db2e607bf8e6..1d8bc8cb35c3 100644 --- a/openmp/runtime/test/affinity/format/nested.c +++ b/openmp/runtime/test/affinity/format/nested.c @@ -1,4 +1,4 @@ -// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true OMP_PLACES=threads OMP_PROC_BIND=spread,close %libomp-run | %python %S/check.py -c 'CHECK' %s +// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true OMP_PLACES=threads OMP_PROC_BIND=spread,close %platform-flag %libomp-run | %python %S/check.py -c 'CHECK' %s // REQUIRES: affinity #include diff --git a/openmp/runtime/test/affinity/format/nested2.c b/openmp/runtime/test/affinity/format/nested2.c index f259aeace0d6..059ea6a9c425 100644 --- a/openmp/runtime/test/affinity/format/nested2.c +++ b/openmp/runtime/test/affinity/format/nested2.c @@ -1,4 +1,4 @@ -// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true OMP_PLACES=threads OMP_PROC_BIND=spread,close KMP_HOT_TEAMS_MAX_LEVEL=2 %libomp-run | %python %S/check.py -c 'CHECK' %s +// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true OMP_PLACES=threads OMP_PROC_BIND=spread,close KMP_HOT_TEAMS_MAX_LEVEL=2 %platform-flag %libomp-run | %python %S/check.py -c 'CHECK' %s #include #include diff --git a/openmp/runtime/test/affinity/format/nested_mixed.c b/openmp/runtime/test/affinity/format/nested_mixed.c index 288e1c21c2bf..dd1376a07b64 100644 --- a/openmp/runtime/test/affinity/format/nested_mixed.c +++ b/openmp/runtime/test/affinity/format/nested_mixed.c @@ -1,4 +1,4 @@ -// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true %libomp-run | %python %S/check.py -c 'CHECK' %s +// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true %platform-flag %libomp-run | %python %S/check.py -c 'CHECK' %s #include #include diff --git a/openmp/runtime/test/affinity/format/nested_serial.c b/openmp/runtime/test/affinity/format/nested_serial.c index 70ccf5be3c84..5e0ffc9cbbaf 100644 --- a/openmp/runtime/test/affinity/format/nested_serial.c +++ b/openmp/runtime/test/affinity/format/nested_serial.c @@ -1,4 +1,4 @@ -// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true %libomp-run | %python %S/check.py -c 'CHECK' %s +// RUN: %libomp-compile && env OMP_DISPLAY_AFFINITY=true %platform-flag %libomp-run | %python %S/check.py -c 'CHECK' %s #include #include diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg index 45e65d9c3ef6..d4507c06d865 100644 --- a/openmp/runtime/test/lit.cfg +++ b/openmp/runtime/test/lit.cfg @@ -51,6 +51,9 @@ if config.has_omit_frame_pointer_flag: config.test_flags = " -I " + config.omp_header_directory + flags config.test_flags_use_compiler_omp_h = flags +# OHOS LOCAL +if config.operating_system == 'OHOS': + config.test_flags += " --target=aarch64-linux-ohos" # extra libraries libs = "" @@ -105,7 +108,7 @@ if 'Linux' in config.operating_system: if config.operating_system == 'NetBSD': config.available_features.add("netbsd") -if config.operating_system in ['Linux', 'Windows']: +if config.operating_system in ['Linux', 'Windows', 'OHOS']: config.available_features.add('affinity') import multiprocessing @@ -134,7 +137,27 @@ config.substitutions.append(("%libomp-compile", \ "%clang %openmp_flags %flags %s -o %t" + libs)) config.substitutions.append(("%libomp-c99-compile", \ "%clang %openmp_flags %flags -std=c99 %s -o %t" + libs)) -config.substitutions.append(("%libomp-run", "%t")) + +# OHOS_LOCAL begin +if config.operating_system == 'OHOS': + # Settings required to run test cases remotely on OHOS + if not (config.environment.get('HDC') != None and config.environment.get('HDC_SERVER') != None + and config.environment.get('HDC_TARGET_SERIAL') != None and config.environment.get('LIB_PATH_ON_TARGET') != None): + raise ValueError("Error: One or more environment variables in HDC, HDC_SERVER, HDC_TARGET_SERIAL or LIB_PATH_ON_TARGET are not set.") + hdc = f"{config.environment['HDC']} -s {config.environment['HDC_SERVER']} -t {config.environment['HDC_TARGET_SERIAL']}" + cmd_set_ld_library_path = f"env LD_LIBRARY_PATH={config.environment['LIB_PATH_ON_TARGET']}:$LD_LIBRARY_PATH" + cmd_mkdir_to_device = f"{hdc} shell mkdir -p /data/local/temp/$(dirname %t)" + cmd_push_to_device = f"{hdc} file send %t %root-path%t" + cmd_chmod_to_test = f"{hdc} shell chmod 755 %root-path%t" + cmd_run_on_device = f"{hdc} shell {cmd_set_ld_library_path} %root-path%t" + config.substitutions.append(("%libomp-env-run", f"{cmd_mkdir_to_device} && {cmd_push_to_device} && {cmd_chmod_to_test} && {hdc} shell {cmd_set_ld_library_path}")) + config.substitutions.append(("%libomp-run", f"{cmd_mkdir_to_device} && {cmd_push_to_device} && {cmd_chmod_to_test} && {cmd_run_on_device}")) + config.substitutions.append(("%root-path", "/data/local/temp")) + config.substitutions.append(("%platform-flag", "KMP_WARNINGS=false")) +# OHOS_LOCAL end +else: + config.substitutions.append(("%libomp-run", "%t")) + config.substitutions.append(("%platform-flag", "")) config.substitutions.append(("%clangXX", config.test_cxx_compiler)) config.substitutions.append(("%clang", config.test_c_compiler)) config.substitutions.append(("%openmp_flags", config.test_openmp_flags)) diff --git a/openmp/tools/multiplex/tests/lit.cfg b/openmp/tools/multiplex/tests/lit.cfg index 69df2fd944cb..3e0666d360e6 100644 --- a/openmp/tools/multiplex/tests/lit.cfg +++ b/openmp/tools/multiplex/tests/lit.cfg @@ -67,6 +67,10 @@ append_dynamic_library_path(config.test_obj_root+"/..") if config.operating_system == 'Darwin': config.test_flags += " -Wl,-rpath," + config.omp_library_dir +# OHOS LOCAL +if config.operating_system == 'OHOS': + config.test_flags += " --target=aarch64-linux-ohos" + # Find the SDK on Darwin if config.operating_system == 'Darwin': cmd = subprocess.Popen(['xcrun', '--show-sdk-path'], @@ -90,7 +94,24 @@ config.substitutions.append(("%libomp-compile", \ "%clang %cflags %s -o %t")) config.substitutions.append(("%libomp-tool", \ "%clang %cflags -shared -fPIC -g")) -config.substitutions.append(("%libomp-run", "%t")) + +# OHOS_LOCAL begin +if config.operating_system == 'OHOS': + if not (config.environment.get('HDC') != None and config.environment.get('HDC_SERVER') != None + and config.environment.get('HDC_TARGET_SERIAL') != None and config.environment.get('LIB_PATH_ON_TARGET') != None): + raise ValueError("Error: One or more environment variables in HDC, HDC_SERVER, HDC_TARGET_SERIAL or LIB_PATH_ON_TARGET are not set.") + hdc = f"{config.environment['HDC']} -s {config.environment['HDC_SERVER']} -t {config.environment['HDC_TARGET_SERIAL']}" + cmd_set_ld_library_path = f"env LD_LIBRARY_PATH={config.environment['LIB_PATH_ON_TARGET']}:$LD_LIBRARY_PATH" + cmd_mkdir_to_device = f"{hdc} shell mkdir -p /data/local/temp/$(dirname %t)" + cmd_push_to_device = f"{hdc} file send %t %root-path%t" + cmd_chmod_to_test = f"{hdc} shell chmod 755 %root-path%t" + cmd_run_on_device = f"{hdc} shell {cmd_set_ld_library_path} %root-path%t" + config.substitutions.append(("%libomp-env-run", f"{cmd_mkdir_to_device} && {cmd_push_to_device} && {cmd_chmod_to_test} && {hdc} shell {cmd_set_ld_library_path}")) + config.substitutions.append(("%libomp-run", f"{cmd_mkdir_to_device} && {cmd_push_to_device} && {cmd_chmod_to_test} && {cmd_run_on_device}")) + config.substitutions.append(("%root-path", "/data/local/temp")) +# OHOS_LOCAL end +else: + config.substitutions.append(("%libomp-run", "%t")) config.substitutions.append(("%clang", config.test_c_compiler)) config.substitutions.append(("%openmp_flag", config.test_openmp_flags)) config.substitutions.append(("%cflags", config.test_flags)) -- Gitee