[Mac] Fix metal device build#12
Conversation
| #include "taichi/rhi/device.h" | ||
| #include "taichi/rhi/device_capability.h" | ||
| #include "taichi/rhi/impl_support.h" | ||
| #include "taichi/rhi/metal/metal_device.h" |
There was a problem hiding this comment.
What does this include do? Is it required for passing the build?
| @@ -1,8 +1,12 @@ | |||
| #include "taichi/rhi/metal/metal_device.h" | |||
| #include <math.h> | |||
There was a problem hiding this comment.
nit: not really necessary since sincospi.h has math.h already.
| #include <math.h> | ||
|
|
||
| extern "C" { | ||
| void __sincospif(float x, float *sinp, float *cosp) { |
There was a problem hiding this comment.
I'm wondering whether this function was just moved to another library file. I'm just worried that redefining it my cause symbol conflict in future.
|
Digging a little, math.h contains: So it looks like math.h should already be providing __sincospi(float, float*, float*) and __sincospi(double, double*, double*). Kind of mysterious 🤔 |
Cool. We could use it's implementation directly now. |
Yeah, but mysteriously we are following the other branch of the #if. Digging. |
…taichi into hp/mac-fix-metal-device
|
Removed a bunch of things. Much simpler now 🙌 |
|
Here's what I found by the way:
|
| #include "taichi/rhi/device.h" | ||
| #include "taichi/rhi/device_capability.h" | ||
| #include "taichi/rhi/impl_support.h" | ||
| #include "taichi/rhi/metal/metal_device.h" |
| # comes from; probably a XCode preset? | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections") | ||
| endif() | ||
| add_definitions(-D__MAC_OS_X_VERSION_MIN_REQUIRED=140000) |
There was a problem hiding this comment.
I think you should rather specify:
-DCMAKE_OSX_ARCHITECTURES="${OSX_ARCHITECTURES}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}" \
with
OSX_DEPLOYMENT_TARGET: "11.0"
OSX_ARCHITECTURES: "x86_64;arm64"
There was a problem hiding this comment.
Thanks! Will give it a shot, and see what happens. (I'm using generic clang, not OS X clang, so it's unclear to me whether these will be honored => will try, and report back on what happens).
There was a problem hiding this comment.
Tried this. Here is the new code:
if(LINUX OR APPLE)
if (NOT IOS)
# (penguinliong) Not compatible with -fembed-bitcode. Not sure where it
# comes from; probably a XCode preset?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()
Result:
/Users/hugh/.cache/ti-build-cache/sccache-v041/bin/sccache /opt/homebrew/opt/llvm@15/bin/clang++ -I/Users/hugh/.cache/ti-build-cache/miniforge/envs/3.10/lib/python3.10/site-packages/numpy/_core/include -I/Users/hugh/git/taichi -I/Users/hugh/git/taichi/external/SPIRV-Cross -I/Users/hugh/git/taichi/external/spdlog/include -I/Users/hugh/git/taichi/external/glad/include -I/Users/hugh/git/taichi/external/glfw/include -ffunction-sections -fdata-sections -DTI_ISE_NONE -std=c++17 -fsized-deallocation -Wno-deprecated-declarations -Wno-shorten-64-to-32 -Wall -Werror -Wno-ignored-attributes -Wno-nullability-completeness -Wno-unused-private-field -Wno-unneeded-internal-declaration -Wno-unused-but-set-variable -DTI_ARCH_ARM -DTI_PASS_EXCEPTION_TO_PYTHON -DTI_INCLUDED -fno-objc-arc -DTI_WITH_LLVM -DTI_WITH_METAL -DTI_WITH_METAL -O3 -DNDEBUG -std=gnu++17 -arch x86_64 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk -mmacosx-version-min=14.0 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o -MF taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o.d -o taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o -c /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.mm
In file included from /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.mm:7:
In file included from /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.h:14:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:9:
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:626:74: error: unknown type name 'NSUInteger'
FOUNDATION_EXPORT const char *NSGetSizeAndAlignment(const char *typePtr, NSUInteger * _Nullable sizep, NSUInteger * _Nullable alignp);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:626:104: error: unknown type name 'NSUInteger'
FOUNDATION_EXPORT const char *NSGetSizeAndAlignment(const char *typePtr, NSUInteger * _Nullable sizep, NSUInteger * _Nullable alignp);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:642:24: error: unknown type name 'NSInteger'
typedef NS_CLOSED_ENUM(NSInteger, NSComparisonResult) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:642:24: error: unknown type name 'NSInteger'
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:650:20: error: unknown type name 'NSUInteger'
typedef NS_OPTIONS(NSUInteger, NSEnumerationOptions) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:655:20: error: unknown type name 'NSUInteger'
typedef NS_OPTIONS(NSUInteger, NSSortOptions) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:660:17: error: unknown type name 'NSInteger'
typedef NS_ENUM(NSInteger, NSQualityOfService) {
There was a problem hiding this comment.
(tested on this branch, https://github.com/genesis-company/taichi/tree/hp/mac-fix-metal-device-change-approach2 (since have to enable mac build etc, which isnt enabled on this PR branch yet))
There was a problem hiding this comment.
I think you should remove x86 actually because Metal is not available on old Intel MacBook.
There was a problem hiding this comment.
NSUIinteger needs TARGET_OS_OSX to be defined.
There was a problem hiding this comment.
(Note: I'm not intending to cross-compile here. What makes you feel I am cross-compiling? 🤔 )
There was a problem hiding this comment.
oh -arch x86_64. Alright, I'll remove that. But the errors will persist I predict :)
There was a problem hiding this comment.
with x86 removed:
FAILED: taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o
/Users/hugh/.cache/ti-build-cache/sccache-v041/bin/sccache /opt/homebrew/opt/llvm@15/bin/clang++ -I/Users/hugh/.cache/ti-build-cache/miniforge/envs/3.10/lib/python3.10/site-packages/numpy/_core/include -I/Users/hugh/git/taichi -I/Users/hugh/git/taichi/external/SPIRV-Cross -I/Users/hugh/git/taichi/external/spdlog/include -I/Users/hugh/git/taichi/external/glad/include -I/Users/hugh/git/taichi/external/glfw/include -ffunction-sections -fdata-sections -DTI_ISE_NONE -std=c++17 -fsized-deallocation -Wno-deprecated-declarations -Wno-shorten-64-to-32 -Wall -Werror -Wno-ignored-attributes -Wno-nullability-completeness -Wno-unused-private-field -Wno-unneeded-internal-declaration -Wno-unused-but-set-variable -DTI_ARCH_ARM -DTI_PASS_EXCEPTION_TO_PYTHON -DTI_INCLUDED -fno-objc-arc -DTI_WITH_LLVM -DTI_WITH_METAL -DTI_WITH_METAL -O3 -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk -mmacosx-version-min=14.0 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o -MF taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o.d -o taichi/rhi/metal/CMakeFiles/metal_rhi.dir/metal_device.mm.o -c /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.mm
In file included from /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.mm:7:
In file included from /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.h:14:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:9:
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:626:74: error: unknown type name 'NSUInteger'
FOUNDATION_EXPORT const char *NSGetSizeAndAlignment(const char *typePtr, NSUInteger * _Nullable sizep, NSUInteger * _Nullable alignp);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:626:104: error: unknown type name 'NSUInteger'
FOUNDATION_EXPORT const char *NSGetSizeAndAlignment(const char *typePtr, NSUInteger * _Nullable sizep, NSUInteger * _Nullable alignp);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:642:24: error: unknown type name 'NSInteger'
typedef NS_CLOSED_ENUM(NSInteger, NSComparisonResult) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:642:24: error: unknown type name 'NSInteger'
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:650:20: error: unknown type name 'NSUInteger'
typedef NS_OPTIONS(NSUInteger, NSEnumerationOptions) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:655:20: error: unknown type name 'NSUInteger'
typedef NS_OPTIONS(NSUInteger, NSSortOptions) {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:660:17: error: unknown type name 'NSInteger'
typedef NS_ENUM(NSInteger, NSQualityOfService) {
There was a problem hiding this comment.
Ok I see. Probably related to using classic clang instead of the one provided with Xcode.



Issue: #
Brief Summary
Upgrade metal device from building on Mac OS ~11 to building on Mac OS 15.
See https://genesis-ai-company.slack.com/archives/C08UKDR6KGR/p1749077734526669?thread_ts=1749076147.261559&cid=C08UKDR6KGR for context
Pre-requisite for merging #5
Fix metal device build, that is currently failing on https://github.com/genesis-company/taichi/actions/runs/15453980092/job/43502395019?pr=5
copilot:summary
Walkthrough
copilot:walkthrough