@Override public void computeOutputShape() { outputShape = inputShape[0]; if(softmaxScript!=null){ int n = inputShape[0][0]; int h = inputShape[0][1]; int w = inputShape[0][2]; int c = inputShape[0][3]; Type expSumType = Type.createX(renderScript, Element.F32(renderScript), n * h * w); expSumAlloc = Allocation.createTyped(renderScript, expSumType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); softmaxScript.set_channel(c); softmaxScript.set_expSum(expSumAlloc); } } }
@Override public void setup(){ int n = inputShape[0][0]; int h = inputShape[0][1]; int w = inputShape[0][2]; int c = inputShape[0][3]; Type expSumType = Type.createX(renderScript, Element.F32(renderScript), n * h * w); expSumAlloc = Allocation.createTyped(renderScript, expSumType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); softmaxScript = new ScriptC_Softmax(renderScript); softmaxScript.set_channel(c); softmaxScript.set_expSum(expSumAlloc); }
@Override public void setup() { int channel = outputShape[3]; int channelAlign = channel; if(channel % 4 != 0){ channelAlign = channel + 4 - channel % 4; } scriptScale = new ScriptC_Scale(renderScript); float[] scaleArray = new float[channelAlign]; float[] biasArray = new float[channelAlign]; for(int i=0;i<channel;i++){ scaleArray[i] = scale[i]; biasArray[i] = bias[i]; } Allocation scaleAllocation; Allocation biasAllocation; Type scaleType = Type.createX(renderScript, Element.F32_4(renderScript), channelAlign / 4); Type biasType = Type.createX(renderScript, Element.F32_4(renderScript), channelAlign / 4); scaleAllocation = Allocation.createTyped(renderScript, scaleType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); scaleAllocation.copyFrom(scaleArray); biasAllocation = Allocation.createTyped(renderScript, biasType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); biasAllocation.copyFrom(biasArray); scriptScale.set_scale(scaleAllocation); scriptScale.set_bias(biasAllocation); }
Type outType = Type.createX(renderScript, Element.F32(renderScript), outNum * outHeight * outWidth * outChannel);
Type outType = Type.createX(renderScript, Element.F32_4(renderScript), outNum * outHeight * outWidth * outChannelAlign / 4);
kernelType.setX(inputChannelAligned); kernelType.setY(kernelH * kernelW); Type biasType = Type.createX(renderScript, Element.F32(renderScript), inputChannelAligned); kernelAllocation = Allocation.createTyped(renderScript, kernelType.create(), Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT); biasAllocation = Allocation.createTyped(renderScript, biasType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_SCRIPT);
kernelType.setY(outputChannelAligned); kernelType.setX(kernelH * kernelW * inputChannelGroup); Type biasType = Type.createX(renderScript, Element.F32(renderScript), outputChannelAligned);