ZhennanQin commented on a change in pull request #17265: Add bfloat16 
floating-point format support based on AMP 
URL: https://github.com/apache/incubator-mxnet/pull/17265#discussion_r365518893
 
 

 ##########
 File path: 3rdparty/mshadow/mshadow/bfloat.h
 ##########
 @@ -0,0 +1,167 @@
+/*!
+ *  Copyright (c) 2019 by Contributors
+ * \file bfloat.h
+ * \brief definition of bfloat type.
+ *
+ * \author Zhennan Qin
+ */
+#ifndef MSHADOW_BFLOAT_H_
+#define MSHADOW_BFLOAT_H_
+#include "./base.h"
+
+/*! \brief namespace for mshadow */
+namespace mshadow {
+/* \brief name space for host/device portable bfloats */
+namespace bfloat {
+
+#define MSHADOW_BF16_OPERATOR_TYPE(RTYPE, ITYPE, OP)                      \
+  MSHADOW_XINLINE RTYPE operator OP (ITYPE a, bf16_t b) {                 \
+    return RTYPE(a OP float(b));  /* NOLINT(*) */                         \
+  }                                                                       \
+  MSHADOW_XINLINE RTYPE operator OP (bf16_t a, ITYPE b) {                 \
+    return RTYPE(float(a) OP b);  /* NOLINT(*) */                         \
+  }
+
+#define MSHADOW_BF16_OPERATOR(RTYPE, OP)                                  \
+  MSHADOW_XINLINE RTYPE operator OP (bf16_t a, bf16_t b) {                \
+    return RTYPE(static_cast<float>(a) OP float(b));  /* NOLINT(*) */     \
+  }                                                                       \
+  MSHADOW_BF16_OPERATOR_TYPE(float, float, OP)                            \
+  MSHADOW_BF16_OPERATOR_TYPE(double, double, OP)                          \
+  MSHADOW_BF16_OPERATOR_TYPE(float, int8_t, OP)                           \
+  MSHADOW_BF16_OPERATOR_TYPE(float, uint8_t, OP)                          \
+  MSHADOW_BF16_OPERATOR_TYPE(float, int32_t, OP)                          \
+  MSHADOW_BF16_OPERATOR_TYPE(float, uint32_t, OP)                         \
+  MSHADOW_BF16_OPERATOR_TYPE(float, int64_t, OP)                          \
+  MSHADOW_BF16_OPERATOR_TYPE(float, uint64_t, OP)
 
 Review comment:
   Sure. Any suggestion here?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to