IQ.Pilot Release Commit @ b6534c0

This commit is contained in:
IQ.Lvbs CI [bot]
2026-08-27 20:17:33 -05:00
commit 00f07cac48
4706 changed files with 1257146 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,148 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1 @@
int run_server(const char *sock_path);

View File

@@ -0,0 +1,48 @@
import SwiftUI
private let dextID = "org.tinygrad.tinygpu.driver2"
@main
struct TinyGPUApp: App {
private static var runner: TinyGPUCLIRunner? // prevent dealloc before callback
@State private var text = ""
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
init() {
guard CommandLine.arguments.count > 1 else { return }
Self.runner = TinyGPUCLIRunner(dextID)
Self.runner?.run(args: CommandLine.arguments) { exit($0.rawValue) }
dispatchMain()
}
var body: some Scene {
WindowGroup("TinyGPU") {
ScrollView {
Text(text).font(.custom("Menlo", size: 11)).frame(maxWidth: .infinity, alignment: .leading).padding(8)
}
.frame(width: 500, height: 300).padding()
.onAppear { setup() }
}
.commands { CommandGroup(replacing: .newItem) {} }
}
func setup() {
let bundlePath = Bundle.main.bundlePath
guard bundlePath.hasPrefix("/Applications/") else {
var error: NSDictionary?
NSAppleScript(source: "do shell script \"mv '\(bundlePath)' '/Applications/'\" with administrator privileges")?.executeAndReturnError(&error)
text = error == nil ? "Moved! Please reopen from /Applications/\n" : "Move TinyGPU to /Applications first.\n"
return
}
let state = TinyGPUCLIRunner.queryDextState(dextID)
if state == .unloaded || state == .activating {
Self.runner = TinyGPUCLIRunner(dextID)
Self.runner?.run(args: ["", "install"]) { _ in }
}
text = "TinyGPU - Remote PCI Device Server\n\n" + TinyGPUCLIRunner.statusText(state)
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
}

View File

@@ -0,0 +1,122 @@
import Foundation
import SystemExtensions
enum TinyGPUCLIExit: Int32 { case ok = 0, usage = 2, failed = 3, needsApproval = 4 }
enum DextState { case unloaded, activating, needsApproval, activated }
final class TinyGPUCLIRunner: NSObject, OSSystemExtensionRequestDelegate {
private let dextID: String
private var done: ((TinyGPUCLIExit) -> Void)?
private var isInstall = true
init(_ dextID: String) { self.dextID = dextID }
static func queryDextState(_ bundleID: String) -> DextState {
let p = Process()
p.executableURL = URL(fileURLWithPath: "/usr/bin/systemextensionsctl")
p.arguments = ["list"]
let pipe = Pipe()
p.standardOutput = pipe
p.standardError = Pipe()
guard (try? p.run()) != nil else { return .unloaded }
p.waitUntilExit()
guard let output = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8),
let line = output.split(separator: "\n").first(where: { $0.contains(bundleID) }) else { return .unloaded }
if line.contains("[activated enabled]") { return .activated }
if line.contains("[activated waiting for user]") { return .needsApproval }
return line.contains("terminated waiting to uninstall") ? .unloaded : .activating
}
private static let approvalHelp = """
Please go to System Settings > Privacy & Security and allow the extension.
If previously disabled: System Settings > General > Login Items & Extensions > Driver Extensions > Toggle TinyGPU ON
"""
static func statusText(_ state: DextState) -> String {
switch state {
case .unloaded: return "Driver extension not installed.\n\n"
case .activating: return "Extension is activating...\n\n"
case .needsApproval: return "Extension awaiting approval.\n\n" + approvalHelp
case .activated: return "Extension is ready! Run tinygrad to use your eGPU.\n\n"
}
}
func run(args: [String], done: @escaping (TinyGPUCLIExit) -> Void) {
self.done = done
guard args.count > 1 else { return usage() }
switch args[1] {
case "status":
print(Self.statusText(Self.queryDextState(dextID)))
done(.ok)
case "install":
if Self.queryDextState(dextID) == .needsApproval { print(Self.statusText(.needsApproval)); return done(.needsApproval) }
print("Installing TinyGPU driver extension...\nYou may need to approve in System Settings.\n")
submitRequest(activate: true)
case "uninstall":
guard Self.queryDextState(dextID) != .unloaded else { print("Not installed.\n"); return done(.ok) }
print("Uninstalling TinyGPU driver extension...\n")
isInstall = false
submitRequest(activate: false)
case "server":
guard args.count > 2 else { print("Error: server requires socket path\n"); return usage() }
done(run_server(args[2]) == 0 ? .ok : .failed)
case "help", "-h", "--help":
usage(); done(.ok)
default:
print("Unknown command: \(args[1])\n"); usage()
}
}
private func usage() {
print("""
Usage: TinyGPU <command>
status Show extension status
install Install the driver extension
uninstall Remove the driver extension
server <path> Start server on Unix socket
""")
done?(.usage)
}
private func submitRequest(activate: Bool) {
let req = activate
? OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: dextID, queue: .main)
: OSSystemExtensionRequest.deactivationRequest(forExtensionWithIdentifier: dextID, queue: .main)
req.delegate = self
OSSystemExtensionManager.shared.submitRequest(req)
}
// MARK: - OSSystemExtensionRequestDelegate
func requestNeedsUserApproval(_ request: OSSystemExtensionRequest) {
print("\nUser approval required!\n\n\(Self.approvalHelp)After approval, connect the gpu and use it with tinygrad.\n")
done?(.needsApproval)
}
func request(_ request: OSSystemExtensionRequest, didFinishWithResult result: OSSystemExtensionRequest.Result) {
switch result {
case .completed: print("Driver extension \(isInstall ? "installed" : "uninstalled") successfully!\n")
case .willCompleteAfterReboot: print("Will complete after reboot.\n")
@unknown default: print("Completed: \(result)\n")
}
done?(.ok)
}
func request(_ request: OSSystemExtensionRequest, didFailWithError error: Error) {
print("\nError: \(error.localizedDescription)\n")
let code = (error as NSError).code
if code == 4 { print("Missing entitlements. Rebuild with proper signing.\n") }
else if code == 8 { print("Extension not found in app bundle.\n") }
else if code == 9 { print("Extension disabled by user.\n\n\(Self.approvalHelp)") }
done?(.failed)
}
func request(_ request: OSSystemExtensionRequest, actionForReplacingExtension existing: OSSystemExtensionProperties,
withExtension ext: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction {
print("Updating v\(existing.bundleShortVersion) -> v\(ext.bundleShortVersion)...\n")
return .replace
}
}

