ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

FC Layer using the GEMM

Open uu-praveeng opened this issue 9 years ago • 6 comments

Hi,

I am trying to implement the FCLayer using the GEMM below are the dimensions and configuration im using. Please let me know if this is correct Since im facing below error while running/. "What(): in Iterator ./arm_compute/core/Helpers.inl:211: Maximum number of dimensions expected 1 but dimension 1 is not empty"

NEGEMM FcLayer;

LayerTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)4096), 1, DataType::F32));
FcLayerWgtTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)4096,(long unsigned int)4096), 1, DataType::F32));
FcLayerBiasTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)4096), 1, DataType::F32));
FcTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)4096), 1, DataType::F32));

/*Done the allocations of the above */ ....................... ........................

FcLayer.configure(&LayerTensor, &FcLayerWgtTensor, &FcLayerBiasTensor, &FcTensor,1.0,1.0);
FcLayer.run()

Are there any transpose need to be done before passing to run. Thanks.

uu-praveeng avatar Apr 18 '17 11:04 uu-praveeng

The same dimensions may confuse so changing the dimensions:

NEGEMM FcLayer;

LayerTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)9216), 1, DataType::F32)); FcLayerWgtTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)9216,(long unsigned int)4096), 1, DataType::F32)); FcLayerBiasTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)4096), 1, DataType::F32)); FcTensor.allocator()->init(TensorInfo(TensorShape((long unsigned int)4096), 1, DataType::F32));

/*Done the allocations of the above */ ....................... ........................

FcLayer.configure(&LayerTensor, &FcLayerWgtTensor, &FcLayerBiasTensor, &FcTensor,1.0,1.0); FcLayer.run()

uu-praveeng avatar Apr 18 '17 12:04 uu-praveeng

Hi @uu-praveeng, from your code I have noticed that the allocation of the tensors happens before calling the configure() method. The tensor's allocation should be after the configure method in order to calculate properly the padding bytes needed for computing GEMM. Could you try to move the allocation of the tensors just before the run()?

Also I noticed that the tensor for the weights has the following shape: Colums = 9216 Rows = 4096 But I think should be: Rows = 9216 Columns = 4096 in case you do not transpose the weights.

Hope this can help you, Gian Marco

gmiodice avatar Apr 18 '17 13:04 gmiodice

Hello @uu-praveeng , Any reason why not use FullyConnectedLayer which already is implemented using GEMM?

GeorgeARM avatar Apr 18 '17 14:04 GeorgeARM

gmiodice , Allocations are done after configure.My bad I have kept query in such a way. Will check with what you have suggested.

GeorgeARM We implemented the FCLayer using the NEFullyConnectedLayer.We wanted to see if there any difference in speed with NEFullyConnectedLayer vs NEGEMM .

Thanks

uu-praveeng avatar Apr 19 '17 04:04 uu-praveeng

Hi @uu-praveeng and many thanks for all your information.

Regarding the aspect "We wanted to see if there any difference in speed with NEFullyConnectedLayer vs NEGEMM", you shouldn't see any performance difference between NEFullyConnectedLayer and NEGEMM as the implementation of NEFullyConnectedLayer is actually based on sgemm.

In particular, NEFullyConnectedLayer would call the kernel NEGEMMMatrixMultiplyKernel for your specific case.

Thanks

gmiodice avatar Apr 19 '17 10:04 gmiodice

ok thanks

uu-praveeng avatar Apr 19 '17 10:04 uu-praveeng