Skip to content

Commit

Permalink
Automatically set CTS device triples based on which adapters are built.
Browse files Browse the repository at this point in the history
Also adds the capability to detect the amd arch string we pass for
--offload-arch by finding and using rocm_agent_enumerator.
  • Loading branch information
aarongreig committed Dec 6, 2023
1 parent 95db255 commit a34d19b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ jobs:
strategy:
matrix:
adapter: [
{name: CUDA, triplet: nvptx64-nvidia-cuda, platform: ""},
{name: HIP, triplet: amdgcn-amd-amdhsa, platform: ""},
{name: L0, triplet: spir64, platform: ""},
{name: OPENCL, triplet: spir64, platform: "Intel(R) OpenCL"}
{name: CUDA, platform: ""},
{name: HIP, platform: ""},
{name: L0, platform: ""},
{name: OPENCL, platform: "Intel(R) OpenCL"}
]
build_type: [Debug, Release]
compiler: [{c: gcc, cxx: g++}, {c: clang, cxx: clang++}]
Expand Down Expand Up @@ -198,7 +198,6 @@ jobs:
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
-DUR_CONFORMANCE_TARGET_TRIPLES=${{matrix.adapter.triplet}}
${{ matrix.adapter.name == 'HIP' && '-DAMD_ARCH=gfx1030' || '' }}
${{ matrix.adapter.name == 'HIP' && '-DUR_HIP_PLATFORM=AMD' || '' }}
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")
set(UR_SYCL_LIBRARY_DIR "" CACHE PATH
"Path of the SYCL runtime library directory")
set(UR_CONFORMANCE_TARGET_TRIPLES "" CACHE STRING
"List of sycl targets to build CTS device binaries for")
set(UR_CONFORMANCE_AMD_ARCH "AMD device target ID to build CTS binaries for" CACHE STRING)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ List of options provided by CMake:
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
| UR_CONFORMANCE_AMD_ARCH | AMD device target ID to build CTS binaries for | string | `""` |
| UR_BUILD_ADAPTER_L0 | Build the Level-Zero adapter | ON/OFF | OFF |
| UR_BUILD_ADAPTER_OPENCL | Build the OpenCL adapter | ON/OFF | OFF |
| UR_BUILD_ADAPTER_CUDA | Build the CUDA adapter | ON/OFF | OFF |
Expand Down
19 changes: 19 additions & 0 deletions cmake/FindRocmAgentEnumerator.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2023 Intel Corporation
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#
# FindRocmAgentEnumerator.cmake -- module searching for rocm_agent_enumerator.
# ROCM_AGENT_ENUMERATOR_FOUND is set to true if
# rocm_agent_enumerator is found.
#

find_program(ROCM_AGENT_ENUMERATOR NAMES not_rocm_agent_enumerator)

if(ROCM_AGENT_ENUMERATOR)
set(ROCM_AGENT_ENUMERATOR_FOUND TRUE)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RocmAgentEnumerator DEFAULT_MSG ROCM_AGENT_ENUMERATOR)
13 changes: 9 additions & 4 deletions test/conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ if(UR_DPCXX)
if(NOT "${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
else()
message(WARNING
"UR_CONFORMANCE_TARGET_TRIPLES wasn't set, defaulting to only \
generate spir64 device binaries")
list(APPEND TARGET_TRIPLES "spir64")
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "spir64")
endif()
if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "nvptx64-nvidia-cuda")
endif()
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "amdgcn-amd-amdhsa")
endif()
endif()

add_subdirectory(device_code)
Expand Down
31 changes: 31 additions & 0 deletions test/conformance/device_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(AMD_ARCH "${UR_CONFORMANCE_AMD_ARCH}")

if("${AMD_ARCH}" STREQUAL "" AND "${TARGET_TRIPLES}" MATCHES "amd")
find_package(RocmAgentEnumerator)
if(NOT ROCM_AGENT_ENUMERATOR_FOUND)
message(FATAL_ERROR
"rocm_agent_enumerator could not be found so detecting target "
"HIP device has failed. Set target device with UR_CONFORMANCE_AMD_ARCH "
"or ensure rocm_agent_enumerator is available on the PATH.")
endif()
execute_process(COMMAND ${ROCM_AGENT_ENUMERATOR} OUTPUT_VARIABLE ROCM_AGENTS)
string(REGEX MATCHALL "[A-Za-z0-9]+" ROCM_AGENT_LIST "${ROCM_AGENTS}")
# rocm_agent_enumerator will return gfx000 to represent non-amd-gpu devices,
# we should skip over these
list(GET ROCM_AGENT_LIST 0 FIRST_ROCM_AGENT)
if("${FIRST_ROCM_AGENT}" STREQUAL "gfx000")
list(POP_FRONT ROCM_AGENT_LIST)
endif()
list(LENGTH ROCM_AGENT_LIST NUM_ROCM_AGENTS)
if(${NUM_ROCM_AGENTS} EQUAL 0)
message(FATAL_ERROR
"No target HIP devices detected with rocm_agent_enumerator, "
"specify a target with the UR_CONFORMANCE_AMD_ARCH variable.")
elseif(${NUM_ROCM_AGENTS} GREATER 1)
message(FATAL_ERROR
"Multiple possible target HIP devices found: ${ROCM_AGENT_LIST} "
"please specify which target to use by setting UR_CONFORMANCE_AMD_ARCH.")
endif()
list(GET ROCM_AGENT_LIST 0 AMD_ARCH)
endif()

macro(add_device_binary SOURCE_FILE)
get_filename_component(KERNEL_NAME ${SOURCE_FILE} NAME_WE)
set(DEVICE_BINARY_DIR "${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/${KERNEL_NAME}")
Expand Down

0 comments on commit a34d19b

Please sign in to comment.