Apple Silicon

RSS for tag

Build apps, libraries, frameworks, plug-ins, and other executable code that run natively on Apple silicon.

Posts under Apple Silicon tag

67 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Audio Workgroups: Aux threads joined to workgroup executed on E-Cores when App is in background
We develop virtual instruments for Mac/AU and are trying to get our AU-Plugins and our Standalone player to work with Audio Workgroups. When the Standalone App or Logic Pro is in the foreground and active all is well and as expected. However when the App or Logic Pro is not in focus all my auxiliary threads are running on E-Cores. Even though they are properly joined to the processing thread's workgroup. This leads to a lot of audible drop outs because deadlines are not met anymore. The processing thread itself stays on a p-core. But has to wait for the other threads to finish. How can I opt out of this behaviour? Our users certainly have use cases where they expect the Player to run smoothly even though they currently have a different App in focus.
0
0
455
Mar ’24
smc keys for M3 pro chip, returning temperature values
Im honestly a bit lost and looking for general pointers. Here is the general flow of my project. I have an Xcode project where I want to return and convert the temperature values accessed from the apple smc and I found a GitHub repo with all the smc key sensors for the M3Pros/Max chips: https://github.com/exelban/stats/issues/1703 basically, I have all these keys stored in an array in obj-c like so: NSArray *smcKeys = @[ @"Tp01", @"Tp05", @"Tp09", @"Tp0D", @"Tp0b", @"Tp0f", @"Tp0j", @"Tp0n",@"Tp0h", @"Tp0L", @"Tp0S", @"Tp0V", @"Tp0z", @"Tp0v", @"Tp17", @"Tp1F", @"Tp1J", @"Tp1p", @"Tp1h", @"Tp1R", ]; I am passing all these keys by passing 'smcKeys' in a regular C code file I have here that is meant to open, close and read the data shown here: #include "smc.h" #include <mach/mach.h> #include <IOKit/IOKitLib.h> #include "smckeys.h" io_connect_t conn; kern_return_t openSMC(void) { kern_return_t result; kern_return_t service; io_iterator_t iterator; service = IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceMatching("AppleSMC"), &iterator); if(service == 0) { printf("error: could not match dictionary"); return 0; } result = IOServiceOpen(service, mach_task_self(), 0, &conn); IOObjectRelease(service); return 0; } kern_return_t closeSMC(void) { return IOServiceClose(conn); } kern_return_t readSMC(char *smcKeys, SMCVal_t *val) { kern_return_t result; uint32_t keyCode = *(uint32_t *)smcKeys; SMCVal_t inputStruct; SMCVal_t outputStruct; inputStruct.datasize = sizeof(SMCVal_t); inputStruct.datatype = 'I' << 24; //a left shift operation. turning the I into an int by shifting the ASCII value 24 bits to the left inputStruct.data[0] = keyCode; result = IOConnectCallStructMethod(conn, 5, &inputStruct, sizeof(SMCVal_t), &outputStruct, (size_t*)&inputStruct.datasize); if (result == kIOReturnSuccess) { if (val -> datasize > 0) { if (val -> datatype == ('f' << 24 | 'l' << 16 | 't' << 8 )) { //bit shifting to from 32bit operation associated with the ASCII charecters'f', 'l', and 't', sets datatype field. double temp = *(double *)val -> data; return temp; } } } return 0.0; } Which I am then then calling the functions from this file in a swift file and converting the values to Fahrenheit but no data is being printed in my console: import IOKit public class getTemperature { public struct SMCVal_t { var datasize: UInt32 var datatype: UInt32 var data: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) } @_silgen_name("openSMC") func openSMC() -> kern_return_t @_silgen_name("closeSMC") func closeSMC() -> kern_return_t @_silgen_name("readSMC") func readSMC(key: UnsafePointer<CChar>?,val: UnsafeMutablePointer<SMCVal_t>) -> kern_return_t func convertAndPrintTempValue(key:UnsafePointer<CChar>?,scale: Character, showTemp: Bool ) -> kern_return_t { let openSM = openSMC() guard openSM == 0 else { print("Failed to open SMC: \(openSM)") return kern_return_t() } let closeSM = closeSMC() guard closeSM == 0 else { print("could not close SMC: \(closeSM)") return IOServiceClose(conn) } func convertAndPrint(val: SMCVal_t) -> Double { if val.datatype == (UInt32("f".utf8.first!) << 24 | UInt32("l".utf8.first!) << 16 | UInt32("t".utf8.first!) << 8) { let extractedTemp = Double(val.data.0) return( extractedTemp * 9.0 / 5.0 + 32.0 ) } return 0.0 } let smcValue = SMCVal_t(datasize: 0, datatype: 0, data: (0,0,0,0,0,0,0,0)) let convertedVal = convertAndPrint(val: smcValue) print("Temperarure:\(convertedVal)F°") return kern_return_t() } } I know this is a lot but I am honestly looking for any tips to fill in any gaps in my knowledge for anyone who's built a similar application meant to extract any sort of data from Mac hardware.
1
0
487
Feb ’24
Extract GPU usage percentage on Apple Silicon M-series Mac in Xcode (graphics card monitoring with Swift)
I'm working on an app for macOS where it would be very useful to display the GPU (graphics card) workload usage as a percentage. CPU usage monitoring is easy, but GPU monitoring on Apple Silicon is next-to-impossible. Apple only seems to give us our app’s GPU usage which is not what we want, since we want to total GPU workload for the whole system. I'm using the latest version of Xcode and Swift, any ideas how to achieve this?
0
0
567
Feb ’24
otool doesn't list "Load" commands?
I'm struggling with compiling lib opus so that it works in the simulator on Apple silicon. I found a thread on the forums that seems to address part of the issue, but I am unable to build the static lib so that it shows the platform it is targeting. The thread mentions that I should be able to run otool and see a "load commands" that indicate the platform. When I run otool against the static library that we have created, it doesn't list any load commands. I don't see LC_BUILD_VERSION or LC_VERSION_MIN_***. Why would there not be any "Load command" entries? % otool -l -arch arm64 dependencies/lib/libopus.a Archive : dependencies/lib/libopus.a dependencies/lib/libopus.a(bands.o): is an LLVM bit-code file dependencies/lib/libopus.a(celt.o): is an LLVM bit-code file dependencies/lib/libopus.a(celt_encoder.o): is an LLVM bit-code file dependencies/lib/libopus.a(celt_decoder.o): is an LLVM bit-code file ... dependencies/lib/libopus.a(mlp.o): is an LLVM bit-code file dependencies/lib/libopus.a(mlp_data.o): is an LLVM bit-code file The static library has the two architectures embedded in it, but when compiling the framework for the simulator platform the linking phase complains that we are building for the simulator, but linking object code built for ios. % lipo -info dependencies/lib/libopus.a Architectures in the fat file: dependencies/lib/libopus.a are: x86_64 arm64 In case you are curious, I'm just piggybacking on this project that has a build-libopus.sh script in the root directory that builds the official open source Opus library files. My hope is to build this static library for ios, ios-simulator, and mac-catalyst platforms and then include them in a xcframework.
1
0
547
Jan ’24
Detect if iOS app is running on Apple Silicon Mac using pure C
Is there a way in pure C (not Objective-C, and certainly not Swift) way to detect if an iOS app is running on a Mac? I'm aware of iOSAppOnMac, but AFAICT I'd need to write Objective-C code to use it. My application is quite old and large, with portions going back to the 1980s, so the burden of moving on the anything that can't be accessible directly from C is quite high.
2
0
473
Jan ’24
/usr/bin/leaks Still Reachable Leak Detection
Consider the following program, memory-leak.c: #include <stdlib.h> void *p; int main() { p = malloc(7); p = 0; // The memory is leaked here. return 0; } If I compile this with clang memory-leak.c and test the output with the built-in MacOS memory leak detector leaks using leaks -quiet -atExit -- ./a.out, I get (partly) the following output: 1 leak for 16 total leaked bytes. However, if I remove the 'leaking' line like so: #include <stdlib.h> void *p; int main() { p = malloc(7); return 0; } Compiling this file and again running leaks now (partly) returns: 0 leaks for 0 total leaked bytes. The man page for leaks shows that it is only un-reachable memory that is considered a leak. Is there a configuration to detect un-free'd reachablemalloc segments?
2
0
715
Jan ’24
Incorrect Registers Values with Rosetta 2
#include <stdio.h> int main() { unsigned long a, d; __asm__ volatile ( "\n\t" "movl $0x77777777, %%eax\n\t" "movl $0xffffffff, %%ecx\n\t" "xorl %%edx, %%edx\n\t" "divl %%ecx\n\t" "cwtd\n\t" "movq %%rax, %0\n\t" "movq %%rdx, %1\n\t" : "=r"(a), "=r"(d) :: "rax", "rdx" ); printf("rax: %lx, rdx, %lx", a, d); } The minimal program above was expected to give rax: 0, rdx: 77770000 but on macOS with Rosetta 2 it gave rax: 0, rdx, 0. It causes specfic programs (e.g. Genshin Impact) to crash.
3
12
1.3k
Jan ’24
Building OpenCL code for Apple Silicon
I am asking this more in hope than expectation, but would greatly appreciate any help or suggestions (with apologies for a rather lengthy post). The problem I have with my existing OpenCL code is, quite simply, that I am unable to get it to build in Xcode (I have always used Xcode without problems in the past). So my question, quite simply, is: Can anyone advise how to configure and use Xcode in order to successfully build OpenCL code for Apple Silicon? Background: Having just received a shiny new M3 MacBook Pro, I would really like to try out one or two of my GPU programs. They were all written several years using OpenCL, before Apple decided to give up on it in favour of Metal. (In fact, I have since converted one of them to use CUDA, but that is not useful here.) Now, I completely understand that the right thing to do is to convert them to use Metal directly, and will do this when I have time, but I suspect that it will take me several days, if not weeks (I have never had reason to use Metal until now, so I will also have to learn how to convert my code; there are quite a few kernels). I don’t have time to do that at the moment. Meanwhile, I would very much like to try the programs right now, using OpenCL, simply to find out how they run on Apple Silicon (I have previously only used them on older, Intel Macs with AMD GPUs). It would be great to see my code running on the M3’s GPU! The reasons I think this must still be possible are (a) there are plenty of Geekbench OpenCL results for the M3 chips; and (b) I have managed to compile and run a really trivial OpenCL program (but only using clang from the command line; I have been unable to work out how to compile individual .cl files containing OpenCL kernels). The problem I am getting is that, having cloned one of my sets of programs into Xcode on my new M3 Mac, I am unable to get any of the kernels even to build. The failure I’m getting is that Xcode is trying to run a version of openclc in the directory /System/Library/Frameworks/OpenCL.framework/Libraries/, which gives the error condition Bad CPU type in executable when Xcode tries to use it. It seems that this is an x86_64 version of openclc. There is a universal binary version in /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/Libraries/, but I have been unable to find a way to configure (or force ….) Xcode to use that one. It may well be, of course, that if I manage to get past this problem, another one will present itself. Nonetheless, if any of you can suggest anything that I might try, I would be most grateful. One secondary question, if I may: Using openclc to compile a .cl file (containing a kernel) from the command line, is there a parameter (e.g. a value to specify with -arch) or combination of parameters that will cause it to produce a .bc file for an Apple Silicon GPU and also the .cl.h header file that has to be #included in the C or C++ code that will dispatch the kernel? Thanks …. Andrew PS. I’ve also posted this question on MacRumors, because there seem to be quite a number of people there who understand Apple Silicon, but I rather suspect there’s a better chance of getting getting the help I need here ….
0
0
821
Dec ’23
How to get MacOS Version and device model from iOS app running on the Mac with Apple Silicon?
Hello, we're trying to running Unity game built for iPhones and iPads on Mac, just like this. https://developer.apple.com/documentation/apple-silicon/running-your-ios-apps-in-macos Getting device model with Unity API works on iPhone and iPad, but we got "iPad8,1"(or iPad8,2/3/4/..., one of the model of iPad Pro 3) for device model, and get "iPadOS 16.6" for Operating system on Mac. They are not Mac device information, how we get Mac device model and Mac OS version if we are running on Mac? (Additionally, not Mac Catalyst.)
1
0
471
Nov ’23
Problem with variadic C functions
I am the author of the open-source Dynace. This is an OO extension to C. It has been in production use for around 20 years. It has been used on DOS, all Windows, Linux, macOS/Intel, VMS, PLAN9, COSMIC, SUNOS, etc. all without a problem. However it does not run on Apple M1, M2 machines. I traced the problem to variadic function calls. I am creating a va_list in a ... function. I then pass the va_list to a second function. I wrote something to copy the the va_list (via va_copy) to see what I am getting. The first function works okay. But the second function does not. (I know you can't re-use a va_list.) I have spend a couple of days on this and can't find a problem with my code. I tried creating a simple example but it worked. Apparently the problem is situational. Anyway, I have no idea what is wrong or what to do next. I'd sure appreciate any help! Thanks!
2
0
582
Nov ’23
I am unable to run my iPad app on the Vision Pro simulator
My device has an M2 Max chip, and I am using Xcode version 15.1 Beta 3. My app runs normally in iOS and iPad simulators, but when I attempt to run it in the Vision Pro simulator, even though the compilation is successful, a dialog box appears stating, 'AppName's architectures (Intel 64-bit) include none that Apple Vision Pro can execute (arm64).' Consequently, the app is not successfully installed in the Vision Pro simulator. Additionally, my project uses Cocoapods for dependency management. I would appreciate any help, thank you!
5
1
2.5k
Jan ’24
python code runs on other OS but not on MacOS
I have a Python code that parses XML string. When I run that code on MacOS, it shows me an error. But when I run the same code on my Linux machine or on Windows it works completely fine. I'm wondering how is possible for a platform-independent language that runs on Linux but not on Mac. from lxml.etree import fromstring s = """<Abstract><AbstractText>The genus Cinchona is known for a range of alkaloids, such as quinine, quinidine, cinchonine, and cinchonidine. Cinchona bark has been used as an antimalarial agent for more than 400 years. Quinine was first isolated in 1820 and is still acknowledged in the therapy of chloroquine-resistant falciparum malaria; in lower dosage quinine has been used as treatment for leg cramps since the 1940s. Here we report the effects of the quinoline derivatives quinine, quinidine, and chloroquine on human adult and fetal muscle nicotinic acetylcholine receptors (nAChRs). It could be demonstrated that the compounds blocked acetylcholine (ACh)-evoked responses in Xenopus laevis oocytes expressing the adult nAChR composed of αβ𝜀δ subunits in a concentration-dependent manner, with a ranked potency of quinine (IC50 = 1.70 **M), chloroquine (IC50 = 2.22 **M) and quinidine (IC50 = 3.96 **M). At the fetal nAChR composed of ** subunits, the IC50 for quinine was found to be 2.30 **M. The efficacy of the block by quinine was independent of the ACh concentration. Therefore, quinine is proposed to inhibit ACh-evoked currents in a non-competitive manner. The present results add to the pharmacological characterization of muscle nAChRs and indicate that quinine is effective at the muscular nAChRs close to therapeutic blood concentrations required for the therapy and prophylaxis of nocturnal leg cramps, suggesting that the clinically proven efficacy of quinine could be based on targeting nAChRs.</AbstractText></Abstract>""" print(fromstring(s))
1
1
492
Nov ’23
Debug a process by hand from a c program on an Apple Silicon CPU
Hello, My purpose is to understand how macOS works. Here is what i've done: I have wrote a c program on a M1 CPU with this lines: printf("Before breakpoint\n"); asm volatile("brk #0"); printf("After breakpoint\n"); When i run this program with lldb, a breakpoint is hit on the second line. So i suppose lldb is writing a "brk #0" instruction when we put a breakpoint manually. I can't continue to next line with lldb "c" command. PC stays on the brk instruction. I need to manually set PC to next instruction in lldb. Now, what i want to do is to create my own debugger. (I want to understand how lldb works). I have managed to ptrace the target program and i was able to catch an event with waitpid when "brk #0" is hit. But i don't know how i can increase PC value and continue execution because i can't do this on Silicon CPU: ptrace(PTRACE_GETREGS, child_pid, NULL, &amp;regs); ptrace(PTRACE_SETREGS, child_pid, NULL, &amp;regs); kill(child_pid, SIGCONT); So my question is: How does lldb managed to change ARM64 registers of a remote process ? Thanks
2
0
739
Nov ’23
Xcode 15 linker error: not 8-byte aligned, which cannot be encoded as a target of LDR/STR
In an old project we just moved on mac ARM + Sonoma + Xcode 15 (fresh install), we get this link error: '_yytext' from '.../Objects-normal/arm64/html.lexer.o' not 8-byte aligned, which cannot be encoded as a target of LDR/STR in '_PHPyylex' from '.../Objects-normal/arm64/php.lexer.o' We don't get this error on Xcode 15 on mac Intel, nor with Xcode 14 on mac ARM. Does anyone know what we could do to fix that? thanks!
4
0
625
Oct ’23
UI tests ran on simulator hang after a couple of minutes on M1 Mac
Hi there! I have a problem running UI tests on simulator, while using M1 Mac. After running for a couple of minutes, usually 3 minutes is enough, tests begin to fail every ±60s on XCUIApplication().launch() with Failed to terminate com.***.***:10552: Failed to terminate com.***.***:0 At this point, my simulator window does not even react to any manual input. That issue have been happening since Xcode 13. Unit tests are running completely fine though. Also, that issue does not appear on an Intel-based Mac. Sadly, I haven't found any information on that issue, however, there are some posts on SO mentioning the same issue, and only one of those posts has an answer, but it mentions unchecking 'Open using Rosetta' option for Xcode, which is not possible anymore. I would appreciate any advice, as I feel like I have tried everything already :(
0
2
582
Sep ’23
replace macOs app (intel) with macOs app (silicon , iOs based)
Hi How can i delete macOs versions 1.1 and 1.2 (both are macOs compiled, NOT iOs based)? In fact, I want to submit my iOs version for macOs devices (with apple silicon, and ignore intel onces). But: In App Store Connect In Pricing & Availability section there is this section : Apple Silicon Mac Availability when i click on checkbox :"Make this app available", and try to save, the save do not happen (stays blue) , and if i try to go to another section, it tells me that i have to save otherwise changes will be ignored (so that another confirms that my intent is not saved). so i assume i have to delete app first. in this link https://developer.apple.com/help/app-store-connect/create-an-app-record/remove-an-app/ it says that all versions (so in my case, event curent iOS App) should not be Ready for sale so is the only solution is te remove app from all appstores and refill things again?
0
1
384
Sep ’23
missing libSystem.B.dylib
I just transitioned to an M2 silicon and compiled some of my previous programs. However, I am running into some execution problems when my code is not able to find the libSystem.B.dylib. I am runing Apple M2 Max, OS 13.5.2 (22G91) I installed XCODE and command line utilities as normal and installed gcc/gfortran using homebrew. The resulting fault text is below dyld[13777]: dyld cache '(null)' not loaded: syscall to map cache into shared region failed dyld[13777]: Library not loaded: /usr/lib/libSystem.B.dylib Referenced from: /Users/gamalakabani/Applications/TALYS_CODE/talys/bin/talys Reason: tried: '/usr/lib/libSystem.B.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/libSystem.B.dylib' (no such file), '/usr/lib/libSystem.B.dylib' (no such file, no dyld cache), '/usr/local/lib/libSystem.B.dylib' (no such file) ./verify: line 12: 13777 Abort trap: 6 $talys &lt; talys.inp &gt; talys.out Is this an issue with homebrew gcc? Any help will be appreciated. Thanks
5
0
966
Sep ’23
Apple Silicon Native Support For CarbonAPI
Hi all, I'm working on migrating a legacy codebase to run natively on Apple Silicon macOS. The project builds and runs fine on Rosetta, but anytime I try to build it for Apple Silicon I get build errors from referencing CarbonAPI. Is it possible to resolve these issues and get CarbonAPI to build natively for Apple Silicon, or will I have to rewrite the offending pieces of code? Thanks!
1
0
654
Sep ’23