diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift b/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift index 8b3f1efc9d1df83c11f96a1d4b0795183d64a4d5..e4697135e96d9b7a34dd4bf84c81dccc8ea7fafd 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift +++ b/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift @@ -109,7 +109,7 @@ class ViewController: UIViewController { threadPickerView.delegate = self threadPickerView.dataSource = self - selectImage = UIImage.init(named: "hand.jpg") + selectImage = UIImage.init(named: "banana.jpeg") selectImageView.image = selectImage net.getTexture(image: selectImage!.cgImage!) {[weak self] (texture) in self?.toPredictTexture = texture diff --git a/metal/paddle-mobile/paddle-mobile/Executor.swift b/metal/paddle-mobile/paddle-mobile/Executor.swift index d28525b187e5c61bcf709defd338ba036b3ea111..1d7e5a452a91deb2e6cfccbbac2a6b5622bb25a2 100644 --- a/metal/paddle-mobile/paddle-mobile/Executor.swift +++ b/metal/paddle-mobile/paddle-mobile/Executor.swift @@ -119,7 +119,7 @@ public class Executor { // }) // print(inputArr.strideArray()) // -// writeToLibrary(fileName: "genet_input_hand", array: inputArr) +// writeToLibrary(fileName: "banana", array: inputArr) // print("write to library done") // return // print(inputArr) @@ -128,11 +128,13 @@ public class Executor { // print(stridableInput) // let _: Flo? = input.logDesc(header: "input: ", stridable: true) -// for i in 0..: OpParam { scale = try ConvAddBatchNormReluParam.inputScale(inputs: opDesc.paraInputs, from: inScope) mean = try ConvAddBatchNormReluParam.inputMean(inputs: opDesc.paraInputs, from: inScope) - y = try ConvAddBatchNormReluParam.inputY(inputs: opDesc.inputs, from: inScope) + y = try ConvAddBatchNormReluParam.inputY(inputs: opDesc.paraInputs, from: inScope) } catch let error { throw error } diff --git a/metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift index d15ec685a545c298cb1f25deab1cdf2122378fde..5e184844d886beb19ac5ff297f8a270af8a076fa 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift @@ -93,34 +93,24 @@ class ConvAddOp: Operator, ConvAddParam

>, } func delogOutput() { +// print("op \(type): ") +// print(" padding: ") +// print(para.paddings) +// print("stride: ") +// print(para.stride) +// print("dilations: ") +// print(para.dilations) +// print(" para input dim: ") +// print(para.input.dim) +// print(" para filter dim: ") +// print(para.filter.dim) +// print(" para output dim: ") +// print(para.output.dim) +// print(" biase: ") +// let biase: [Float32] = para.y.buffer.array() +// print(biase) - - print("op \(type): ") print(" \(type) output: ") - print(" padding: ") - print(para.paddings) - print("stride: ") - print(para.stride) - print("dilations: ") - print(para.dilations) - print(" para input dim: ") - print(para.input.dim) - print(" para filter dim: ") - print(para.filter.dim) - print(" para output dim: ") - print(para.output.dim) - print(" biase: ") - let biase: [Float32] = para.y.buffer.array() - print(biase) - - print(" - filter - ") - let array: [Float32] = para.filter.buffer.array() - print(array) - - print(" - y - ") - let yArray: [Float32] = para.y.buffer.array() - print(yArray) - print(para.output.metalTexture.toTensor(dim: (n: para.output.tensorDim[0], c: para.output.tensorDim[1], h: para.output.tensorDim[2], w: para.output.tensorDim[3])).strideArray()) } } diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift index 909ff47e819e8cc4d1c37d6e8499a86fd9a5b03c..66324dd47086fd7c1ccffb674c0f8b8623416e0d 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift @@ -81,8 +81,6 @@ class ConvAddBatchNormReluKernel: Kernel, Computable, Testable fatalError() } - - let offsetX = param.filter.width/2 - Int(param.paddings[0]) let offsetY = param.filter.height/2 - Int(param.paddings[1]) @@ -121,10 +119,10 @@ class ConvAddBatchNormReluKernel: Kernel, Computable, Testable var newBiaseBuffer: MTLBuffer var newScaleBuffer: MTLBuffer - if computePrecision == .Float16 { + if computePrecision == .Float32 { newBiaseBuffer = device.makeBuffer(bytes: newBiase, length: param.bias.buffer.length)! newScaleBuffer = device.makeBuffer(bytes: newScale, length: param.scale.buffer.length)! - } else if computePrecision == .Float32 { + } else if computePrecision == .Float16 { newBiaseBuffer = device.makeBuffer(length: param.bias.buffer.length / 2)! newScaleBuffer = device.makeBuffer(length: param.bias.buffer.length / 2)! @@ -151,7 +149,6 @@ class ConvAddBatchNormReluKernel: Kernel, Computable, Testable throw PaddleMobileError.predictError(message: " encode is nil") } - encoder.setTexture(param.input.metalTexture, index: 0) encoder.setTexture(param.output.metalTexture, index: 1) encoder.setBytes(&metalParam, length: MemoryLayout.size, index: 0) diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift index 6f6d0af477f62d7f438b8b6a38c825c2eb95163f..0c166c3563149d60dc8cbee451ef23e6a1fb9b93 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift @@ -21,6 +21,17 @@ struct SoftmaxMetalParam { class SoftmaxKernel: Kernel, Computable{ + required init(device: MTLDevice, param: SoftmaxParam

) { + param.output.initTexture(device: device, computePrecision: computePrecision) + if computePrecision == .Float32 { + super.init(device: device, inFunctionName: "softmax") + } else if computePrecision == .Float16 { + super.init(device: device, inFunctionName: "softmax_half") + } else { + fatalError() + } + } + func compute(commandBuffer: MTLCommandBuffer, param: SoftmaxParam

) throws { guard let encoder = commandBuffer.makeComputeCommandEncoder() else { throw PaddleMobileError.predictError(message: " encoder is nil") @@ -32,19 +43,12 @@ class SoftmaxKernel: Kernel, Computable{ N: Int32(param.input.tensorDim[0]), K: Int32(param.input.tensorDim[1]) ) + + print(" soft max param: ") + print(smp) encoder.setBytes(&smp, length: MemoryLayout.size, index: 0) encoder.dispatch(computePipline: pipline, outTexture: param.output.metalTexture) encoder.endEncoding() } - required init(device: MTLDevice, param: SoftmaxParam

) { - param.output.initTexture(device: device, computePrecision: computePrecision) - if computePrecision == .Float32 { - super.init(device: device, inFunctionName: "softmax") - } else if computePrecision == .Float16 { - super.init(device: device, inFunctionName: "softmax_half") - } else { - fatalError() - } - } } diff --git a/metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift index 71c7918d4e12733a6289017c020e5dea3ac4c76f..26a50f1533d0ad173ec21a8f131bccbf073e2895 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift @@ -52,7 +52,9 @@ class SoftmaxOp: Operator, SoftmaxParam

>, func delogOutput() { print("softmax delog") - + print(para.input) + + print(para.output) let originDim = para.output.originDim let outputArray: [Float32] = para.output.metalTexture.realNHWC(dim: (n: originDim[0], h: originDim[1], w: originDim[2], c: originDim[3])) print(outputArray.strideArray())