Changesets · Branches · Tags · Compare
| Changeset | 97d85537e7363fee53556fccc80217b65786d4cb3e5e6dbad9367eb82982a54c |
|---|---|
| Author | nihui <nihuini@tencent.com> · 2024-07-12 10:25 +08:00 |
| Committer | GitHub <noreply@github.com> · 2024-07-12 10:25 +08:00 |
| Parents | c40b67352970 |
2 files changed
modified src/net.cpp +33 −3
| @@ -621,8 +621,17 @@ | ||
| 621 | 621 | // clang-format off |
| 622 | 622 | // *INDENT-OFF* |
| 623 | 623 | |
| 624 | +#if NCNN_ARM82 | |
| 625 | + if (opt.use_fp16_storage && cpu_support_arm_asimdhp() && layer->support_fp16_storage) | |
| 626 | + { | |
| 627 | + Mat bottom_blob_fp16; | |
| 628 | + cast_float32_to_float16(bottom_blob, bottom_blob_fp16, opt); | |
| 629 | + bottom_blob = bottom_blob_fp16; | |
| 630 | + } | |
| 631 | + else | |
| 632 | +#endif // NCNN_ARM82 | |
| 624 | 633 | #if NCNN_VFPV4 |
| 625 | - if (opt.use_fp16_storage && cpu_support_arm_vfpv4() && layer->support_fp16_storage) | |
| 634 | + if (opt.use_fp16_storage && !opt.use_bf16_storage && cpu_support_arm_vfpv4() && layer->support_fp16_storage) | |
| 626 | 635 | { |
| 627 | 636 | Mat bottom_blob_fp16; |
| 628 | 637 | cast_float32_to_float16(bottom_blob, bottom_blob_fp16, opt); |
| @@ -740,8 +749,17 @@ | ||
| 740 | 749 | // clang-format off |
| 741 | 750 | // *INDENT-OFF* |
| 742 | 751 | |
| 752 | +#if NCNN_ARM82 | |
| 753 | + if (opt.use_fp16_storage && cpu_support_arm_asimdhp() && !layer->support_fp16_storage) | |
| 754 | + { | |
| 755 | + Mat bottom_blob_fp32; | |
| 756 | + cast_float16_to_float32(bottom_blob, bottom_blob_fp32, opt); | |
| 757 | + bottom_blob = bottom_blob_fp32; | |
| 758 | + } | |
| 759 | + else | |
| 760 | +#endif // NCNN_ARM82 | |
| 743 | 761 | #if NCNN_VFPV4 |
| 744 | - if (opt.use_fp16_storage && cpu_support_arm_vfpv4() && !layer->support_fp16_storage) | |
| 762 | + if (opt.use_fp16_storage && !opt.use_bf16_storage && cpu_support_arm_vfpv4() && !layer->support_fp16_storage) | |
| 745 | 763 | { |
| 746 | 764 | Mat bottom_blob_fp32; |
| 747 | 765 | cast_float16_to_float32(bottom_blob, bottom_blob_fp32, opt); |
| @@ -2719,8 +2737,20 @@ | ||
| 2719 | 2737 | |
| 2720 | 2738 | // clang-format off |
| 2721 | 2739 | // *INDENT-OFF* |
| 2740 | +#if NCNN_ARM82 | |
| 2741 | + if (d->opt.use_fp16_storage && cpu_support_arm_asimdhp() && (type == 0)) | |
| 2742 | + { | |
| 2743 | + if (feat.elembits() == 16) | |
| 2744 | + { | |
| 2745 | + Mat feat_fp32; | |
| 2746 | + cast_float16_to_float32(feat, feat_fp32, d->opt); | |
| 2747 | + feat = feat_fp32; | |
| 2748 | + } | |
| 2749 | + } | |
| 2750 | + else | |
| 2751 | +#endif // NCNN_ARM82 | |
| 2722 | 2752 | #if NCNN_VFPV4 |
| 2723 | - if (d->opt.use_fp16_storage && cpu_support_arm_vfpv4() && (type == 0)) | |
| 2753 | + if (d->opt.use_fp16_storage && !d->opt.use_bf16_storage && cpu_support_arm_vfpv4() && (type == 0)) | |
| 2724 | 2754 | { |
| 2725 | 2755 | if (feat.elembits() == 16) |
| 2726 | 2756 | { |
modified tests/testutil.cpp +16 −2
| @@ -328,8 +328,15 @@ | ||
| 328 | 328 | { |
| 329 | 329 | // clang-format off |
| 330 | 330 | // *INDENT-OFF* |
| 331 | +#if NCNN_ARM82 | |
| 332 | + if (opt.use_fp16_storage && ncnn::cpu_support_arm_asimdhp() && op->support_fp16_storage && !(flag & TEST_LAYER_DISABLE_AUTO_INPUT_CASTING)) | |
| 333 | + { | |
| 334 | + ncnn::cast_float32_to_float16(a, a4, opt); | |
| 335 | + } | |
| 336 | + else | |
| 337 | +#endif // NCNN_ARM82 | |
| 331 | 338 | #if NCNN_VFPV4 |
| 332 | - if (opt.use_fp16_storage && ncnn::cpu_support_arm_vfpv4() && op->support_fp16_storage && !(flag & TEST_LAYER_DISABLE_AUTO_INPUT_CASTING)) | |
| 339 | + if (opt.use_fp16_storage && !opt.use_bf16_storage && ncnn::cpu_support_arm_vfpv4() && op->support_fp16_storage && !(flag & TEST_LAYER_DISABLE_AUTO_INPUT_CASTING)) | |
| 333 | 340 | { |
| 334 | 341 | ncnn::cast_float32_to_float16(a, a4, opt); |
| 335 | 342 | } |
| @@ -449,8 +456,15 @@ | ||
| 449 | 456 | |
| 450 | 457 | // clang-format off |
| 451 | 458 | // *INDENT-OFF* |
| 459 | +#if NCNN_ARM82 | |
| 460 | + if (opt.use_fp16_storage && ncnn::cpu_support_arm_asimdhp() && op->support_fp16_storage && c4_unpacked.elembits() == 16) | |
| 461 | + { | |
| 462 | + ncnn::cast_float16_to_float32(c4_unpacked, c, opt); | |
| 463 | + } | |
| 464 | + else | |
| 465 | +#endif // NCNN_ARM82 | |
| 452 | 466 | #if NCNN_VFPV4 |
| 453 | - if (opt.use_fp16_storage && ncnn::cpu_support_arm_vfpv4() && op->support_fp16_storage && c4_unpacked.elembits() == 16) | |
| 467 | + if (opt.use_fp16_storage && !opt.use_bf16_storage && ncnn::cpu_support_arm_vfpv4() && op->support_fp16_storage && c4_unpacked.elembits() == 16) | |
| 454 | 468 | { |
| 455 | 469 | ncnn::cast_float16_to_float32(c4_unpacked, c, opt); |
| 456 | 470 | } |