[libc-commits] [libc] [libc] Enable missing memory tests on the GPU (PR #68111)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Oct 3 07:36:47 PDT 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/68111

Summary:
There were a few tests that weren't enabled on the GPU. This is because
the logic caused them to be skipped as we don't use CPU featured on the
host. This also disables the logic making multiple versions of the
memory functions.


>From b8fee13b63d2c0cb1654e9737664a3e3dc894c02 Mon Sep 17 00:00:00 2001
From: Joseph Huber <jhuber6 at vols.utk.edu>
Date: Tue, 3 Oct 2023 09:35:14 -0500
Subject: [PATCH] [libc] Enable missing memory tests on the GPU

Summary:
There were a few tests that weren't enabled on the GPU. This is because
the logic caused them to be skipped as we don't use CPU featured on the
host. This also disables the logic making multiple versions of the
memory functions.
---
 libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake |  4 ----
 libc/src/string/CMakeLists.txt                    | 12 ++++++++++++
 libc/test/src/string/CMakeLists.txt               |  5 ++++-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index 0b522318aaa129e..73b249374a0667c 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -22,10 +22,6 @@ list(SORT ALL_CPU_FEATURES)
 #   <list of cpu features>
 # )
 function(cpu_supports output_var features)
-  if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
-    unset(${output_var} PARENT_SCOPE)
-    return()
-  endif()
   _intersection(var "${LIBC_CPU_FEATURES}" "${features}")
   if("${var}" STREQUAL "${features}")
     set(${output_var} TRUE PARENT_SCOPE)
diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index f2e5654d03ccece..67675b682081c67 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -498,6 +498,8 @@ if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
   add_bcmp(bcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW)
   add_bcmp(bcmp_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_bcmp(bcmp)
+elseif(LIBC_TARGET_ARCHITECTURE_IS_GPU)
+  add_bcmp(bcmp)
 else()
   add_bcmp(bcmp_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_bcmp(bcmp)
@@ -525,6 +527,8 @@ if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
   add_bzero(bzero_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
   add_bzero(bzero_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_bzero(bzero)
+elseif(LIBC_TARGET_ARCHITECTURE_IS_GPU)
+  add_bzero(bzero)
 else()
   add_bzero(bzero_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_bzero(bzero)
@@ -555,6 +559,8 @@ if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
 elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
   add_memcmp(memcmp_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_memcmp(memcmp)
+elseif(LIBC_TARGET_ARCHITECTURE_IS_GPU)
+  add_memcmp(memcmp)
 else()
   add_memcmp(memcmp_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_memcmp(memcmp)
@@ -589,6 +595,8 @@ elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
   add_memcpy(memcpy_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
                                       MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
   add_memcpy(memcpy                   MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
+elseif(LIBC_TARGET_ARCHITECTURE_IS_GPU)
+  add_memcpy(memcpy)
 else()
   add_memcpy(memcpy_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_memcpy(memcpy)
@@ -621,6 +629,8 @@ elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
   add_memmove(memmove_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
                                         MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
   add_memmove(memmove                   MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
+elseif(LIBC_TARGET_ARCHITECTURE_IS_GPU)
+  add_memmove(memmove)
 else()
   add_memmove(memmove_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_memmove(memmove)
@@ -653,6 +663,8 @@ elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
   add_memset(memset_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
                                       MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
   add_memset(memset                   MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
+elseif(LIBC_TARGET_ARCHITECTURE_IS_GPU)
+  add_memset(memset)
 else()
   add_memset(memset_opt_host          COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
   add_memset(memset)
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
index b90da43f9a7b94c..6088289532d771d 100644
--- a/libc/test/src/string/CMakeLists.txt
+++ b/libc/test/src/string/CMakeLists.txt
@@ -425,8 +425,11 @@ function(add_libc_multi_impl_test name)
     get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
     cpu_supports(can_run "${required_cpu_features}")
     if(can_run)
+      string(FIND ${fq_config_name} "." last_dot_loc REVERSE)
+      math(EXPR name_loc "${last_dot_loc} + 1")
+      string(SUBSTRING ${fq_config_name} ${name_loc} -1 target_name)
       add_libc_test(
-        ${fq_config_name}_test
+        ${target_name}_test
         SUITE
           libc-string-tests
         COMPILE_OPTIONS



More information about the libc-commits mailing list