Skip to content

Commit 8dd0613

Browse files
authored
[SYCL][E2E] Add LIT feature for HIP (#17692)
We already have features for Level Zero and CUDA, add one for HIP. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent 0a406c9 commit 8dd0613

File tree

9 files changed

+71
-27
lines changed

9 files changed

+71
-27
lines changed

sycl/test-e2e/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ if(NOT DEFINED CUDA_LIBS_DIR AND NOT DEFINED CUDA_INCLUDE)
7878
endif()
7979
endif()
8080

81+
find_package(hip HINTS ENV ROCM_PATH "/opt/rocm")
82+
if(hip_FOUND)
83+
set(HIP_LIBS_DIR "${hip_LIB_INSTALL_DIR}")
84+
set(HIP_INCLUDE "${hip_INCLUDE_DIRS}")
85+
endif()
86+
8187
if(SYCL_TEST_E2E_STANDALONE)
8288
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in"
8389
"${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py")

sycl/test-e2e/EnqueueNativeCommand/custom-command-hip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64
1+
// RUN: %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options
22
// RUN: %{run} %t.out
33
// REQUIRES: target-amd
44

sycl/test-e2e/Graph/NativeCommand/hip_explicit_usm.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
// FIXME: the rocm include path and link path are highly platform dependent,
2-
// we should set this with some variable instead.
3-
// https://github.com/intel/llvm/issues/17018
4-
5-
// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64
1+
// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options
62
// RUN: %{run} %t.out
7-
// 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 %}
3+
// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out %hip_options %}
84
// RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %}
95
// REQUIRES: target-amd
106

sycl/test-e2e/Graph/NativeCommand/hip_record_buffer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
// FIXME: the rocm include path and link path are highly platform dependent,
2-
// we should set this with some variable instead.
3-
// https://github.com/intel/llvm/issues/17018
4-
5-
// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64
1+
// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options
62
// RUN: %{run} %t.out
7-
// 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 %}
3+
// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out %hip_options %}
84
// RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %}
95
// REQUIRES: target-amd
106

sycl/test-e2e/Graph/NativeCommand/hip_record_usm.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
// FIXME: the rocm include path and link path are highly platform dependent,
2-
// we should set this with some variable instead.
3-
// https://github.com/intel/llvm/issues/17018
4-
5-
// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64
1+
// RUN: %{run-aux} %{build} -Wno-error=deprecated-pragma -o %t.out %hip_options
62
// RUN: %{run} %t.out
7-
// 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 %}
3+
// RUN: %if preview-breaking-changes-supported %{ %{run-aux} %{build} -Wno-error=deprecated-pragma -fpreview-breaking-changes -o %t2.out %hip_options %}
84
// RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %}
95
// REQUIRES: target-amd
106

sycl/test-e2e/HostInteropTask/interop-task-hip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %{build} -Wno-error=deprecated-pragma -Wno-error=deprecated-declarations -o %t.out -I%rocm_path/include -L%rocm_path/lib -lamdhip64
1+
// RUN: %{build} -Wno-error=deprecated-pragma -Wno-error=deprecated-declarations -o %t.out %hip_options
22
// RUN: %{run} %t.out
33
// REQUIRES: target-amd
44

sycl/test-e2e/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ at the full path specified by this variable.
190190
191191
***CUDA_LIBS_DIR*** - path to CUDA libraries (autodetected).
192192
193+
***HIP_INCLUDE*** - path to HIP headers (autodetected).
194+
195+
***HIP_LIBS_DIR*** - path to HIP libraries (autodetected).
196+
193197
***AMD_ARCH*** - flag may be set for when using HIP AMD triple. For example it
194198
may be set to "gfx906". Otherwise must be provided via the ***amd_arch*** LIT
195199
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:
297301
CMake variable CUDA_INCLUDE (autodetected).
298302
* **cuda_libs_dir** - directory containing CUDA SDK libraries, can be also set
299303
by CMake variable CUDA_LIBS_DIR (autodetected).
304+
* **hip_include** - directory containing HIP SDK headers, can be also set by
305+
CMake variable HIP_INCLUDE (autodetected).
306+
* **hip_libs_dir** - directory containing HIP SDK libraries, can be also set
307+
by CMake variable HIP_LIBS_DIR (autodetected).
300308
* **run_launcher** - part of `%{run*}` expansion/substitution to alter execution
301309
of the test by, e.g., running it through Valgrind.
302310

sycl/test-e2e/lit.cfg.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,53 @@ def open_check_file(file_name):
441441
else:
442442
config.substitutions.append(("%cuda_options", ""))
443443

444+
# Check for HIP SDK
445+
check_hip_file = "hip_include.cpp"
446+
with open_check_file(check_hip_file) as fp:
447+
print(
448+
textwrap.dedent(
449+
"""
450+
#define __HIP_PLATFORM_AMD__ 1
451+
#include <hip/hip_runtime.h>
452+
int main() { hipError_t r = hipInit(0); return r; }
453+
"""
454+
),
455+
file=fp,
456+
)
457+
config.hip_libs_dir = lit_config.params.get("hip_libs_dir", config.hip_libs_dir)
458+
config.hip_include = lit_config.params.get(
459+
"hip_include",
460+
(config.hip_include if config.hip_include else config.sycl_include),
461+
)
462+
463+
hip_options = hip_options = (
464+
(" -L" + config.hip_libs_dir if config.hip_libs_dir else "")
465+
+ " -lamdhip64 "
466+
+ " -I"
467+
+ config.hip_include
468+
)
469+
if cl_options:
470+
hip_options = (
471+
" "
472+
+ (
473+
config.hip_libs_dir + "/amdhip64.lib "
474+
if config.hip_libs_dir
475+
else "amdhip64.lib"
476+
)
477+
+ " /I"
478+
+ config.hip_include
479+
)
480+
481+
with test_env():
482+
sp = subprocess.getstatusoutput(
483+
config.dpcpp_compiler + " -fsycl " + check_hip_file + hip_options
484+
)
485+
if sp[0] == 0:
486+
config.available_features.add("hip_dev_kit")
487+
config.substitutions.append(("%hip_options", hip_options))
488+
else:
489+
config.substitutions.append(("%hip_options", ""))
490+
444491
# Check for OpenCL ICD
445492
if config.opencl_libs_dir:
446493
if cl_options:
@@ -585,13 +632,6 @@ def remove_level_zero_suffix(devices):
585632
if be not in available_devices or dev not in available_devices[be]:
586633
lit_config.error("Unsupported device {}".format(d))
587634

588-
# Set ROCM_PATH to help clang find the HIP installation.
589-
if "target-amd" in config.sycl_build_targets:
590-
llvm_config.with_system_environment("ROCM_PATH")
591-
config.substitutions.append(
592-
("%rocm_path", os.environ.get("ROCM_PATH", "/opt/rocm"))
593-
)
594-
595635
if "cuda:gpu" in config.sycl_devices:
596636
if "CUDA_PATH" not in os.environ:
597637
if platform.system() == "Windows":

sycl/test-e2e/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ config.level_zero_libs_dir = "@LEVEL_ZERO_LIBS_DIR@"
2323
config.level_zero_include = "@LEVEL_ZERO_INCLUDE@"
2424
config.cuda_libs_dir = "@CUDA_LIBS_DIR@"
2525
config.cuda_include = "@CUDA_INCLUDE@"
26+
config.hip_libs_dir = "@HIP_LIBS_DIR@"
27+
config.hip_include = "@HIP_INCLUDE@"
2628

2729
config.opencl_include_dir = os.path.join(config.sycl_include, 'sycl')
2830

0 commit comments

Comments
 (0)