Skip to content

[SYCL] Enable builds on macOS host #6706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/sycl_macos_build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Reusable SYCL macOS build and test workflow

on:
workflow_call:
inputs:
build_ref:
type: string
required: false
build_cache_suffix:
type: string
required: false
default: "default"
build_cache_size:
type: string
required: false
default: 2G
build_configure_extra_args:
type: string
required: false
default: ""
build_artifact_suffix:
type: string
required: false
default: "default"

jobs:
build:
name: Build
runs-on: macos-12
steps:
- name: Install dependencies
run: brew install ccache ninja
- uses: actions/checkout@v3
with:
ref: ${{ inputs.build_ref }}
path: src
- uses: actions/cache@v3
with:
path: build_cache_${{ inputs.build_cache_suffix }}
key: sycl-${{ runner.os }}-${{ inputs.build_cache_suffix }}-${{ github.sha }}
restore-keys: sycl-${{ runner.os }}-${{ inputs.build_cache_suffix }}-
- name: Configure
env:
CACHE_SUFFIX: ${{ inputs.build_cache_suffix }}
CACHE_SIZE: ${{ inputs.build_cache_size }}
ARGS: ${{ inputs.build_configure_extra_args }}
run: |
mkdir -p $GITHUB_WORKSPACE/build_cache_$CACHE_SUFFIX
mkdir -p $GITHUB_WORKSPACE/build
cd $GITHUB_WORKSPACE/build
python3 $GITHUB_WORKSPACE/src/buildbot/configure.py -w $GITHUB_WORKSPACE \
-s $GITHUB_WORKSPACE/src -o $GITHUB_WORKSPACE/build -t Release \
--ci-defaults $ARGS \
--cmake-opt="-DLLVM_CCACHE_BUILD=ON" \
--cmake-opt="-DLLVM_CCACHE_DIR=$GITHUB_WORKSPACE/build_cache_$CACHE_SUFFIX" \
--cmake-opt="-DLLVM_CCACHE_MAXSIZE=$CACHE_SIZE" \
--cmake-opt="-DLLVM_INSTALL_UTILS=ON" \
--cmake-opt="-DSYCL_PI_TESTS=OFF"
- name: Compile
id: build
run: cmake --build $GITHUB_WORKSPACE/build --target sycl-toolchain
- name: Install
run: |
cmake --build $GITHUB_WORKSPACE/build --target deploy-sycl-toolchain

- name: Pack toolchain
run: tar -cJf llvm_sycl.tar.xz -C $GITHUB_WORKSPACE/build/install .
- name: Upload toolchain
uses: actions/upload-artifact@v2
with:
name: sycl_macos_${{ inputs.build_artifact_suffix }}
path: llvm_sycl.tar.xz

5 changes: 5 additions & 0 deletions .github/workflows/sycl_post_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ jobs:
name: Windows
if: github.repository == 'intel/llvm'
uses: ./.github/workflows/sycl_windows_build_and_test.yml

macos_default:
name: macOS
if: github.repository == 'intel/llvm'
uses: ./.github/workflows/sycl_macos_build_and_test.yml
37 changes: 23 additions & 14 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def do_configure(args):
if not os.path.isdir(abs_obj_dir):
os.makedirs(abs_obj_dir)

llvm_external_projects = 'sycl;llvm-spirv;opencl;libdevice;xpti;xptifw'
llvm_external_projects = 'sycl;llvm-spirv;opencl;xpti;xptifw'

# libdevice build requires a working SYCL toolchain, which is not the case
# with macOS target right now.
if sys.platform != "darwin":
llvm_external_projects += ';libdevice'

libclc_amd_target_names = ';amdgcn--;amdgcn--amdhsa'
libclc_nvidia_target_names = ';nvptx64--;nvptx64--nvidiacl'
Expand All @@ -39,11 +44,14 @@ def do_configure(args):
llvm_enable_sphinx = 'OFF'
llvm_build_shared_libs = 'OFF'
llvm_enable_lld = 'OFF'
sycl_enabled_plugins = ["opencl", "level_zero"]
sycl_enabled_plugins = ["opencl"]

