From 52e3bd329da2bfd2f9d0fe9ac7eb3f3795a7e220 Mon Sep 17 00:00:00 2001 From: hlu1 <14827759+hlu1@users.noreply.github.com> Date: Wed, 16 Jan 2019 17:21:40 -0800 Subject: [PATCH] [Runtime] Make runtime compatible with android ndk api 15 (#2446) --- src/runtime/cpu_device_api.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime/cpu_device_api.cc b/src/runtime/cpu_device_api.cc index d166a3a43dfa..6bd7022fd9f6 100644 --- a/src/runtime/cpu_device_api.cc +++ b/src/runtime/cpu_device_api.cc @@ -10,6 +10,10 @@ #include #include "workspace_pool.h" +#ifdef __ANDROID__ +#include +#endif + namespace tvm { namespace runtime { class CPUDeviceAPI final : public DeviceAPI { @@ -28,10 +32,11 @@ class CPUDeviceAPI final : public DeviceAPI { #if _MSC_VER ptr = _aligned_malloc(nbytes, alignment); if (ptr == nullptr) throw std::bad_alloc(); -#elif defined(_LIBCPP_SGX_CONFIG) +#elif defined(_LIBCPP_SGX_CONFIG) || (defined(__ANDROID__) && __ANDROID_API__ < 16) ptr = memalign(alignment, nbytes); if (ptr == nullptr) throw std::bad_alloc(); #else + // posix_memalign is available in android ndk since __ANDROID_API__ >= 16 int ret = posix_memalign(&ptr, alignment, nbytes); if (ret != 0) throw std::bad_alloc(); #endif