diff --git a/.github/workflows/sycl_macos_build_and_test.yml b/.github/workflows/sycl_macos_build_and_test.yml new file mode 100644 index 0000000000000..15ed0cf972166 --- /dev/null +++ b/.github/workflows/sycl_macos_build_and_test.yml @@ -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 + diff --git a/.github/workflows/sycl_post_commit.yml b/.github/workflows/sycl_post_commit.yml index fc032f4e79ab7..e09a12f402355 100644 --- a/.github/workflows/sycl_post_commit.yml +++ b/.github/workflows/sycl_post_commit.yml @@ -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 diff --git a/buildbot/configure.py b/buildbot/configure.py index 2ef894a845174..aae2f42d4151a 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -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' @@ -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' @@ -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 diff --git a/sycl/cmake/modules/AddSYCL.cmake b/sycl/cmake/modules/AddSYCL.cmake index aa0cfcadda92d..dbf539e9a7591 100644 --- a/sycl/cmake/modules/AddSYCL.cmake +++ b/sycl/cmake/modules/AddSYCL.cmake @@ -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() diff --git a/sycl/include/sycl/detail/pi.hpp b/sycl/include/sycl/detail/pi.hpp index 4c05c5d52aad5..a74e925c4f45c 100644 --- a/sycl/include/sycl/detail/pi.hpp +++ b/sycl/include/sycl/detail/pi.hpp @@ -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) +#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). diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index 23b161480b17a..e699b438ec2c5 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -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() diff --git a/sycl/source/detail/online_compiler/online_compiler.cpp b/sycl/source/detail/online_compiler/online_compiler.cpp index ab73f11a02d43..704113282338b 100644 --- a/sycl/source/detail/online_compiler/online_compiler.cpp +++ b/sycl/source/detail/online_compiler/online_compiler.cpp @@ -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(Source.c_str())}; diff --git a/sycl/source/detail/os_util.cpp b/sycl/source/detail/os_util.cpp index 1bbe6fa91cf96..19cc2ee9d73e7 100644 --- a/sycl/source/detail/os_util.cpp +++ b/sycl/source/detail/os_util.cpp @@ -233,6 +233,8 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) { return reinterpret_cast(Res.dli_fbase); } +std::string OSUtil::getCurrentDSODir() { return ""; } + #endif // __SYCL_RT_OS size_t OSUtil::getOSMemSize() { @@ -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()); diff --git a/sycl/source/detail/persistent_device_code_cache.cpp b/sycl/source/detail/persistent_device_code_cache.cpp index 0fc779c359163..114a6dd82e520 100644 --- a/sycl/source/detail/persistent_device_code_cache.cpp +++ b/sycl/source/detail/persistent_device_code_cache.cpp @@ -14,7 +14,7 @@ #include #include -#if defined(__SYCL_RT_OS_LINUX) +#if defined(__SYCL_RT_OS_POSIX_SUPPORT) #include #else #include diff --git a/sycl/source/detail/platform_util.cpp b/sycl/source/detail/platform_util.cpp index 57162f17b7ce4..491dda30bbb70 100644 --- a/sycl/source/detail/platform_util.cpp +++ b/sycl/source/detail/platform_util.cpp @@ -18,6 +18,8 @@ #endif #elif defined(__SYCL_RT_OS_WINDOWS) #include +#elif defined(__SYCL_RT_OS_DARWIN) +#include #endif namespace sycl { @@ -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(CPUInfo), Type, SubType); @@ -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")) diff --git a/sycl/test/CMakeLists.txt b/sycl/test/CMakeLists.txt index 97963414a6abc..a4465a532b7d9 100644 --- a/sycl/test/CMakeLists.txt +++ b/sycl/test/CMakeLists.txt @@ -31,7 +31,6 @@ list(APPEND SYCL_TEST_DEPS sycl-toolchain FileCheck not - get_device_count_by_type llvm-config llvm-cxxdump llvm-dis diff --git a/sycl/tools/CMakeLists.txt b/sycl/tools/CMakeLists.txt index eb62c48e1adff..ed11e98b1f9c8 100644 --- a/sycl/tools/CMakeLists.txt +++ b/sycl/tools/CMakeLists.txt @@ -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 - $<$,$,$>>:cudadrv> - # The HIP for AMD plugin needs rocmdrv - $<$,$>:rocmdrv> - # The HIP for NVIDIA plugin also needs cudart - $<$,$>:cudart> -) -target_compile_definitions(get_device_count_by_type - PRIVATE - $<$:USE_PI_CUDA> - $<$:USE_PI_HIP> - # For HIP set defines depending on the platform - $<$,$>:__HIP_PLATFORM_AMD__> - $<$,$>:__HIP_PLATFORM_NVIDIA__> -) - -if(SYCL_BUILD_PI_HIP) - target_include_directories(get_device_count_by_type - PRIVATE - ${SYCL_BUILD_PI_HIP_INCLUDE_DIR}) -endif() diff --git a/sycl/tools/sycl-trace/CMakeLists.txt b/sycl/tools/sycl-trace/CMakeLists.txt index 385a348f67801..6f36b83a29391 100644 --- a/sycl/tools/sycl-trace/CMakeLists.txt +++ b/sycl/tools/sycl-trace/CMakeLists.txt @@ -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 - $<$:cuda_trace_collector.cpp> + ${EXTRA_SRC} ) find_package(Python3 REQUIRED) @@ -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) @@ -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) diff --git a/sycl/tools/sycl-trace/collector.cpp b/sycl/tools/sycl-trace/collector.cpp old mode 100755 new mode 100644 index 3b1656986fc0f..416dfc3f6b762 --- a/sycl/tools/sycl-trace/collector.cpp +++ b/sycl/tools/sycl-trace/collector.cpp @@ -51,6 +51,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int /*major_version*/, piCallback); xptiRegisterCallback(StreamID, xpti::trace_function_with_args_end, piCallback); +#ifdef SYCL_HAS_LEVEL_ZERO } else if (std::string_view(StreamName) == "sycl.experimental.level_zero.debug" && std::getenv("SYCL_TRACE_ZE_ENABLE")) { @@ -60,6 +61,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int /*major_version*/, zeCallback); xptiRegisterCallback(StreamID, xpti::trace_function_with_args_end, zeCallback); +#endif #ifdef USE_PI_CUDA } else if (std::string_view(StreamName) == "sycl.experimental.cuda.debug" && std::getenv("SYCL_TRACE_CU_ENABLE")) { @@ -77,10 +79,12 @@ XPTI_CALLBACK_API void xptiTraceFinish(const char *StreamName) { if (std::string_view(StreamName) == "sycl.pi.debug" && std::getenv("SYCL_TRACE_PI_ENABLE")) piPrintersFinish(); +#ifdef SYCL_HAS_LEVEL_ZERO else if (std::string_view(StreamName) == "sycl.experimental.level_zero.debug" && std::getenv("SYCL_TRACE_ZE_ENABLE")) zePrintersFinish(); +#endif #ifdef USE_PI_CUDA else if (std::string_view(StreamName) == "sycl.experimental.cuda.debug" && std::getenv("SYCL_TRACE_CU_ENABLE")) diff --git a/sycl/tools/sycl-trace/main.cpp b/sycl/tools/sycl-trace/main.cpp index 394b77085f29c..7302ba7f62667 100755 --- a/sycl/tools/sycl-trace/main.cpp +++ b/sycl/tools/sycl-trace/main.cpp @@ -48,8 +48,13 @@ int main(int argc, char **argv, char *env[]) { NewEnv.emplace_back(env[I++]); } +#ifdef __linux__ NewEnv.push_back("XPTI_FRAMEWORK_DISPATCHER=libxptifw.so"); NewEnv.push_back("XPTI_SUBSCRIBERS=libsycl_pi_trace_collector.so"); +#elif defined(__APPLE__) + NewEnv.push_back("XPTI_FRAMEWORK_DISPATCHER=libxptifw.dylib"); + NewEnv.push_back("XPTI_SUBSCRIBERS=libsycl_pi_trace_collector.dylib"); +#endif NewEnv.push_back("XPTI_TRACE_ENABLE=1"); const auto EnablePITrace = [&]() {