Home

Awesome

cuCollections

Table of Content

Building cuCollections

Building cuCollections is very straightforward. If your system doesn't have CUDA Toolkit, please install it. The latest version of CUDA toolkit can be found here. Subsequently, please perform the following steps to build the project.

Prerequisite: Make sure CUDA Toolkit is installed on your system.

export CUDACXX=/path/to/nvcc
cuCollectionsPath=$(pwd)/cuCollections
git clone --recurse-submodules  https://github.com/rapidsai/cuCollections.git $cuCollectionsPath
cd $cuCollectionsPath
git submodule update --init --recursive
mkdir build && cd build
cmake ..
make -j$(nproc)
make test # optional

Quick Start

Building the project as instructed, will build the examples under build/examples path. Examples are designed to be simple and standalone. In what follows, the most basic map operations (i.e., insertion and find) is detailed. The corresponding program can be found in $cuCollectionsPath/examples/map/insert_find.cu.

int main() {
  // Synthesizing dummy data to put in hashmap
  std::vector<int> keys(N);
  std::vector<double> vals(N);
  for (unsigned int i = 0; i < N; i++) {
    keys[i] = i;
    vals[i] = i * 0.5;
  }

  cuCollections::unordered_map<int, double> map(N);
  map.insert(keys, vals);
  auto results = map.find(keys);

  for (unsigned int i = 0; i < results.size(); i++) {
    std::cout << keys[i] << ": " << results[i] << std::endl;
  }
}

Using a GPU-based map can be very beneficial when the workload includes some parallelism. As a result, cuCollections::unordered_map will accept, vectors of keys and values and insert them concurrently. This code snippet synthesizes dummy vectors for keys and values, then it inserts them in a cuCollections::unordered_map. Subsequently, it queries the map and prints the results which are returned in a vector called results. You may refer to the examples directory for more usage instances.

Integration

cuCollections is designed to be added to projects as a submodule. In such settings, examples and benchmarks will not be build. As instructed in what follows, it is straightforward to integrate cuCollections in an existing project.

mkdir thirdparty && cd thirdparty
git submodule add https://github.com/rapidsai/cuCollections.git cuCollections
git submodule update --init --recursive

References

cuCollections was initially copied from CUDF repository of RAPIDS (Commit: 5cde46d). The main goal of creating this copy is to develop a lightweight repository that is quick and easy to integrate to any CUDA/C++ project.