ane docs continue
ADD
ane/2_compile/ane.py
+../lib/ane.py
\ No newline at end of file

MODIFY
ane/2_compile/hwx_parse.py
ane/2_compile/hwx_parse.py
@@ -40,6 +40,17 @@ for k,v in syms.items():
print(k, hex(v))
+from ane import ANE_Struct
+
+aneb = set()
+for typ, num, nam in ANE_Struct:
+ ltyp = {"u32": 4, "u16": 2, "u8": 1}[typ]
+ for l in range(num, num+ltyp):
+ aneb.add(l)
+
+# we understand these too
+for l in range(0x34, 0xF4):
+ aneb.add(l)
from termcolor import colored
def compare(x, y):
@@ -79,6 +90,10 @@ def compare(x, y):
if highlight:
ln.append(colored(a[0], 'yellow'))
ln2.append(colored(a[1], 'yellow'))
+ else:
+ if i in aneb:
+ ln.append(colored(a[0], 'white'))
+ ln2.append(colored(a[1], 'white'))
else:
ln.append(a[0])
ln2.append(a[1])

ADD
ane/2_compile/simple/concat.plist
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Networks</key>
+ <array>
+ <string>net</string>
+ </array>
+ <key>Version</key>
+ <string>1.0.9</string>
+ <key>net</key>
+ <dict>
+ <key>Inputs</key>
+ <array>
+ <string>input_1</string>
+ <string>input_0</string>
+ </array>
+ <key>Outputs</key>
+ <array>
+ <string>output@output</string>
+ </array>
+ <key>Units</key>
+ <array>
+ <string>output</string>
+ </array>
+ <key>Weights</key>
+ <array>
+ <string>/private/var/folders/l8/38vj8bm52_gfgsqgdn__sh2w0000gn/T/tmp0yvkl2ux.mlmodelc/model.espresso.weights</string>
+ <string>net.additional.weights</string>
+ </array>
+ <key>input_0</key>
+ <dict>
+ <key>InputChannels</key>
+ <integer>1</integer>
+ <key>InputHeight</key>
+ <integer>1</integer>
+ <key>InputWidth</key>
+ <integer>77</integer>
+
+ <key>InputType</key>
+ <string>Float16</string>
+ </dict>
+ <key>input_1</key>
+ <dict>
+ <key>InputChannels</key>
+ <integer>1</integer>
+ <key>InputHeight</key>
+ <integer>1</integer>
+ <key>InputWidth</key>
+ <integer>77</integer>
+
+ <key>InputType</key>
+ <string>Float16</string>
+ </dict>
+ <key>output</key>
+ <dict>
+ <key>Bottom</key>
+ <array>
+ <string>input_0</string>
+ <string>input_1</string>
+ </array>
+ <key>Name</key>
+ <string>output</string>
+ <key>OutputType</key>
+ <string>Float16</string>
+ <key>Type</key>
+ <string>Concat</string>
+ </dict>
+ <key>output@output</key>
+ <dict>
+ <key>Bottom</key>
+ <string>output</string>
+ <key>OutputType</key>
+ <string>Float16</string>
+ </dict>
+ </dict>
+</dict>
+</plist>

MODIFY
ane/2_compile/simple/neuron.plist
ane/2_compile/simple/neuron.plist
<key>InputHeight</key>
<integer>1</integer>
<key>InputWidth</key>
- <integer>200</integer>
+ <integer>77</integer>
<key>InputType</key>
<string>Float16</string>

MODIFY
ane/lib/ane.py
ane/lib/ane.py
@@ -6,6 +6,9 @@ import faulthandler
import struct
faulthandler.enable()
+libane = None
+def init_libane():
+ global libane
libane = cdll.LoadLibrary(os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"libane.dylib"))
@@ -23,6 +26,10 @@ libane.ANE_Run.restype = c_int
ANE_Struct = [
# section @ 0x2C len 0xF4
+ # reloc 0x2c-0x34?? = weights
+ # u32[16] 0x34-0x74 = 0x80 | 1 if used
+ # u32[16] 0x74-0xB4 = <channel data offset>
+ # u32[16] 0xB4-0xF4 = <channel data length>
# section @ 0x128 len 0x3C (conv)
("u16", 0x128, "InputWidth"),
@@ -53,20 +60,25 @@ ANE_Struct = [
("u8", 0x1A7, "InputInterleave"),
# section @ 0x1E0 len 0x44
+ # [0x1ec, 0x1f0, 0x1f4, 0x1f8, 0x214] = number of engines
# section @ 0x22c len 0xC (scaling)
("u16", 0x230, "BiasScalar"),
("u16", 0x232, "ScaleScalar"),
# section @ 0x240 len 0x10
+ ("u16", 0x246, "NeuronType"), # 0x10 = copy, 0x11 = ReLU, 0x12 = custom
# section @ 0x258 len 0x18
+ ("u32", 0x25C, "OutputOffset"), # offset into output buffer to write at
+
("u32", 0x260, "OutputRowStride"),
("u32", 0x264, "OutputPlaneStride"),
("u32", 0x268, "OutputDepthStride"),
("u32", 0x26C, "OutputBatchStride"),
- ("u8", 0x273, "OutputInterleave")]
+ ("u8", 0x273, "OutputInterleave"), # i also have this at 0x211?
+]
ANE_Struct_Dict = {}
for typ, num, nam in ANE_Struct:
@@ -93,6 +105,7 @@ class ANETensor:
class ANE:
def __init__(self):
+ init_libane()
libane.ANE_Open()
def compile(self, dat):

MODIFY
tinygrad/ops_ane.py
tinygrad/ops_ane.py
@@ -13,9 +13,10 @@ def compile_relu(ane, sz):
dat = list(open("ane/ops/relu.hwx", "rb").read())
# TODO: make this all nice and once
# number of engines? (max 0x100)
- dat = ane.fill(dat, [0x1ec, 0x1f0, 0x1f4, 0x1f8], "I", max(0x100, roundup(sz*2, 0x10)))
+ dat = ane.fill(dat, [0x1ec, 0x1f0, 0x1f4, 0x1f8, 0x214], "I", max(0x100, roundup(sz*2, 0x10)))
stride = roundup(sz*2, 0x40)
dat = ane.filln(dat, {
+ "NeuronType": 0x11, # 0x10 makes this a copy, 0x11 = ReLU, 0x12 = crash
"InputWidth": sz, "OutputWidth": sz,
"InputRowStride": stride, "InputPlaneStride": stride, "InputDepthStride": stride,
"OutputRowStride": stride, "OutputPlaneStride": stride, "OutputDepthStride": stride})

ane docs continue