sycl_enable_xpti_tracing = 'ON'
xpti_enable_werror = 'OFF'

if sys.platform != "darwin":
sycl_enabled_plugins.append("level_zero")

# lld is needed on Windows or for the HIP plugin on AMD
if platform.system() == 'Windows' or (args.hip and args.hip_platform == 'AMD'):
llvm_enable_projects += ';lld'
Expand Down Expand Up @@ -104,18 +112,19 @@ def do_configure(args):

# For clang-format, clang-tidy and code coverage
llvm_enable_projects += ";clang-tools-extra;compiler-rt"
# libclc is required for CI validation
if 'libclc' not in llvm_enable_projects:
llvm_enable_projects += ';libclc'
# libclc passes `--nvvm-reflect-enable=false`, build NVPTX to enable it
if 'NVPTX' not in llvm_targets_to_build:
llvm_targets_to_build += ';NVPTX'
# Add both NVIDIA and AMD libclc targets
if libclc_amd_target_names not in libclc_targets_to_build:
libclc_targets_to_build += libclc_amd_target_names
if libclc_nvidia_target_names not in libclc_targets_to_build:
libclc_targets_to_build += libclc_nvidia_target_names
libclc_gen_remangled_variants = 'ON'
if sys.platform != "darwin":
# libclc is required for CI validation
if 'libclc' not in llvm_enable_projects:
llvm_enable_projects += ';libclc'
# libclc passes `--nvvm-reflect-enable=false`, build NVPTX to enable it
if 'NVPTX' not in llvm_targets_to_build:
llvm_targets_to_build += ';NVPTX'
# Add both NVIDIA and AMD libclc targets
if libclc_amd_target_names not in libclc_targets_to_build:
libclc_targets_to_build += libclc_amd_target_names
if libclc_nvidia_target_names not in libclc_targets_to_build:
libclc_targets_to_build += libclc_nvidia_target_names
libclc_gen_remangled_variants = 'ON'

if args.enable_plugin:
sycl_enabled_plugins += args.enable_plugin
Expand Down
2 changes: 1 addition & 1 deletion sycl/cmake/modules/AddSYCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function(add_sycl_library LIB_NAME TYPE)
add_dependencies(sycl-toolchain ${LIB_NAME})
endif()

if (ARG_LINKER_SCRIPT AND UNIX)
if (ARG_LINKER_SCRIPT AND UNIX AND NOT APPLE)
target_link_libraries(${LIB_NAME} PRIVATE
"-Wl,--version-script=${ARG_LINKER_SCRIPT}")
endif()
Expand Down
10 changes: 9 additions & 1 deletion sycl/include/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ bool trace(TraceLevel level);
#define __SYCL_CUDA_PLUGIN_NAME "pi_cuda.dll"
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "pi_esimd_emulator.dll"
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dll"
#else
#elif defined(__SYCL_RT_OS_LINUX)
#define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.so"
#define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.so"
#define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.so"
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.so"
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.so"
#elif defined(__SYCL_RT_OS_DARWIN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I wonder if we simply need to define a suffix (like .dll, .so or .dylib) to use it in library names instead of duplicating almost the same lines three times

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The right way to do this is to autogenerate these names from CMake, but that'd be outside of the scope of this patch.

#define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.dylib"
#define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.dylib"
#define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.dylib"
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.dylib"
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dylib"
#else
#error "Unsupported OS"
#endif

