Skip to content

aabhinavg1/OpenCLModular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCLModular

A modular, portable OpenCL C++ project supporting Linux, macOS, Windows, and Android. It features runtime-loadable OpenCL kernels, clean host/kernel separation, and optional auto-download of OpenCL headers.


📁 Directory Layout

.
├── CMakeLists.txt               # Project build script
├── toolchain\_android.cmake     # Android toolchain file
├── include/                    # Project headers
├── src/                        # Host C++ code (main.cpp, platform\_model.cpp, etc.)
├── kernels/                    # OpenCL .cl kernels
├── opencl\_headers/             # OpenCL headers (auto-cloned if missing)
├── libs/                       # Android native libs (contains libOpenCL.so)
├── build/                      # Build output

✨ Features

  • Cross-platform OpenCL C++ host code
  • Modular, CMake-based build system
  • Auto-cloning of Khronos OpenCL-Headers (optional)
  • Android NDK toolchain support
  • Platform-aware messages and diagnostics

🧰 Requirements

  • CMake ≥ 3.10
  • Git (only if using auto-clone)
  • OpenCL SDK / runtime (platform-dependent)
  • Android only:
    • Android NDK
    • libOpenCL.so pulled from device if not locally present

🛠️ Build Instructions

🖥️ Linux / macOS / Windows

mkdir build
cd build
cmake .. -DDEBUG=ON
make

macOS uses -framework OpenCL, Linux/Windows use -lOpenCL.


🤖 Android (NDK)

mkdir -p build/android
cd build/android
cmake ../.. \
  -DCMAKE_TOOLCHAIN_FILE=../../toolchain_android.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-24 \
  -DENABLE_AUTO_CLONE_OPENCL_HEADERS=ON \
  -DDEBUG=ON
make

⚠️ Make sure libs/arm64-v8a/libOpenCL.so exists. If not, pull it from a connected Android device using:

adb pull /data/local/tmp/libOpenCL.so libs/arm64-v8a/libOpenCL.so

▶️ Usage

./opencl_app kernels/vector_add.cl

This executes a vector addition example where:

  • A = [2, 2, ..., 2]
  • B = [3, 3, ..., 3]
  • C = A + B

Example Output

[INFO] Input vector A: 2 2 2 2 2 2 2 2 2 2
[INFO] Input vector B: 3 3 3 3 3 3 3 3 3 3
[INFO] Reading back results from device...
[RESULT] C = 5 5 5 5 5 5 5 5 5 5
[INFO] Cleaning up OpenCL resources...
[INFO] Execution complete.

⚙️ Configuration Options

Option Description
-DOPENCL_HEADERS_DIR=/path Set path to OpenCL headers (should contain CL/cl.h)
-DENABLE_AUTO_CLONE_OPENCL_HEADERS=ON Clone OpenCL-Headers from Khronos if not present
-DDEBUG=ON Enable debug messages in both CMake and C++ runtime

🐛 Troubleshooting

  • Missing OpenCL headers

    • Set -DOPENCL_HEADERS_DIR=/your/path
    • Or use -DENABLE_AUTO_CLONE_OPENCL_HEADERS=ON
  • Missing libOpenCL.so on Android

    • Pull from a real Android device:

      adb pull /data/local/tmp/libOpenCL.so libs/arm64-v8a/libOpenCL.so
    • Ensure your Android device is connected and USB debugging is enabled.

  • OpenCL runtime not found

    • On Linux, ensure libOpenCL.so is available via driver or SDK.
    • On macOS, no extra install is needed (uses system framework).

📄 License

Licensed under the MIT License. See the LICENSE file.


---

Would you like me to also generate a `README.android.md` or embed commands for auto-checking `.so` availability with fallback in the script?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors