Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Get rid of half2 in mshadow
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrendx committed Mar 5, 2020
1 parent 28e5877 commit 541aebb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 258 deletions.
48 changes: 0 additions & 48 deletions 3rdparty/mshadow/mshadow/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ extern "C" {
}

#include "./half.h"
#include "./half2.h"
#include "./bfloat.h"
#define MSHADOW_HALF_BF_OPERATOR(RTYPE, OP) \
MSHADOW_XINLINE RTYPE operator OP(mshadow::half::half_t a, mshadow::bfloat::bf16_t b) { \
Expand Down Expand Up @@ -392,11 +391,6 @@ struct DataType<half::half_t> {
#endif
};
template<>
struct DataType<half::half2_t> {
static const int kFlag = kFloat16;
static const int kLanes = 2;
};
template<>
struct DataType<bfloat::bf16_t> {
static const int kFlag = kBfloat16;
static const int kLanes = 1;
Expand Down Expand Up @@ -1149,48 +1143,6 @@ struct minimum {
}
#endif

#define MSHADOW_TYPE_SWITCH_WITH_HALF2(type, DType, ...) \
switch (type) { \
case mshadow::kFloat32: \
{ \
typedef float DType; \
{__VA_ARGS__} \
} \
break; \
case mshadow::kFloat64: \
{ \
typedef double DType; \
{__VA_ARGS__} \
} \
break; \
case mshadow::kFloat16: \
{ \
typedef mshadow::half::half2_t DType; \
{__VA_ARGS__} \
} \
break; \
case mshadow::kUint8: \
{ \
typedef uint8_t DType; \
{__VA_ARGS__} \
} \
break; \
case mshadow::kInt32: \
{ \
typedef int32_t DType; \
{__VA_ARGS__} \
} \
break; \
case mshadow::kInt64: \
{ \
typedef int64_t DType; \
{__VA_ARGS__} \
} \
break; \
default: \
LOG(FATAL) << "Unknown type enum " << type; \
}

#define MSHADOW_SGL_DBL_TYPE_SWITCH(type, DType, ...) \
switch (type) { \
case mshadow::kFloat32: \
Expand Down
143 changes: 0 additions & 143 deletions 3rdparty/mshadow/mshadow/half2.h

This file was deleted.

67 changes: 0 additions & 67 deletions src/operator/mshadow_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,22 +742,8 @@ MXNET_BINARY_MATH_OP(rminus, b - a);

MXNET_BINARY_MATH_OP(div_grad, 1.0f / math::id(b));

template<>
MSHADOW_XINLINE mshadow::half::half2_t div_grad::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
return mshadow::half::half2_t(1) / b;
}

MXNET_BINARY_MATH_OP(div_rgrad, -math::id(a) / math::sqr(b));

template<>
MSHADOW_XINLINE mshadow::half::half2_t div_rgrad::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
return -a / (b * b);
}

MXNET_BINARY_MATH_OP(rdiv, math::id(b) / math::id(a));

MXNET_BINARY_MATH_OP(rdiv_grad, -math::id(b) / math::sqr(a));
Expand Down Expand Up @@ -807,13 +793,6 @@ struct mod : public mxnet_op::tunable {
}
};

template<>
MSHADOW_XINLINE mshadow::half::half2_t mod::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
return a%b;
}

struct mod_grad : public mxnet_op::tunable {
template<typename DType>
MSHADOW_XINLINE static DType Map(DType a, DType b) {
Expand All @@ -835,19 +814,6 @@ MSHADOW_XINLINE mshadow::half::half_t mod_grad::Map<mshadow::half::half_t>
mshadow::half::half_t b) {
return mshadow::half::half_t(1.0f);
}
template<>
MSHADOW_XINLINE mshadow::half::half2_t mod_grad::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
mshadow::half::half2_t result = mshadow::half::half2_t();
#if (defined(__CUDACC__) && MSHADOW_CUDA_HALF2)
result.half2_ = ::__float2half2_rn(1.0f);
#else
result.half_t2[0] = mshadow::half::half_t(0.0f);
result.half_t2[1] = mshadow::half::half_t(1.0f);
#endif
return result;
}

struct mod_rgrad : public mxnet_op::tunable {
template<typename DType>
Expand All @@ -870,19 +836,6 @@ MSHADOW_XINLINE mshadow::half::half_t mod_rgrad::Map<mshadow::half::half_t>
mshadow::half::half_t b) {
return mshadow::half::half_t(-::floorf(static_cast<float>(a/b)));
}
template<>
MSHADOW_XINLINE mshadow::half::half2_t mod_rgrad::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
#if (defined(__CUDACC__) && MSHADOW_CUDA_HALF2)
return mshadow::half::half2_t(__hneg2(::h2floor((a/b).half2_)));
#else
return mshadow::half::half2_t(mshadow::half::half_t(-::floorf(
static_cast<float>(a.half_t2[0]/b.half_t2[0]))),
mshadow::half::half_t(-::floorf(
static_cast<float>(a.half_t2[1]/b.half_t2[1]))));
#endif
}

struct rmod : public mxnet_op::tunable {
template<typename DType>
Expand Down Expand Up @@ -919,13 +872,6 @@ struct rmod : public mxnet_op::tunable {
}
};

template<>
MSHADOW_XINLINE mshadow::half::half2_t rmod::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
return b%a;
}

struct rmod_grad {
template<typename DType>
MSHADOW_XINLINE static DType Map(DType a, DType b) {
Expand All @@ -947,19 +893,6 @@ MSHADOW_XINLINE mshadow::half::half_t rmod_grad::Map<mshadow::half::half_t>
mshadow::half::half_t b) {
return mshadow::half::half_t(-::floorf(static_cast<float>(b/a)));
}
template<>
MSHADOW_XINLINE mshadow::half::half2_t rmod_grad::Map<mshadow::half::half2_t>
(mshadow::half::half2_t a,
mshadow::half::half2_t b) {
#if (defined(__CUDACC__) && MSHADOW_CUDA_HALF2)
return mshadow::half::half2_t(::__hneg2(::h2floor((b/a).half2_)));
#else
return mshadow::half::half2_t(mshadow::half::half_t(-::floorf(
static_cast<float>(b.half_t2[0]/a.half_t2[0]))),
mshadow::half::half_t(-::floorf(
static_cast<float>(b.half_t2[1]/a.half_t2[1]))));
#endif
}

struct clip : public mxnet_op::tunable {
template<typename DType>
Expand Down

0 comments on commit 541aebb

Please sign in to comment.