Loading...
Loading...
Apple Silicon skill for M-series development and profiling. Use when leveraging unified memory, Metal Performance Shaders, Instruments profiling, sysctl hardware queries, Rosetta 2 behavior, or 16KB page size considerations. Activates on queries about Apple Silicon, unified memory, AMX, MPS, Instruments, Rosetta, or M-series page size.
npx skill4agent add mohitmishra786/low-level-dev-skills apple-siliconsysctlApple Silicon SoC
├── CPU cores (P + E cores)
├── GPU cores
├── Neural Engine (NPU)
└── Unified DRAM — single address space, no PCIe copycudaMemcpy# CPU and chip info
sysctl -n machdep.cpu.brand_string
sysctl hw.physicalcpu hw.logicalcpu
sysctl hw.memsize
# ARM64 features (keys vary by chip — grep if specific FEAT_* is missing)
sysctl -a hw.optional.arm 2>/dev/null | grep -iE 'sve|bf16|mte'
# Cache line size
sysctl hw.cachelinesize
# Page size (16KB on macOS Apple Silicon)
sysctl hw.pagesize # 16384
getconf PAGESIZE// Align hot buffers to page size
size_t page = sysconf(_SC_PAGESIZE); // 16384
void *buf = aligned_alloc(page, size);
// mmap alignment must be page-aligned
mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);posix_memalign// Accelerate framework — uses AMX internally for matrix ops
#include <Accelerate/Accelerate.h>
void matrix_multiply(const float *A, const float *B, float *C,
int M, int N, int K) {
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
M, N, K, 1.0f, A, K, B, N, 0.0f, C, N);
}# Link Accelerate (default on macOS)
clang -framework Accelerate -o gemm gemm.c -lcblas// Objective-C / Swift — GPU compute via MPS
#import <Metal/Metal.h>
#import <MetalPerformanceShaders/MetalPerformanceShaders.h>
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> queue = [device newCommandQueue];
MPSMatrixMultiplication *gemm = [[MPSMatrixMultiplication alloc]
initWithDevice:device transposeLeft:NO transposeRight:NO
resultRows:M columns:N interiorColumns:K alpha:1.0 beta:0.0];MTLResourceStorageModeShared# Command-line Instruments (xctrace)
xctrace record --template 'Time Profiler' --launch -- /path/to/app
xctrace record --template 'Allocations' --launch -- /path/to/app
xctrace record --template 'Leaks' --launch -- /path/to/app
xctrace export --input trace.trace --toc| Template | Use |
|---|---|
| Time Profiler | CPU hotspots, P/E core usage |
| Allocations | Heap growth, allocation call trees |
| Leaks | Retained memory |
| System Trace | Thread scheduling, syscalls |
# Process memory map
vmmap <pid>
# Heap analysis
heap <pid>
heap <pid> -addresses all # all allocations
# Leak detection
leaks <pid>
leaks --list <pid>
# Sample call stacks
sample <pid> 5 -file sample.txt# Check if process runs under Rosetta
sysctl sysctl.proc_translated # 1 = translated x86
# Force arch
arch -arm64 ./native_binary
arch -x86_64 ./x86_binary
# Universal binary info
lipo -info myapp
file myapp| Runs native ARM64 | Runs under Rosetta |
|---|---|
| ARM64 build | x86_64-only binary |
| Downloaded Intel-only app |
sysctl hw.optional.arm.FEAT_MTE # when available# Native optimized build
clang -arch arm64 -O3 -mcpu=apple-m1 -o app app.c
# Use -mcpu matching target: apple-m1, apple-m2, apple-m3, apple-m4
# P/E core awareness — dispatch heavy work to performance cores
# pthread_set_qos_class_self_np(QOS_CLASS_USER_INITIATED, 0);| Symptom | Cause | Fix |
|---|---|---|
| mmap fails with EINVAL | 4KB alignment on 16KB system | Align to |
| Slow x86 binary | Rosetta overhead | Ship universal or arm64-only build |
| Metal buffer nil | Simulator vs device | Test GPU on real hardware |
| Accelerate wrong results | Row/column major mismatch | Check BLAS leading dimensions |
| Instruments empty trace | Sandbox/permissions | Run from Xcode or sign app |
| sysctl not found | Wrong key name | `sysctl -a |
skills/low-level-programming/assembly-armskills/platform/arm-sveskills/gpu/cudaskills/profilers/heaptrackskills/compilers/clangskills/low-level-programming/cpu-cache-opt