From a13923ffba188883b7f2354fc18a988ecef4d565 Mon Sep 17 00:00:00 2001 From: "Sarnie, Nick" Date: Thu, 27 Mar 2025 08:12:32 -0700 Subject: [PATCH 1/3] [SYCL] Add LIT feature for HIP Signed-off-by: Sarnie, Nick --- sycl/test-e2e/CMakeLists.txt | 6 +++ .../custom-command-hip.cpp | 2 +- .../Graph/NativeCommand/hip_explicit_usm.cpp | 8 +-- .../Graph/NativeCommand/hip_record_buffer.cpp | 8 +-- .../Graph/NativeCommand/hip_record_usm.cpp | 8 +-- .../HostInteropTask/interop-task-hip.cpp | 2 +- sycl/test-e2e/README.md | 8 +++ sycl/test-e2e/lit.cfg.py | 50 ++++++++++++++++--- sycl/test-e2e/lit.site.cfg.py.in | 2 + 9 files changed, 67 insertions(+), 27 deletions(-) diff --git a/sycl/test-e2e/CMakeLists.txt b/sycl/test-e2e/CMakeLists.txt index 98a9d15e0197f..6f99aa28527ea 100644 --- a/sycl/test-e2e/CMakeLists.txt +++ b/sycl/test-e2e/CMakeLists.txt @@ -78,6 +78,12 @@ if(NOT DEFINED CUDA_LIBS_DIR AND NOT DEFINED CUDA_INCLUDE) endif() endif() +find_package(hip HINTS ENV ROCM_PATH "/opt/rocm") +if(hip_FOUND) + set(HIP_LIBS_DIR "${hip_LIB_INSTALL_DIR}") + set(HIP_INCLUDE "${hip_INCLUDE_DIRS}") +endif() + if(SYCL_TEST_E2E_STANDALONE) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in" "${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py") diff --git a/sycl/test-e2e/EnqueueNativeCommand/custom-command-hip.cpp b/sycl/test-e2e/EnqueueNativeCommand/custom-command-hip.cpp index 141ca12793cc1..b93c66a467a8f 100644 --- a/sycl/test-e2e/EnqueueNativeCommand/custom-command-hip.cpp +++ b/sycl/test-e2e/EnqueueNativeCommand/custom-command-hip.cpp @@ -1,4 +1,4 @@ -// RUN: %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 +// RUN: %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options // RUN: %{run} %t.out // REQUIRES: target-amd diff --git a/sycl/test-e2e/Graph/NativeCommand/hip_explicit_usm.cpp b/sycl/test-e2e/Graph/NativeCommand/hip_explicit_usm.cpp index 54f702bce95f2..ed29417c41675 100644 --- a/sycl/test-e2e/Graph/NativeCommand/hip_explicit_usm.cpp +++ b/sycl/test-e2e/Graph/NativeCommand/hip_explicit_usm.cpp @@ -1,10 +1,6 @@ -// FIXME: the rocm include path and link path are highly platform dependent, -// we should set this with some variable instead. -// https://github.com/intel/llvm/issues/17018 - -// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 +// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options // RUN: %{run} %t.out -// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 %} +// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out %hip_options %} // RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %} // REQUIRES: target-amd diff --git a/sycl/test-e2e/Graph/NativeCommand/hip_record_buffer.cpp b/sycl/test-e2e/Graph/NativeCommand/hip_record_buffer.cpp index 1b84e2f075cb2..47cfeb366e901 100644 --- a/sycl/test-e2e/Graph/NativeCommand/hip_record_buffer.cpp +++ b/sycl/test-e2e/Graph/NativeCommand/hip_record_buffer.cpp @@ -1,10 +1,6 @@ -// FIXME: the rocm include path and link path are highly platform dependent, -// we should set this with some variable instead. -// https://github.com/intel/llvm/issues/17018 - -// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 +// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options // RUN: %{run} %t.out -// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 %} +// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out %hip_options %} // RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %} // REQUIRES: target-amd diff --git a/sycl/test-e2e/Graph/NativeCommand/hip_record_usm.cpp b/sycl/test-e2e/Graph/NativeCommand/hip_record_usm.cpp index 15288ac5652c0..a24ec6fd105ff 100644 --- a/sycl/test-e2e/Graph/NativeCommand/hip_record_usm.cpp +++ b/sycl/test-e2e/Graph/NativeCommand/hip_record_usm.cpp @@ -1,10 +1,6 @@ -// FIXME: the rocm include path and link path are highly platform dependent, -// we should set this with some variable instead. -// https://github.com/intel/llvm/issues/17018 - -// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 +// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options // RUN: %{run} %t.out -// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 %} +// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out %hip_options %} // RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %} // REQUIRES: target-amd diff --git a/sycl/test-e2e/HostInteropTask/interop-task-hip.cpp b/sycl/test-e2e/HostInteropTask/interop-task-hip.cpp index 4dd40fa56b4ce..3d854590ad43c 100644 --- a/sycl/test-e2e/HostInteropTask/interop-task-hip.cpp +++ b/sycl/test-e2e/HostInteropTask/interop-task-hip.cpp @@ -1,4 +1,4 @@ -// RUN: %{build} -Wno-error=deprecated-pragma -Wno-error=deprecated-declarations -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64 +// RUN: %{build} -Wno-error=deprecated-pragma -Wno-error=deprecated-declarations -o %t.out %hip_options // RUN: %{run} %t.out // REQUIRES: target-amd diff --git a/sycl/test-e2e/README.md b/sycl/test-e2e/README.md index 59044dec9ec79..bcca7dfdf38de 100644 --- a/sycl/test-e2e/README.md +++ b/sycl/test-e2e/README.md @@ -190,6 +190,10 @@ at the full path specified by this variable. ***CUDA_LIBS_DIR*** - path to CUDA libraries (autodetected). +***HIP_INCLUDE*** - path to HIP headers (autodetected). + +***HIP_LIBS_DIR*** - path to HIP libraries (autodetected). + ***AMD_ARCH*** - flag may be set for when using HIP AMD triple. For example it may be set to "gfx906". Otherwise must be provided via the ***amd_arch*** LIT parameter (e.g., ***--param amd_arch=gfx906***) at runtime via the command line @@ -297,6 +301,10 @@ configure specific single test execution in the command line: CMake variable CUDA_INCLUDE (autodetected). * **cuda_libs_dir** - directory containing CUDA SDK libraries, can be also set by CMake variable CUDA_LIBS_DIR (autodetected). +* **hip_include** - directory containing HIP SDK headers, can be also set by + CMake variable HIP_INCLUDE (autodetected). +* **hip_libs_dir** - directory containing HIP SDK libraries, can be also set + by CMake variable HIP_LIBS_DIR (autodetected). * **run_launcher** - part of `%{run*}` expansion/substitution to alter execution of the test by, e.g., running it through Valgrind. diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index c53aaadebb430..ed2a3b47724a7 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -441,6 +441,49 @@ def open_check_file(file_name): else: config.substitutions.append(("%cuda_options", "")) +# Check for HIP SDK +check_hip_file = "hip_include.cpp" +with open_check_file(check_hip_file) as fp: + print( + textwrap.dedent( + """ + #define __HIP_PLATFORM_AMD__ 1 + #include + int main() { hipError_t r = hipInit(0); return r; } + """ + ), + file=fp, + ) +config.hip_libs_dir = lit_config.params.get("hip_libs_dir", config.hip_libs_dir) +config.hip_include = lit_config.params.get( + "hip_include", + (config.hip_include if config.hip_include else config.sycl_include), +) + +hip_options = hip_options = ( + (" -L" + config.hip_libs_dir if config.hip_libs_dir else "") + + " -lamdhip64 " + + " -I" + + config.hip_include +) +if cl_options: + hip_options = ( + " " + + (config.hip_libs_dir + "/amdhip64_6.lib " if config.hip_libs_dir else "amdhip64_6.lib") + + " /I" + + config.hip_include + ) + +with test_env(): + sp = subprocess.getstatusoutput( + config.dpcpp_compiler + " -fsycl " + check_hip_file + hip_options + ) + if sp[0] == 0: + config.available_features.add("hip_dev_kit") + config.substitutions.append(("%hip_options", hip_options)) + else: + config.substitutions.append(("%hip_options", "")) + # Check for OpenCL ICD if config.opencl_libs_dir: if cl_options: @@ -585,13 +628,6 @@ def remove_level_zero_suffix(devices): if be not in available_devices or dev not in available_devices[be]: lit_config.error("Unsupported device {}".format(d)) -# Set ROCM_PATH to help clang find the HIP installation. -if "target-amd" in config.sycl_build_targets: - llvm_config.with_system_environment("ROCM_PATH") - config.substitutions.append( - ("%rocm_path", os.environ.get("ROCM_PATH", "/opt/rocm")) - ) - if "cuda:gpu" in config.sycl_devices: if "CUDA_PATH" not in os.environ: if platform.system() == "Windows": diff --git a/sycl/test-e2e/lit.site.cfg.py.in b/sycl/test-e2e/lit.site.cfg.py.in index 75d8e24af3183..e2d6bfc282896 100644 --- a/sycl/test-e2e/lit.site.cfg.py.in +++ b/sycl/test-e2e/lit.site.cfg.py.in @@ -23,6 +23,8 @@ config.level_zero_libs_dir = "@LEVEL_ZERO_LIBS_DIR@" config.level_zero_include = "@LEVEL_ZERO_INCLUDE@" config.cuda_libs_dir = "@CUDA_LIBS_DIR@" config.cuda_include = "@CUDA_INCLUDE@" +config.hip_libs_dir = "@HIP_LIBS_DIR@" +config.hip_include = "@HIP_INCLUDE@" config.opencl_include_dir = os.path.join(config.sycl_include, 'sycl') From 3d70ed88bf1eefadb4d2011fd63cc11736c35e34 Mon Sep 17 00:00:00 2001 From: "Sarnie, Nick" Date: Thu, 27 Mar 2025 10:47:04 -0700 Subject: [PATCH 2/3] format Signed-off-by: Sarnie, Nick --- sycl/test-e2e/lit.cfg.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index ed2a3b47724a7..224d7e35de414 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -469,7 +469,11 @@ def open_check_file(file_name): if cl_options: hip_options = ( " " - + (config.hip_libs_dir + "/amdhip64_6.lib " if config.hip_libs_dir else "amdhip64_6.lib") + + ( + config.hip_libs_dir + "/amdhip64_6.lib " + if config.hip_libs_dir + else "amdhip64_6.lib" + ) + " /I" + config.hip_include ) @@ -483,7 +487,7 @@ def open_check_file(file_name): config.substitutions.append(("%hip_options", hip_options)) else: config.substitutions.append(("%hip_options", "")) - + # Check for OpenCL ICD if config.opencl_libs_dir: if cl_options: From b2f98c96af01bb34e3ffe38e8683d9fb6ee14bac Mon Sep 17 00:00:00 2001 From: "Sarnie, Nick" Date: Thu, 27 Mar 2025 12:45:01 -0700 Subject: [PATCH 3/3] lib name Signed-off-by: Sarnie, Nick --- sycl/test-e2e/lit.cfg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index 224d7e35de414..c0e9f9c926c20 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -470,9 +470,9 @@ def open_check_file(file_name): hip_options = ( " " + ( - config.hip_libs_dir + "/amdhip64_6.lib " + config.hip_libs_dir + "/amdhip64.lib " if config.hip_libs_dir - else "amdhip64_6.lib" + else "amdhip64.lib" ) + " /I" + config.hip_include