Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sources/MPSX/ONNX/Nodes/Equal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import MetalPerformanceShadersGraph

extension MPSGraph {
/// https://github.com/onnx/onnx/blob/main/docs/Operators.md#Equal
func equal(
_ node: Onnx_NodeProto,
_ tensors: [String: MPSGraphTensor]
) throws -> MPSGraphTensor {
guard let a = tensors(node.input(0)),
let b = tensors(node.input(1))
else { throw OnnxError.invalidInput(node.name) }

return equal(a, b, name: nil)
}
}
15 changes: 13 additions & 2 deletions Sources/MPSX/ONNX/Nodes/Onnx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extension MPSGraph {
output = try log(node, tensors)
case "Floor":
output = try floor(node, tensors)
case "Equal":
output = try equal(node, tensors)
case "Less":
output = try less(node, tensors)
case "Greater":
Expand Down Expand Up @@ -100,14 +102,23 @@ extension MPSGraph {
output = try dropout(node, tensors, constants)
case "DepthToSpace":
output = try depthToSpace(node, tensors)
case "Constant":
case "Constant",
"ConstantOfShape":
guard let value = node.attr("value") else {
throw OnnxError.invalidInput(node.name)
}

node.output.forEach {
constants[$0] = value.t
}
output = try constant(value.t, targetDataType: tensorsDataType)

let x = try constant(value.t, targetDataType: tensorsDataType)

if let shape = tensors(node.input(0)) {
output = reshape(x, shapeTensor: shape, name: nil)
} else {
output = x
}
case "Cast",
"Clip":
output = try passthrough(node, tensors)
Expand Down