View File

@@ -0,0 +1,285 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <dispatch/dispatch.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOMessage.h>
#include <mach/mach.h>
// Protocol
enum {
CMD_PROBE = 0, // probe devices, returns count
CMD_MAP_BAR = 1, // map PCI BAR, returns size
CMD_MAP_SYSMEM_FD = 2, // alloc DMA memory, returns fd via SCM_RIGHTS
CMD_CFG_READ = 3, // read PCI config space
CMD_CFG_WRITE = 4, // write PCI config space
CMD_RESET = 5, // reset device
CMD_MMIO_READ = 6, // bulk read from BAR
CMD_MMIO_WRITE = 7, // bulk write to BAR
CMD_MAP_SYSMEM = 8, // map system memory
CMD_SYSMEM_READ = 9, // bulk read from system memory
CMD_SYSMEM_WRITE = 10, // bulk write to system memory
CMD_RESIZE_BAR = 11, // resize bar (noop)
RESP_OK = 0, RESP_ERR = 1,
};
typedef struct { uint8_t cmd; uint32_t dev_id, bar; uint64_t arg0, arg1, arg2; } __attribute__((packed)) request_t;
typedef struct { uint8_t status; uint64_t resp0, resp1; } __attribute__((packed)) response_t;
// Constants and state
#define BULK_BUF_SIZE (64 << 20)
#define MAX_BARS 6
#define MAX_SYSMEM 128
static uint8_t g_bulk_buf[BULK_BUF_SIZE];
static io_connect_t g_conn = IO_OBJECT_NULL;
static int g_client_active = 0;
static struct { mach_vm_address_t addr; mach_vm_size_t size; } g_bars[MAX_BARS];
static struct { mach_vm_address_t addr; mach_vm_size_t size; int shm_fd; char shm_name[32]; } g_sysmem[MAX_SYSMEM];
static int g_sysmem_count = 0;
// Utilities
static void recvall(int fd, void *buf, size_t len) {
for (size_t off = 0; off < len; ) {
ssize_t r = recv(fd, (uint8_t*)buf + off, len - off, 0);
if (r <= 0) break;
off += r;
}
}
// MMIO requires 32-bit aligned volatile accesses
static void mmio_copy(void *dst, void *src, size_t len) {
volatile uint32_t *d = dst, *s = src;
for (size_t i = 0; i < len / 4; i++) d[i] = s[i];
for (size_t i = len & ~3; i < len; i++) ((volatile uint8_t*)dst)[i] = ((volatile uint8_t*)src)[i];
}
static int send_response(int fd, response_t *resp, int send_fd) {
char cmsgbuf[CMSG_SPACE(sizeof(int))];
struct iovec iov = {resp, sizeof(*resp)};
struct msghdr msg = {.msg_iov = &iov, .msg_iovlen = 1};
if (send_fd >= 0) {
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
*cmsg = (struct cmsghdr){.cmsg_level = SOL_SOCKET, .cmsg_type = SCM_RIGHTS, .cmsg_len = CMSG_LEN(sizeof(int))};
memcpy(CMSG_DATA(cmsg), &send_fd, sizeof(int));
}
return sendmsg(fd, &msg, 0) > 0 ? 0 : -1;
}
static void send_error(int fd, const char *msg) {
response_t resp = {.status = RESP_ERR, .resp0 = strlen(msg)};
send_response(fd, &resp, -1);
send(fd, msg, strlen(msg), 0);
}
// Driver interface
static void on_disconnect(void *refcon, io_service_t svc, uint32_t msg, void *arg) {
if (msg == kIOMessageServiceIsTerminated) _exit(0);
}
static io_connect_t open_tinygpu(void) {
static io_object_t notif;
io_service_t svc = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceNameMatching("tinygpu"));
if (!svc) return IO_OBJECT_NULL;
if (!notif) {
IONotificationPortRef port = IONotificationPortCreate(kIOMainPortDefault);
IONotificationPortSetDispatchQueue(port, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
IOServiceAddInterestNotification(port, svc, kIOGeneralInterest, on_disconnect, NULL, &notif);
}
io_connect_t conn;
kern_return_t kr = IOServiceOpen(svc, mach_task_self(), 0, &conn);
IOObjectRelease(svc);
return kr == KERN_SUCCESS ? conn : IO_OBJECT_NULL;
}
static int dext_rpc(uint32_t sel, uint64_t *in, uint32_t in_cnt, uint64_t *out_val) {
uint64_t out[2];
uint32_t out_cnt = 2;
if (IOConnectCallMethod(g_conn, sel, in, in_cnt, NULL, 0, out, &out_cnt, NULL, NULL) != KERN_SUCCESS) return -1;
if (out_val) *out_val = out[0];
return 0;
}
static int map_bar(uint32_t bar, response_t *resp) {
if (bar >= MAX_BARS) return -1;
if (!g_bars[bar].addr && IOConnectMapMemory64(g_conn, bar, mach_task_self(), &g_bars[bar].addr, &g_bars[bar].size, kIOMapAnywhere)) return -1;
resp->resp0 = g_bars[bar].addr;
resp->resp1 = g_bars[bar].size;
return 0;
}
static int map_sysmem_fd(uint64_t size, int contiguous, response_t *resp, int *out_fd) {
if (g_sysmem_count >= MAX_SYSMEM) return -1;
int idx = g_sysmem_count;
int fd = -1;
void *ptr = MAP_FAILED;
char shm_name[32];
// page-align, min 16KB for IOMemoryDescriptor
size_t alloc_sz = (size + 0xfff) & ~0xfff;
if (alloc_sz < 0x4000) alloc_sz = 0x4000;
snprintf(shm_name, sizeof(shm_name), "/tinygpu_%d", idx);
shm_unlink(shm_name);
if ((fd = shm_open(shm_name, O_CREAT | O_RDWR, 0600)) < 0) goto fail;
if (ftruncate(fd, alloc_sz) < 0) goto fail;
if ((ptr = mmap(NULL, alloc_sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) goto fail;
// PrepareDMA writes physical addresses to output buffer, copy to shared mem
uint8_t paddr_buf[8192] = {0};
size_t out_sz = sizeof(paddr_buf);
if (IOConnectCallStructMethod(g_conn, 3, ptr, alloc_sz, paddr_buf, &out_sz) != KERN_SUCCESS) goto fail;
memcpy(ptr, paddr_buf, out_sz);
g_sysmem[idx] = (typeof(g_sysmem[idx])){.addr = (mach_vm_address_t)ptr, .size = alloc_sz, .shm_fd = fd};
strncpy(g_sysmem[idx].shm_name, shm_name, sizeof(g_sysmem[idx].shm_name));
g_sysmem_count++;
*resp = (response_t){.resp0 = alloc_sz, .resp1 = idx};
*out_fd = fd;
return 0;
fail:
if (ptr != MAP_FAILED) munmap(ptr, alloc_sz);
if (fd >= 0) close(fd);
shm_unlink(shm_name);
return -1;
}
static int validate_bar(uint8_t bar, uint64_t off, uint64_t sz) {
return (bar < MAX_BARS && g_bars[bar].addr && off + sz <= g_bars[bar].size && sz <= BULK_BUF_SIZE) ? 0 : -1;
}
static void cleanup(void) {
for (int i = 0; i < MAX_BARS; i++)
if (g_bars[i].addr) { IOConnectUnmapMemory64(g_conn, i, mach_task_self(), g_bars[i].addr); g_bars[i].addr = 0; }
for (int i = 0; i < g_sysmem_count; i++) {
munmap((void*)g_sysmem[i].addr, g_sysmem[i].size);
close(g_sysmem[i].shm_fd);
shm_unlink(g_sysmem[i].shm_name);
}
g_sysmem_count = 0;
if (g_conn != IO_OBJECT_NULL) { IOServiceClose(g_conn); g_conn = IO_OBJECT_NULL; }
}
static void handle_client(int fd) {
int bufsize = BULK_BUF_SIZE;
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize));
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
printf("client connected\n");
g_conn = open_tinygpu();
if (g_conn == IO_OBJECT_NULL) {
fprintf(stderr, "failed to connect to tinygpu driver\n");
request_t req; recv(fd, &req, sizeof(req), 0);
send_error(fd, "Driver not available. Check: System Report > PCI for GPU, System Settings > Privacy & Security.");
return;
}
request_t req;
response_t resp;
while (recv(fd, &req, sizeof(req), 0) == sizeof(req)) {
resp = (response_t){0};
switch (req.cmd) {
case CMD_MAP_BAR:
resp.status = map_bar(req.bar, &resp) ? 1 : 0;
break;
case CMD_MAP_SYSMEM_FD: {
int shm_fd = -1;
resp.status = map_sysmem_fd(req.arg0, (int)req.arg1, &resp, &shm_fd) ? 1 : 0;
send_response(fd, &resp, shm_fd);
continue;
}
case CMD_CFG_READ: {
uint64_t in[2] = {req.arg0, req.arg1};
resp.status = dext_rpc(0, in, 2, &resp.resp0) ? 1 : 0;
break;
}
case CMD_CFG_WRITE: {
uint64_t in[3] = {req.arg0, req.arg1, req.arg2};
resp.status = dext_rpc(1, in, 3, NULL) ? 1 : 0;
break;
}
case CMD_RESIZE_BAR:
break;
case CMD_RESET:
resp.status = dext_rpc(2, NULL, 0, NULL) ? 1 : 0;
break;
case CMD_MMIO_READ:
if (validate_bar(req.bar, req.arg0, req.arg1)) { resp.status = 1; break; }
mmio_copy(g_bulk_buf, (void*)(g_bars[req.bar].addr + req.arg0), req.arg1);
resp.resp0 = req.arg1;
send_response(fd, &resp, -1);
send(fd, g_bulk_buf, req.arg1, 0);
continue;
case CMD_MMIO_WRITE:
recvall(fd, g_bulk_buf, req.arg1);
if (!validate_bar(req.bar, req.arg0, req.arg1))
mmio_copy((void*)(g_bars[req.bar].addr + req.arg0), g_bulk_buf, req.arg1);
continue;
default:
resp.status = 1;
}
send_response(fd, &resp, -1);
}
printf("client disconnected\n");
cleanup();
}
int run_server(const char *sock_path) {
int server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (server_fd < 0) { perror("socket"); return 1; }
struct sockaddr_un addr = {.sun_family = AF_UNIX};
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
unlink(sock_path);
if (bind(server_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { perror("bind"); close(server_fd); return 1; }
if (listen(server_fd, 1) < 0) { perror("listen"); close(server_fd); return 1; }
printf("listening on %s\n", sock_path);
while (1) {
int client_fd = accept(server_fd, NULL, NULL);
if (client_fd < 0) { if (errno == EINTR) continue; perror("accept"); break; }
if (g_client_active) { printf("rejected: client already connected\n"); close(client_fd); continue; }
g_client_active = 1;
handle_client(client_fd);
g_client_active = 0;
close(client_fd);
}
close(server_fd);
unlink(sock_path);
cleanup();
return 0;
}

View File

@@ -0,0 +1,18 @@
<svg viewBox="0 0 130 50" xmlns="http://www.w3.org/2000/svg">
<!-- t -->
<rect x="10" y="0" width="10" height="40" fill="#000000"></rect>
<rect x="0" y="10" width="30" height="10" fill="#000000"></rect>
<rect x="10" y="30" width="20" height="10" fill="#000000"></rect>
<!-- i -->
<rect x="40" y="0" width="10" height="10" fill="#000000"></rect>
<rect x="40" y="20" width="10" height="20" fill="#000000"></rect>
<!-- n -->
<rect x="60" y="10" width="10" height="30" fill="#000000"></rect>
<rect x="60" y="10" width="20" height="10" fill="#000000"></rect>
<rect x="80" y="20" width="10" height="20" fill="#000000"></rect>
<!-- y -->
<rect x="100" y="10" width="10" height="20" fill="#000000"></rect>
<rect x="100" y="20" width="30" height="10" fill="#000000"></rect>
<rect x="120" y="10" width="10" height="30" fill="#000000"></rect>
<rect x="100" y="40" width="20" height="10" fill="#000000"></rect>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -0,0 +1,52 @@
{
"fill" : "automatic",
"groups" : [
{
"layers" : [
{
"fill-specializations" : [
{
"value" : "automatic"
},
{
"appearance" : "dark",
"value" : {
"solid" : "display-p3:0.94011,0.96611,0.94301,1.00000"
}
},
{
"appearance" : "tinted",
"value" : {
"solid" : "display-p3:0.79528,0.79528,0.79528,1.00000"
}
}
],
"hidden" : false,
"image-name" : "tiny.svg",
"name" : "tiny_svg",
"position" : {
"scale" : 5,
"translation-in-points" : [
0,
19
]
}
}
],
"shadow" : {
"kind" : "neutral",
"opacity" : 0.5
},
"translucency" : {
"enabled" : true,
"value" : 0.5
}
}
],
"supported-platforms" : {
"circles" : [
"watchOS"
],
"squares" : "shared"
}
}