From 1bfba112536650e33d0fd8a7ac8a8f4555a2b459 Mon Sep 17 00:00:00 2001 From: dolphin8 Date: Wed, 29 Aug 2018 19:49:17 +0800 Subject: [PATCH] elementwise_add --- .../paddle-mobile/paddle-mobile/Executor.swift | 2 +- .../paddle-mobile/Operators/ConcatOp.swift | 1 + .../Operators/ElementwiseAddOp.swift | 17 +++++++++++++++++ .../Kernels/ElementwiseAddKernel.swift | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/metal/paddle-mobile/paddle-mobile/Executor.swift b/metal/paddle-mobile/paddle-mobile/Executor.swift index 303e35bf73..f569b74c02 100644 --- a/metal/paddle-mobile/paddle-mobile/Executor.swift +++ b/metal/paddle-mobile/paddle-mobile/Executor.swift @@ -14,7 +14,7 @@ import Foundation -let testTo = 10 +let testTo = 12 public class ResultHolder { public let dim: [Int] diff --git a/metal/paddle-mobile/paddle-mobile/Operators/ConcatOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/ConcatOp.swift index 361761c753..117fd8c39f 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/ConcatOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/ConcatOp.swift @@ -68,6 +68,7 @@ class ConcatOp: Operator, ConcatParam

>, Run let originDim = para.output.originDim let outputArray = para.output.metalTexture.realNHWC(dim: (n: originDim[0], h: originDim[1], w: originDim[2], c: originDim[3])) print(outputArray.strideArray()) + 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/ElementwiseAddOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift index 8f95be2114..a6c3162155 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift @@ -56,7 +56,24 @@ class ElementwiseAddOp: Operator, Elem // para.output.dim = para.input.dim } + func delogOutput() { + print(" \(type) inputX: ") + print(para.inputX.metalTexture.toTensor(dim: (n: para.inputX.tensorDim[0], c: para.inputX.tensorDim[1], h: para.inputX.tensorDim[2], w: para.inputX.tensorDim[3])).strideArray()) + print(" \(type) inputY: ") + print(para.inputY.metalTexture.toTensor(dim: (n: para.inputY.tensorDim[0], c: para.inputY.tensorDim[1], h: para.inputY.tensorDim[2], w: para.inputY.tensorDim[3])).strideArray()) + print(" \(type) output: ") + let originDim = para.output.originDim + let outputArray = para.output.metalTexture.realNHWC(dim: (n: originDim[0], h: originDim[1], w: originDim[2], c: originDim[3])) + print(outputArray.strideArray()) + 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()) + } + func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws { + do { + try kernel.compute(commandBuffer: buffer, param: para) + } catch let error { + throw error + } } } diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ElementwiseAddKernel.swift b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ElementwiseAddKernel.swift index 0a1aeeb8bf..884b2ae3c3 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ElementwiseAddKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/ElementwiseAddKernel.swift @@ -55,6 +55,7 @@ class ElementwiseAddKernel: Kernel, Computable { } emp.yoff = 4 - Int32(param.inputY.tensorDim.cout()) if (param.inputX.dim == param.inputY.dim) && (param.inputX.transpose == param.inputY.transpose) { + print("===> elementwise_add fast!!!") emp.fast = 1 } -- GitLab