Skip to content
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

[UR] Allow compilation on apple for OpenCL support #697

Merged
merged 3 commits into from
Jul 10, 2023
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
30 changes: 30 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,33 @@ jobs:
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|umf|loader|validation|tracing|unit|urtrace"


macos-build:
name: Build - MacOS
strategy:
matrix:
os: ['macos-12', 'macos-13']
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install prerequisites
run: python3 -m pip install -r third_party/requirements.txt

- name: Configure CMake
run: >
cmake
-B${{github.workspace}}/build
-DUR_ENABLE_TRACING=ON
-DUR_DEVELOPER_MODE=ON
-DCMAKE_BUILD_TYPE=Release
-DUR_BUILD_TESTS=ON
-DUR_FORMAT_CPP_STYLE=ON
- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc)
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ include(CTest)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(helpers)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()

find_package(Python3 COMPONENTS Interpreter)

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -52,7 +56,7 @@ endif()
if(NOT MSVC)
add_compile_options(-fPIC -Wall -Wpedantic
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>)
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>)
if(UR_DEVELOPER_MODE)
add_compile_options(-Werror -fno-omit-frame-pointer)
endif()
Expand Down
5 changes: 1 addition & 4 deletions examples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ add_executable(${TARGET_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp
)

target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/include
)

if(MSVC)
set_target_properties(${TARGET_NAME}
PROPERTIES
Expand All @@ -24,4 +20,5 @@ endif()
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::loader
${CMAKE_DL_LIBS}
${PROJECT_NAME}::headers
)
2 changes: 1 addition & 1 deletion source/common/linux/ur_lib_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "logger/ur_logger.hpp"
#include "ur_lib_loader.hpp"

#if defined(SANITIZER_ANY)
#if defined(SANITIZER_ANY) || defined(__APPLE__)
#define LOAD_DRIVER_LIBRARY(NAME) dlopen(NAME, RTLD_LAZY | RTLD_LOCAL)
#else
#define LOAD_DRIVER_LIBRARY(NAME) \
Expand Down
1 change: 1 addition & 0 deletions source/common/umf_pools/disjoint_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <atomic>
#include <memory>
#include <string>

#include "../umf_helpers.hpp"

Expand Down
4 changes: 4 additions & 0 deletions source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ inline int ur_getpid(void) { return static_cast<int>(getpid()); }
#define MAKE_LIBRARY_NAME(NAME, VERSION) NAME ".dll"
#else
#define HMODULE void *
#if defined(__APPLE__)
#define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME "." VERSION ".dylib"
#else
#define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME ".so." VERSION
#endif
#endif

inline std::string create_library_path(const char *name, const char *path) {
std::string library_path;
Expand Down
6 changes: 6 additions & 0 deletions test/unified_malloc_framework/common/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#ifndef UMF_TEST_POOL_HPP
#define UMF_TEST_POOL_HPP 1

#if defined(__APPLE__)
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <umf/base.h>
#include <umf/memory_provider.h>

Expand Down Expand Up @@ -61,6 +65,8 @@ struct malloc_pool : public pool_base {
size_t malloc_usable_size(void *ptr) noexcept {
#ifdef _WIN32
return _msize(ptr);
#elif __APPLE__
return ::malloc_size(ptr);
#else
return ::malloc_usable_size(ptr);
#endif
Expand Down