Skip to content
Snippets Groups Projects
Commit 0079eb58 authored by Sandipan Mohanty's avatar Sandipan Mohanty
Browse files

Fix CMake for TSP-stdpar example

TSP-stdpar can be built using g++ or clang
for the CPU and using nvc++ for the GPU.
The CMake file now has the necessary code.
There is a README file explaining the compilation
process as well.
parent 4be1c909
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_COMPILER nvc++)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdpar")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(TSP-stdpar CXX) project(TSP-stdpar CXX)
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdpar")
endif()
include(cmake/CPM.cmake) include(cmake/CPM.cmake)
CPMAddPackage("gh:bfgroup/Lyra#1.6.1") CPMAddPackage("gh:bfgroup/Lyra#1.6.1")
add_executable(tsp TSP.cc) add_executable(tsp TSP.cc)
target_link_libraries(tsp PRIVATE bfg::lyra) target_link_libraries(tsp PRIVATE bfg::lyra)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
find_package(TBB REQUIRED)
target_link_libraries(tsp PRIVATE TBB::tbb TBB::tbbmalloc)
endif()
TSP example for the GPU with -stdpar
====================================
This example is meant to demonstrate solving
problems using standard library algorithms on
a GPU. This is NOT a CUDA program, but just
a regular C++ code, which can be built using
g++ or clang++ for the CPU. You can see that
by bulding it like this (for CPU):
mkdir build_cpu
cd build_cpu
CXX=g++ cmake -DCMAKE_BUILD_TYPE=Release ..
make
./tsp -r -n 13
Without changing any code, you should also be
able to build the same program for the GPU.
First make sure that the NVidia NVHPC tool kit
is in the relevant PATH variables. This is not
the regular CUDA compiler, nvcc, but instead
the nvc++ compiler. In many supercomputing
centres, that compiler is added to the PATH
when you load a module, usually having NVHPC
in its name. Here is how you build for the GPU:
ml NVHPC CMake
mkdir build_gpu
cd build_gpu
CXX=nvc++ cmake -DCMAKE_CXX_FLAGS="-gpu=cc70" -DCMAKE_BUILD_TYPE=Release ..
make
./tsp -r -n 15
Note 1: We need a GPU with a compute capability of
at least 70 for std::execution::par to be converted
into GPU code. That's why the -gpu=cc70 option.
Without that, the compilation goes through very quickly,
but it is only being built for serial CPU execution.
Note 2: When building for more recent GPUs, automatic
GPU code generation does take place. But, as of version
12 of the nvc++ compiler, linking fails with a message
nvlink: Undefined reference to '__blt_pgi_clzl'
If you successfully build and run this on a GPU, with
-gpu=cc70 or higher, I would like to hear about what
you did to fix it!
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment