Skip to content

Commit b05c5b5

Browse files
authored
Merge pull request #1155 from aarongreig/aaron/detectCTSTriple
Automatically set CTS device triples based on which adapters are built.
2 parents 6032f6f + 44191dd commit b05c5b5

File tree

6 files changed

+76
-13
lines changed

6 files changed

+76
-13
lines changed

.github/workflows/cmake.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ jobs:
166166
strategy:
167167
matrix:
168168
adapter: [
169-
{name: CUDA, triplet: nvptx64-nvidia-cuda, platform: ""},
170-
{name: HIP, triplet: amdgcn-amd-amdhsa, platform: ""},
171-
{name: L0, triplet: spir64, platform: ""},
172-
{name: OPENCL, triplet: spir64, platform: "Intel(R) OpenCL"}
169+
{name: CUDA, platform: ""},
170+
{name: HIP, platform: ""},
171+
{name: L0, platform: ""},
172+
{name: OPENCL, platform: "Intel(R) OpenCL"}
173173
]
174174
build_type: [Debug, Release]
175175
compiler: [{c: gcc, cxx: g++}, {c: clang, cxx: clang++}]
@@ -201,8 +201,7 @@ jobs:
201201
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
202202
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
203203
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
204-
-DUR_CONFORMANCE_TARGET_TRIPLES=${{matrix.adapter.triplet}}
205-
${{ matrix.adapter.name == 'HIP' && '-DAMD_ARCH=gfx1030' || '' }}
204+
${{ matrix.adapter.name == 'HIP' && '-DUR_CONFORMANCE_AMD_ARCH=gfx1030' || '' }}
206205
${{ matrix.adapter.name == 'HIP' && '-DUR_HIP_PLATFORM=AMD' || '' }}
207206
208207
- name: Build

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ option(UR_BUILD_ADAPTER_NATIVE_CPU "Build the Native-CPU adapter" OFF)
4545
option(UR_BUILD_ADAPTER_ALL "Build all currently supported adapters" OFF)
4646
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
4747
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
48+
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
4849
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")
4950
set(UR_SYCL_LIBRARY_DIR "" CACHE PATH
5051
"Path of the SYCL runtime library directory")
51-
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
52+
set(UR_CONFORMANCE_TARGET_TRIPLES "" CACHE STRING
53+
"List of sycl targets to build CTS device binaries for")
54+
set(UR_CONFORMANCE_AMD_ARCH "" CACHE STRING "AMD device target ID to build CTS binaries for")
5255

5356
include(Assertions)
5457

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ List of options provided by CMake:
128128
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
129129
| UR_ENABLE_SANITIZER | Enable device sanitizer layer | ON/OFF | ON |
130130
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
131+
| UR_CONFORMANCE_AMD_ARCH | AMD device target ID to build CTS binaries for | string | `""` |
131132
| UR_BUILD_ADAPTER_L0 | Build the Level-Zero adapter | ON/OFF | OFF |
132133
| UR_BUILD_ADAPTER_OPENCL | Build the OpenCL adapter | ON/OFF | OFF |
133134
| UR_BUILD_ADAPTER_CUDA | Build the CUDA adapter | ON/OFF | OFF |

cmake/FindRocmAgentEnumerator.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2023 Intel Corporation
2+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See LICENSE.TXT
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#
7+
# FindRocmAgentEnumerator.cmake -- module searching for rocm_agent_enumerator.
8+
# ROCM_AGENT_ENUMERATOR_FOUND is set to true if
9+
# rocm_agent_enumerator is found.
10+
#
11+
12+
find_program(ROCM_AGENT_ENUMERATOR NAMES not_rocm_agent_enumerator)
13+
14+
if(ROCM_AGENT_ENUMERATOR)
15+
set(ROCM_AGENT_ENUMERATOR_FOUND TRUE)
16+
endif()
17+
18+
include(FindPackageHandleStandardArgs)
19+
find_package_handle_standard_args(RocmAgentEnumerator DEFAULT_MSG ROCM_AGENT_ENUMERATOR)

