Skip to content

Commit 460713e

Browse files
authored
Merge pull request #697 from veselypeta/petr/support-apple
[UR] Allow compilation on apple for OpenCL support
2 parents 0ae3b04 + 8653be6 commit 460713e

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

.github/workflows/cmake.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,33 @@ jobs:
125125
- name: Test
126126
working-directory: ${{github.workspace}}/build
127127
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|umf|loader|validation|tracing|unit|urtrace"
128+
129+
130+
macos-build:
131+
name: Build - MacOS
132+
strategy:
133+
matrix:
134+
os: ['macos-12', 'macos-13']
135+
runs-on: ${{matrix.os}}
136+
137+
steps:
138+
- uses: actions/checkout@v3
139+
140+
- uses: actions/setup-python@v4
141+
with:
142+
python-version: 3.9
143+
144+
- name: Install prerequisites
145+
run: python3 -m pip install -r third_party/requirements.txt
146+
147+
- name: Configure CMake
148+
run: >
149+
cmake
150+
-B${{github.workspace}}/build
151+
-DUR_ENABLE_TRACING=ON
152+
-DUR_DEVELOPER_MODE=ON
153+
-DCMAKE_BUILD_TYPE=Release
154+
-DUR_BUILD_TESTS=ON
155+
-DUR_FORMAT_CPP_STYLE=ON
156+
- name: Build
157+
run: cmake --build ${{github.workspace}}/build -j $(nproc)

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ include(CTest)
1414
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1515
include(helpers)
1616

17+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
18+
set(CMAKE_FIND_FRAMEWORK NEVER)
19+
endif()
20+
1721
find_package(Python3 COMPONENTS Interpreter)
1822

1923
set(CMAKE_CXX_STANDARD 17)
@@ -52,7 +56,7 @@ endif()
5256
if(NOT MSVC)
5357
add_compile_options(-fPIC -Wall -Wpedantic
5458
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
55-
$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>)
59+
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>)
5660
if(UR_DEVELOPER_MODE)
5761
add_compile_options(-Werror -fno-omit-frame-pointer)
5862
endif()

examples/hello_world/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ add_executable(${TARGET_NAME}
99
${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp
1010
)
1111

12-
target_include_directories(${TARGET_NAME} PRIVATE
13-
${CMAKE_SOURCE_DIR}/include
14-
)
15-
1612
if(MSVC)
1713
set_target_properties(${TARGET_NAME}
1814
PROPERTIES
@@ -24,4 +20,5 @@ endif()
2420
target_link_libraries(${TARGET_NAME} PRIVATE
2521
${PROJECT_NAME}::loader
2622
${CMAKE_DL_LIBS}
23+
${PROJECT_NAME}::headers
2724
)

source/common/linux/ur_lib_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "logger/ur_logger.hpp"
1313
#include "ur_lib_loader.hpp"
1414

15-
#if defined(SANITIZER_ANY)
15+
#if defined(SANITIZER_ANY) || defined(__APPLE__)
1616
#define LOAD_DRIVER_LIBRARY(NAME) dlopen(NAME, RTLD_LAZY | RTLD_LOCAL)
1717
#else
1818
#define LOAD_DRIVER_LIBRARY(NAME) \

source/common/umf_pools/disjoint_pool.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <atomic>
1313
#include <memory>
14+
#include <string>
1415

1516
#include "../umf_helpers.hpp"
1617

source/common/ur_util.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ inline int ur_getpid(void) { return static_cast<int>(getpid()); }
5757
#define MAKE_LIBRARY_NAME(NAME, VERSION) NAME ".dll"
5858
#else
5959
#define HMODULE void *
60+
#if defined(__APPLE__)
61+
#define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME "." VERSION ".dylib"
62+
#else
6063
#define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME ".so." VERSION
6164
#endif
65+
#endif
6266

6367
inline std::string create_library_path(const char *name, const char *path) {
6468
std::string library_path;

test/unified_malloc_framework/common/pool.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#ifndef UMF_TEST_POOL_HPP
1212
#define UMF_TEST_POOL_HPP 1
1313

14+
#if defined(__APPLE__)
15+
#include <malloc/malloc.h>
16+
#else
1417
#include <malloc.h>
18+
#endif
1519
#include <umf/base.h>
1620
#include <umf/memory_provider.h>
1721

@@ -61,6 +65,8 @@ struct malloc_pool : public pool_base {
6165
size_t malloc_usable_size(void *ptr) noexcept {
6266
#ifdef _WIN32
6367
return _msize(ptr);
68+
#elif __APPLE__
69+
return ::malloc_size(ptr);
6470
#else
6571
return ::malloc_usable_size(ptr);
6672
#endif

0 commit comments

Comments
 (0)