fix iOS build errors
This commit is contained in:
committed by
Attila Afra
parent
b748b982a2
commit
983b45b302
@@ -857,6 +857,16 @@ jobs:
|
||||
artifact-path: build install deps
|
||||
cmd: scripts/build.py install --full -D OIDN_SANITIZER=Address
|
||||
|
||||
build-ios-arm:
|
||||
secrets: inherit
|
||||
uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
|
||||
with:
|
||||
project: oidn
|
||||
runs-on: '[ "macOS", "ARM64", "build" ]'
|
||||
artifact-out: build-ios-arm
|
||||
artifact-path: build install deps
|
||||
cmd: scripts/build.py install -D OIDN_DEVICE_CPU=OFF -D OIDN_DEVICE_METAL=ON -D CMAKE_SYSTEM_NAME=iOS
|
||||
|
||||
test-macos-arm:
|
||||
needs: build-macos-arm
|
||||
secrets: inherit
|
||||
|
||||
@@ -32,6 +32,7 @@ Version History
|
||||
the specified type (e.g. CUDA) is not supported but there are other
|
||||
supported non-default devices of that type in the system
|
||||
- Fixed CMake error when building with Metal support using non-Apple Clang
|
||||
- Fixed iOS build errors
|
||||
- Added support for building with ROCm 6.x
|
||||
- `oidnNewCUDADevice` and `oidnNewHIPDevice` no longer accept negative device
|
||||
IDs. If the goal is to use the current device, its actual ID needs to be
|
||||
|
||||
+6
-13
@@ -2,20 +2,13 @@
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(NOT IOS)
|
||||
set(SDK_VERSION_COMMAND xcrun -sdk macosx --show-sdk-version)
|
||||
set(SDK_TARGET 11.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MIN 11.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MAX 11.0)
|
||||
else()
|
||||
set(SDK_VERSION_COMMAND xcrun -sdk iphoneos --show-sdk-version)
|
||||
set(SDK_TARGET 14.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MIN 14.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MAX 14.0)
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${SDK_VERSION_COMMAND}
|
||||
OUTPUT_VARIABLE SDK_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(SDK_VERSION VERSION_LESS SDK_TARGET)
|
||||
message(FATAL_ERROR "Building with BNNS support requires Apple SDK version ${SDK_TARGET} or newer")
|
||||
endif()
|
||||
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS SDK_TARGET)
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET ${SDK_TARGET})
|
||||
if(OIDN_APPLE_SDK_VERSION VERSION_LESS OIDN_APPLE_SDK_VERSION_MAX)
|
||||
message(FATAL_ERROR "Building with BNNS support requires Apple SDK version ${OIDN_APPLE_SDK_VERSION_MAX} or newer")
|
||||
endif()
|
||||
+8
-12
@@ -2,19 +2,15 @@
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(NOT IOS)
|
||||
set(SDK_VERSION_COMMAND xcrun -sdk macosx --show-sdk-version)
|
||||
set(SDK_TARGET 14.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MIN 13.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MAX 14.0)
|
||||
else()
|
||||
set(SDK_VERSION_COMMAND xcrun -sdk iphoneos --show-sdk-version)
|
||||
set(SDK_TARGET 17.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MIN 16.0)
|
||||
set(OIDN_APPLE_SDK_VERSION_MAX 17.0)
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${SDK_VERSION_COMMAND}
|
||||
OUTPUT_VARIABLE SDK_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(SDK_VERSION VERSION_LESS SDK_TARGET)
|
||||
message(FATAL_ERROR "Building with Metal support requires Apple SDK version ${SDK_TARGET} or newer")
|
||||
if(OIDN_APPLE_SDK_VERSION VERSION_LESS OIDN_APPLE_SDK_VERSION_MAX)
|
||||
message(FATAL_ERROR "Building with Metal support requires Apple SDK version ${OIDN_APPLE_SDK_VERSION_MAX} or newer")
|
||||
endif()
|
||||
|
||||
# Builds a Metal library from the given Metal shader sources and
|
||||
@@ -48,7 +44,7 @@ function(metallib_target_add_sources target metallib)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${air_file}
|
||||
COMMAND xcrun -sdk macosx metal
|
||||
COMMAND xcrun --sdk ${OIDN_APPLE_SDK} metal
|
||||
-c ${src_file}
|
||||
${include_dirs}
|
||||
${compile_defs}
|
||||
@@ -69,7 +65,7 @@ function(metallib_target_add_sources target metallib)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${metallib_file}
|
||||
COMMAND xcrun -sdk macosx metallib ${air_files} -o ${metallib_file}
|
||||
COMMAND xcrun --sdk ${OIDN_APPLE_SDK} metallib ${air_files} -o ${metallib_file}
|
||||
DEPENDS ${air_files}
|
||||
COMMENT "Linking Metal library ${metallib_file_rel}"
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ include(CheckCXXCompilerFlag)
|
||||
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
message(FATAL_ERROR "Intel(R) Open Image Denoise supports 64-bit platforms only")
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64|aarch64|ARM64")
|
||||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64|aarch64|ARM64" OR IOS)
|
||||
set(OIDN_ARCH "ARM64")
|
||||
else()
|
||||
set(OIDN_ARCH "X64")
|
||||
@@ -154,13 +154,24 @@ if((UNIX OR MINGW) AND CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
# Make sure code runs on older macOS versions
|
||||
if(OIDN_ARCH STREQUAL "ARM64")
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
|
||||
# Make sure code runs on older macOS/iOS versions
|
||||
if(NOT IOS)
|
||||
set(OIDN_APPLE_SDK "macosx")
|
||||
if(OIDN_ARCH STREQUAL "ARM64")
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
|
||||
else()
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11)
|
||||
endif()
|
||||
else()
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11)
|
||||
set(OIDN_APPLE_SDK "iphoneos")
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 14.0)
|
||||
endif()
|
||||
|
||||
# Get the SDK version
|
||||
execute_process(COMMAND xcrun --sdk ${OIDN_APPLE_SDK} --show-sdk-version
|
||||
OUTPUT_VARIABLE OIDN_APPLE_SDK_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
# Link against libc++ which supports C++11 features
|
||||
append(OIDN_CXX_FLAGS "-stdlib=libc++")
|
||||
|
||||
@@ -240,8 +251,10 @@ else()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
append(CMAKE_SHARED_LINKER_FLAGS "-Wl,-bind_at_load")
|
||||
append(CMAKE_EXE_LINKER_FLAGS "-Wl,-bind_at_load")
|
||||
if(NOT IOS)
|
||||
append(CMAKE_SHARED_LINKER_FLAGS "-Wl,-bind_at_load")
|
||||
append(CMAKE_EXE_LINKER_FLAGS "-Wl,-bind_at_load")
|
||||
endif()
|
||||
elseif(NOT OIDN_SANITIZER OR OIDN_SANITIZER STREQUAL "None")
|
||||
append(CMAKE_EXE_LINKER_FLAGS "-pie")
|
||||
append(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
#include <Windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <sys/sysctl.h>
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if defined(OIDN_ARCH_X64)
|
||||
|
||||
@@ -29,7 +29,7 @@ metallib_target_add_sources(OpenImageDenoise_device_metal metal_kernels
|
||||
INCLUDE_DIRECTORIES
|
||||
${PROJECT_SOURCE_DIR}
|
||||
COMPILE_OPTIONS
|
||||
-std=metal3.0 -fno-fast-math -mmacosx-version-min=13.0
|
||||
-std=metal3.0 -fno-fast-math -m${OIDN_APPLE_SDK}-version-min=${OIDN_APPLE_SDK_VERSION_MIN}
|
||||
)
|
||||
|
||||
set_target_properties(OpenImageDenoise_device_metal PROPERTIES
|
||||
|
||||
@@ -60,9 +60,11 @@ OIDN_NAMESPACE_BEGIN
|
||||
case MTLStorageModePrivate:
|
||||
this->storage = Storage::Device;
|
||||
break;
|
||||
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
|
||||
case MTLStorageModeManaged:
|
||||
this->storage = Storage::Managed; // we allow importing managed buffers
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
throw Exception(Error::InvalidArgument, "Metal buffer storage mode is not supported");
|
||||
}
|
||||
@@ -147,7 +149,7 @@ OIDN_NAMESPACE_BEGIN
|
||||
|
||||
@autoreleasepool
|
||||
{
|
||||
const MTLResourceOptions options = MTLResourceStorageModeShared | MTLResourceOptionCPUCacheModeDefault;
|
||||
const MTLResourceOptions options = MTLResourceStorageModeShared | MTLResourceCPUCacheModeDefaultCache;
|
||||
id<MTLBuffer> tempBuffer = [engine->getMTLDevice() newBufferWithLength: byteSize
|
||||
options: options];
|
||||
if (!tempBuffer)
|
||||
@@ -185,7 +187,7 @@ OIDN_NAMESPACE_BEGIN
|
||||
|
||||
@autoreleasepool
|
||||
{
|
||||
const MTLResourceOptions options = MTLResourceStorageModeShared | MTLResourceOptionCPUCacheModeDefault;
|
||||
const MTLResourceOptions options = MTLResourceStorageModeShared | MTLResourceCPUCacheModeDefaultCache;
|
||||
id<MTLBuffer> tempBuffer = [engine->getMTLDevice() newBufferWithBytes: srcHostPtr
|
||||
length: byteSize
|
||||
options: options];
|
||||
|
||||
@@ -16,8 +16,10 @@ OIDN_NAMESPACE_BEGIN
|
||||
return MTLResourceStorageModeShared | MTLResourceCPUCacheModeDefaultCache;
|
||||
case Storage::Device:
|
||||
return MTLResourceStorageModePrivate;
|
||||
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
|
||||
case Storage::Managed:
|
||||
return MTLResourceStorageModeManaged | MTLResourceCPUCacheModeDefaultCache;
|
||||
#endif
|
||||
default:
|
||||
throw Exception(Error::InvalidArgument, "invalid storage mode");
|
||||
}
|
||||
|
||||
@@ -25,8 +25,13 @@ OIDN_NAMESPACE_BEGIN
|
||||
@autoreleasepool
|
||||
{
|
||||
std::vector<Ref<PhysicalDevice>> physicalDevices;
|
||||
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
|
||||
NSArray* devices = [MTLCopyAllDevices() autorelease];
|
||||
#else
|
||||
NSArray* devices = @[MTLCreateSystemDefaultDevice()];
|
||||
#endif
|
||||
const int numDevices = static_cast<int>(devices.count);
|
||||
|
||||
for (int deviceID = 0; deviceID < numDevices; ++deviceID)
|
||||
{
|
||||
id<MTLDevice> device = devices[deviceID];
|
||||
@@ -36,6 +41,7 @@ OIDN_NAMESPACE_BEGIN
|
||||
physicalDevices.push_back(makeRef<MetalPhysicalDevice>(device, score));
|
||||
}
|
||||
}
|
||||
|
||||
return physicalDevices;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +54,7 @@ OIDN_NAMESPACE_BEGIN
|
||||
if (@available(macOS 13, iOS 16, tvOS 16, *))
|
||||
{
|
||||
return [device supportsFamily: MTLGPUFamilyMetal3] &&
|
||||
[device supportsFamily: MTLGPUFamilyApple7] && // validated only on Apple GPUs
|
||||
[device supportsFamily: MTLGPUFamilyApple6] && // validated only on Apple GPUs
|
||||
device.maxThreadsPerThreadgroup.width >= 1024;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user