Browse Source

fix cast arm packing test

tags/20200413
nihui 6 years ago
parent
commit
44eb28fadc
3 changed files with 11 additions and 54 deletions
  1. +4
    -0
      src/layer/arm/cast_arm.cpp
  2. +6
    -1
      src/layer/arm/packing_arm.cpp
  3. +1
    -53
      src/mat.cpp

+ 4
- 0
src/layer/arm/cast_arm.cpp View File

@@ -49,7 +49,11 @@ int Cast_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt)
#if __ARM_NEON
if (elempack % 4 == 0)
{
#if (__ARM_FP & 2)
if (!cpu_support_arm_vfpv4() && (type_from == 2 || type_to == 2))
#else
if (type_from == 2 || type_to == 2)
#endif // (__ARM_FP & 2)
{
// no fp16 conversion instruction, fallback
return Cast::forward(bottom_blob, top_blob, opt);


+ 6
- 1
src/layer/arm/packing_arm.cpp View File

@@ -34,6 +34,7 @@ int Packing_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& op
return Packing::forward(bottom_blob, top_blob, opt);
}

size_t elemsize = bottom_blob.elemsize;
int elempack = bottom_blob.elempack;

if (elempack == out_elempack)
@@ -42,6 +43,11 @@ int Packing_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& op
return 0;
}

if (elemsize / elempack != 4u)
{
return Packing::forward(bottom_blob, top_blob, opt);
}

bool pack1to4 = elempack == 1 && out_elempack == 4;
bool pack4to1 = elempack == 4 && out_elempack == 1;

@@ -54,7 +60,6 @@ int Packing_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& op
int h = bottom_blob.h;
int channels = bottom_blob.c;
int dims = bottom_blob.dims;
size_t elemsize = bottom_blob.elemsize;

if (!use_padding)
{


+ 1
- 53
src/mat.cpp View File

@@ -113,58 +113,6 @@ void Mat::substract_mean_normalize(const float* mean_vals, const float* norm_val
delete op;
}

// convert half precision floating point to float
static float half2float(unsigned short value)
{
// 1 : 5 : 10
unsigned short sign = (value & 0x8000) >> 15;
unsigned short exponent = (value & 0x7c00) >> 10;
unsigned short significand = value & 0x03FF;

// fprintf(stderr, "%d %d %d\n", sign, exponent, significand);

// 1 : 8 : 23
union
{
unsigned int u;
float f;
} tmp;
if (exponent == 0)
{
if (significand == 0)
{
// zero
tmp.u = (sign << 31);
}
else
{
// denormal
exponent = 0;
// find non-zero bit
while ((significand & 0x200) == 0)
{
significand <<= 1;
exponent++;
}
significand <<= 1;
significand &= 0x3FF;
tmp.u = (sign << 31) | ((-exponent + (-15 + 127)) << 23) | (significand << 13);
}
}
else if (exponent == 0x1F)
{
// infinity or NaN
tmp.u = (sign << 31) | (0xFF << 23) | (significand << 13);
}
else
{
// normalized
tmp.u = (sign << 31) | ((exponent + (-15 + 127)) << 23) | (significand << 13);
}

return tmp.f;
}

Mat Mat::from_float16(const unsigned short* data, int size)
{
Mat m(size);
@@ -224,7 +172,7 @@ Mat Mat::from_float16(const unsigned short* data, int size)
#endif // __ARM_NEON
for (; remain>0; remain--)
{
*ptr = half2float(*data);
*ptr = float16_to_float32(*data);

data++;
ptr++;


Loading…
Cancel
Save