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 2020/01/18 02:21:46 UTC

[GitHub] [incubator-mxnet] Kh4L commented on a change in pull request #17368: Faster GPU frozen BatchNorm

Kh4L commented on a change in pull request #17368: Faster GPU frozen BatchNorm
URL: https://github.com/apache/incubator-mxnet/pull/17368#discussion_r368199696
 
 

 ##########
 File path: src/operator/nn/batch_norm.cu
 ##########
 @@ -44,9 +46,30 @@
 
 using namespace mxnet;
 
+namespace {
+
 /*! \brief inverse standard deviation <-> variance */
-#define VARIANCE_TO_INVSTD(__var$,    __eps$)   (1.0/sqrt((__var$) + DType(__eps$)))
-#define INVSTD_TO_VARIANCE(__invstd$, __eps$)   ((1.0 / ((__invstd$) * (__invstd$))) - (__eps$))
+template <typename DType, typename AccReal>
+MSHADOW_XINLINE AccReal variance_to_invstd(DType var, AccReal eps) {
+  return rsqrtf(static_cast<AccReal>(var) + eps);
+}
+
+template <>
+MSHADOW_XINLINE double variance_to_invstd(double var, double eps) {
+  return rsqrt(var + eps);
+}
+
+template <typename AccReal>
+MSHADOW_XINLINE AccReal invstd_to_variance(AccReal invstd, AccReal eps) {
+  return 1.0f / (invstd * invstd) - eps;
 
 Review comment:
   What about:
   ```suggestion
     return static_cast<AccReal>(1.0) / (invstd * invstd) - eps;
   ```

----------------------------------------------------------------
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