// Report error and no return (keeps compiler happy about no return statements).
Expand Down
10 changes: 6 additions & 4 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
else()
target_compile_options(${LIB_OBJ_NAME} PUBLIC
-fvisibility=hidden -fvisibility-inlines-hidden)
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
target_link_libraries(
${LIB_NAME} PRIVATE "-Wl,--version-script=${linker_script}")
set_target_properties(${LIB_NAME} PROPERTIES LINK_DEPENDS ${linker_script})
if (NOT APPLE)
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
target_link_libraries(
${LIB_NAME} PRIVATE "-Wl,--version-script=${linker_script}")
set_target_properties(${LIB_NAME} PROPERTIES LINK_DEPENDS ${linker_script})
endif()
if (SYCL_ENABLE_XPTI_TRACING)
target_link_libraries(${LIB_NAME} PRIVATE dl)
endif()
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/online_compiler/online_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ compileToSPIRV(const std::string &Source, sycl::info::device_type DeviceType,

uint32_t NumOutputs = 0;
byte **Outputs = nullptr;
size_t *OutputLengths = nullptr;
uint64_t *OutputLengths = nullptr;
char **OutputNames = nullptr;

const byte *Sources[] = {reinterpret_cast<const byte *>(Source.c_str())};
Expand Down
4 changes: 3 additions & 1 deletion sycl/source/detail/os_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
return reinterpret_cast<OSModuleHandle>(Res.dli_fbase);
}

std::string OSUtil::getCurrentDSODir() { return ""; }

#endif // __SYCL_RT_OS

