-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add macOS support #602
base: main
Are you sure you want to change the base?
Add macOS support #602
Changes from all commits
5b49a93
36384f1
cb7105e
0de3e36
7c717e9
ebdb4d9
a932459
8d7937e
031cef5
13d0052
e4db075
4c3a586
ddc56b0
648febc
d674499
159aa43
f0b9328
c6c4af8
f6a556d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,30 @@ | |
|
||
# temporary | ||
set(CMAKE_WARN_DEPRECATED OFF) | ||
add_compile_options(-Wno-format-extra-args -mf16c) | ||
|
||
# Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/17702 | ||
#FIXME: For my machine (Apple M1 Max), this just returns "" | ||
message("ARCH <${CMAKE_SYSTEM_PROCESSOR}> <${CMAKE_HOST_SYSTEM_PROCESSOR}>") | ||
# From PROCESSOR_ARCHITECTURE, see https://learn.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details?redirectedfrom=MSDN | ||
if ("{CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") | ||
set(ARCH "x64") | ||
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86") | ||
set(ARCH "x86") | ||
# From uname -p | ||
elseif ("{CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386") | ||
# We can't differentiate x86 or x64, but we guess x64 | ||
set(ARCH "x64") | ||
else() | ||
set(ARCH "unknown") | ||
endif() | ||
|
||
add_compile_options(-Wno-format-extra-args) | ||
if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "x86") | ||
add_compile_options(-mf16c) | ||
elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "x64") | ||
add_compile_options(-mf16c) | ||
endif() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How important is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-duplicate-decl-specifier \ | ||
-Wno-tautological-constant-compare -Wno-c++20-extensions -Wno-unused-result \ | ||
|
@@ -67,13 +90,16 @@ endforeach() | |
# chipStar CMAKE DEPENDENCIES | ||
if(NOT DEFINED OpenCL_LIBRARY) | ||
message(STATUS "OpenCL_LIBRARY was not set. Searching for libOpenCL.so in LD_LIBRARY_PATH") | ||
find_library(OpenCL_LIBRARY NAMES OpenCL PATHS ENV LD_LIBRARY_PATH ./ NO_CACHE) | ||
if(OpenCL_LIBRARY) | ||
get_filename_component(OpenCL_DIR ${OpenCL_LIBRARY} DIRECTORY CACHE) | ||
message(STATUS "Setting OpenCL_DIR to ${OpenCL_DIR}") | ||
else() | ||
message(STATUS "OpenCL not found") | ||
endif() | ||
#find_library(OpenCL_LIBRARY NAMES OpenCL PATHS ENV LD_LIBRARY_PATH ./ NO_CACHE) | ||
|
||
find_package(OpenCLHeaders) | ||
find_package(OpenCLICDLoader) | ||
|
||
#add_library(OpenCL ALIAS OpenCLICDLoader) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
message("OpenCL_FOUND: ${OpenCL_FOUND}") | ||
set(OpenCL_FOUND ${OpenCLICDLoader_FOUND}) | ||
message("OpenCL_FOUND: ${OpenCL_FOUND}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug leftover |
||
|
||
endif() | ||
|
||
if(NOT DEFINED LevelZero_LIBRARY) | ||
|
@@ -114,10 +140,10 @@ if(NOT DEFINED LevelZero_LIBRARY) | |
endif() | ||
endif() | ||
|
||
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}") | ||
message(STATUS "OpenCL_FOUND: ${OpenCL_FOUND}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is obviously ugly; I'll have to figure out how to show the path with import targets. |
||
message(STATUS "LevelZero_LIBRARY: ${LevelZero_LIBRARY}") | ||
|
||
if(NOT OpenCL_LIBRARY AND NOT LevelZero_LIBRARY) | ||
if(NOT OpenCL_FOUND AND NOT LevelZero_LIBRARY) | ||
message(FATAL_ERROR "At least one of OpenCL,Level0 libraries must be available") | ||
endif() | ||
|
||
|
@@ -155,7 +181,7 @@ set(CHIP_SRC | |
src/SPIRVFuncInfo.cc | ||
) | ||
|
||
if(OpenCL_LIBRARY) | ||
if(OpenCL_FOUND) | ||
list(APPEND CHIP_SRC | ||
src/backend/OpenCL/CHIPBackendOpenCL.cc | ||
src/backend/OpenCL/SVMemoryRegion.cc) | ||
|
@@ -313,18 +339,18 @@ endif() | |
if(CHIP_BUILD_SHARED_LIBS) | ||
message(STATUS "Buiding chipStar as a shared library") | ||
add_library(CHIP SHARED ${CHIP_SRC}) | ||
set(CHIP_LIB_NAME "libCHIP.so") | ||
else() | ||
message(STATUS "Buiding chipStar as a static library") | ||
add_library(CHIP STATIC ${CHIP_SRC}) | ||
set(CHIP_LIB_NAME "libCHIP.a") | ||
endif() | ||
|
||
set(CHIP_INTERFACE_LIBS ${PTHREAD_LIBRARY}) | ||
|
||
if(OpenCL_LIBRARY) | ||
if(OpenCL_FOUND) | ||
list(APPEND CHIP_SPV_DEFINITIONS HAVE_OPENCL) | ||
list(PREPEND CHIP_INTERFACE_LIBS ${OpenCL_LIBRARY}) | ||
list(PREPEND CHIP_INTERFACE_LIBS | ||
#OpenCL::Headers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deadcode |
||
OpenCL::OpenCL) | ||
endif() | ||
|
||
if(LevelZero_LIBRARY) | ||
|
@@ -452,10 +478,10 @@ set(HIP_OFFLOAD_COMPILE_OPTIONS_BUILD_ | |
list(APPEND HIP_OFFLOAD_LINK_OPTIONS_INSTALL_ "-L${LIB_INSTALL_DIR}" "-lCHIP") | ||
list(APPEND HIP_OFFLOAD_LINK_OPTIONS_BUILD_ "-L${CMAKE_BINARY_DIR}" "-lCHIP") | ||
|
||
if(OpenCL_LIBRARY) | ||
target_link_options(CHIP PUBLIC -Wl,-rpath,${OpenCL_DIR}) | ||
target_link_directories(CHIP PUBLIC ${OpenCL_DIR}) | ||
target_link_libraries(CHIP PUBLIC OpenCL) | ||
if(OpenCL_FOUND) | ||
target_link_libraries(CHIP PUBLIC | ||
# OpenCL::Headers | ||
OpenCL::OpenCL) | ||
endif() | ||
|
||
if(LevelZero_LIBRARY) | ||
|
@@ -662,7 +688,7 @@ install(TARGETS CHIP | |
) | ||
|
||
install(FILES ${CMAKE_BINARY_DIR}/include/CHIPSPVConfig.hh DESTINATION ${INCLUDE_INSTALL_DIR}) | ||
install(FILES ${PROJECT_BINARY_DIR}/${CHIP_LIB_NAME} DESTINATION lib) | ||
install(TARGETS CHIP) | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/HIP/include DESTINATION . USE_SOURCE_PERMISSIONS) | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION . USE_SOURCE_PERMISSIONS) | ||
|
||
|
@@ -708,7 +734,7 @@ endif() | |
|
||
# Short Summary | ||
# print if Level Zero or OpenCL are enabbled | ||
if(OpenCL_LIBRARY) | ||
if(OpenCL_FOUND) | ||
message(STATUS "OpenCL is enabled: ${OpenCL_LIBRARY}") | ||
endif() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,7 +525,10 @@ | |
#endif | ||
|
||
#if defined(__APPLE__) || defined(__MACOSX) | ||
#include <OpenCL/opencl.h> | ||
#define CL_DEPRECATED(...) | ||
#define GCL_API_SUFFIX__VERSION_1_1 | ||
//#include <OpenCL/opencl.h> | ||
#include <CL/opencl.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can probably be changed back; I believe ICD Loader also overloads <OpenCL/opencl.h> |
||
#else | ||
#include <CL/opencl.h> | ||
#endif // !__APPLE__ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,4 +52,7 @@ | |
typedef _Float16 api_half; | ||
typedef _Float16 api_half2 __attribute__((ext_vector_type(2))); | ||
|
||
typedef unsigned int uint; | ||
typedef unsigned long ulong; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary on macOS? Does it still work for other platforms or will it report duplicate identifier? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might cause troubles. On my system (Ubuntu 22.04) <stdlib.h> includes <sys/types.h> which defines typedefs for u{short,int,long}. /usr/include/x86_64-linux-gnu/sys/types.h:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it's not a problem as long as the duplicate typedefs aliases the same type. |
||
|
||
#endif // include guard |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. | ||
// Distributed under the MIT License (http://opensource.org/licenses/MIT) | ||
|
||
#pragma once | ||
|
||
#ifndef SPDLOG_HEADER_ONLY | ||
# include <spdlog/async_logger.h> | ||
#endif | ||
|
||
#include <spdlog/sinks/sink.h> | ||
#include <spdlog/details/thread_pool.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
SPDLOG_INLINE spdlog::async_logger::async_logger( | ||
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy) | ||
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy) | ||
{} | ||
|
||
SPDLOG_INLINE spdlog::async_logger::async_logger( | ||
std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy) | ||
: async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) | ||
{} | ||
|
||
// send the log message to the thread pool | ||
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){ | ||
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){pool_ptr->post_log(shared_from_this(), msg, overflow_policy_); | ||
} | ||
else | ||
{ | ||
throw_spdlog_ex("async log: thread pool doesn't exist anymore"); | ||
} | ||
} | ||
SPDLOG_LOGGER_CATCH(msg.source) | ||
} | ||
|
||
// send flush request to the thread pool | ||
SPDLOG_INLINE void spdlog::async_logger::flush_(){ | ||
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){pool_ptr->post_flush(shared_from_this(), overflow_policy_); | ||
} | ||
else | ||
{ | ||
throw_spdlog_ex("async flush: thread pool doesn't exist anymore"); | ||
} | ||
} | ||
SPDLOG_LOGGER_CATCH(source_loc()) | ||
} | ||
|
||
// | ||
// backend functions - called from the thread pool to do the actual job | ||
// | ||
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) | ||
{ | ||
for (auto &sink : sinks_) | ||
{ | ||
if (sink->should_log(msg.level)) | ||
{ | ||
SPDLOG_TRY | ||
{ | ||
sink->log(msg); | ||
} | ||
SPDLOG_LOGGER_CATCH(msg.source) | ||
} | ||
} | ||
|
||
if (should_flush_(msg)) | ||
{ | ||
backend_flush_(); | ||
} | ||
} | ||
|
||
SPDLOG_INLINE void spdlog::async_logger::backend_flush_() | ||
{ | ||
for (auto &sink : sinks_) | ||
{ | ||
SPDLOG_TRY | ||
{ | ||
sink->flush(); | ||
} | ||
SPDLOG_LOGGER_CATCH(source_loc()) | ||
} | ||
} | ||
|
||
SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name) | ||
{ | ||
auto cloned = std::make_shared<spdlog::async_logger>(*this); | ||
cloned->name_ = std::move(new_name); | ||
return cloned; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire block is super ugly. I'm not sure how to do this best