working on gemm
MODIFY
ane/1_build/coreml_ane.py
ane/1_build/coreml_ane.py
@@ -3,23 +3,26 @@ import numpy as np
import coremltools as ct
from coremltools.models.neural_network import datatypes, NeuralNetworkBuilder
-input_features = [('image', datatypes.Array(3))]
-output_features = [('probs', datatypes.Array(3))]
+# KxK GEMM with bias
+K = 64
-weights = np.zeros((3, 3)) + 3
-bias = np.ones(3)
+input_features = [('image', datatypes.Array(K))]
+output_features = [('probs', datatypes.Array(K))]
+
+weights = np.zeros((K, K)) + 3
+bias = np.ones(K)
builder = NeuralNetworkBuilder(input_features, output_features)
-builder.add_inner_product(name='ip_layer', W=weights, b=None, input_channels=3, output_channels=3, has_bias=False, input_name='image', output_name='med')
+builder.add_inner_product(name='ip_layer', W=weights, b=None, input_channels=K, output_channels=K, has_bias=False, input_name='image', output_name='med')
#builder.add_inner_product(name='ip_layer_2', W=weights, b=None, input_channels=3, output_channels=3, has_bias=False, input_name='med', output_name='probs')
#builder.add_elementwise(name='element', input_names=['med', 'med'], output_name='probs', mode='ADD')
-builder.add_bias(name='bias', b=bias, input_name='med', output_name='probs', shape_bias=(3,))
+builder.add_bias(name='bias', b=bias, input_name='med', output_name='probs', shape_bias=(K,))
#builder.add_activation(name='act_layer', non_linearity='SIGMOID', input_name='med', output_name='probs')
# compile the spec
mlmodel = ct.models.MLModel(builder.spec)
# trigger the ANE!
-out = mlmodel.predict({"image": np.array([1337,0,0], dtype=np.float32)})
+out = mlmodel.predict({"image": np.zeros(K, dtype=np.float32)+1})
print(out)
mlmodel.save('test.mlmodel')

MODIFY
ane/1_build/test.mlmodel
ane/1_build/test.mlmodel
Binary files a/ane/1_build/test.mlmodel and b/ane/1_build/test.mlmodel differ

MODIFY
ane/2_compile/hwx_parse.py
ane/2_compile/hwx_parse.py
@@ -40,6 +40,7 @@ for k,v in syms.items():
print(k, hex(v))
+# **** document what we know ***
from ane import ANE_Struct
aneb = set()

