Added compilation example

main
Kenneth Jao 2 years ago
parent 2b6753cc7c
commit 2a920ca7ba
  1. 53
      docs/source/usage.rst

@ -244,3 +244,56 @@ BLAS Examples
Compilation and Linking
=======================
To compile with this library, there are only a few things necessary.
First, it is recommended you use the provided template ``Makefile``, which can be
easily modified to suit your project needs. It already default handles the compilation
and linking with ``nvcc``, so long as you fulfill a few requirements.
#. Use the compiler flag ``CUDA`` to mark where GPU-specific code is, if necessary.
#. Any files that use ``CUDA`` functionality, (i.e defining a kernel), should have the file
extension ``.cu.cpp``.
#. When including the ``Core.h`` header file, in only **one** file, you must define the
macro ``CUDATOOLS_IMPLEMENTATION``. That file must also compile for CUDA, so its
extension must be ``.cu.cpp``. It's recommended to put this with your kernel definitions.
Afterwards the ``Makefile`` will have two targets ``cpu`` and ``gpu``, which compile
the CPU and GPU compatible binaries respectively. As an example, we can look at the whole
file for the first example:
.. code-block:: cpp
// main.cu.cpp
#define CUDATOOLS_IMPLEMENTATION
#include <Core.h>
DEFINE_KERNEL(add, int x, int y) {
printf("Kernel: %i\n", x + y);
}
int main() {
KERNEL(add, CudaTools::Kernel::basic(1), 1, 1); // Prints 2.
return 0;
}
.. code-block::
// Makefile
CC := g++-10
NVCC := nvcc
CFLAGS := -Wall -std=c++17 -fopenmp -MMD
NVCC_FLAGS := -MMD -w -Xcompiler
INCLUDE := ../../
LIBS_DIR :=
LIBS_DIR_GPU := /usr/local/cuda/lib64
LIBS :=
LIBS_GPU := cuda cudart cublas
TARGET = coreKernel
SRC_DIR = .
BUILD_DIR = build
The lines above are the first few lines of the ``Makefile``, which are the only
lines you should need to modify, consisting of libraries and flags, as well as
the name of the target.

Loading…
Cancel
Save