size_t OSUtil::getOSMemSize() {
Expand Down Expand Up @@ -288,7 +290,7 @@ int OSUtil::makeDir(const char *Dir) {
do {
pos = Path.find_first_of("/\\", ++pos);
CurPath = Path.substr(0, pos);
#if defined(__SYCL_RT_OS_LINUX)
#if defined(__SYCL_RT_OS_POSIX_SUPPORT)
auto Res = mkdir(CurPath.c_str(), 0777);
#else
auto Res = _mkdir(CurPath.c_str());
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/persistent_device_code_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <cstdio>
#include <optional>

#if defined(__SYCL_RT_OS_LINUX)
#if defined(__SYCL_RT_OS_POSIX_SUPPORT)
#include <unistd.h>
#else
#include <direct.h>
Expand Down
6 changes: 4 additions & 2 deletions sycl/source/detail/platform_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#endif
#elif defined(__SYCL_RT_OS_WINDOWS)
#include <intrin.h>
#elif defined(__SYCL_RT_OS_DARWIN)
#include <cpuid.h>
#endif

namespace sycl {
Expand All @@ -27,7 +29,7 @@ namespace detail {
#if defined(__x86_64__) || defined(__i386__)
// Used by methods that duplicate OpenCL behaviour in order to get CPU info
static void cpuid(uint32_t *CPUInfo, uint32_t Type, uint32_t SubType = 0) {
#if defined(__SYCL_RT_OS_LINUX)
#if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
__cpuid_count(Type, SubType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
#elif defined(__SYCL_RT_OS_WINDOWS)
__cpuidex(reinterpret_cast<int *>(CPUInfo), Type, SubType);
Expand Down Expand Up @@ -115,7 +117,7 @@ uint32_t PlatformUtil::getNativeVectorWidth(PlatformUtil::TypeIndex TIndex) {
// AVX512 has 64 byte (ZMM) registers
static constexpr uint32_t VECTOR_WIDTH_AVX512[] = {64, 32, 16, 8, 16, 8, 0};

#if defined(__SYCL_RT_OS_LINUX)
#if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
if (__builtin_cpu_supports("avx512f"))
return VECTOR_WIDTH_AVX512[Index];
if (__builtin_cpu_supports("avx2"))
Expand Down
1 change: 0 additions & 1 deletion sycl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ list(APPEND SYCL_TEST_DEPS
sycl-toolchain
FileCheck
not
get_device_count_by_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it dead? I thought we use it in either in-tree LIT or llvm-test-suite tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so, too. Turns out, there's not a single mention of this tool, other than these, that I'd removed. It was dead for a long time now. LLVM Test Suite does not check for devices at all, fully relying on user input, and device-dependent tests have been removed from this repo.

llvm-config
llvm-cxxdump
llvm-dis
Expand Down
48 changes: 0 additions & 48 deletions sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,3 @@ if (SYCL_ENABLE_XPTI_TRACING)
endif()
endif()

# TODO: move each tool in its own sub-directory
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
add_dependencies(get_device_count_by_type
level-zero-loader
)

if(MSVC)
set(LEVEL_ZERO_LIBRARY
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_loader${CMAKE_STATIC_LIBRARY_SUFFIX}")
else()
set(LEVEL_ZERO_LIBRARY
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}ze_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()

if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_CUDA ON)
endif()
if ("hip" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_HIP ON)
endif()

target_link_libraries(get_device_count_by_type
PRIVATE
OpenCL-Headers
LevelZeroLoader::Headers
OpenCL-ICD
${LEVEL_ZERO_LIBRARY}
# The CUDA and HIP for NVIDA plugins need cudadrv
$<$<OR:$<BOOL:${SYCL_BUILD_PI_CUDA}>,$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},NVIDIA>>>:cudadrv>
# The HIP for AMD plugin needs rocmdrv
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},AMD>>:rocmdrv>
# The HIP for NVIDIA plugin also needs cudart
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},NVIDIA>>:cudart>
)
target_compile_definitions(get_device_count_by_type
PRIVATE
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
$<$<BOOL:${SYCL_BUILD_PI_HIP}>:USE_PI_HIP>
# For HIP set defines depending on the platform
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},AMD>>:__HIP_PLATFORM_AMD__>
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},NVIDIA>>:__HIP_PLATFORM_NVIDIA__>
)

if(SYCL_BUILD_PI_HIP)
target_include_directories(get_device_count_by_type
PRIVATE
${SYCL_BUILD_PI_HIP_INCLUDE_DIR})
endif()
43 changes: 30 additions & 13 deletions sycl/tools/sycl-trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ link_llvm_libs(sycl-trace
LLVMSupport
)

if ("level_zero" IN_LIST SYCL_ENABLE_PLUGINS)
set(EXTRA_SRC
ze_trace_collector.cpp
)
endif()

if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
set(EXTRA_SRC
${EXTRA_SRC}
cuda_trace_collector.cpp
)
endif()

add_library(sycl_pi_trace_collector SHARED
collector.cpp
pi_trace_collector.cpp
ze_trace_collector.cpp
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:cuda_trace_collector.cpp>
${EXTRA_SRC}
)

find_package(Python3 REQUIRED)
Expand All @@ -30,18 +42,23 @@ add_custom_target(pi-pretty-printers
)

# To get L0 loader
add_dependencies(sycl_pi_trace_collector pi_level_zero)
if ("level_zero" IN_LIST SYCL_ENABLE_PLUGINS)
add_dependencies(sycl_pi_trace_collector pi_level_zero)

target_link_libraries(sycl_pi_trace_collector PRIVATE LevelZeroLoader::Headers)
target_link_libraries(sycl_pi_trace_collector PRIVATE LevelZeroLoader::Headers)
target_compile_definitions(sycl_pi_trace_collector PRIVATE SYCL_HAS_LEVEL_ZERO)

add_custom_target(ze-pretty-printers
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/generate_ze_pretty_printers.py
${SYCL_INCLUDE_BUILD_DIR}/sycl/level_zero/ze_api.h
DEPENDS pi_level_zero
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/ze_printers.def
)
add_custom_target(ze-pretty-printers
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/generate_ze_pretty_printers.py
${SYCL_INCLUDE_BUILD_DIR}/sycl/level_zero/ze_api.h
DEPENDS pi_level_zero
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/ze_printers.def
)

add_dependencies(sycl_pi_trace_collector ze-pretty-printers)
endif()

target_compile_definitions(sycl_pi_trace_collector PRIVATE XPTI_CALLBACK_API_EXPORTS)
target_link_libraries(sycl_pi_trace_collector PRIVATE xptifw)
Expand All @@ -56,7 +73,7 @@ target_include_directories(sycl_pi_trace_collector PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}"
)

add_dependencies(sycl_pi_trace_collector pi-pretty-printers ze-pretty-printers)
add_dependencies(sycl_pi_trace_collector pi-pretty-printers)

if(SYCL_BUILD_PI_CUDA)

Expand Down
Loading