diff --git a/cpp/examples/README.md b/cpp/examples/README.md index 30b291d38f4..b2e8dd399d0 100644 --- a/cpp/examples/README.md +++ b/cpp/examples/README.md @@ -5,4 +5,5 @@ libcudf examples. Current examples: -- Basic: example that demonstrates basic use case with libcudf and building a custom application with libcudf. +- Basic: demonstrates a basic use case with libcudf and building a custom application with libcudf +- Strings: demonstrates using libcudf for accessing and creating strings columns and for building custom kernels for strings diff --git a/cpp/examples/basic/README.md b/cpp/examples/basic/README.md index 75f16e54033..471dcf6694f 100644 --- a/cpp/examples/basic/README.md +++ b/cpp/examples/basic/README.md @@ -15,7 +15,7 @@ cmake -S . -B build/ # Build cmake --build build/ --parallel $PARALLEL_LEVEL # Execute -build/libcudf_example +build/basic_example ``` If your machine does not come with a pre-built libcudf binary, expect the diff --git a/cpp/examples/basic/src/process_csv.cpp b/cpp/examples/basic/src/process_csv.cpp index 5a3914da453..edd14d9ee5f 100644 --- a/cpp/examples/basic/src/process_csv.cpp +++ b/cpp/examples/basic/src/process_csv.cpp @@ -19,6 +19,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -72,6 +76,21 @@ std::unique_ptr average_closing_price(cudf::table_view stock_info_t int main(int argc, char** argv) { + // Construct a CUDA memory resource using RAPIDS Memory Manager (RMM) + // This is the default memory resource for libcudf for allocating device memory. + rmm::mr::cuda_memory_resource cuda_mr{}; + // Construct a memory pool using the CUDA memory resource + // Using a memory pool for device memory allocations is important for good performance in libcudf. + // The pool defaults to allocating half of the available GPU memory. + rmm::mr::pool_memory_resource mr{&cuda_mr}; + + // Set the pool resource to be used by default for all device memory allocations + // Note: It is the user's responsibility to ensure the `mr` object stays alive for the duration of + // it being set as the default + // Also, call this before the first libcudf API call to ensure all data is allocated by the same + // memory resource. + rmm::mr::set_current_device_resource(&mr); + // Read data auto stock_table_with_metadata = read_csv("4stock_5day.csv"); diff --git a/cpp/examples/strings/README.md b/cpp/examples/strings/README.md new file mode 100644 index 00000000000..241aa064bcc --- /dev/null +++ b/cpp/examples/strings/README.md @@ -0,0 +1,37 @@ +# libcudf C++ examples using strings columns + +This C++ example demonstrates using libcudf APIs to access and create +strings columns. + +The example source code loads a csv file and produces a redacted strings +column from the names column using the values from the visibilities column. + +Four examples are included: +1. Using libcudf APIs to build the output +2. Using a simple custom kernel with dynamic memory +3. Using a custom kernel with pre-allocated device memory +4. Using a two-pass approach to improve performance + +These examples are described in more detail in +https://developer.nvidia.com/blog/mastering-string-transformations-in-rapids-libcudf/ + +## Compile and execute + +```bash +# Configure project +cmake -S . -B build/ +# Build +cmake --build build/ --parallel $PARALLEL_LEVEL +# Execute +build/libcudf_apis names.csv +--OR-- +build/custom_with_malloc names.csv +--OR-- +build/custom_prealloc names.csv +--OR-- +build/custom_optimized names.csv +``` + +If your machine does not come with a pre-built libcudf binary, expect the +first build to take some time, as it would build libcudf on the host machine. +It may be sped up by configuring the proper `PARALLEL_LEVEL` number.