Skip to content

Commit 60c634c

Browse files
authored
[SYCL] Enable builds on macOS host (#6706)
This patch contains minimal changes to make compiler toolchain builds succeed on macOS: - Add stubs for platform-dependent functions - Disable level zero plugin for macOS exclusively - Fix platform-dependent library names - Remove get_device_count_by_type tool (which is unused, and rather than fixing it, removal is much simpler) - Add minimal CI in post-commit to prevent build breakages in future The above changes are far from fully working SYCL on Darwin targets, this patch only fixes toolchain builds, and does not attempt to make the toolchain itself functional. Fixes #258 Fixes #982
1 parent 1d8a6d6 commit 60c634c

File tree

15 files changed

+165
-87
lines changed

15 files changed

+165
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Reusable SYCL macOS build and test workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
build_ref:
7+
type: string
8+
required: false
9+
build_cache_suffix:
10+
type: string
11+
required: false
12+
default: "default"
13+
build_cache_size:
14+
type: string
15+
required: false
16+
default: 2G
17+
build_configure_extra_args:
18+
type: string
19+
required: false
20+
default: ""
21+
build_artifact_suffix:
22+
type: string
23+
required: false
24+
default: "default"
25+
26+
jobs:
27+
build:
28+
name: Build
29+
runs-on: macos-12
30+
steps:
31+
- name: Install dependencies
32+
run: brew install ccache ninja
33+
- uses: actions/checkout@v3
34+
with:
35+
ref: ${{ inputs.build_ref }}
36+
path: src
37+
- uses: actions/cache@v3
38+
with:
39+
path: build_cache_${{ inputs.build_cache_suffix }}
40+
key: sycl-${{ runner.os }}-${{ inputs.build_cache_suffix }}-${{ github.sha }}
41+
restore-keys: sycl-${{ runner.os }}-${{ inputs.build_cache_suffix }}-
42+
- name: Configure
43+
env:
44+
CACHE_SUFFIX: ${{ inputs.build_cache_suffix }}
45+
CACHE_SIZE: ${{ inputs.build_cache_size }}
46+
ARGS: ${{ inputs.build_configure_extra_args }}
47+
run: |
48+
mkdir -p $GITHUB_WORKSPACE/build_cache_$CACHE_SUFFIX
49+
mkdir -p $GITHUB_WORKSPACE/build
50+
cd $GITHUB_WORKSPACE/build
51+
python3 $GITHUB_WORKSPACE/src/buildbot/configure.py -w $GITHUB_WORKSPACE \
52+
-s $GITHUB_WORKSPACE/src -o $GITHUB_WORKSPACE/build -t Release \
53+
--ci-defaults $ARGS \
54+
--cmake-opt="-DLLVM_CCACHE_BUILD=ON" \
55+
--cmake-opt="-DLLVM_CCACHE_DIR=$GITHUB_WORKSPACE/build_cache_$CACHE_SUFFIX" \
56+
--cmake-opt="-DLLVM_CCACHE_MAXSIZE=$CACHE_SIZE" \
57+
--cmake-opt="-DLLVM_INSTALL_UTILS=ON" \
58+
--cmake-opt="-DSYCL_PI_TESTS=OFF"
59+
- name: Compile
60+
id: build
61+
run: cmake --build $GITHUB_WORKSPACE/build --target sycl-toolchain
62+
- name: Install
63+
run: |
64+
cmake --build $GITHUB_WORKSPACE/build --target deploy-sycl-toolchain
65+
66+
- name: Pack toolchain
67+
run: tar -cJf llvm_sycl.tar.xz -C $GITHUB_WORKSPACE/build/install .
68+
- name: Upload toolchain
69+
uses: actions/upload-artifact@v2
70+
with:
71+
name: sycl_macos_${{ inputs.build_artifact_suffix }}
72+
path: llvm_sycl.tar.xz
73+

.github/workflows/sycl_post_commit.yml

+5
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ jobs:
113113
name: Windows
114114
if: github.repository == 'intel/llvm'
115115
uses: ./.github/workflows/sycl_windows_build_and_test.yml
116+
117+
macos_default:
118+
name: macOS
119+
if: github.repository == 'intel/llvm'
120+
uses: ./.github/workflows/sycl_macos_build_and_test.yml

buildbot/configure.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ def do_configure(args):
1313
if not os.path.isdir(abs_obj_dir):
1414
os.makedirs(abs_obj_dir)
1515

16-
llvm_external_projects = 'sycl;llvm-spirv;opencl;libdevice;xpti;xptifw'
16+
llvm_external_projects = 'sycl;llvm-spirv;opencl;xpti;xptifw'
17+
18+
# libdevice build requires a working SYCL toolchain, which is not the case
19+
# with macOS target right now.
20+
if sys.platform != "darwin":
21+
llvm_external_projects += ';libdevice'
1722

1823
libclc_amd_target_names = ';amdgcn--;amdgcn--amdhsa'
1924
libclc_nvidia_target_names = ';nvptx64--;nvptx64--nvidiacl'
@@ -39,11 +44,14 @@ def do_configure(args):
3944
llvm_enable_sphinx = 'OFF'
4045
llvm_build_shared_libs = 'OFF'
4146
llvm_enable_lld = 'OFF'
42-
sycl_enabled_plugins = ["opencl", "level_zero"]
47+
sycl_enabled_plugins = ["opencl"]
4348

4449
sycl_enable_xpti_tracing = 'ON'
4550
xpti_enable_werror = 'OFF'
4651

52+
if sys.platform != "darwin":
53+
sycl_enabled_plugins.append("level_zero")
54+
4755
# lld is needed on Windows or for the HIP plugin on AMD
4856
if platform.system() == 'Windows' or (args.hip and args.hip_platform == 'AMD'):
4957
llvm_enable_projects += ';lld'
@@ -104,18 +112,19 @@ def do_configure(args):
104112

105113
# For clang-format, clang-tidy and code coverage
106114
llvm_enable_projects += ";clang-tools-extra;compiler-rt"
107-
# libclc is required for CI validation
108-
if 'libclc' not in llvm_enable_projects:
109-
llvm_enable_projects += ';libclc'
110-
# libclc passes `--nvvm-reflect-enable=false`, build NVPTX to enable it
111-
if 'NVPTX' not in llvm_targets_to_build:
112-
llvm_targets_to_build += ';NVPTX'
113-
# Add both NVIDIA and AMD libclc targets
114-
if libclc_amd_target_names not in libclc_targets_to_build:
115-
libclc_targets_to_build += libclc_amd_target_names
116-
if libclc_nvidia_target_names not in libclc_targets_to_build:
117-
libclc_targets_to_build += libclc_nvidia_target_names
118-
libclc_gen_remangled_variants = 'ON'
115+
if sys.platform != "darwin":
116+
# libclc is required for CI validation
117+
if 'libclc' not in llvm_enable_projects:
118+
llvm_enable_projects += ';libclc'
119+
# libclc passes `--nvvm-reflect-enable=false`, build NVPTX to enable it
120+
if 'NVPTX' not in llvm_targets_to_build:
121+
llvm_targets_to_build += ';NVPTX'
122+
# Add both NVIDIA and AMD libclc targets
123+
if libclc_amd_target_names not in libclc_targets_to_build:
124+
libclc_targets_to_build += libclc_amd_target_names
125+
if libclc_nvidia_target_names not in libclc_targets_to_build:
126+
libclc_targets_to_build += libclc_nvidia_target_names
127+
libclc_gen_remangled_variants = 'ON'
119128

120129
if args.enable_plugin:
121130
sycl_enabled_plugins += args.enable_plugin

sycl/cmake/modules/AddSYCL.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function(add_sycl_library LIB_NAME TYPE)
1313
add_dependencies(sycl-toolchain ${LIB_NAME})
1414
endif()
1515

16-
if (ARG_LINKER_SCRIPT AND UNIX)
16+
if (ARG_LINKER_SCRIPT AND UNIX AND NOT APPLE)
1717
target_link_libraries(${LIB_NAME} PRIVATE
1818
"-Wl,--version-script=${ARG_LINKER_SCRIPT}")
1919
endif()

sycl/include/sycl/detail/pi.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,20 @@ bool trace(TraceLevel level);
6767
#define __SYCL_CUDA_PLUGIN_NAME "pi_cuda.dll"
6868
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "pi_esimd_emulator.dll"
6969
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dll"
70-
#else
70+
#elif defined(__SYCL_RT_OS_LINUX)
7171
#define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.so"
7272
#define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.so"
7373
#define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.so"
7474
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.so"
7575
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.so"
76+
#elif defined(__SYCL_RT_OS_DARWIN)
77+
#define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.dylib"
78+
#define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.dylib"
79+
#define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.dylib"
80+
#define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.dylib"
81+
#define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dylib"
82+
#else
83+
#error "Unsupported OS"
7684
#endif
7785

7886
// Report error and no return (keeps compiler happy about no return statements).

sycl/source/CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
6363
else()
6464
target_compile_options(${LIB_OBJ_NAME} PUBLIC
6565
-fvisibility=hidden -fvisibility-inlines-hidden)
66-
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
67-
target_link_libraries(
68-
${LIB_NAME} PRIVATE "-Wl,--version-script=${linker_script}")
69-
set_target_properties(${LIB_NAME} PROPERTIES LINK_DEPENDS ${linker_script})
66+
if (NOT APPLE)
67+
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
68+
target_link_libraries(
69+
${LIB_NAME} PRIVATE "-Wl,--version-script=${linker_script}")
70+
set_target_properties(${LIB_NAME} PROPERTIES LINK_DEPENDS ${linker_script})
71+
endif()
7072
if (SYCL_ENABLE_XPTI_TRACING)
7173
target_link_libraries(${LIB_NAME} PRIVATE dl)
7274
endif()

sycl/source/detail/online_compiler/online_compiler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ compileToSPIRV(const std::string &Source, sycl::info::device_type DeviceType,
143143

144144
uint32_t NumOutputs = 0;
145145
byte **Outputs = nullptr;
146-
size_t *OutputLengths = nullptr;
146+
uint64_t *OutputLengths = nullptr;
147147
char **OutputNames = nullptr;
148148

149149
const byte *Sources[] = {reinterpret_cast<const byte *>(Source.c_str())};

sycl/source/detail/os_util.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
233233
return reinterpret_cast<OSModuleHandle>(Res.dli_fbase);
234234
}
235235

236+
std::string OSUtil::getCurrentDSODir() { return ""; }
237+
236238
#endif // __SYCL_RT_OS
237239

238240
size_t OSUtil::getOSMemSize() {
@@ -288,7 +290,7 @@ int OSUtil::makeDir(const char *Dir) {
288290
do {
289291
pos = Path.find_first_of("/\\", ++pos);
290292
CurPath = Path.substr(0, pos);
291-
#if defined(__SYCL_RT_OS_LINUX)
293+
#if defined(__SYCL_RT_OS_POSIX_SUPPORT)
292294
auto Res = mkdir(CurPath.c_str(), 0777);
293295
#else
294296
auto Res = _mkdir(CurPath.c_str());

sycl/source/detail/persistent_device_code_cache.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <cstdio>
1515
#include <optional>
1616

17-
#if defined(__SYCL_RT_OS_LINUX)
17+
#if defined(__SYCL_RT_OS_POSIX_SUPPORT)
1818
#include <unistd.h>
1919
#else
2020
#include <direct.h>

sycl/source/detail/platform_util.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#endif
1919
#elif defined(__SYCL_RT_OS_WINDOWS)
2020
#include <intrin.h>
21+
#elif defined(__SYCL_RT_OS_DARWIN)
22+
#include <cpuid.h>
2123
#endif
2224

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

118-
#if defined(__SYCL_RT_OS_LINUX)
120+
#if defined(__SYCL_RT_OS_LINUX) || defined(__SYCL_RT_OS_DARWIN)
119121
if (__builtin_cpu_supports("avx512f"))
120122
return VECTOR_WIDTH_AVX512[Index];
121123
if (__builtin_cpu_supports("avx2"))

sycl/test/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ list(APPEND SYCL_TEST_DEPS
3131
sycl-toolchain
3232
FileCheck
3333
not
34-
get_device_count_by_type
3534
llvm-config
3635
llvm-cxxdump
3736
llvm-dis

sycl/tools/CMakeLists.txt

-48
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,3 @@ if (SYCL_ENABLE_XPTI_TRACING)
1515
endif()
1616
endif()
1717

18-
# TODO: move each tool in its own sub-directory
19-
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
20-
add_dependencies(get_device_count_by_type
21-
level-zero-loader
22-
)
23-
24-
if(MSVC)
25-
set(LEVEL_ZERO_LIBRARY
26-
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_loader${CMAKE_STATIC_LIBRARY_SUFFIX}")
27-
else()
28-
set(LEVEL_ZERO_LIBRARY
29-
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}ze_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
30-
endif()
31-
32-
if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
33-
set(SYCL_BUILD_PI_CUDA ON)
34-
endif()
35-
if ("hip" IN_LIST SYCL_ENABLE_PLUGINS)
36-
set(SYCL_BUILD_PI_HIP ON)
37-
endif()
38-
39-
target_link_libraries(get_device_count_by_type
40-
PRIVATE
41-
OpenCL-Headers
42-
LevelZeroLoader::Headers
43-
OpenCL-ICD
44-
${LEVEL_ZERO_LIBRARY}
45-
# The CUDA and HIP for NVIDA plugins need cudadrv
46-
$<$<OR:$<BOOL:${SYCL_BUILD_PI_CUDA}>,$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},NVIDIA>>>:cudadrv>
47-
# The HIP for AMD plugin needs rocmdrv
48-
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},AMD>>:rocmdrv>
49-
# The HIP for NVIDIA plugin also needs cudart
50-
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},NVIDIA>>:cudart>
51-
)
52-
target_compile_definitions(get_device_count_by_type
53-
PRIVATE
54-
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
55-
$<$<BOOL:${SYCL_BUILD_PI_HIP}>:USE_PI_HIP>
56-
# For HIP set defines depending on the platform
57-
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},AMD>>:__HIP_PLATFORM_AMD__>
58-
$<$<AND:$<BOOL:${SYCL_BUILD_PI_HIP}>,$<STREQUAL:${SYCL_BUILD_PI_HIP_PLATFORM},NVIDIA>>:__HIP_PLATFORM_NVIDIA__>
59-
)
60-
61-
if(SYCL_BUILD_PI_HIP)
62-
target_include_directories(get_device_count_by_type
63-
PRIVATE
64-
${SYCL_BUILD_PI_HIP_INCLUDE_DIR})
65-
endif()

sycl/tools/sycl-trace/CMakeLists.txt

+30-13
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@ link_llvm_libs(sycl-trace
1010
LLVMSupport
1111
)
1212

13+
if ("level_zero" IN_LIST SYCL_ENABLE_PLUGINS)
14+
set(EXTRA_SRC
15+
ze_trace_collector.cpp
16+
)
17+
endif()
18+
19+
if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
20+
set(EXTRA_SRC
21+
${EXTRA_SRC}
22+
cuda_trace_collector.cpp
23+
)
24+
endif()
25+
1326
add_library(sycl_pi_trace_collector SHARED
1427
collector.cpp
1528
pi_trace_collector.cpp
16-
ze_trace_collector.cpp
17-
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:cuda_trace_collector.cpp>
29+
${EXTRA_SRC}
1830
)
1931

2032
find_package(Python3 REQUIRED)
@@ -30,18 +42,23 @@ add_custom_target(pi-pretty-printers
3042
)
3143

3244
# To get L0 loader
33-
add_dependencies(sycl_pi_trace_collector pi_level_zero)
45+
if ("level_zero" IN_LIST SYCL_ENABLE_PLUGINS)
46+
add_dependencies(sycl_pi_trace_collector pi_level_zero)
3447

35-
target_link_libraries(sycl_pi_trace_collector PRIVATE LevelZeroLoader::Headers)
48+
target_link_libraries(sycl_pi_trace_collector PRIVATE LevelZeroLoader::Headers)
49+
target_compile_definitions(sycl_pi_trace_collector PRIVATE SYCL_HAS_LEVEL_ZERO)
3650

37-
add_custom_target(ze-pretty-printers
38-
COMMAND ${Python3_EXECUTABLE}
39-
${CMAKE_CURRENT_SOURCE_DIR}/generate_ze_pretty_printers.py
40-
${SYCL_INCLUDE_BUILD_DIR}/sycl/level_zero/ze_api.h
41-
DEPENDS pi_level_zero
42-
BYPRODUCTS
43-
${CMAKE_CURRENT_BINARY_DIR}/ze_printers.def
44-
)
51+
add_custom_target(ze-pretty-printers
52+
COMMAND ${Python3_EXECUTABLE}
53+
${CMAKE_CURRENT_SOURCE_DIR}/generate_ze_pretty_printers.py
54+
${SYCL_INCLUDE_BUILD_DIR}/sycl/level_zero/ze_api.h
55+
DEPENDS pi_level_zero
56+
BYPRODUCTS
57+
${CMAKE_CURRENT_BINARY_DIR}/ze_printers.def
58+
)
59+
60+
add_dependencies(sycl_pi_trace_collector ze-pretty-printers)
61+
endif()
4562

4663
target_compile_definitions(sycl_pi_trace_collector PRIVATE XPTI_CALLBACK_API_EXPORTS)
4764
target_link_libraries(sycl_pi_trace_collector PRIVATE xptifw)
@@ -56,7 +73,7 @@ target_include_directories(sycl_pi_trace_collector PRIVATE
5673
"${CMAKE_CURRENT_BINARY_DIR}"
5774
)
5875

59-
add_dependencies(sycl_pi_trace_collector pi-pretty-printers ze-pretty-printers)
76+
add_dependencies(sycl_pi_trace_collector pi-pretty-printers)
6077

6178
if(SYCL_BUILD_PI_CUDA)
6279

0 commit comments

Comments
 (0)