You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/09/09 19:27:35 UTC

[GitHub] [incubator-mxnet] rondogency commented on a change in pull request #16104: Faster Transpose 2D

rondogency commented on a change in pull request #16104: Faster Transpose 2D
URL: https://github.com/apache/incubator-mxnet/pull/16104#discussion_r322414142
 
 

 ##########
 File path: src/operator/tensor/matrix_op-inl.h
 ##########
 @@ -257,6 +257,43 @@ struct TransposeParam : public dmlc::Parameter<TransposeParam> {
   }
 };
 
+
+/*!
+ * \brief This function performs transpose operation on a 2D matrix by utilizing the L1 cache
+ * \param in      input tensor
+ * \param out     output tensor
+ * \param shape_0 shape of dim 0 of input
+ * \param shape_1 shape of dim 1 of input
+ */
+template<typename xpu, typename DType>
+MSHADOW_XINLINE void Transpose2D(DType *in, DType *out, index_t shape_0, index_t shape_1) {
+  // ensure cache line hits and prevent cache miss for any configuration
+  // L1 cache size to be utilized = 32kb = 2^15
+  // Largest size of a single unit of any dtype <= 8 byte = 2^3
+  // Number of elements - (2^15/2^3) = 2^12
+  // Block-size - 2^6 v 2^6 (64 v 64)
+
+  // But we could leverage unrolling of for loops (for parallelization)
+  // Block-size - 2^5 v 2^5 (32 v 32) with 4 pragma for loop unrolled
+  index_t blocksize = 32;
+  index_t n = shape_0;
 
 Review comment:
   Yes, and we can also make function parameters be named row and col get rid of unnecessary copies.
   Also I think we can add the formula "blocksize * blocksize * num_threads = cache_size / dtype_size" to the docblock to increase readability.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services