Skip to content

rayglover-ibm/cuda-bindings

Repository files navigation

CUDA language bindings – Minimum working examples

This is the accompanying code for the tutorial CUDA language bindings – with modern C++ (available here.) This repository contains everything you need to follow that tutorial, and serves as a reference for your own projects.

Example Bindings

Linux
Build Status
Mac
Build Status
Windows
Build status
Android
 
Python 3 3 3
Node.js (v8) 4/5 4/5 4/5
Java 1.7 1.7 1.7

Build

Requirements: you'll need CMake 3.5. If you want to build for Android (see below) 3.7 is required. Refer to the tutorial for concrete examples.

mkdir build && cd build
cmake [-G <generator>] <cmake-options> ..
cmake --build . [--config Debug]
  • CMake options

    CMake option Description Default
    kernelpp_WITH_CUDA Enable cuda support OFF
    mwe_WITH_TESTS Enable unit tests ON
    mwe_WITH_PYTHON Enable python binding OFF
    mwe_WITH_NODEJS Enable nodejs binding OFF
    mwe_WITH_JAVA Enable java binding OFF
  • Compilers / Runtimes

    (Minimum tested versions)

    Windows Linux (Ubuntu 15/16) Android Mac
    C++ compiler VS 2015 gcc 5.3 / clang 3.6 NDK r13 (clang) XCode 7
    CUDA SDK 8 8 8

Build & Test for Android

As of version 3.7 of CMake, it's possible to cross-compile for Android out-of-the-box. Here I assume you've installed Android Studio, or at a minimum, the Android command-line tools. I also assume you've installed the NDK.

  1. Install the Ninja build system. We'll use Ninja in place of Visual Studio because VS doesn't support the various NDK toolchains.

  2. From the mwe repository root:

    $ mkdir build-android && cd build-android
    $ cmake -G "Ninja"                      \
        -DCMAKE_SYSTEM_NAME=Android         \
        -DCMAKE_SYSTEM_VERSION=24           \
        -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
        -DCMAKE_ANDROID_ARCH_ABI=x86        \
        -DCMAKE_ANDROID_NDK="<path to ndk>" \
        -DCMAKE_ANDROID_STL_TYPE=c++_static \
        -DCMAKE_BUILD_TYPE=Debug ..

    The documentation for the various options is vailable here. Next, we build in the usual way:

    cmake --build . --config Debug
  3. Launch your virtual device. In Android studio, you can use the AVD Manager. You should make sure the CMAKE_ANDROID_ARCH_ABI and CMAKE_SYSTEM_VERSION you gave above reflects the Android device you're testing on.

  4. With the Android Debug Bridge (adb) tool (usually located in the platform-tools directory) upload the unit-test binary to the device, make it executable, and run:

    adb push mwe_test /data/local/tmp/mwe_test
    adb shell
    chmod 755 /data/local/tmp/mwe_test
    /data/local/tmp/mwe_test
    

License

Copyright 2017 International Business Machines Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.