Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Enable Intel GPU plugin build on macOS (#38262)

Arseniy Obolenskiyc46a95d99f62
diff --git a/cmake/features.cmake b/cmake/features.cmake
index 78dd3adfdb5..449c48b8769 100644
--- a/cmake/features.cmake
+++ b/cmake/features.cmake
@@ -33,9 +33,9 @@ else()
set(ENABLE_INTEL_GPU_DEFAULT OFF)
endif()
-ov_dependent_option (ENABLE_INTEL_GPU "GPU OpenCL-based plugin for OpenVINO Runtime" ${ENABLE_INTEL_GPU_DEFAULT} "X86_64 OR AARCH64;NOT APPLE;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" OFF)
+ov_dependent_option (ENABLE_INTEL_GPU "GPU OpenCL-based plugin for OpenVINO Runtime" ${ENABLE_INTEL_GPU_DEFAULT} "X86_64 OR AARCH64;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" OFF)
-if (ANDROID OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
+if (APPLE OR ANDROID OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
# oneDNN doesn't support old compilers and Android builds for now, so we'll build GPU plugin without oneDNN
set(ENABLE_ONEDNN_FOR_GPU_DEFAULT OFF)
else()
@@ -58,7 +58,12 @@ if (ENABLE_INTEL_GPU)
endif()
ov_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENABLE_ONEDNN_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF)
-ov_dependent_option (ENABLE_CM_FOR_GPU "Enable C for Metal (CM) kernels at GPU runtime" ON "ENABLE_INTEL_GPU" OFF)
+if(APPLE)
+ set(ENABLE_CM_FOR_GPU_DEFAULT OFF)
+else()
+ set(ENABLE_CM_FOR_GPU_DEFAULT ON)
+endif()
+ov_dependent_option (ENABLE_CM_FOR_GPU "Enable C for Metal (CM) kernels at GPU runtime" ${ENABLE_CM_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF)
ov_dependent_option (ENABLE_INTEL_NPU "NPU plugin for OpenVINO runtime" ON "X86_64;WIN32 OR LINUX OR ANDROID" OFF)
# matches ENABLE_INTEL_NPU_COMPILER default: internal NPU tools aren't built for static libs
@@ -211,7 +216,12 @@ ov_option (ENABLE_SYSTEM_PUGIXML "Enables use of system PugiXML" OFF)
# the option is on by default, because we use only flatc compiler and don't use any libraries
ov_dependent_option(ENABLE_SYSTEM_FLATBUFFERS "Enables use of system flatbuffers" ${ENABLE_SYSTEM_FLATBUFFERS_DEFAULT}
"ENABLE_OV_TF_LITE_FRONTEND OR ENABLE_INTEL_NPU" OFF)
-ov_dependent_option (ENABLE_SYSTEM_OPENCL "Enables use of system OpenCL" ${ENABLE_SYSTEM_LIBS_DEFAULT}
+if(APPLE)
+ set(ENABLE_SYSTEM_OPENCL_DEFAULT ON)
+else()
+ set(ENABLE_SYSTEM_OPENCL_DEFAULT ${ENABLE_SYSTEM_LIBS_DEFAULT})
+endif()
+ov_dependent_option (ENABLE_SYSTEM_OPENCL "Enables use of system OpenCL" ${ENABLE_SYSTEM_OPENCL_DEFAULT}
"ENABLE_INTEL_GPU" OFF)
# the option is turned off by default, because we compile our own static version of protobuf
# with LTO and -fPIC options, while system one does not have such flags
diff --git a/src/plugins/intel_gpu/CMakeLists.txt b/src/plugins/intel_gpu/CMakeLists.txt
index 9096ee965ca..d472d5a4e66 100644
--- a/src/plugins/intel_gpu/CMakeLists.txt
+++ b/src/plugins/intel_gpu/CMakeLists.txt
@@ -113,10 +113,19 @@ if(ENABLE_GPU_DEBUG_CAPS)
add_definitions(-DENABLE_DEBUG_CAPS=1)
endif()
-set(INTEL_GPU_TARGET_OCL_VERSION "300"
+if(APPLE)
+ set(INTEL_GPU_TARGET_OCL_VERSION_DEFAULT "120")
+else()
+ set(INTEL_GPU_TARGET_OCL_VERSION_DEFAULT "300")
+endif()
+
+set(INTEL_GPU_TARGET_OCL_VERSION "${INTEL_GPU_TARGET_OCL_VERSION_DEFAULT}"
CACHE STRING "Target version of OpenCL which should be used by GPU plugin")
add_definitions(-DCL_TARGET_OPENCL_VERSION=${INTEL_GPU_TARGET_OCL_VERSION})
+if(APPLE)
+ add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=${INTEL_GPU_TARGET_OCL_VERSION})
+endif()
set(MAIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp
index 33d700d8336..dc24d16e2a2 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp
@@ -343,7 +343,7 @@ struct format {
static const std::vector<std::pair<size_t, int>> per_axis_block_size(format fmt);
- static format find_format(const std::vector<uint64_t>& order,
+ static format find_format(const std::vector<size_t>& order,
const std::vector<std::pair<size_t, int>>& block_sizes,
bool is_weights = false,
bool is_grouped = false,
@@ -373,7 +373,9 @@ struct format {
/// @brief Returns number of group dimensions.
size_t group_num() const { return traits().group_num; }
/// @brief Returns an order of dimensions.
- const std::vector<uint64_t>& dims_order() const { return traits()._order; }
+ const std::vector<size_t>& dims_order() const {
+ return traits()._order;
+ }
/// @brief Returns an order of dimensions in form of string.
const std::string& order() const { return traits().order; }
/// @brief Returns an internal orders of dimensions form of string.
diff --git a/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp b/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp
index 060ae9a5297..8f3ccb67baf 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/auto_tuner.cpp
@@ -32,7 +32,6 @@
#else
#include <unistd.h>
#include <climits>
-#include <link.h>
#include <dlfcn.h>
#endif
@@ -236,7 +235,7 @@ TuningCache* TuningCache::get() {
GetModuleFileName(hm, module_path, sizeof(module_path));
std::string bin_path(module_path);
path = bin_path.substr(0, bin_path.find_last_of("\\")) + "\\cache.json";
-#elif __linux__
+#elif defined(__linux__) || defined(__APPLE__)
const char* device_info_failed_msg = "Device lookup failed";
Dl_info dl_info;
dladdr((void*)(device_info_failed_msg), &dl_info); // NOLINT
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h
index 81625b6afac..b3ce7af9f49 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h
@@ -406,8 +406,8 @@ struct EngineInfo {
gpu_arch arch = gpu_arch::unknown;
uint32_t maxThreadsPerExecutionUnit = 0;
uint32_t maxThreadsPerDevice = 0;
- uint64_t maxWorkGroupSize = 0;
- uint64_t maxLocalMemSize = 0;
+ size_t maxWorkGroupSize = 0;
+ size_t maxLocalMemSize = 0;
uint64_t maxImage2dWidth = 0;
uint64_t maxImage2dHeight = 0;
std::string deviceId;
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_mmad_bfyx_to_b_fs_yx_fsv32.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_mmad_bfyx_to_b_fs_yx_fsv32.cpp
index ee16853be2f..01a9041bea5 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_mmad_bfyx_to_b_fs_yx_fsv32.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_mmad_bfyx_to_b_fs_yx_fsv32.cpp
@@ -164,7 +164,7 @@ ConvolutionKernelBase::DispatchData ConvolutionKernel_mmad_bfyx_to_b_fs_yx_fsv32
dispatchData.cldnnStyle.blockHeight = tuneOptions.blockHeight;
dispatchData.cldnnStyle.prefetch = tuneOptions.prefetch;
- const size_t max_lws = std::max((size_t)1, cp.engineInfo.maxWorkGroupSize / sub_group_size);
+ const size_t max_lws = std::max<size_t>(1, cp.engineInfo.maxWorkGroupSize / sub_group_size);
dispatchData.gws[0] = Align(cp.outputs[0].Feature().v, 32) / 2;
dispatchData.gws[1] = CeilDiv(cp.outputs[0].X().v, dispatchData.cldnnStyle.blockWidth);
dispatchData.gws[2] = cp.outputs[0].Batch().v * CeilDiv(cp.outputs[0].Y().v, dispatchData.cldnnStyle.blockHeight) * cp.outputs[0].Z().v;
diff --git a/src/plugins/intel_gpu/src/plugin/custom_layer.cpp b/src/plugins/intel_gpu/src/plugin/custom_layer.cpp
index 977d68465e8..5d9f2ed5a2c 100644
--- a/src/plugins/intel_gpu/src/plugin/custom_layer.cpp
+++ b/src/plugins/intel_gpu/src/plugin/custom_layer.cpp
@@ -254,7 +254,7 @@ void CustomLayer::LoadFromFile(const std::string configFile, CustomLayerMap& cus
#ifdef _WIN32
char path[MAX_PATH];
char* abs_path_ptr = _fullpath(path, configFile.c_str(), MAX_PATH);
-#elif __linux__
+#elif defined(__linux__) || defined(__APPLE__)
char path[PATH_MAX];
char* abs_path_ptr = realpath(configFile.c_str(), path);
#else
diff --git a/src/plugins/intel_gpu/src/plugin/ops/pad.cpp b/src/plugins/intel_gpu/src/plugin/ops/pad.cpp
index 44d025a4a49..8edd8949caf 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/pad.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/pad.cpp
@@ -21,18 +21,18 @@ static void CreatePadOpInternal(ProgramBuilder& p, const std::shared_ptr<op::uti
int32_t non_constant_input_mask = 0;
auto pads_begin_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->input_value(1).get_node_shared_ptr());
- std::vector<int64_t> pads_begin = std::vector<int64_t>{};
+ ov::CoordinateDiff pads_begin;
if (pads_begin_constant) {
- pads_begin = pads_begin_constant->cast_vector<int64_t>();
+ pads_begin = pads_begin_constant->cast_vector<ptrdiff_t>();
} else {
non_constant_inputs.push_back(inputs[1]);
non_constant_input_mask |= cldnn::border::PAD_NON_CONST_INPUT::BEGIN;
}
auto pads_end_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->input_value(2).get_node_shared_ptr());
- std::vector<int64_t> pads_end = std::vector<int64_t>{};
+ ov::CoordinateDiff pads_end;
if (pads_end_constant) {
- pads_end = pads_end_constant->cast_vector<int64_t>();
+ pads_end = pads_end_constant->cast_vector<ptrdiff_t>();
} else {
non_constant_inputs.push_back(inputs[2]);
non_constant_input_mask |= cldnn::border::PAD_NON_CONST_INPUT::END;
diff --git a/src/plugins/intel_gpu/src/plugin/program_builder.cpp b/src/plugins/intel_gpu/src/plugin/program_builder.cpp
index 3578457029a..aa57411afde 100644
--- a/src/plugins/intel_gpu/src/plugin/program_builder.cpp
+++ b/src/plugins/intel_gpu/src/plugin/program_builder.cpp
@@ -23,8 +23,8 @@
#include "intel_gpu/op/placeholder.hpp"
#include "openvino/util/pp.hpp"
-#ifdef __linux__
-# include <dlfcn.h>
+#if defined(__linux__) || defined(__APPLE__)
+# include <dlfcn.h>
#endif
#if defined(__unix__) && !defined(__ANDROID__)
@@ -89,7 +89,7 @@ ProgramBuilder::ProgramBuilder(std::shared_ptr<ov::Model> model, cldnn::engine&
(LPCSTR)CustomLayer::LoadFromFile,
&nModule);
GetModuleFileName(nModule, mpath, sizeof(mpath));
-#elif __linux__
+#elif defined(__linux__) || defined(__APPLE__)
Dl_info dl_info;
dladdr(reinterpret_cast<void *>(CustomLayer::LoadFromFile), &dl_info);
const char* mpath = dl_info.dli_fname;
diff --git a/src/plugins/intel_gpu/src/runtime/format.cpp b/src/plugins/intel_gpu/src/runtime/format.cpp
index af6ea474f21..28a18a3f1c2 100644
--- a/src/plugins/intel_gpu/src/runtime/format.cpp
+++ b/src/plugins/intel_gpu/src/runtime/format.cpp
@@ -347,7 +347,7 @@ const std::vector<std::pair<size_t, int>> format::per_axis_block_size(format fmt
return sizes_for_dims;
}
-format format::find_format(const std::vector<uint64_t>& order,
+format format::find_format(const std::vector<size_t>& order,
const std::vector<std::pair<size_t, int>>& block_sizes,
bool is_weights,
bool is_grouped,
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp
index ecd8fe4dd49..d9a1b6a367b 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp
@@ -41,9 +41,12 @@
# include <cstring>
#else
# include <dlfcn.h>
-# include <link.h>
# include <unistd.h>
+# ifdef __linux__
+# include <link.h>
+# endif
+
# include <climits>
#endif
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp
index 432f6dc874f..f57a9d44581 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp
@@ -116,15 +116,13 @@ memory::ptr ocl_engine::import_buffer(const layout& layout, ov::intel_gpu::os_ha
"[GPU] Selected OpenCL device does not advertise cl_khr_external_memory; "
"external memory import is not supported");
-#ifndef CL_VERSION_3_0
+#if !defined(CL_VERSION_3_0) || (!defined(_WIN32) && !defined(__linux__))
OPENVINO_THROW("[GPU] External memory import is not supported on this platform");
#else
# ifdef _WIN32
constexpr auto handle_type_token = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR;
-# elif defined(__linux__)
- constexpr auto handle_type_token = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR;
# else
- OPENVINO_THROW("[GPU] External memory import is not supported on this platform");
+ constexpr auto handle_type_token = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR;
# endif
cl_mem_properties props[] = {
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/format_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/format_test.cpp
index 80c56c42c36..861e5e6d789 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/format_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/format_test.cpp
@@ -151,7 +151,7 @@ INSTANTIATE_TEST_SUITE_P(smoke, axes_test_format,
axes_test_format::PrintToString);
struct find_format_test_params {
- std::vector<uint64_t> dims_order;
+ std::vector<size_t> dims_order;
std::vector<std::pair<size_t, int>> block_sizes;
bool is_weights;
bool is_grouped;
diff --git a/thirdparty/dependencies.cmake b/thirdparty/dependencies.cmake
index 457f9300d20..dc2b5b220e7 100644
--- a/thirdparty/dependencies.cmake
+++ b/thirdparty/dependencies.cmake
@@ -120,6 +120,14 @@ if(ENABLE_INTEL_GPU)
endif()
if(TARGET OpenCL::OpenCL)
+ if(APPLE)
+ add_subdirectory(thirdparty/ocl/cl_headers
+ thirdparty/ocl/cl_headers
+ EXCLUDE_FROM_ALL)
+ list(APPEND opencl_cpp_include_dirs
+ "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ocl/clhpp_headers/include")
+ endif()
+
# try to find CL/opencl.hpp
find_file(OpenCL_HPP
NAMES CL/opencl.hpp OpenCL/opencl.hpp
@@ -155,6 +163,12 @@ if(ENABLE_INTEL_GPU)
set(opencl_target OpenCL::OpenCL)
endif()
+ if(APPLE)
+ target_include_directories(${opencl_target} INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/thirdparty/ocl/cl_headers>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ocl/clhpp_headers/include>)
+ endif()
+
if(SUGGEST_OVERRIDE_SUPPORTED)
set_target_properties(${opencl_target} PROPERTIES INTERFACE_COMPILE_OPTIONS
$<$<COMPILE_LANGUAGE:CXX>:-Wno-suggest-override>)