今年夏天我打算在我的机器学习工作中再迈出一步,我想了解 Metal API 以及如何编写用于计算的内核。
然而,第一步(除了 metal api 的“hello worlds”)是将 Numpy 包装到我可以在 metal 中实现的 API 中。
这个想法有意义吗?
src/math/matlib.py
import platform
_impl = None
o_system = platform.platform()
if o_system == 'Darwin':
import impls.metal_math as metal
_impl = metal
elif o_system == 'Linux':
import numpy as np
_impl = np
elif o_system == 'Windows':
import numpy as np
_impl = np
else:
import numpy as np
_impl = np
def array(x):
"""docs to be written"""
return _impl.array(x)
def square(x, y):
"""docs to be written"""
return _impl.square(x, y)
def T(x):
"""docs to be written"""
return array(x).T
def dot(x, y):
"""docs to be written"""
return _impl.dot(x, y)
def add(x, y):
"""docs to be written"""
return _impl.add(x, y)
src/math/impls/metal.py(还没写,待理解学习)
def array(x):
return 'MY NATIVE METAL ARRAY WRAPPER'
... all other functions.