diff --git a/metal/paddle-mobile/paddle-mobile/Executor.swift b/metal/paddle-mobile/paddle-mobile/Executor.swift index 303e35bf73d5c90dc6311aa29b25e77b47ba053b..0f3b8824ad77de379ee575546a3e262ceb7833bb 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 = 7 public class ResultHolder { public let dim: [Int] diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/metal/PreluKernel.metal b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/metal/PreluKernel.metal index f07b636052f823bd11e0aaa3f6be6ae17d8ca804..1c5b08ee7eeaaa4fd2a8b5064a6af66c77596120 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/metal/PreluKernel.metal +++ b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/metal/PreluKernel.metal @@ -28,16 +28,16 @@ kernel void prelu_channel(texture2d_array inTexture [[tex } constexpr sampler sample(coord::pixel, filter::nearest, address::clamp_to_zero); - float4 input = inTexture.sample(sample, gid.x, gid.y, gid.z); + float4 input = inTexture.sample(sample, float2(gid.x, gid.y), gid.z); + float4 alpha_value = alpha[gid.z]; float4 output; - output.x = input.x > 0 ? input.x : alpha[gid.z].x; - output.x = input.y > 0 ? input.y : alpha[gid.z].y; - output.x = input.z > 0 ? input.z : alpha[gid.z].z; - output.x = input.w > 0 ? input.w : alpha[gid.z].w; + output.x = input.x > 0 ? input.x : (alpha_value.x * input.x); + output.y = input.y > 0 ? input.y : (alpha_value.y * input.y); + output.z = input.z > 0 ? input.z : (alpha_value.z * input.z); + output.w = input.w > 0 ? input.w : (alpha_value.w * input.w); outTexture.write(output, gid.xy, gid.z); } - kernel void prelu_element(texture2d_array inTexture [[texture(0)]], texture2d_array outTexture [[texture(1)]], const device float4 *alpha [[buffer(0)]], @@ -49,19 +49,19 @@ kernel void prelu_element(texture2d_array inTexture [[tex } constexpr sampler sample(coord::pixel, filter::nearest, address::clamp_to_zero); - float4 input = inTexture.sample(sample, gid.x, gid.y, gid.z); - + float4 input = inTexture.sample(sample, float2(gid.x, gid.y), gid.z); + int alpha_to = (gid.y * inTexture.get_width() + gid.x) * inTexture.get_array_size(); - + float4 alpha_value = alpha[alpha_to + gid.z]; + float4 output; - output.x = input.x > 0 ? input.x : alpha[alpha_to + gid.z].x; - output.x = input.y > 0 ? input.y : alpha[alpha_to + gid.z].y; - output.x = input.z > 0 ? input.z : alpha[alpha_to + gid.z].z; - output.x = input.w > 0 ? input.w : alpha[alpha_to + gid.z].w; + output.x = input.x > 0 ? input.x : (alpha_value.x * input.x); + output.y = input.y > 0 ? input.y : (alpha_value.y * input.y); + output.z = input.z > 0 ? input.z : (alpha_value.z * input.z); + output.w = input.w > 0 ? input.w : (alpha_value.w * input.w); outTexture.write(output, gid.xy, gid.z); } - kernel void prelu_other(texture2d_array inTexture [[texture(0)]], texture2d_array outTexture [[texture(1)]], const device float *alpha [[buffer(0)]], @@ -73,12 +73,12 @@ kernel void prelu_other(texture2d_array inTexture [[textu } constexpr sampler sample(coord::pixel, filter::nearest, address::clamp_to_zero); - float4 input = inTexture.sample(sample, gid.x, gid.y, gid.z); - + float4 input = inTexture.sample(sample, float2(gid.x, gid.y), gid.z); + float alpha_value = alpha[0]; float4 output; - output.x = input.x > 0 ? input.x : alpha[0]; - output.x = input.y > 0 ? input.y : alpha[0]; - output.x = input.z > 0 ? input.z : alpha[0]; - output.x = input.w > 0 ? input.w : alpha[0]; + output.x = input.x > 0 ? input.x : (alpha_value * input.x); + output.y = input.y > 0 ? input.y : (alpha_value * input.y); + output.z = input.z > 0 ? input.z : (alpha_value * input.z); + output.w = input.w > 0 ? input.w : (alpha_value * input.w); outTexture.write(output, gid.xy, gid.z); } diff --git a/metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift index ec1437a3c2f084dbfa0e4922a305db7bd40b5b8f..10b5816d7b4528572cdc6b84d53b73499dde93b4 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift @@ -50,8 +50,17 @@ class PreluOp: Operator, PreluParam

>, Runabl } func delogOutput() { + print(" \(type) input: ") + print(para.input.metalTexture.toTensor(dim: (n: para.input.originDim[0], c: para.input.originDim[1], h: para.input.originDim[2], w: para.input.originDim[3])).strideArray()) + + print(" \(type) Alpha: ") + let _: Float32? = para.alpha.buffer.logDesc(header: " alpha: ", stridable: false) + + print(" \(type) output: ") + print(para.output.metalTexture.toTensor(dim: (n: para.output.originDim[0], c: para.output.originDim[1], h: para.output.originDim[2], w: para.output.originDim[3])).strideArray()) + } + // print("softmax delog") // let _: P? = para.input.metalTexture.logDesc(header: "softmax input: ", stridable: false) // let _: P? = para.output.metalTexture.logDesc(header: "softmax output: ", stridable: false) - } }