func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws {
- print("this is BatchNormOp")
}
}
diff --git a/metal/paddle-mobile/paddle-mobile/Operators/ConvOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/ConvOp.swift
index b4623bf567cbcb17c99b28e246d3bf0d242bc23b..aea34976fcc2e8d1518966055112ed1509598c82 100644
--- a/metal/paddle-mobile/paddle-mobile/Operators/ConvOp.swift
+++ b/metal/paddle-mobile/paddle-mobile/Operators/ConvOp.swift
@@ -64,6 +64,17 @@ class ConvOp >, Runable,
typealias OpType = ConvOp
func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws {
- print("this is conv")
+ do {
+ try kernel.compute(commandBuffer: buffer, param: para)
+ } catch let error {
+ throw error
+ }
+
+ }
+
+ func delogOutput() {
+ print("conv output : ")
+ print(para.output.metalTexture)
+// let _: Float16? = para.output.metalTexture.logDesc()
}
}
diff --git a/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift
index 12c0b832b76b0975d4b5a138c283866166e06130..18aed606f9be9d2e03d1927ffdae8c4144e5bc51 100644
--- a/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift
+++ b/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift
@@ -40,7 +40,6 @@ class ElementwiseAddOp
func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws {
- print("this is ElementwiseAddOp")
}
}
diff --git a/metal/paddle-mobile/paddle-mobile/Operators/FeedOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/FeedOp.swift
index 87b71a7a95d316cd226e4e648506fbe011d5e4c8..eea42425423f391771338213a7d34ca3a42decbe 100644
--- a/metal/paddle-mobile/paddle-mobile/Operators/FeedOp.swift
+++ b/metal/paddle-mobile/paddle-mobile/Operators/FeedOp.swift
@@ -33,26 +33,37 @@ struct FeedParam >, Runable, Creator, InferShaperable {
+class FeedOp >, Runable, Creator, InferShaperable {
typealias OpType = FeedOp
func inferShape() {
-// print("feed input: \(para.input.expectDim)")
+ // print("feed input: \(para.input.expectDim)")
print("feed output: \(para.output.dim)")
// para.output.dim =
-// para.output.dim = para.input.expectDim
+ // para.output.dim = para.input.expectDim
}
func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws {
- let resizeKernel = ResizeKernel .init(device: device)
- let resizeParam = ResizeParam.init(input: para.input.mtlTexture, output: para.output.metalTexture, expectDim: para.input.expectDim)
+ let locPara = Texture2DTo2DArrayParam.init(input: para.input.mtlTexture, output: para.output.metalTexture, expectDim: para.input.expectDim)
do {
- print("feed op to compute ")
- try resizeKernel.compute(commandBuffer: buffer, param: resizeParam)
- print("feed op end compute ")
+ try kernel.compute(commandBuffer: buffer, param: locPara)
} catch let error {
throw error
}
+
+// let resizeKernel = ResizeKernel .init(device: device)
+// let resizeParam = ResizeParam.init(input: para.input.mtlTexture, output: para.output.metalTexture, expectDim: para.input.expectDim)
+// do {
+// try resizeKernel.compute(commandBuffer: buffer, param: resizeParam)
+// } catch let error {
+// throw error
+// }
+ }
+
+ func delogOutput() {
+// para.input.mtlTexture.logDesc()
+ let _: Float16? = para.input.mtlTexture.logDesc(header: "feed input: ")
+ let _: Float16? = para.output.metalTexture.logDesc(header: "feed output: ")
}
}
diff --git a/metal/paddle-mobile/paddle-mobile/Operators/FetchOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/FetchOp.swift
index b79538fe7770dd818eb7399547d2621249938c89..a671c0fa45f9f7d4a31b31e8caa816900292da71 100644
--- a/metal/paddle-mobile/paddle-mobile/Operators/FetchOp.swift
+++ b/metal/paddle-mobile/paddle-mobile/Operators/FetchOp.swift
@@ -32,13 +32,11 @@ struct FetchParam >, Runable, Creator, InferShaperable{
func inferShape() {
-
print(para.input.dim)
}
typealias OpType = FetchOp
func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws {
- print("fetch op")
}
}
diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvKernel.swift b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvKernel.swift
index 0cdab6f6b967214a0d9e8a11ae8768b252ead38e..e153233d0becb40354bfa63aee1049b0c5b8182e 100644
--- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvKernel.swift
+++ b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvKernel.swift
@@ -11,10 +11,18 @@ import Foundation
class ConvKernel ) throws {
-
+ guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
+ throw PaddleMobileError.predictError(message: " encode is nil")
+ }
+ encoder.setTexture(param.input.metalTexture, index: 0)
+ encoder.setTexture(param.output.metalTexture, index: 1)
+ encoder.dispatch(computePipline: pipline, outTexture: param.output.metalTexture)
+ encoder.endEncoding()
}
required init(device: MTLDevice) {
super.init(device: device, inFunctionName: "conv")
}
+
+
}
diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
index 0d872196c9d19497fa37a35dc9b294843624ca56..56d9ca78ce93ac3f5159b7d415db72c42d8f751c 100644
--- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
+++ b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
@@ -36,7 +36,6 @@ kernel void resize(texture2d .size == 1 {
- tmpTextureDes.pixelFormat = .r8Sint
+ tmpTextureDes.pixelFormat = .rgba8Unorm
} else if MemoryLayout .size == 2 {
- tmpTextureDes.pixelFormat = .r16Float
+ tmpTextureDes.pixelFormat = .rgba16Float
} else if MemoryLayout .size == 4 {
- tmpTextureDes.pixelFormat = .r32Float
+// tmpTextureDes.pixelFormat = .r32Float
+ tmpTextureDes.pixelFormat = .rgba32Float
+
}
- tmpTextureDes.usage = .unknown
+ tmpTextureDes.usage = [.shaderRead, .shaderWrite]
tmpTextureDes.storageMode = .shared
textureDesc = tmpTextureDes
metalTexture = device.makeTexture(descriptor: tmpTextureDes) ?! " texture nil "
@@ -123,6 +125,7 @@ extension Texture {
public var debugDescription: String{
var str = ""
str += "Dim: \(dim) \n value:[ "
+// str += "\(metalTexture)"
str += " ]"
return str
}