Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NNPACK UNIFIED API PROBLEM #24

Open
Darwin2011 opened this issue Aug 12, 2016 · 2 comments
Open

NNPACK UNIFIED API PROBLEM #24

Darwin2011 opened this issue Aug 12, 2016 · 2 comments

Comments

@Darwin2011
Copy link

Hi,

I am trying to figure out NNPACK API usage.

  • for convolution with stride = 1, I should use compute_convolution_output.
  • for convolution with stride >= 2, I should use nnp_convolution_inference. In this case, patche2cols and sgemm will be used as computation backend.

Is there any possibility to integrate there two API into one and provide users one unified and transparent interface? That can make things much easy when using the library.

Best Regards.

@Maratyszcza
Copy link
Owner

Maratyszcza commented Aug 12, 2016

The difference between inference and output (forward pass in training) functions is based on two considerations:

  1. inference functions are optimized for batch = 1 case, while output functions are optimized for moderately large batch sizes (64 and above).
  2. While none of the following is currently implemented, I have plans to merge some extra operations into convolutional/fully connected layers. The type of operations which can be merged, depends on whether the framework would need to run backward pass on the layer using the outputs:
  • Both ReLU and ELU can be merged into the preceding convolutional (or fully connected) layer.
  • If the model is used for inference, 2x2 pooling with 2x2 stride can be merged into preceding convolutional or fully connected layer (potentially with embedded ReLU/ELU). If the layer is used for training, this fusion is impossible, because the backward pass on the convolutional layer would need the output of the convolutional layer before 2x2 pooling, which wouldn't be produced by the forward pass.
  • If the model is used for training, batch normalization layer can be partially merged into preceding convolutional or fully connected layer. Specifically, computation of per-channel mean values can be merged into the store stage of the preceding layer. In inference, batch normalization layer becomes a static scale + bias layer, and often can be statically merged into preceding convolutional or fully connected layer, so computation of per-channel mean activations makes no sense.

The reason why nnp_convolution_inference supports strides while nnp_convolution_output does not is that NNPACK is in active development and implicit_gemm algorithm and strided convolutions were implemented for inference function first. Support for implicit_gemm algorithm and strided convolutions in the training functions is in short-term plans, but for now you'd need to fall back to an implementation outside NNPACK.

One more clarification about implicit_gemm algorithm: it does not do patch2cols+sgemm, but rather does something smarter. High-performance implementations of SGEMM internally repack the matrix into cache-friendly form. Thus, a typical SGEMM-based implementation of a convolutional layer would involve two repacking operations: one inside patch2cols and another inside sgemm. NNPACK's implicit_gemm algorithm combines these two repacking operations into one; the main motivation is to operate with low memory overhead (NNPACK doesn't allocate memory for the whole patch2cols matrix, just for L3-sized block of it), but you'd likely find it performing better than traditional patch2cols+sgemm implementations due to fewer memory repacking operations.

@lironmo
Copy link

lironmo commented May 27, 2018

any update about the short term implementation, for stride size bigger than 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants