Skip to content

Commit 02db4f4

Browse files
committed
fix the issue of build libappbuilder.so
1 parent 6e4d4c8 commit 02db4f4

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/LibAppBuilder.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include "Utils/Utils.hpp"
3535
#endif
3636

37+
#if !defined(__ANDROID__)
38+
#include <execution>
39+
#endif
40+
3741
using namespace qnn;
3842
using namespace qnn::log;
3943
using namespace qnn::tools;
@@ -63,7 +67,7 @@ std::string getFileNameFromPath(const std::string& path) {
6367
return path.substr(pos + 1);
6468
}
6569

66-
70+
#if !defined(__ANDROID__)
6771
void warmup_parallel_stl()
6872
{
6973
static std::once_flag once;
@@ -75,7 +79,7 @@ void warmup_parallel_stl()
7579
});
7680
QNN_WAR("warmup_parallel_stl");
7781
}
78-
82+
#endif
7983

8084
std::unique_ptr<sample_app::QnnSampleApp> initQnnSampleApp(std::string cachedBinaryPath, std::string backEndPath, std::string systemLibraryPath,
8185
bool loadFromCachedBinary, std::vector<LoraAdapter>& lora_adapters,
@@ -132,8 +136,10 @@ std::unique_ptr<sample_app::QnnSampleApp> initQnnSampleApp(std::string cachedBin
132136
}
133137
}
134138

135-
if ((input_data_type == "float") || (output_data_type == "float")) // We need 'std::transform' only for ‘float’ mode. It need data conversation.
139+
#if !defined(__ANDROID__)
140+
if ((input_data_type == "float") || (output_data_type == "float")) // We need 'std::transform' only for �float� mode. It need data conversation.
136141
warmup_parallel_stl();
142+
#endif
137143

138144
sg_qnnInterface = qnnFunctionPointers.qnnInterface;
139145
std::unique_ptr<sample_app::QnnSampleApp> app(new sample_app::QnnSampleApp(qnnFunctionPointers, "null", opPackagePaths, sg_backendHandle, "null",

src/Utils/DataUtil.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <cstddef>
2525
#include <cstdint>
2626

27-
#if defined(__aarch64__) || defined(_M_ARM64)
27+
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__ANDROID__)
2828
#include <arm_neon.h>
2929
#endif
3030
#ifdef _WIN32
@@ -396,6 +396,7 @@ static inline uint32_t datautil::fp32_to_bits(float f) {
396396
#endif
397397
}
398398

399+
#if !defined(__ANDROID__)
399400
// Enabling fp16 execution
400401
static inline uint16_t datautil::fp16_ieee_from_fp32_value(float f) {
401402
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)
@@ -422,7 +423,22 @@ static inline uint16_t datautil::fp16_ieee_from_fp32_value(float f) {
422423
const uint32_t nonsign = exp_bits + mantissa_bits;
423424
return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
424425
}
426+
#endif
425427

428+
#if defined(__ANDROID__)
429+
static inline uint16_t datautil::fp16_ieee_from_fp32_hw(float f)
430+
{
431+
float32x4_t v32 = vdupq_n_f32(f);
432+
//VCVT F16.F32
433+
float16x4_t v16 = vcvt_f16_f32(v32);
434+
__fp16 h = v16[0];
435+
uint16_t out;
436+
memcpy(&out, &h, sizeof(out));
437+
return out;
438+
}
439+
#endif
440+
441+
#if !defined(__ANDROID__)
426442
static inline uint16_t datautil::fp16_ieee_from_fp32_value_v2(float f) noexcept {
427443
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)
428444
constexpr float scale_to_inf = 0x1.0p+112f;
@@ -523,6 +539,7 @@ void datautil::float32_to_float16_parallel(uint16_t* __restrict dst,
523539
[](float x) noexcept -> uint16_t { return fp16_ieee_from_fp32_value_v2(x); });
524540

525541
}
542+
#endif
526543

527544
// Enabling fp16 execution
528545
bool datautil::float32ToFloatN(uint8_t* out,
@@ -535,13 +552,17 @@ bool datautil::float32ToFloatN(uint8_t* out,
535552
}
536553

537554
if(bitWidth == 16){
538-
#ifdef PARALLEL // wd. Improve performance through std::transform and NEON.
555+
#if defined(PARALLEL) && !defined(__ANDROID__)// wd. Improve performance through std::transform and NEON.
539556
auto* dst = reinterpret_cast<uint16_t*>(out);
540557
float32_to_float16_parallel(dst, in, numElements);
541558
#else
542559
uint16_t *temp = (uint16_t *)out;
543560
for(size_t i = 0; i < numElements; i++){
544-
temp[i] = fp16_ieee_from_fp32_value(in[i]);
561+
#if defined(__ANDROID__)
562+
temp[i] = fp16_ieee_from_fp32_hw(in[i]);
563+
#else
564+
temp[i] = fp16_ieee_from_fp32_value(in[i]);
565+
#endif
545566
}
546567
#endif //__hexagon__
547568
}

src/Utils/DataUtil.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ StatusCode writeBinaryToFile(std::string fileDir,
8888
size_t bufferSize);
8989
#endif
9090

91+
#if !defined(__ANDROID__)
9192
// Enabling fp16 execution
9293
static inline uint16_t fp16_ieee_from_fp32_value(float f);
9394

@@ -108,6 +109,10 @@ void float32_to_float16_dispatch(uint16_t* __restrict dst,
108109
void float32_to_float16_parallel(uint16_t* __restrict dst,
109110
const float* __restrict src,
110111
size_t n) noexcept;
112+
#endif
113+
#if defined(__ANDROID__)
114+
static inline uint16_t fp16_ieee_from_fp32_hw(float f);
115+
#endif
111116

112117
static inline float fp16_ieee_to_fp32_value(uint16_t h);
113118
static inline uint32_t fp32_to_bits(float f);

0 commit comments

Comments
 (0)