test/conformance/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,18 @@ if(UR_DPCXX)
102102
"${CMAKE_CURRENT_BINARY_DIR}/device_binaries" CACHE INTERNAL UR_CONFORMANCE_DEVICE_BINARIES_DIR)
103103
file(MAKE_DIRECTORY ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
104104

105-
if(NOT "${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
106-
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
105+
if("${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
106+
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL)
107+
list(APPEND TARGET_TRIPLES "spir64")
108+
endif()
109+
if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
110+
list(APPEND TARGET_TRIPLES "nvptx64-nvidia-cuda")
111+
endif()
112+
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
113+
list(APPEND TARGET_TRIPLES "amdgcn-amd-amdhsa")
114+
endif()
107115
else()
108-
message(WARNING
109-
"UR_CONFORMANCE_TARGET_TRIPLES wasn't set, defaulting to only \
110-
generate spir64 device binaries")
111-
list(APPEND TARGET_TRIPLES "spir64")
116+
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
112117
endif()
113118

114119
add_subdirectory(device_code)

test/conformance/device_code/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,42 @@
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
if(NOT "${AMD_ARCH}" STREQUAL "" AND "${UR_CONFORMANCE_AMD_ARCH}" STREQUAL "")
7+
message(WARNING "Passing the HIP target architecture with AMD_ARCH is deprecated. "
8+
"Please use UR_CONFORMANCE_AMD_ARCH instead.")
9+
else()
10+
set(AMD_ARCH "${UR_CONFORMANCE_AMD_ARCH}")
11+
endif()
12+
13+
if("${AMD_ARCH}" STREQUAL "" AND "${TARGET_TRIPLES}" MATCHES "amd")
14+
find_package(RocmAgentEnumerator)
15+
if(NOT ROCM_AGENT_ENUMERATOR_FOUND)
16+
message(FATAL_ERROR
17+
"rocm_agent_enumerator could not be found so detecting target "
18+
"HIP device has failed. Set target device with UR_CONFORMANCE_AMD_ARCH "
19+
"or ensure rocm_agent_enumerator is available on the PATH.")
20+
endif()
21+
execute_process(COMMAND ${ROCM_AGENT_ENUMERATOR} OUTPUT_VARIABLE ROCM_AGENTS)
22+
string(REGEX MATCHALL "[A-Za-z0-9]+" ROCM_AGENT_LIST "${ROCM_AGENTS}")
23+
# rocm_agent_enumerator will return gfx000 to represent non-amd-gpu devices,
24+
# we should skip over these
25+
list(GET ROCM_AGENT_LIST 0 FIRST_ROCM_AGENT)
26+
if("${FIRST_ROCM_AGENT}" STREQUAL "gfx000")
27+
list(POP_FRONT ROCM_AGENT_LIST)
28+
endif()
29+
list(LENGTH ROCM_AGENT_LIST NUM_ROCM_AGENTS)
30+
if(${NUM_ROCM_AGENTS} EQUAL 0)
31+
message(FATAL_ERROR
32+
"No target HIP devices detected with rocm_agent_enumerator, "
33+
"specify a target with the UR_CONFORMANCE_AMD_ARCH variable.")
34+
elseif(${NUM_ROCM_AGENTS} GREATER 1)
35+
message(FATAL_ERROR
36+
"Multiple possible target HIP devices found: ${ROCM_AGENT_LIST} "
37+
"please specify which target to use by setting UR_CONFORMANCE_AMD_ARCH.")
38+
endif()
39+
list(GET ROCM_AGENT_LIST 0 AMD_ARCH)
40+
endif()
41+
642
macro(add_device_binary SOURCE_FILE)
743
get_filename_component(KERNEL_NAME ${SOURCE_FILE} NAME_WE)
844
set(DEVICE_BINARY_DIR "${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/${KERNEL_NAME}")

0 commit comments

Comments
 (0)