fix example ane
MODIFY
ane/2_compile/min_uint8.weights
ane/2_compile/min_uint8.weights
Binary files a/ane/2_compile/min_uint8.weights and b/ane/2_compile/min_uint8.weights differ

MODIFY
ane/2_compile/simple/convuint8.plist
ane/2_compile/simple/convuint8.plist
<key>Name</key>
<string>my_layer</string>
<key>OutputChannels</key>
- <integer>1</integer>
+ <integer>3</integer>
<key>OutputType</key>
<string>UInt8</string>

MODIFY
ane/3_run/test.mm
ane/3_run/test.mm
@@ -76,13 +76,10 @@ int main() {
ret = dev->ANE_ProgramPrepare(&pas);
printf("program prepare: %lx\n", ret);
- H11ANEProgramRequestArgsStruct *pras = new H11ANEProgramRequestArgsStruct;
- memset(pras, 0, sizeof(H11ANEProgramRequestArgsStruct));
-
// input buffer
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:16], kIOSurfaceWidth,
- [NSNumber numberWithInt:1], kIOSurfaceHeight,
+ [NSNumber numberWithInt:16], kIOSurfaceHeight,
[NSNumber numberWithInt:1], kIOSurfaceBytesPerElement,
[NSNumber numberWithInt:64], kIOSurfaceBytesPerRow,
[NSNumber numberWithInt:1278226536], kIOSurfacePixelFormat,
@@ -102,9 +99,9 @@ int main() {
// output buffer
NSDictionary* odict = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:1], kIOSurfaceWidth,
- [NSNumber numberWithInt:2], kIOSurfaceHeight,
- [NSNumber numberWithInt:2], kIOSurfaceBytesPerElement,
+ [NSNumber numberWithInt:16], kIOSurfaceWidth,
+ [NSNumber numberWithInt:16], kIOSurfaceHeight,
+ [NSNumber numberWithInt:1], kIOSurfaceBytesPerElement,
[NSNumber numberWithInt:64], kIOSurfaceBytesPerRow,
[NSNumber numberWithInt:1278226536], kIOSurfacePixelFormat,
nil];
@@ -112,8 +109,11 @@ int main() {
int out_surf_id = IOSurfaceGetID(out_surf);
printf("we have surface %p with id 0x%x\n", out_surf, out_surf_id);
+ H11ANEProgramRequestArgsStruct *pras = new H11ANEProgramRequestArgsStruct;
+ memset(pras, 0, sizeof(H11ANEProgramRequestArgsStruct));
+
// TODO: make real struct
- pras->args[0] = out->program_handle;
+ pras->args[0] = program_handle;
pras->args[4] = 0x0000002100000003;
// inputs

ADD
ane/lib/ane.mm
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#import <IOSurface/IOSurfaceRef.h>
+
+#import <Foundation/Foundation.h>
+#import <CoreFoundation/CoreFoundation.h>
+
+#include "h11ane.h"
+using namespace H11ANE;
+
+extern "C" {
+
+// global vars
+H11ANEDevice *dev;
+
+int ANE_Open() {
+ H11ANEDeviceController dc(MyH11ANEDeviceControllerNotification, NULL);
+ dc.SetupDeviceController();
+ assert(device != NULL);
+ H11ANEDevice *dev = device;
+ dev->EnableDeviceMessages();
+
+ char empty[0x90] = {0};
+ H11ANEDeviceInfoStruct dis = {0};
+ ret = dev->H11ANEDeviceOpen(MyH11ANEDeviceMessageNotification, empty, UsageCompile, &dis);
+ printf("open 0x%x %p\n", ret, dev);
+
+ ret = dev->ANE_PowerOn();
+ printf("power on: %d\n", ret);
+
+ ret = dev->ANE_IsPowered();
+ printf("powered? %d\n", ret);
+}
+
+int stride_for_width(int width) {
+ int ret = width*2;
+ ret += (64-ret) % 64;
+ return ret;
+}
+
+int ANE_CreateTensor(int width, int height) {
+ // all float16
+ // input buffer
+
+ NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:width], kIOSurfaceWidth,
+ [NSNumber numberWithInt:height], kIOSurfaceHeight,
+ [NSNumber numberWithInt:2], kIOSurfaceBytesPerElement,
+ [NSNumber numberWithInt:stride_for_width(width)], kIOSurfaceBytesPerRow,
+ [NSNumber numberWithInt:1278226536], kIOSurfacePixelFormat,
+ nil];
+ IOSurfaceRef in_surf = IOSurfaceCreate((CFDictionaryRef)dict);
+ int in_surf_id = IOSurfaceGetID(in_surf);
+ printf("we have surface %p with id 0x%x\n", in_surf, in_surf_id);
+
+ return in_surf_id;
+}
+
+uint64_t ANE_Compile(char *prog, int sz) {
+ H11ANEProgramCreateArgsStruct mprog = {0};
+ mprog.program = prog;
+ mprog.program_length = 0x8000;
+
+ H11ANEProgramCreateArgsStructOutput *out = new H11ANEProgramCreateArgsStructOutput;
+ memset(out, 0, sizeof(H11ANEProgramCreateArgsStructOutput));
+ ret = dev->ANE_ProgramCreate(&mprog, out);
+ uint64_t program_handle = out->program_handle;
+ delete out;
+ printf("program create: %lx %lx\n", ret, program_handle);
+
+ H11ANEProgramPrepareArgsStruct pas = {0};
+ pas.program_handle = program_handle;
+ pas.flags = 0x0000000100010001;
+ ret = dev->ANE_ProgramPrepare(&pas);
+ printf("program prepare: %lx\n", ret);
+
+ return program_handle;
+}
+
+void ANE_Run(uint64_t program_handle, int in_surf_id, int out_surf_id) {
+ H11ANEProgramRequestArgsStruct *pras = new H11ANEProgramRequestArgsStruct;
+ memset(pras, 0, sizeof(H11ANEProgramRequestArgsStruct));
+
+ // TODO: make real struct
+ pras->args[0] = out->program_handle;
+ pras->args[4] = 0x0000002100000003;
+
+ // inputs
+ pras->args[0x28/8] = 1;
+ pras->args[0x128/8] = (long long)in_surf_id<<32LL;
+
+ // outputs
+ pras->args[0x528/8] = 1;
+ // 0x628 = outputBufferSurfaceId
+ pras->args[0x628/8] = (long long)out_surf_id<<32LL;
+
+ mach_port_t recvPort = 0;
+ IOCreateReceivePort(kOSAsyncCompleteMessageID, &recvPort);
+ printf("recv port: 0x%x\n", recvPort);
+
+ // run program
+ ret = dev->ANE_ProgramSendRequest(pras, recvPort);
+ printf("send 0x%x\n", ret);
+
+ struct {
+ mach_msg_header_t header;
+ char data[256];
+ } message;
+
+ ret = mach_msg(&message.header,
+ MACH_RCV_MSG,
+ 0, sizeof(message),
+ recvPort,
+ MACH_MSG_TIMEOUT_NONE,
+ MACH_PORT_NULL);
+ printf("got message: %d sz %d\n", ret, message.header.msgh_size);
+}
+
+}
+

ADD
ane/lib/h11ane.h
+../3_run/h11ane.h
\ No newline at end of file

ADD
tinygrad/ops_ane.py
+if __name__ == "__main__":
+ pass
+

fix example ane