From bc5df477de2052ec8a463fabcd189e3d1db07c0b Mon Sep 17 00:00:00 2001 From: George Hotz Date: Sat, 12 Dec 2020 16:15:38 -0800 Subject: [PATCH] readme and .ane() --- README.md | 12 +++++++++++- examples/use_ane.py | 2 +- tinygrad/tensor.py | 6 ++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5d61102c54..59604a96bf 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,17 @@ from tinygrad.tensor import Tensor ### ANE Support?!?! -So it doesn't work yet, but see the `ane` directory for code to use the Apple Neural Engine at a low level. +If you all want to do is ReLU, you are in luck! You can do very fast ReLU (fastness not confirmed) + +Requires your Python to be signed with `ane/lib/sign_python.sh` to add the `com.apple.ane.iokit-user-access` entitlement. + +```python +from tinygrad.tensor import Tensor + +a = Tensor([-2,-1,0,1,2]).ane() +b = a.relu() +print(b.cpu()) +``` ### ImageNet inference diff --git a/examples/use_ane.py b/examples/use_ane.py index 9165a65800..c80d20fd1b 100755 --- a/examples/use_ane.py +++ b/examples/use_ane.py @@ -2,7 +2,7 @@ import numpy as np from tinygrad.tensor import Tensor -a = Tensor([-2,-1,0,1,2]).ane_() +a = Tensor([-2,-1,0,1,2]).ane() print(a.cpu()) b = a.relu() print(b.cpu()) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 6e0adde781..60da203960 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -200,14 +200,12 @@ class Tensor: else: return self - def ane_(self): + def ane(self): assert(not self.gpu) require_init_ane() - self.device = Tensor.ANE ndata = ane.tensor(self.shape) ndata.data()[:] = self.data - self.data = ndata - return self + return Tensor(ndata) def detach(self): return Tensor(self.data, self.gpu)