ADD
ane/2_compile/plists/gemm.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>image</string>
+ </array>
+ <key>Outputs</key>
+ <array>
+ <string>probs@output</string>
+ </array>
+ <key>Units</key>
+ <array>
+ <string>probs_tmp_0</string>
+ <string>probs</string>
+ </array>
+ <key>Weights</key>
+ <array>
+ <string>/private/var/folders/l8/38vj8bm52_gfgsqgdn__sh2w0000gn/T/tmph2sg50xi.mlmodelc/model.espresso.weights</string>
+ <string>net.additional.weights</string>
+ </array>
+ <key>image</key>
+ <dict>
+ <key>BatchSize</key>
+ <integer>1</integer>
+ <key>InputChannels</key>
+ <integer>64</integer>
+ <key>InputHeight</key>
+ <integer>1</integer>
+ <key>InputInterleave</key>
+ <integer>1</integer>
+ <key>InputPlaneStride</key>
+ <integer>64</integer>
+ <key>InputRowStride</key>
+ <integer>64</integer>
+ <key>InputType</key>
+ <string>Float16</string>
+ <key>InputWidth</key>
+ <integer>1</integer>
+ </dict>
+ <key>probs</key>
+ <dict>
+ <key>Bottom</key>
+ <string>probs_tmp_0</string>
+ <key>Name</key>
+ <string>probs</string>
+ <key>OutputType</key>
+ <string>Float16</string>
+ <key>Params</key>
+ <dict>
+ <key>BiasScaleGroupData</key>
+ <dict>
+ <key>BiasCount</key>
+ <integer>64</integer>
+ <key>BiasIndex</key>
+ <integer>1</integer>
+ <key>BiasOffset</key>
+ <integer>0</integer>
+ <key>BiasType</key>
+ <string>Float16</string>
+ </dict>
+ </dict>
+ <key>Type</key>
+ <string>GOC</string>
+ <key>UnescapedBottom</key>
+ <string>probs_tmp_0</string>
+ <key>UnescapedName</key>
+ <string>probs</string>
+ </dict>
+ <key>probs@output</key>
+ <dict>
+ <key>Bottom</key>
+ <string>probs</string>
+ <key>OutputInterleave</key>
+ <integer>1</integer>
+ <key>OutputPlaneStride</key>
+ <integer>64</integer>
+ <key>OutputRowStride</key>
+ <integer>64</integer>
+ <key>OutputType</key>
+ <string>Float16</string>
+ </dict>
+ <key>probs_tmp_0</key>
+ <dict>
+ <key>Bottom</key>
+ <string>image</string>
+ <key>Name</key>
+ <string>probs_tmp_0</string>
+ <key>OutputChannels</key>
+ <integer>64</integer>
+ <key>OutputType</key>
+ <string>Float16</string>
+ <key>Params</key>
+ <dict>
+ <key>KernelGroupReuse</key>
+ <false/>
+ <key>KernelHeight</key>
+ <integer>1</integer>
+ <key>KernelIndex</key>
+ <integer>0</integer>
+ <key>KernelMode</key>
+ <string>Dense</string>
+ <key>KernelOffset</key>
+ <integer>384</integer>
+ <key>KernelType</key>
+ <string>Float32</string>
+ <key>KernelWidth</key>
+ <integer>1</integer>
+ <key>Step</key>
+ <array>
+ <integer>1</integer>
+ <integer>1</integer>
+ </array>
+ <key>Type</key>
+ <string>Conv</string>
+ </dict>
+ <key>Type</key>
+ <string>Conv</string>
+ <key>UnescapedBottom</key>
+ <string>image</string>
+ <key>UnescapedName</key>
+ <string>probs_tmp_0</string>
+ </dict>
+ </dict>
+</dict>
+</plist>

ADD
ane/2_compile/simple/gemm.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">
+<!-- dd if=/dev/zero of=/tmp/zero bs=1024 count=16384 -->
+<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>image</string>
+ </array>
+ <key>Outputs</key>
+ <array>
+ <string>probs@output</string>
+ </array>
+ <key>Units</key>
+ <array>
+ <string>probs</string>
+ </array>
+ <key>Weights</key>
+ <array>
+ <string>/tmp/zero</string>
+ </array>
+
+ <key>image</key>
+ <dict>
+ <key>InputChannels</key>
+ <integer>128</integer>
+ <key>InputHeight</key>
+ <integer>1</integer>
+ <key>InputWidth</key>
+ <integer>1</integer>
+ <key>InputType</key>
+ <string>Float16</string>
+ </dict>
+ <key>probs</key>
+ <dict>
+ <key>Bottom</key>
+ <string>image</string>
+ <key>Name</key>
+ <string>probs</string>
+ <key>OutputChannels</key>
+ <integer>128</integer>
+ <key>OutputType</key>
+ <string>Float16</string>
+ <key>Params</key>
+ <dict>
+ <key>KernelHeight</key>
+ <integer>1</integer>
+ <key>KernelWidth</key>
+ <integer>1</integer>
+ <key>KernelType</key>
+ <string>Float16</string>
+
+ <key>KernelMode</key>
+ <string>Dense</string>
+ <key>KernelOffset</key>
+ <integer>0</integer>
+
+ <key>Step</key>
+ <array>
+ <integer>1</integer>
+ <integer>1</integer>
+ </array>
+
+ <key>Type</key>
+ <string>Conv</string>
+ </dict>
+ <key>Type</key>
+ <string>Conv</string>
+ </dict>
+ <key>probs@output</key>
+ <dict>
+ <key>Bottom</key>
+ <string>probs</string>
+ <key>OutputType</key>
+ <string>Float16</string>
+ </dict>
+ </dict>
+</dict>
+</plist>

ADD
ane/ops/gemm.hwx
ane/ops/gemm.hwx
Binary files /dev/null and b/ane/ops/gemm.hwx differ

working on gemm