Skip to content

Commit d9a860a

Browse files
committed
Automatically set CTS device triples based on which adapters are built.
Also adds the capability to detect the amd arch string we pass for --offload-arch by finding and using rocm_agent_enumerator.
1 parent c63ad9b commit d9a860a

File tree

6 files changed

+71
-13
lines changed

6 files changed

+71
-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
@@ -44,10 +44,13 @@ option(UR_BUILD_ADAPTER_NATIVE_CPU "Build the Native-CPU adapter" OFF)
4444
option(UR_BUILD_ADAPTER_ALL "Build all currently supported adapters" OFF)
4545
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
4646
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
47+
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
4748
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")
4849
set(UR_SYCL_LIBRARY_DIR "" CACHE PATH
4950
"Path of the SYCL runtime library directory")
50-
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
51+
set(UR_CONFORMANCE_TARGET_TRIPLES "" CACHE STRING
52+
"List of sycl targets to build CTS device binaries for")
53+
set(UR_CONFORMANCE_AMD_ARCH "" CACHE STRING "AMD device target ID to build CTS binaries for")
5154

5255
include(Assertions)
5356

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ List of options provided by CMake:
127127
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
128128
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
129129
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
130+
| UR_CONFORMANCE_AMD_ARCH | AMD device target ID to build CTS binaries for | string | `""` |
130131
| UR_BUILD_ADAPTER_L0 | Build the Level-Zero adapter | ON/OFF | OFF |
131132
| UR_BUILD_ADAPTER_OPENCL | Build the OpenCL adapter | ON/OFF | OFF |
132133
| 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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,37 @@
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

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

0 commit comments

Comments
 (0)