summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-10-29 12:07:07 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2017-10-29 12:07:07 +0100
commit319762f15075b7c80812b578a0da613cf867b9f2 (patch)
tree8a1b354e25a5931326aecaadbaac7f705ba2a70a
parent12b08ae49154379f7471a40809ace6418857b387 (diff)
Added Android support using the GNU C++ STL library and the GCC toolchain
-rw-r--r--README.md12
-rw-r--r--src/clpp11.hpp5
-rw-r--r--src/utilities/android.hpp7
3 files changed, 15 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0d01b11a..055d05f9 100644
--- a/README.md
+++ b/README.md
@@ -338,17 +338,17 @@ For deployment on Android, there are three options to consider.
First of all, you can use Google's recommended route of installing Android Studio with the NDK, and then use the JNI to interface to the CLBlast library. For this, we refer to the official Android Studio documentation and the online tutorials.
-Alternatively, you can cross-compile the library and the test/client/tuner executables directly. To do so, first install the NDK, then find your vendor's OpenCL library (e.g. in `/system/vendor/lib`), and invoke CMake as follows:
+Alternatively, you can cross-compile the library and the test/client/tuner executables directly. To do so, first install the NDK, then find your vendor's OpenCL library (e.g. in `/system/vendor/lib`), get OpenCL headers from the Khronos registry, and invoke CMake as follows:
cmake .. \
-DCMAKE_SYSTEM_NAME=Android \
- -DCMAKE_SYSTEM_VERSION=26 \ # Set the appropriate Android API level
- -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ # Set the appropriate device architecture
+ -DCMAKE_SYSTEM_VERSION=19 \ # Set the appropriate Android API level
+ -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \ # Set the appropriate device architecture (e.g. armeabi-v7a or arm64-v8a)
-DCMAKE_ANDROID_NDK=$ANDROID_NDK_PATH \ # Assumes $ANDROID_NDK_PATH points to your NDK installation
- -DCMAKE_ANDROID_STL_TYPE=c++_shared \
- -DOPENCL_ROOT=/path/to/vendor/OpenCL/lib/folder/
+ -DCMAKE_ANDROID_STL_TYPE=gnustl_shared \
+ -DOPENCL_ROOT=/path/to/vendor/OpenCL/lib/folder/ # Should contain libOpenCL.so and CL/cl.h
-For any potential issues, first check [cmath 'has not been declared' errors](https://stackoverflow.com/questions/45183525/compilation-error-with-ndk-using-cstatic/46433625).
+For any potential issues, first check [cmath 'has not been declared' errors](https://stackoverflow.com/questions/45183525/compilation-error-with-ndk-using-cstatic/46433625). Also, if you are encountering errors such as `#error Bionic header ctype.h does not define either _U nor _CTYPE_U`, make sure CMake is not including system paths.
Finally, a third option is to use the [Collective Knowledge framework](https://github.com/ctuning/ck) in combination with the NDK, e.g. as follows:
diff --git a/src/clpp11.hpp b/src/clpp11.hpp
index 0cdd92e7..82fc44fd 100644
--- a/src/clpp11.hpp
+++ b/src/clpp11.hpp
@@ -53,6 +53,11 @@
#include <CL/opencl.h>
#endif
+// Android support (missing C++11 functions to_string, stod, and stoi)
+#ifdef __ANDROID__
+ #include "utilities/android.hpp"
+#endif
+
// Exception classes
#include "cxpp11_common.hpp"
diff --git a/src/utilities/android.hpp b/src/utilities/android.hpp
index c14f92f3..64e9b3f4 100644
--- a/src/utilities/android.hpp
+++ b/src/utilities/android.hpp
@@ -7,7 +7,8 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file provides macro's and definitions to make compilation work for Android.
+// This file provides macro's and definitions to make compilation work for Android. Note that this
+// header should only be included when compiling for Android, e.g. when __ANDROID__ is defined.
//
// =================================================================================================
@@ -22,7 +23,7 @@
namespace std {
-// No support for these standard library functions when compiling with 'gnustl_cpp'
+// No support for these standard library functions when compiling with the GNU C++ STL
template<typename T>
std::string to_string(T value) {
std::ostringstream os;
@@ -30,7 +31,7 @@ std::string to_string(T value) {
return os.str();
}
inline double stod(const std::string& value) {
- return -1.0; // Not implemented
+ return std::atof(value.c_str());
}
inline int stoi( const std::string& str, std::size_t* pos = 0, int base = 10) {
char * p_end;